最近在弄linux下web端的SD卡内容的预览问题,研究了一下关于SD卡由前端web到下层调用的相关的代码。在此黏贴出来分享一下。
大概思路是这样的:在web端的代码是创建对话框显示SD卡的内容
web端事件在boa中通过哈希表调用对应的响应函数。
在应用层有对应的事件的响应函数。对事件的处理。
整体思路是这样的
web端显示SD卡内容的函数
mkElem("sdleft",{src:IPNC.serverURL + "sdget.htm", "class":"ipnc-iframe"}),
boa中的哈希表及对应的事件处理函数
{"/sdget.htm" ,uri_sdget_htm ,AUTHORITY_VIEWER ,URI_FLAG_VIRTUAL_PAGE ,NULL },
int uri_sdget_htm(request * req)
{
char *addr, sdpath[128] = {0};
if (req->query_string && uri_decoding(req, req->query_string) < 0) {
send_r_bad_request(req);
return 0;
}
addr = (char *)malloc(MAX_SDLIST_LENGTH);
if (addr == NULL) {
send_r_error(req);
return 0;
}
req->filesize = http_sdget_cmd(req, req->cmd_arg, addr, MAX_SDLIST_LENGTH, sdpath);
if (req->filesize > 0) {
SQUASH_KA(req);
req->mem_flag |= MFLAG_IS_MEMORY;
req->data_mem = addr;
send_request_ok_sdget(req);
req->status = WRITE;
return 1;
}
free(addr);
if (req->pathname){
free(req->pathname);
}
strcat(sdpath, "/");
if(req->cmd_arg[0].value==NULL){
send_r_bad_request(req);
dbg("req->cmd_arg[0].value is NULL, no SD card\n");
return 0;
}
strcat(sdpath, req->cmd_arg[0].value);
req->pathname = strdup(sdpath);
if (!req->pathname) {
send_r_error(req);
WARN("unable to strdup buffer onto req->pathname");
return 0;
}
strncpy(req->request_uri, req->cmd_arg[0].value, MAX_HEADER_LENGTH);
return -1;
}
应用层中对事件处理
#define MMC_NODE "/dev/mmcblk0p1"
#define MMC_PATH "/mnt/mmc/ipnc/" //注意这个路径是根据你自己的SD卡的路径来设置的。不是固定的
int http_sdget_cmd(request *req, COMMAND_ARGUMENT *argm, char *addr, int max_size, char *sdpath)
{
int ret = 0;
if (argm->value != "\0")
{
if( CheckFileExist(MMC_PATH,argm->value) == 0 )
{
strcpy(sdpath, MMC_PATH);
return 0;
}
}
MEM_List_files_To_html( MMC_PATH, MMC_PATH, addr, max_size);
ret = strlen(addr);
return ret;
}
int MEM_List_files_To_html(char *pInputDir,char *pOutDisk, void *pOutMem, int MaxSize)
{
char http_ip_addr[100];
int count = 0;
int i = 0;
int error_code = 0;
FILE_INFO *pFilelist = NULL;
char tempbuff[100];
char recodingName[30];
int ret = 0;
int string_length = 0;
ret = ControlSystemData(SFIELD_GET_SD_FILE_NAME, (void *)recodingName, sizeof(recodingName));
if(ret >= 0 )
{
string_length = ret;
recodingName[string_length] = '\0';
}else{
string_length = 0;
}
GetIP_Addr(http_ip_addr);
fprintf(stderr,"para_netip %s \n",http_ip_addr);
if (chdir(pInputDir) != 0)
{
printf("Error in chdir \n");
error_code = -1;
goto QUIT_MEM_SAVE;
}
pFilelist = Get_File_List( pInputDir, &count );
if( pFilelist == NULL )
{
fprintf(stderr,"FileList Empty, No Files to Display \n");
error_code = -1;
goto QUIT_MEM_SAVE;
}
strncpy( pOutMem, html_sdget_header, MaxSize );
for (i=0;i
if( string_length > 0 )
{
if( strncmp(pFilelist[i].name, recodingName, sizeof(recodingName) ) == 0 )
{
continue;
}
}
sprintf(html_content,"A(\"%s\",\"%s\",\"%s\",\"%s\");",pFilelist[i].name,
pFilelist[i].date,
pFilelist[i].time,
pFilelist[i].size);
if( MaxSize > strlen(pOutMem) )
strncat(pOutMem, html_content, MaxSize-strlen(pOutMem));
}
if( MaxSize > strlen(pOutMem) )
strncat(pOutMem, "\n\n
只黏贴出了和SD卡预览相关的代码。给阅读带来不便的请谅解。
第一次写博文,主要是对自己做过的工作的一个记录。