This commit is contained in:
zengming 2019-03-21 13:34:44 +08:00
parent 6ebbfbad7d
commit de08533a79
37 changed files with 1519 additions and 0 deletions

Binary file not shown.

Binary file not shown.

BIN
ARM汇编.pdf Normal file

Binary file not shown.

BIN
C语言程序设计.pdf Normal file

Binary file not shown.

BIN
IRAM_STEP_3.rar Normal file

Binary file not shown.

BIN
IRAM_STEP_4.rar Normal file

Binary file not shown.

BIN
IRAM_STEP_5_Doc.rar Normal file

Binary file not shown.

BIN
J2ME&GAME.pdf Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,152 @@
EXT结构详解
前8字节
0~3mr_table 函数表 指针
4~7mr_c_function_st 指针
8~11mr_c_function_load 函数指针
typedef struct _mrc_extChunk_st
{
int32 check;
MR_LOAD_C_FUNCTION init_func; //mr_c_function_load 函数指针
/**
* (void* P, int32 code, uint8* input, int32 input_len, uint8** output, int32* output_len);
* 参数详解:
* pglobal_p_buf 指针
* code定义如下
* 0mrc_init 1mrc_event 2
*/
MR_C_FUNCTION event; //mr_helper 函数指针
uint8* code_buf; //ext内存地址
int32 code_len; //ext长度
uint8* var_buf; //RW段地址
int32 var_len; //RW段长度
mr_c_function_st* global_p_buf; //mr_c_function_st 表地址
int32 global_p_len; //mr_c_function_st 表长度
int32 timer;
mrc_extMainSendAppMsg_t sendAppEvent;
mr_table *extMrTable;
#ifdef MRC_PLUGIN
MR_C_FUNCTION_EX eventEx;
#endif
int32 isPause;/*1: pause 状态0:正常状态*/
} mrc_extChunk_st;
typedef struct _mr_c_function_st
{
uint8* start_of_ER_RW;
uint32 ER_RW_Length;
//uint8* old_start_of_ER_RW;
int32 ext_type;
mrc_extChunk_st * mrc_extChunk;
//stack shell 2008-2-28
int32 stack;
//
} mr_c_function_st;
启动流程:
先调用int32 mr_c_function_load (int32 code),完成 mr_table 函数表设置
时空:
[基址]-4位置是 mr_c_function_st指针。
[基址]-8位置是函数表指针。
mr_c_function_load调用了函数表里偏移为0x64的mr_c_function_new函数这个mr_c_function_new函数就在这里面。
EXT的RW段即EXT全局变量空间EXT内部自己会管理
BinSys
# /* ---- SKY_PLATFORM start ---- */
ifeq ($(strip $(DSM_SUPPORT)),TRUE)
# sky add ,compile switch macro
COM_DEFS += __MMI_DSM_NEW__
ifeq ($(strip $(PLATFORM)),MT6235B)
COMPOBJS += plutommi\mmi\mythroad\mythroadlib\dsm35.lib
endif
ifneq ($(strip $(PLATFORM)),MT6235B)
COMPOBJS += plutommi\mmi\mythroad\mythroadlib\dsm.lib
endif
COMPOBJS += plutommi\mmi\mythroad\mythroadlib\mmidsm111.lib
主要是 dsm.lib 和 mmidsm111.lib
你可以看看目前能拿到的移植层的代码看dsm.lib里的mythroad.obj
天使:
因为所有的API接口 都在函数表
我们写好接口 填到函数表
我看来 目前最主要的工作就是 函数表里所有函数
这个我们可以一起来写
封装NDK底层函数
然后 难点在于 加载EXT之前要做什么调用mrc_init前做了什么怎么调mrc_init
mr_c_function_load 函数地址为ext内存地址 + 8所以其在ext内部位置固定
eleqian
嗯,一般的像图像字符绘制比较容易实现
对话:
我现在最大的疑惑就是 mrc_init mrc_event mrc_pause 等函数 是不是在 ext文件中位置固定的额
无尽时空<timespace_2011@qq.com> 23:35:01
不是
eleqian(1003082820) 23:35:20
ext入口不是它们
天使之翼<edroid@foxmail.com> 23:35:44
那怎么找到 mrc_init 调用它
无尽时空<timespace_2011@qq.com> 23:35:48
它们都被mr_helper调用mr_helper 才是最重要的消息分发器。
eleqian(1003082820) 23:35:51
它们只是普通函数
天使之翼<edroid@foxmail.com> 1:22:58
mr_table 函数表内部函数地址设置是在MTK开机时完成的你改变了这个表里的某个函数地址后下次开机才会恢复
BinSys(123077083) 1:23:03
mr_c_function_load 确实是固定的因为一个elf文件经过fromelf后貌似只剩下代码段并且entry在0字节处。至于为什么偏移了8就不知道了
天使之翼<edroid@foxmail.com> 1:24:09
因为 前面 8个字节 分别用来存储 mr_table 和 mr_c_function_st 函数表地址
first和entry都指定为 mr_c_function_load另外不是armcc指定的是armlink的参数
armlink
输入
-rwpi
-ro
-base0x80000
-remove
-first mr_c_function_load
-entry mr_c_function_load
-o
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\mr_cfunction.fmt
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\mr_sfw_mrc_mrc_win.o
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\mr_src_helloworld.o
C:\SKYMOBI\SDS4CPv1.0\Compiler\mr_helper.lib(mr_helper.o)
C:\SKYMOBI\SDS4CPv1.0\Compiler\mr_helper.lib(mr_helper_s.o)
C:\SKYMOBI\SDS4CPv1.0\Compiler\mr_helperexf.lib
C:\SKYMOBI\SDS4CPv1.0\Compiler\mr_helperexb.lib
不同点:
ext启动
在mr_table里设置ext定时器启动和停止的函数设置ext启动标志。
普通启动:
在mr_internal_table设置字符串"dealtimer"
其他都相同。
普通启动调用的定时器函数在start.mr里设置dealtimer
dealtimer 本身是个函数在start.mr里定义
*(mr_c_function_load - 0x4) + 0xC 处是ext模块句柄
不分析不知道,一分析吓一跳。

Binary file not shown.

BIN
Mythroad API V1.05.chm Normal file

Binary file not shown.

BIN
MythroadSDK.exe Normal file

Binary file not shown.

View File

@ -1,2 +1,18 @@
# mrpdev # mrpdev
老硬盘里翻出来的代码斯凯mrp的开发文档、SDK、相关资料等 老硬盘里翻出来的代码斯凯mrp的开发文档、SDK、相关资料等
# 冒泡开放平台功能机业务停止运营
因冒泡开放平台团队业务调整2013年8月1日起冒泡开放平台功能机业务将停止新应用的审核
2013年10月1日平台将正式停止运营。并于2013年10月30日前完成收益结算此次调整仅针对冒泡开放平台业务不涉及任何斯凯其他功能机业务。给您造成的困扰万分抱歉。冒泡开放平台智能机业务继续运营感谢您对冒泡开放平台业务的支持祝您生活愉快。
# other
很遗憾mrp时代结束这么多年后才终于将这些资料公开可能我是最后一个保留了完整的开发技术的人留着将来考古用
幸运的是我们在安卓手机上有了mrp模拟器以及与mrp开发极其相似的mpc
这里面有基础的API和当时未开放的高级API接口文档以及当时比较高级的自定义字库、扩展内存等技术的资料
青春如同奔流的江河,一去不回来不及道别

Binary file not shown.

Binary file not shown.

BIN
SKYENGINE API.chm Normal file

Binary file not shown.

BIN
Sky_SDK_API_0.1.3.chm Normal file

Binary file not shown.

BIN
VS2005.pdf Normal file

Binary file not shown.

Binary file not shown.

BIN
e_mrp.exe Normal file

Binary file not shown.

BIN
gzip.exe Normal file

Binary file not shown.

BIN
mrc_base_i.7z Normal file

Binary file not shown.

742
mrc_network_http.c Normal file
View File

@ -0,0 +1,742 @@
#include "mrc_base.h"
#include "mrc_network.h"
#include "mrc_network_http.h"
#include "stdarg.h"//for va_list
typedef DWORD HBLOCKHEAP;
#ifndef MAX_HOSTNAME_LEN
#define MAX_HOSTNAME_LEN 112
#endif
#define HTTP_RESPONSECODE_OFFSET 9
static const char sHttpMethods[][5] =
{
"GET",
"HEAD",
"POST"
};
typedef struct HttpRequest_T
{
HTTPMETHOD method;
struct HttpRequest_T* next;
}HTTPREQUEST, *PHTTPREQUEST;
typedef struct HttpData
{
//http event handler
FN_SOCKEVENT fnEvent;
//available when header responsed
uint32 responsecode;
int32 contentLength;
//cache the http header
uint32 hdrsize;
char header[HTTP_HEADER_SIZE];
//http request list on this connection
PHTTPREQUEST requests_head;
PHTTPREQUEST requests_tail;
}HTTPDATA, *PHTTPDATA;
static HTTPDATA sHttpDataPool[SOCKET_MAX_COUNT];
static HBLOCKHEAP sHttpDataHeap;
HBLOCKHEAP BlockHeap_Initialize(VOID* buffer, int buffersize, int blocksize);
VOID BlockHeap_Free(HBLOCKHEAP* pHeap, VOID* pBlock);
VOID* BlockHeap_Alloc(HBLOCKHEAP* pHeap);
static int mrc_i_isNum(uint8 code);
static int mrc_i_isNumText(char * code);
static uint32 inet_addr(const char* cp);
static char* tolower(char* str);
static PCSTR host(PCSTR url, uint16* port, uint16 def);
static uint16 get_port(PCSTR url);
static char* tolower(char* str)
{
int i = 0;
for(; str[i]; i++)
{
if(str[i] >= 'A' && str[i] <= 'Z')
str[i] += 'a' - 'A';
}
return str;
}
static PCSTR host(PCSTR url, uint16* port, uint16 def)
{
static char host[MAX_HOSTNAME_LEN];
int i, j;
if(port) *port = def;
for(i = j = 0; url[i]; i++)
{
if(url[i] == ':' && url[i+1] == '/' && url[i+2] == '/')
{
i+=3;
while(url[i] && url[i]!=':' && url[i]!='/')
{
host[j++] = url[i++];
}
if(port && url[i] == ':')
{
*port = atoi(url+i+1);
}
break;
}
}
host[j] = 0;
return host;
}
static uint16 get_port(PCSTR url)
{
uint16 port = 0;
char* p = NULL;
if( NULL == url )
{
return 80;
}
p = mrc_strstr(url,"://");
if( p )
{
p += 3;
}
else
{
p = (char*)url;
}
p = mrc_strstr(p,":");
if( p )
{
port = atoi(p+1);
}
else
{
port = 80;
}
if( port == 0 )
{
port = 80;
}
return port;
}
static int mrc_i_isNum(uint8 code)
{
if ((code>47 && code<58) || (code=='.') || (code==':') )
{
return 1;
}
return 0;
}
static int mrc_i_isNumText(char * code)
{
char * tempCode = code;
while(*tempCode)
{
if( mrc_i_isNum(*tempCode) ==0 )
{
return 0;
}
tempCode++;
}
return 1;
}
static uint32 inet_addr(const char* cp)
{
uint32 ip = 0;
int i;
char ipstr[100];
mrc_memset(ipstr, 0, 100);
for(i = 0; i < 4; i++)
{
ip <<= 8;
ip |= atoi(cp);
if(i < 3 && (NULL == (cp = mrc_strchr(cp, '.'))))
return 0;
cp++;
}
return ip;
}
#ifdef HTTP_HEAD_METHOD_ENABLE
static BOOL mrc_Http_Request_Add(PHTTPDATA pHttpData, HTTPMETHOD method)
{
PHTTPREQUEST request;
//append to the request list, must not failed
if( NULL == (request = (PHTTPREQUEST)malloc(sizeof(HTTPREQUEST))))
{
return FALSE;
}
//add to the request list
request->method = method;
request->next = NULL;
if(pHttpData->requests_head == NULL)
pHttpData->requests_head = request;
else
pHttpData->requests_tail->next = request;
pHttpData->requests_tail = request;
return TRUE;
}
static void mrc_Http_Request_Clear(PHTTPDATA pHttpData)
{
PHTTPREQUEST request;
while(pHttpData->requests_head)
{
request = pHttpData->requests_head;
pHttpData->requests_head = request->next;
free(request);
}
}
static void mrc_Http_Request_Pop(PHTTPDATA pHttpData)
{
PHTTPREQUEST request = pHttpData->requests_head;
if(request)
{
pHttpData->requests_head = request->next;
if(pHttpData->requests_head == NULL)
pHttpData->requests_tail = NULL;
free(request);
}
}
#endif
#define FIND_HTTP_HEADER_ENDING(pHttpData) \
(pHttpData->hdrsize >= 4 \
&& pHttpData->header[pHttpData->hdrsize - 4] == '\r' \
&& pHttpData->header[pHttpData->hdrsize - 3] == '\n' \
&& pHttpData->header[pHttpData->hdrsize - 2] == '\r' \
&& pHttpData->header[pHttpData->hdrsize -1] == '\n')
#define RESET_HTTP_RESPONSE_INFO(pHttpData) \
pHttpData->contentLength = 0; \
pHttpData->hdrsize = 0; \
pHttpData->responsecode = 0
#ifdef HTTP_HEAD_METHOD_ENABLE
#define HANDLE_RESPONSE_END(socket, pHttpData) \
if(pHttpData->fnEvent(socket, HTTPEVT_RESPONSE_END, NULL)) \
return 1; \
RESET_HTTP_RESPONSE_INFO(pHttpData); \
Http_Request_Pop(pHttpData)
#else
#define HANDLE_RESPONSE_END(socket, pHttpData) \
if(pHttpData->fnEvent(socket, HTTPEVT_RESPONSE_END, NULL)) \
return 1; \
RESET_HTTP_RESPONSE_INFO(pHttpData)
#endif
static DWORD mrc_Http_HandleResponseData(PSOCKET socket, PSOCKEVTDATA data)
{
int32 i;
PCSTR len;
PHTTPDATA pHttpData = (PHTTPDATA)socket->userdata;
if(pHttpData->responsecode == 0)
{
//receive the http header
for(i = 0; i < data->size; i++)
{
//check the http header buffer, when this happen user should adjust the value of HTTP_HEADER_SIZE
//todo
if(pHttpData->hdrsize >= HTTP_HEADER_SIZE)
{
mrc_Http_Close(socket, HTTPEVT_ERROR);
return 1;
}
//copy the byte and continue when not found the http header ending
pHttpData->header[pHttpData->hdrsize++] = data->buffer[i];
if(!FIND_HTTP_HEADER_ENDING(pHttpData))
continue;
//find the header
pHttpData->header[pHttpData->hdrsize] = 0;
//SGL_LOG("header.txt", pHttpData->header, pHttpData->hdrsize);
tolower(pHttpData->header);
//maybe socket been closed, user do not want to deal the data left
//Note:changed by huangsunbo 2008-10-20,respond head data
//todo
if(pHttpData->fnEvent(socket, HTTPEVT_RESPONSE_HEADER, data))
return 1;
#ifdef HTTP_HEAD_METHOD_ENABLE
if(pHttpData->requests_head->method == HEAD)
{
HANDLE_RESPONSE_END(socket, pHttpData);
}else{
#endif
if(NULL == (len = mrc_Http_GetResponseField(socket, HTTP_FIELD_CONTENTLENGTH)) )
{
//can not support the response do not have the field "Content-Length"
mrc_Http_Close(socket, HTTPEVT_ERROR);
return 1;
}
pHttpData->contentLength = atoi(len);
pHttpData->responsecode = mrc_Http_GetResponseCode(socket);
if(pHttpData->contentLength == 0)
{
HANDLE_RESPONSE_END(socket, pHttpData);
}
#ifdef HTTP_HEAD_METHOD_ENABLE
}
#endif
i++; //i is the bytes has been copyed, so should add 1
break;
}
data->buffer += i;
data->size -= i;
}
if(data->size > 0)
{
int32 notifybytes = MIN(pHttpData->contentLength, data->size);
int32 remainbytes = data->size - pHttpData->contentLength;
data->size = notifybytes;
//maybe socket been closed, user do not want to deal the data left
if(pHttpData->fnEvent(socket, HTTPEVT_RESPONSE_DATA, data))
return 1;
pHttpData->contentLength -= notifybytes;
data->size -= notifybytes;
data->buffer += notifybytes;
data->size = remainbytes;
if(pHttpData->contentLength == 0)
{
HANDLE_RESPONSE_END(socket, pHttpData);
}
if(data->size > 0)
return mrc_Http_HandleResponseData(socket, data);
}
return 0;
}
static void mrc_Http_Destroy(PSOCKET socket)
{
PHTTPDATA pHttpData = (PHTTPDATA)socket->userdata;
#ifdef HTTP_HEAD_METHOD_ENABLE
Http_Request_Clear(pHttpData);
#endif
BlockHeap_Free(&sHttpDataHeap, pHttpData);
}
static DWORD mrc_Http_HandleSocketEvents(PSOCKET socket, DWORD evt, PSOCKEVTDATA data)
{
PHTTPDATA pHttpData = (PHTTPDATA)socket->userdata;
FN_SOCKEVENT fnEvent = pHttpData->fnEvent;
switch(evt)
{
case SOCKEVT_CONNECTED:
{
return fnEvent(socket, evt, data);
}
case SOCKEVT_RECVDATA:
{
/*
* HTTPEVT_RESPONSE_HEADER sent to the user after get the http response header
* HTTPEVT_RESPONSE_DATA sent to the user when receive the http data,
* HTTPEVT_RESPONSE_END sent to the user when request finished
*/
return mrc_Http_HandleResponseData(socket, data);
}
case SOCKEVT_CONNECTFAILED:
case SOCKEVT_ERROR:
case SOCKEVT_CLOSED:
{
mrc_Http_Destroy(socket);
return fnEvent(socket, evt, data);
}
}
return 0;
}
void mrc_Http_Initialize(void)
{
sHttpDataHeap = BlockHeap_Initialize(sHttpDataPool, sizeof(sHttpDataPool), sizeof(HTTPDATA));
}
void mrc_Http_Terminate(void)
{
//DO NOTHING
}
/*
2010-03-30
*/
PSOCKET mrc_Http_OpenEx(char*ip_string,uint16 port,FN_SOCKEVENT fnEvent)
{
PHTTPDATA pHttpData;
PSOCKET socket;
if(!ip_string)
{
return NULL;
}
if( NULL == (pHttpData = BlockHeap_Alloc(&sHttpDataHeap)))
{
return NULL;
}
pHttpData->fnEvent = fnEvent;
pHttpData->contentLength = 0;
pHttpData->responsecode = 0;
pHttpData->hdrsize = 0;
#ifdef HTTP_HEAD_METHOD_ENABLE
pHttpData->requests_head = NULL;
pHttpData->requests_tail = NULL;
#endif
if(NULL == (socket = mrc_Socket_Create(SOCKPROTO_TCP,
mrc_Http_HandleSocketEvents, (DWORD)pHttpData)))
{
BlockHeap_Free(&sHttpDataHeap, pHttpData);
return NULL;
}
if(mrc_Socket_ConnectNoProxy(socket, ip_string,port,1))
{
return socket;
}
else
{
mrc_Socket_Close(socket,SOCKEVT_CLOSED);
BlockHeap_Free(&sHttpDataHeap, pHttpData);
return NULL;
}
}
BOOL mrc_Http_Close(PSOCKET socket, DWORD evt)
{
return mrc_Socket_Close(socket, evt);
}
PCSTR mrc_Http_FormatHeader(uint32* size, HTTPMETHOD method, PCSTR url,...)
{
static char header[HTTP_HEADER_SIZE];
uint32 hdrsize;
PCSTR field, value;
va_list args;
va_start(args, url);
//format the request header line
sprintf(header, HTTP_HEADER_FORMAT, sHttpMethods[method], url);
hdrsize = strlen(header);
//parse other fields and values
while(NULL != (field = va_arg(args, PCSTR)))
{
//field name
strcpy(header + hdrsize, field);
hdrsize += strlen(field);
header[hdrsize++] = ':';
header[hdrsize++] = ' ';//add space by huangsunbo
//field value
value = va_arg(args, PCSTR);
strcpy(header + hdrsize, value);
hdrsize += strlen(value);
//field ending
header[hdrsize++] = '\r';
header[hdrsize++] = '\n';
}
//append the http header ending
header[hdrsize++] = '\r';
header[hdrsize++] = '\n';
va_end(args);
*size = hdrsize;
return header;
}
BOOL mrc_Http_Send(PSOCKET socket, HTTPMETHOD method, PBYTE buffer, uint32 size)
{
#ifdef HTTP_HEAD_METHOD_ENABLE
PHTTPDATA pHttpData = (PHTTPDATA)socket->userdata;
#endif
if(!mrc_Socket_Send(socket, buffer, size))
return FALSE;
#ifdef HTTP_HEAD_METHOD_ENABLE
//append to the request list, must not failed
if(!mrc_Http_Request_Add(pHttpData, method))
{
mrc_Http_Close(socket, HTTPEVT_ERROR);
return FALSE;
}
#endif
return TRUE;
}
BOOL mrc_Http_GetEx(PSOCKET socket, PCSTR url, uint32 from, uint32 to)
{
PCSTR pHeader, pHost;
uint32 hdrsize;
uint16 port;
uint8 host_buf[128] = {0};
pHost = host(url,NULL,80);
port = get_port(url);
//网关转发的时候需要主机和端口
/*测试注掉*/
sprintf((char*)host_buf,"%s:%d",pHost,port);
//<1>CP发起的http请求只需要通过sky的proxy服务器进行转发
//因此只需要连接sky的server然后把请求进行转发
//不需要修改url
//<2>当是cmwap拨号方式的时候,由于需要通过cmcc的网关进行转发
//因此需要通过Host中指明的主机和端口来让网关进行转发
if(from > 0)
{
char tmp[24] = {0};
if(to > from)
sprintf(tmp, "bytes=%d-%d", from, to);
else
sprintf(tmp, "bytes=%d-", from);
pHeader = mrc_Http_FormatHeader(&hdrsize, GET, url,
HTTP_FIELD_HOST, host_buf,
HTTP_FIELD_UA, HTTP_VALUE_UA,
HTTP_FIELD_ACCEPT, HTTP_VALUE_ACCEPT,
HTTP_FIELD_CONTENTTYPE, HTTP_VALUE_CONTENTTYPE,
HTTP_FIELD_CONNECTION, HTTP_VALUE_CONNECTION_KEEPALIVE,
HTTP_FIELD_PROXYCONNECTION, HTTP_VALUE_CONNECTION_KEEPALIVE,
HTTP_FIELD_RANGE, tmp,
NULL); //do not forget the NULL ending
}
else
{
/**/
pHeader = mrc_Http_FormatHeader(&hdrsize, GET, url,
HTTP_FIELD_HOST, host_buf,
HTTP_FIELD_UA, HTTP_VALUE_UA,
HTTP_FIELD_ACCEPT, HTTP_VALUE_ACCEPT,
HTTP_FIELD_CONTENTTYPE, HTTP_VALUE_CONTENTTYPE,
HTTP_FIELD_CONNECTION, HTTP_VALUE_CONNECTION_KEEPALIVE,
HTTP_FIELD_PROXYCONNECTION, HTTP_VALUE_CONNECTION_KEEPALIVE,
NULL); //do not forget the NULL ending
}
return mrc_Http_Send(socket, GET, (PBYTE)pHeader, hdrsize);
}
#ifdef HTTP_HEAD_METHOD_ENABLE
BOOL mrc_Http_Head(PSOCKET socket, PCSTR url)
{
PCSTR pHeader, pHost;
uint32 hdrsize;
pHost = host(url, NULL, 0);
pHeader = mrc_Http_FormatHeader(&hdrsize, HEAD, url,
HTTP_FIELD_HOST, pHost,
HTTP_FIELD_UA, HTTP_VALUE_UA,
HTTP_FIELD_ACCEPT, HTTP_VALUE_ACCEPT,
HTTP_FIELD_CONTENTTYPE, HTTP_VALUE_CONTENTTYPE,
HTTP_FIELD_CONNECTION, HTTP_VALUE_CONNECTION_KEEPALIVE,
HTTP_FIELD_PROXYCONNECTION, HTTP_VALUE_CONNECTION_KEEPALIVE,
NULL); //do not forget the NULL ending
return mrc_Http_Send(socket, HEAD, (PBYTE)pHeader, hdrsize);
}
#endif
BOOL mrc_Http_PostEx(PSOCKET socket, PCSTR url, PCSTR buffer, uint32 size)
{
PCSTR pHeader, pHost;
uint32 hdrsize;
char tmp[12]={0};
uint8 host_buf[128] = {0};
uint16 port;
pHost = host(url,NULL,80);
port = get_port(url);
//网关转发的时候需要主机和端口
sprintf((char*)host_buf,"%s:%d",pHost,port);
sprintf(tmp, "%d", size);
pHeader = mrc_Http_FormatHeader(&hdrsize, POST, url,
HTTP_FIELD_HOST, host_buf,
HTTP_FIELD_UA, HTTP_VALUE_UA,
HTTP_FIELD_ACCEPT, HTTP_VALUE_ACCEPT,
HTTP_FIELD_CONTENTTYPE, HTTP_VALUE_CONTENTTYPE,
HTTP_FIELD_CONNECTION, HTTP_VALUE_CONNECTION_KEEPALIVE,
HTTP_FIELD_PROXYCONNECTION, HTTP_VALUE_CONNECTION_KEEPALIVE,
HTTP_FIELD_CONTENTLENGTH, tmp,
NULL); //do not forget the NULL ending
//check that socket have enough buffer
if(socket->begin + SOCKET_SENDBUFFER_SIZE - socket->end < hdrsize + size)
{
return FALSE;
}
//if return false that cause is not about send buffer
if(!mrc_Http_Send(socket, POST, (PBYTE)pHeader, hdrsize))
return FALSE;
//if return false that cause is not about send buffer
if(size > 0 && !mrc_Socket_Send(socket, (PBYTE)buffer, size))
return FALSE;
return TRUE;
}
uint32 mrc_Http_GetResponseCode(PSOCKET socket)
{
PHTTPDATA pHttpData = (PHTTPDATA) socket->userdata;
return atoi(pHttpData->header + HTTP_RESPONSECODE_OFFSET);
}
int mrc_Http_GetResponseHead(PSOCKET socket,uint8** buf, uint32* size)
{
PHTTPDATA pHttpData = NULL;
if( NULL == socket || NULL == buf || size == NULL ||
socket->sd < 0 || socket->protocol != SOCKPROTO_TCP )
{
buf = NULL;
*size = 0;
return MR_FAILED;
}
pHttpData = (PHTTPDATA) socket->userdata;
*buf = (uint8*)pHttpData->header;
*size = pHttpData->hdrsize;
return MR_SUCCESS;
}
PCSTR mrc_Http_GetResponseField(PSOCKET socket, PCSTR field)
{
static char value[HTTP_FIELDVALUE_SIZE];
int32 i = 0;
PCSTR pTmp;
PHTTPDATA pHttpData = (PHTTPDATA)socket->userdata;
strncpy(value, field, HTTP_FIELDVALUE_SIZE-1);
value[HTTP_FIELDVALUE_SIZE-1] = 0;
tolower(value);
if( NULL == (pTmp = mrc_strstr(pHttpData->header, value)))
return NULL;
pTmp += mrc_strlen(field);
while(*pTmp == ' ' || *pTmp == ':')
pTmp++;
while(!(pTmp[i] == '\r' && pTmp[i+1] == '\n'))
{
value[i] = pTmp[i];
i++;
}
value[i] = 0;
return value;
}
HBLOCKHEAP BlockHeap_Initialize(VOID* buffer, int buffersize, int blocksize)
{
PBYTE pBlock = (PBYTE)buffer;
//SGL_ASSERT(0 == MOD(buffersize, blocksize) && 0 == MOD(blocksize, 4));
for(buffersize -= blocksize; pBlock - (PBYTE)buffer < buffersize ; pBlock += blocksize)
*(Uint8**)pBlock = pBlock + blocksize;
*(PBYTE*)pBlock = NULL;
return (HBLOCKHEAP)buffer;
}
VOID* BlockHeap_Alloc(HBLOCKHEAP* pHeap)
{
VOID* pBlock = (VOID*)(*pHeap);
if(pBlock)
*pHeap =(HBLOCKHEAP)( *(PBYTE*)(*pHeap) );
return pBlock;
}
VOID BlockHeap_Free(HBLOCKHEAP* pHeap, VOID* pBlock)
{
*(PBYTE*)pBlock = (PBYTE)(*pHeap);
*pHeap = (HBLOCKHEAP)pBlock;
}

171
mrc_network_http.h Normal file
View File

@ -0,0 +1,171 @@
#ifndef _MRC_NETWORK_HTTP_H_
#define _MRC_NETWORK_HTTP_H_
#include "mrc_base.h"
#include "mrc_network.h"
/*
HTTP协议的网络接口
HTTP是基于socket上的数据包格式重定义HTTP协议及socket开发
freesky.51mrp.com上下载
*/
/**
* \brief max http header size in bytes
*/
#ifndef HTTP_HEADER_SIZE
#define HTTP_HEADER_SIZE 1024
#endif
/**
* \brief max field value length in response header
*/
#ifndef HTTP_FIELDVALUE_SIZE
#define HTTP_FIELDVALUE_SIZE 128
#endif
/**
* \brief supported http method
*/
typedef enum HTTP_METHOD_E
{
GET = 0, //"GET"
HEAD, //"HEAD"
POST//"POST"
}HTTPMETHOD;
/**
* \brief http events
*/
typedef enum HTTP_EVENT_E
{
/** sent when http socket connected */
HTTPEVT_CONNECTED = SOCKEVT_CONNECTED,
/** sent when http socket connect failed */
HTTPEVT_CONNECTFAILED = SOCKEVT_CONNECTFAILED,
/** sent when error happen */
HTTPEVT_ERROR = SOCKEVT_ERROR,
/** sent when socket closed */
HTTPEVT_CLOSED = SOCKEVT_CLOSED,
/** sent when get the http response header */
HTTPEVT_RESPONSE_HEADER,
/** sent when get the http response data */
HTTPEVT_RESPONSE_DATA,
/** sent when one http response finished */
HTTPEVT_RESPONSE_END
}HTTPEVENT;
/**
* :mrc_Http_Initialize
* : HTTP初始化
* :
*/
VOID mrc_Http_Initialize(VOID);
/**
* \brief Terminate the http module.
*
* When the http module is not needed by the application anymore, this function could
* be called to release the http module.
*
* \sa Socket_Initialize
*/
VOID mrc_Http_Terminate(VOID);
/**
* \brief Open a socket for http.
*
* \param ip_string the server ip address or host name,just like 192.168.0.1 or http://www.163.com
* only the authorization user can use this function
* \param port the server port number
* \param fnEvent the http events handler
* \return http socket handle on success, NULL otherwise
*/
PSOCKET mrc_Http_OpenEx(char*ip_string,uint16 port,FN_SOCKEVENT fnEvent);
/**
* \brief Close a http socket .
*
* \param socket the socket handle
* \param evt the close event
* \return TRUE on success, FALSE otherwise
*/
BOOL mrc_Http_Close(PSOCKET socket, DWORD evt);
/**
* \brief Send http get command.
*
* \param socket the http socket handle
* \param url the request url
* \param from the start position of the content
* \param to the end position of the content
* \return TRUE on success, FALSE otherwise
*/
BOOL mrc_Http_GetEx(PSOCKET socket, PCSTR url, uint32 from, uint32 to);
/**
* \brief Post the http data.
*
* \param socket the http socket
* \param url the request url
* \param buffer the post data
* \param size post data size
* \return TRUE on success, FALSE otherwise
*/
BOOL mrc_Http_PostEx(PSOCKET socket, PCSTR url, PCSTR buffer, uint32 size);
/**
* \brief Get the http response code.
*
* This can only be called after receive the EVENT HTTPEVT_RESPONSE_HEADER event.
* otherwise undefined.
*
* \param socket the http socket handle
* \return the response code
*/
uint32 mrc_Http_GetResponseCode(PSOCKET socket);
/**
* \brief Get the field value of the http header
*
* This can only be called after receive the EVENT HTTPEVT_RESPONSE_HEADER event.
* otherwise undefined.
*
* \param socket the http socket handle
* \param field the http header field
* \return the value of the filed on success, NULL otherwise
*/
PCSTR mrc_Http_GetResponseField(PSOCKET socket, PCSTR field);
/**
* \brief Get http response head content
*
*\param socket the http socket handle
* \param buffer the http head point
*\param size the http head data length
* \return the value of MR_SUCCESS on success, MR_FAILED otherwise
*/
int mrc_Http_GetResponseHead(PSOCKET socket,uint8** buf, uint32* size);
#endif

Binary file not shown.

BIN
sky_fontmaker_v2.0.0616.rar Normal file

Binary file not shown.

414
smp_stylebox.c Normal file
View File

@ -0,0 +1,414 @@
#include "smp_stylebox.h"
#include "smp.h"
#include "bmp.h"
#include "mrc_exb.h"
#include "types.h"
#define SMP_BOX_RECOVER_SPEED 3 //滑动恢复的加速度(单位:像素/次)
/*宫格的一项所具有的信息*/
typedef struct SMP_ItemData{
int index; //序号
int width; //宽度
int height; //高度
HBITMAP hBmp; //图片句柄
}SMPITEMDATA, *PSMPITEMDATA;
/*窗口结构体*/
typedef struct
{
int num; //总数量
BOOL focus; //是否有焦点
int onewidth; //一个宽高
int oneheight;
int rows; //行
int stand; //多少列
int topmagin; //滑动时 顶部边距
int leftmagin;
int highlight; //哪个高亮
}BOXDATA, *PBOXDATA;
#define SMP_STYLEBOX_MAX 10
static SMPITEMDATA BoxItem[SMP_STYLEBOX_MAX]; //九宫格每一项
/*设置信息*/
VOID SMP_Stylewnd_SetItem(HWND hWnd, const DWORD* bmps, int size)
{
PBOXDATA pBoxData = _GET_WINDATA(hWnd, PBOXDATA);
int i;
if(size>SMP_STYLEBOX_MAX || !bmps)
return;
for (i=0; i<size; i++)
{
BoxItem[i].index = i;
BoxItem[i].hBmp = SGL_LoadBitmap(bmps[i], &BoxItem[i].width, &BoxItem[i].height);
}
pBoxData->num = size;
pBoxData->highlight = 4; //默认最中间获得焦点
pBoxData->onewidth = _WIDTH(hWnd)/3;
pBoxData->oneheight = _HEIGHT(hWnd)/3;
pBoxData->topmagin = 0;
pBoxData->leftmagin = 0;
pBoxData->rows = 3; //默认3*3 九宫格
pBoxData->stand = 3;
}
VOID SMP_Update_OneBox(HWND hWnd, int index)
{
int hx, hy; //该项源坐标hx, hy
PBOXDATA pBoxData = _GET_WINDATA(hWnd, PBOXDATA);
hx = _LEFT(hWnd) + pBoxData->onewidth*(index%3);
hy = _TOP(hWnd) + pBoxData->oneheight*(index/3);
if (hy + pBoxData->topmagin >= _TOP(hWnd) && hy+pBoxData->topmagin+pBoxData->highlight <= _TOP(hWnd)+_HEIGHT(hWnd))
{
if (pBoxData->highlight == index)//高亮
GAL_FillRoundRrct(hx+(pBoxData->onewidth - BoxItem[index].width)/2 + pBoxData->leftmagin-3,
hy+(pBoxData->oneheight - BoxItem[index].height)/2 + pBoxData->topmagin-2,
BoxItem[index].width+6, BoxItem[index].height+4, COLOR_focus);
else
GAL_FillBox(PHYSICALGC, hx, hy, pBoxData->onewidth, pBoxData->oneheight, _BGCOLOR(hWnd));
mrc_bitmapShowEx(BoxItem[index].hBmp,
hx+(pBoxData->onewidth - BoxItem[index].width)/2 + pBoxData->leftmagin,
hy+(pBoxData->oneheight - BoxItem[index].height)/2 + pBoxData->topmagin,
BoxItem[index].width, BoxItem[index].width, BoxItem[index].height, BM_TRANSPARENT, 0, 0);
GAL_FlushRegion(PHYSICALGC, hx + pBoxData->leftmagin, hy + pBoxData->topmagin, pBoxData->onewidth, pBoxData->oneheight);
}
}
/*绘制所有项,主要是平滑移动的时候
*
*/
VOID SMP_DrawStyleBox(HWND hWnd)
{
int i, j, index = 0;
int x, y, w, h; //起始坐标,及宽高
int hx, hy; //绘制临时坐标
PBOXDATA pBoxData = _GET_WINDATA(hWnd, PBOXDATA);
x = _LEFT(hWnd);
y = _TOP(hWnd);
w = _WIDTH(hWnd);
h = _HEIGHT(hWnd);
hy = y;
for (i=0; i<pBoxData->rows; i++)//行
{
hx = x;
for (j=0; j<pBoxData->stand; j++)//列
{
if (pBoxData->highlight == index)//高亮
GAL_FillRoundRrct(hx+(pBoxData->onewidth - BoxItem[index].width)/2 + pBoxData->leftmagin-3,
hy+(pBoxData->oneheight - BoxItem[index].height)/2 + pBoxData->topmagin-2,
BoxItem[index].width+6, BoxItem[index].height+4, COLOR_focus);
mrc_bitmapShowEx(BoxItem[index].hBmp,
hx+(pBoxData->onewidth - BoxItem[index].width)/2 + pBoxData->leftmagin,
hy+(pBoxData->oneheight - BoxItem[index].height)/2 + pBoxData->topmagin,
BoxItem[index].width, BoxItem[index].width, BoxItem[index].height, BM_TRANSPARENT, 0, 0);
hx+=pBoxData->onewidth;
index++;
}
hy+=pBoxData->oneheight;
}
}
/*获得高亮序号, 在本窗口产生事件时,上一层可以通过(int)lParam获得高亮序号*/
int SMP_Box_GetHilightId(HWND hWnd)
{
PBOXDATA pBoxData = _GET_WINDATA(hWnd, PBOXDATA);
return pBoxData->highlight;
}
/*松开鼠标或者按键,如果不在原位,则需要恢复原位*/
VOID SMP_Box_RecoverLoaction(HWND hWnd)
{
PBOXDATA pBoxData = _GET_WINDATA(hWnd, PBOXDATA);
int i;
//int x_step = 1;
int y_step = 1; //充当加速度
if(pBoxData->leftmagin==0 && pBoxData->topmagin==0)
return;
if(pBoxData->topmagin>0)//从上面回来
{
for (i=0; i<=pBoxData->topmagin; i++, y_step+=SMP_BOX_RECOVER_SPEED)//加 速度为1
{
if(pBoxData->topmagin - y_step<0)
pBoxData->topmagin = 0;
else
pBoxData->topmagin-= y_step;
SGL_TRACE("%d", pBoxData->topmagin);
SGL_UpdateWindow(hWnd);
}
}else if(pBoxData->topmagin<0)//从下面回来
{
for(i=0; i>=pBoxData->topmagin; i--, y_step+=SMP_BOX_RECOVER_SPEED)
{
if(pBoxData->topmagin + y_step>0)
pBoxData->topmagin = 0;
else
pBoxData->topmagin+=y_step;
SGL_TRACE("%d", pBoxData->topmagin);
SGL_UpdateWindow(hWnd);
}
}
}
LRESULT SMP_Box_WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
PBOXDATA pBoxData = _GET_WINDATA(hWnd, PBOXDATA);
//static int start_x = 0;
static int start_y = 0;
static int click_count = 0;
static int key_step = 0; //键盘模拟滑动速度
switch(Msg)
{
case WM_CREATE:
{
//request memory and initialize members
pBoxData = (PBOXDATA)SGL_MALLOC(sizeof(BOXDATA));
if(!pBoxData){
SGL_TRACE("%s, %d: memory out\n", __FILE__, __LINE__);
return 1;
}
SGL_MEMSET(pBoxData, 0, sizeof(BOXDATA));
_SET_WINDATA(hWnd, pBoxData);
return 0;
}
case WM_DESTROY:
{
if(pBoxData) SGL_FREE(pBoxData);
return 0;
}
case WM_SHOW:
{
return 0;
}
case WM_PAINT:
{
_BGCOLOR(hWnd) = 0x00ddeeff;
GAL_FillBox(PHYSICALGC, _LEFT(hWnd), _TOP(hWnd), _WIDTH(hWnd), _HEIGHT(hWnd), _BGCOLOR(hWnd));
SMP_DrawStyleBox(hWnd);
return 0;
}
case WM_MOUSEDOWN:
{
int index_x = 0; //该序号对应区域所在的起始坐标(index_x,index_y)
int index_y = 0;
int oldhl = pBoxData->highlight; //旧高亮图标
index_x = ((int)wParam)/pBoxData->onewidth;
index_y = ((int)lParam)/pBoxData->oneheight;
pBoxData->highlight = (index_x+3*index_y);
if (oldhl == pBoxData->highlight)
{
click_count ++;
SGL_NotifyParent(hWnd, SMP_BOXI_CLICKED, pBoxData->highlight);
}
else if (oldhl != pBoxData->highlight)//高亮切换
{
click_count = 1;
SMP_Update_OneBox(hWnd, oldhl); //刷新图标
SMP_Update_OneBox(hWnd, pBoxData->highlight);
SGL_NotifyParent(hWnd, SMP_BOXI_HILICHANGED, pBoxData->highlight);
}
//位置复原
if (!pBoxData->leftmagin|| !pBoxData->topmagin)
SMP_Box_RecoverLoaction(hWnd);
//////////////////////////////////////////////////////////////////////////
//检测鼠标移动前的Y坐标
start_y = (int)lParam;
return 0;
}
case WM_MOUSEMOVE:
{
//pBoxData->leftmagin = ((int)wParam - start_x);
pBoxData->topmagin = ((int)lParam - start_y);
SGL_UpdateWindow(hWnd);
SGL_NotifyParent(hWnd, SMP_BOXI_MOUSEMOVE, 0);
return 0;
}
case WM_MOUSEUP:
{
int index_x = 0;
int index_y = 0;
int oldhl = pBoxData->highlight;
index_x = ((int)wParam)/pBoxData->onewidth;
index_y = ((int)lParam)/pBoxData->oneheight;
pBoxData->highlight = (index_x+3*index_y);
if (oldhl == pBoxData->highlight)
{
if (click_count == 2)//第二次点击后并且松开
{
click_count = 1;
SGL_NotifyParent(hWnd, SMP_BOXI_SELECTED, pBoxData->highlight);
}
}else if (oldhl != pBoxData->highlight)//高亮切换
{
SMP_Update_OneBox(hWnd, oldhl); //刷新图标
SMP_Update_OneBox(hWnd, pBoxData->highlight);
SGL_NotifyParent(hWnd, SMP_BOXI_HILICHANGED, pBoxData->highlight);
}
//位置复原
if (!pBoxData->leftmagin|| !pBoxData->topmagin)
SMP_Box_RecoverLoaction(hWnd);
return 0;
}
case WM_KEYDOWN:
case WM_KEYDOWNREPEAT:
{
int oldhl = pBoxData->highlight;
switch(wParam)
{
/*处理键盘移动*/
case MR_KEY_UP:
{
if (pBoxData->highlight>2)
pBoxData->highlight-=3;
else
pBoxData->highlight+=6;
SMP_Update_OneBox(hWnd, oldhl); //刷新图标
SMP_Update_OneBox(hWnd, pBoxData->highlight);
SGL_NotifyParent(hWnd, SMP_BOXI_HILICHANGED, pBoxData->highlight);
return 1;
}
case MR_KEY_DOWN:
{
if (pBoxData->highlight<6)
pBoxData->highlight+=3;
else
pBoxData->highlight-=6;
SMP_Update_OneBox(hWnd, oldhl); //刷新图标
SMP_Update_OneBox(hWnd, pBoxData->highlight);
SGL_NotifyParent(hWnd, SMP_BOXI_HILICHANGED, pBoxData->highlight);
return 1;
}
case MR_KEY_LEFT:
{
if (pBoxData->highlight>0)
pBoxData->highlight--;
else
pBoxData->highlight = 8;
SMP_Update_OneBox(hWnd, oldhl); //刷新图标
SMP_Update_OneBox(hWnd, pBoxData->highlight);
SGL_NotifyParent(hWnd, SMP_BOXI_HILICHANGED, pBoxData->highlight);
return 1;
}
case MR_KEY_RIGHT:
{
if (pBoxData->highlight<8)
pBoxData->highlight++;
else
pBoxData->highlight = 0;
SMP_Update_OneBox(hWnd, oldhl); //刷新图标
SMP_Update_OneBox(hWnd, pBoxData->highlight);
SGL_NotifyParent(hWnd, SMP_BOXI_HILICHANGED, pBoxData->highlight);
return 1;
}
case MR_KEY_2://键盘模拟,向上滑动
{
if(pBoxData->topmagin>(-_HEIGHT(hWnd))+30)
{
key_step +=5;
pBoxData->topmagin -= key_step;
SGL_UpdateWindow(hWnd);
SGL_NotifyParent(hWnd, SMP_BOXI_MOUSEMOVE, 0);
}
return 1;
}
case MR_KEY_8://键盘模拟,向下滑动
{
if(pBoxData->topmagin<_HEIGHT(hWnd)-30)
{
key_step +=5;
pBoxData->topmagin += key_step;
SGL_UpdateWindow(hWnd);
SGL_NotifyParent(hWnd, SMP_BOXI_MOUSEMOVE, 0);
}
return 1;
}
}
return 0;
}
case WM_KEYUP:
{
/*选中*/
if(wParam == MR_KEY_SELECT)
{
SGL_NotifyParent(hWnd, SMP_BOXI_SELECTED, pBoxData->highlight);
return 1;
}
//位置复原
if (!pBoxData->leftmagin|| !pBoxData->topmagin)
SMP_Box_RecoverLoaction(hWnd);
key_step = 0;
}
// case WM_COMMAND:
// {
// WORD id = LOWORD(wParam);
// WORD code = HIWORD(wParam);
// switch(id)
// {
// case WM_COMMAND:
// {
// if (code == WM_COMMAND)
// {
// //
// }
// break;
// }
// }
// return 0;
// }
case WM_SETFOCUS:
case WM_KILLFOCUS:
{
SGL_UpdateWindow(hWnd);
break;
}
}
return 0;
}

24
smp_stylebox.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef _SMP_STYLEBOX_H
#define _SMP_STYLEBOX_H
#include "window.h"
#define SMP_BOXI_HILICHANGED 0x0001 //高亮改变
#define SMP_BOXI_CLICKED 0x0002 //鼠标点击
#define SMP_BOXI_SELECTED 0x0003 //选中
#define SMP_BOXI_MOUSEMOVE 0x0004 //鼠标移动
/*获得高亮序号*/
int SMP_Box_GetHilightId(HWND hWnd);
/*设置信息*/
VOID SMP_Stylewnd_SetItem(HWND hWnd, const DWORD* bmps, int size);
LRESULT SMP_Box_WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
#endif

BIN
字库Demo.7z Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.