index.html 未包含<script language="javascript" type="text/javascript" src="./js/ajaxbasic.js "></script>不能成功调用XHRGet函数。与此同时systemlanguage.html也成功调用XHRGet函数。
这部分内容是对配置文件的保存
cgi 里的C语言里边的
ucfg_config.xml ucfg_factory.xml 里的文件看元素是否为顶层元
<language>
<ENABLE>1</ENABLE>
</language>
怎么把文件一个一个读出来?
答:有专门的读函数来读取.
cgi从服务器读取数据的过程 1
#include<sys/ioctl.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<sys/socket.h>
#include<sys/socket.h>
#include<fcntl.h>
#include<unistd.h>
#include<netinet/in.h>
#include<netinet/ether.h>
#include<arpa/inet.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<net/if.h>
#include<arpa/inet.h>
#include<pthread.h>
#include"cgicommon.h"
#include"html-lib.h"
#include"cgi-lib.h"
#include"string-lib.h"
#include"ini.h"
#include "ucfg_lib.h"
static pthread_cond_t cgi_cond = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t cgi_lock = PTHREAD_MUTEX_INITIALIZER;
char langbuf[]={"aaaaa"};//定义字符串
static int GetLanguage(llist entries, int set)
{
if(set == 0)
{
CGI_XML_VALUE("LANGUAGE",langbuf); //langbuf字符数组首地址 LANGUAGE命令
}
return 0;
}
int main()
{
list entries;
int ret=0;
int init_ucfg_ret=-1;
char* command;
list_create(&entries);
CG8I_XML_BEGIN();
init_ucfg_ret=init_ucfg();
if(init_ucfg_ret<0){
CGI_XML_VALUE("Error", "%s", "init_ucfg Fail");
goto out;
}
ret = read_cgi_input(&entries);
if(ret)
{
comand=cgi_val(entries, CGI_REQUEST_COMMAND);
if(command==NULL)
{
CGI_XML_VALUE("Error","%s", "NoCommand");
}
else if(!strcmp(command, ""))
{
pthread_mutex_lock(&cgi_lock);
GetLanguage(entries,0);
pthread_mutex_unlock(&cgi_lock);
}
else
{
CGI_XML_VALUE("Error","%s", "CGI Unkown Command");
}
}
out:
if(init_ucfg_ret==0)
deinit_ucfg();
CGI_XML_END();
list_clear(&entries);
pthread_mutex_destroy(&cgi_lock);
pthread_cond_destroy(&cgi_cond);
return 0;
}
从数组中读取字符串数据,
若是从服务器上读取文件则修改
static void updateLanguageConf()
{
system("ucfg get config language > /tmp/language.conf"); //此处命令是linux下的命令
}
static int GetLanguage(llist entries, int set)
{
char cmd_str[256];
char ini_file[256];
char get_value[LENGTH_INI_KEY_AND_VALUE] ={0,};
char *key;
char ipaddress[32];
char val_set[32];
char *val;
if(set == 0)
{
sprintf(ini_file,"/tmp/language.conf"); //服务器上的文本路径
key="ENABLE"; //Ucfg_factory.xml Ucfg_config.xml 文件里边的属性ENABLE <language> \n <ENABLE>0<ENABLE> \n <language>
if(0 > GetPrivateProfileSring(
"", //Nosection
key,
"0",
get_value,
sizeof(get_value) - 1,
ini_file)) {
return -1;
}
CGI_XML_VALUE("LANGUAGE",get_value);
}
return 0;
}
static int SetStatus(llist entries, int set)
{
char *val;
val = cgi_val(entries, "LANG"); //此处是XHRPost()第三个参数var param = "Command=SetlanguageEnable" + "&LANG=" + autoexec;
write_ucfg_xml(CONF_BLK,"/language/ENABLE",val);
updateLanguageConf();
return 0;
}
int main()
{
llist entries;
int ret=0;
int init_ucfg_ret=-1;
char* command;
list_create(&entries);
CGI_XML_BEGIN();
init_ucfg_ret=init_ucfg();
if(init_ucfg_ret<0){
CGI_XML_VALUE("Error","%s","init_ucfg Fail");
goto out;
}
ret = read_cgi_input(&entries);
if(ret)
{
command = cgi_val(entries, CGI_REQUEST_COMMAND);
if(command == NULL)
{
CGI_XML_VALUE("Error", "%s", "NoCommand");
}
else if(!strcmp(command, "Language"))
{
pthread_mutex_lock(&cgi_lock);
GetLanguage(entries, 0);
pthread_mutex_unlock(&cgi_lock);
}
else if (!strcmp(command, "SetlanguageEnable")) //当js里边XHRPost()命令为SetlanguageEnable
{
SetStatus(entries,0); //写入函数被调用
}
else
{
CGI_XML_VALUE("Error","%s","CGI Unknown Command");
}
}
out:
此处同上分代码
}
如下来解析,此时通过SH,CGI_MXL_VALUE不能解析的三种格式,不支持json的格式需要转换
CGI_MXL_VALUE(element,arg...)\
do{\
fprintf(stdout, "<%s>", element);\
printf(arg);
fprintf(stdout, "</%s>\n",element );\
}while(0)
js部分的代码
function getLanguageResults(xmlDoc)
{
if(hasError(xmlDoc))
{
showError(xmlDoc);
return ;
}
var g_lang_info = getDataFromTag(xmlDoc, "LANGUAGE");
alert("info:"+g_lang_info);
}
function getLanuageHandless()
{
alert("bb");
var url="./cgi-bin/syslanguage.cgi?Command=Language"; 这里的syslanguage.cgi && command一定要改对
XHRGet(getLanuageResults, url, false);
alert("ccc");
}
function initSystem()
{
alert("init");
getLanuageHandless();
}
function initialize()
{
try
{
alert("firxt init");
top.initSystem();
initSystem();
}
catch(E){}
}
并通过wireshark, 搜索http 右键追踪流 TCP流 中搜索Languge并查看CGI_MXL_VALUE函数的解析的数据。
有专门的读函数来读文件,
以下是写函数的命令
系统命令ucfg get config languge ; ucfg get 是命令 languae是对象在ucfg_factory.xml ucfg_config.xml中定义
<language>
<ENABLE>1</ENABLE>
<language>
static void updateLanguageConf()
{
system("ucfg get config language > /tmp/language.conf");
};
写入函数
static int SetStatus(llist entries, int set )
{
char *val;
val = cgi_val(entries, "LANG"); js的param里边的参数LANG
write_ucfg_xml(CONF_BLK,"/language/ENBALE",val); CONF_BLK 配置文件ucfg_config.xml的
<language>
<ENABLE>1</ENABLE>
<language>
/language/ENABLE language是顶层ENABLE子层,若果有多级别就类推
updateLanguageConf();
return 0;
}
js部分代码
var param ="Command=SetlanguageEnable"+"&LANG="+ autoexec;
XHRPost(SetlanguageEnableHandler, "./cgi-bin/syslanguage.cgi", param, true);
以上是发送请求代码
js代码可以返回页面不能刷新,先刷新当前页面location.reload();
当前页面初始化时调用,刷新另一个框架的页面
-
//刷新另一个框架的页面用
-
<script language=JavaScript>
-
parent.另一FrameID.location.reload();
-
</script>
parent.leftmenu.location.reload();
亦或top.location.reload();刷顶层页面