예제 #1
0
debugger_t *debugger_creator(char *ini_file_name)
{
	debugger_t *debugger;
	int8_t type;
	dictionary *d;
	FILE *f;

	debugger =(debugger_t *)malloc(sizeof(debugger_t));

	debugger->d = d = iniparser_new(ini_file_name);
	memcpy(debugger->ini_file_name,ini_file_name,strlen(ini_file_name));

	type = iniparser_getint(d, (char *)"debugger:type", 0);
	if(access(debugger->ini_file_name,F_OK)){
		printf("ini file not exsit\n");
		f = fopen(debugger->ini_file_name, "w");
		iniparser_setstr(d, (char *)"debugger", NULL); 
		/*
		 *itoa(type,type_str,10);
		 */
		iniparser_setstr(d, (char *)"debugger:type","0");
		iniparser_dump_ini(d, f);
		fclose(f);
	}
	printf("debugger type =%d\n",type);
	debugger->debugger_type = type;
	debugger->dbg_ops = &debugger_modules[type].dbg_ops;


	debugger_set_level_infos(debugger);
	debugger_set_businesses(debugger);

	return debugger;

}
예제 #2
0
/*
 *enum debug_business_enum{
 *    DBG_BUSINESS_NORMAL = 0,
 *    DBG_BUSINESS_ALLOC,
 *    DBG_BUSINESS_CONTAINER,
 *    MAX_DEBUG_BUSINESS_NUM
 *};
 */
void debugger_set_businesses(debugger_t *debugger)
{
	dictionary *d = debugger->d;;
	int bussiness_num,i;
#define MAX_STRING_LEN 50
	char switch_str[MAX_STRING_LEN];
	char level_str[MAX_STRING_LEN];
	int sw,lv;

	bussiness_num = iniparser_getint(d, (char *)"businesses:business_num",0);
	if(bussiness_num == 0){
		iniparser_setstr(d, (char *)"businesses", NULL); 
		iniparser_setstr(d, (char *)"businesses:business_num", "3"); 
		for(i = 0; i < MAX_DEBUG_BUSINESS_NUM; i++){
			snprintf(switch_str,MAX_STRING_LEN,"businesses:business%d_switch",i);
			snprintf(level_str,MAX_STRING_LEN,"businesses:business%d_level",i);
			iniparser_setstr(d, switch_str,"1");
			iniparser_setstr(d, level_str,"9");
			debugger_set_business(debugger,i,1,9);
		}
		FILE *f = fopen(debugger->ini_file_name, "w");
		iniparser_dump_ini(d, f);
		fclose(f);
	}else{
		for(i = 0; i < bussiness_num; i++){
			snprintf(switch_str,MAX_STRING_LEN,"businesses:business%d_switch",i);
			snprintf(level_str,MAX_STRING_LEN,"businesses:business%d_level",i);
			printf("debugger_set_businesses,bussiness_num=%d\n",bussiness_num);
			sw = iniparser_getint(d, switch_str,1);
			lv = iniparser_getint(d, level_str,9);
			debugger_set_business(debugger,i,sw,lv);
		}
	}
#undef MAX_BUSINESSES_SETTING_LEN
}
예제 #3
0
void network_print_init(debugger_t *debugger)
{
#define MAX_NETWORK_INIT_BUF_LEN 20
	int sd;
	struct sockaddr_in *raddr;
	debug_network_prive_t *net_priv = &debugger->priv.net;
	dictionary *d = debugger->d;;
	char *ip;
	uint32_t default_dbg_port = 10276;
	char buf[MAX_NETWORK_INIT_BUF_LEN];
	char default_dbg_ip[] = "127.0.0.1";

	net_priv->port = iniparser_getint(d, (char *)"network:debug_port",default_dbg_port);
	ip = iniparser_getstr(d, (char *)"network:debug_ip");
	if(ip == NULL){
		/*
		 *memcpy(debug_ip,get_ipaddr(),strlen(get_ipaddr()));
		 */
		dbg_str(DBG_ERROR,"iniparser_getstr err");
		memcpy(net_priv->ip_str,default_dbg_ip,strlen(default_dbg_ip));
		iniparser_setstr(d, (char *)"network", NULL); 
		debug_string_itoa(default_dbg_port,buf,10);
		iniparser_setstr(d, (char *)"network:debug_port",buf);
		iniparser_setstr(d, (char *)"network:debug_ip", net_priv->ip_str);

		FILE *f = fopen(debugger->ini_file_name, "w");
		iniparser_dump_ini(d, f);
		fclose(f);
	}
	else 
		memcpy(net_priv->ip_str,ip,strlen(ip));

	sd = socket(AF_INET,SOCK_DGRAM,0);
	if(sd <0){
		printf("create socket\n");
		exit(1);
	}   
	int val=1;
	if(setsockopt(sd,SOL_SOCKET,SO_REUSEADDR,&val,sizeof(val))<0){
		printf("setsocgketopt error\n");
		exit(1);
	}      
	pthread_mutex_init(&debugger->priv.net.send_dgram_lock,NULL);
	debugger->priv.net.sd = sd;

	raddr = &debugger->priv.net.raddr;
	raddr->sin_family = AF_INET;
	raddr->sin_port = htons(net_priv->port);
	inet_pton(AF_INET,net_priv->ip_str,&raddr->sin_addr);
#undef MAX_NETWORK_INIT_BUF_LEN 
}
예제 #4
0
/**********************************************************************************************
 * 函数名	:set_board_seq()
 * 功能	:设置板卡批次字符串
 * 输入	:板卡批次信息
 * 返回值	:0表示成功负值表示失败
 **********************************************************************************************/
int set_board_seq(char *seq)
{
	int len;
	dictionary      		*ini=NULL;
	FILE				*fp=NULL;
	char				*pstr=NULL;
	len=strlen(seq);
	if((len+1)>sizeof(info.board_seq))
		len=sizeof(info.board_seq)-1;
	memcpy(info.board_seq,seq,len+1);
	info.board_seq[len]='\0';
	ini=iniparser_load_lockfile(DEVINFO_PARA_FILE,1,&fp);
	if(ini==NULL)
	{
                printf("init_devinfo() cannot parse ini file file [%s]", DEVINFO_PARA_FILE);
                return -ENOENT ;
        }
	pstr=iniparser_getstring(ini,"devinfo:cpuboard","NULL");
	gtloginfo("devinfo:cpuboard %s->%s",pstr,info.board_seq);
	iniparser_setstr(ini,"devinfo:cpuboard",info.board_seq);

	save_inidict_file(DEVINFO_PARA_FILE,ini,&fp);
	iniparser_freedict(ini);
	return 0;
}
예제 #5
0
/**********************************************************************************************
 * 函数名	:set_devtype_str()
 * 功能	:设置设备的型号字符串
 * 输入	:type_str:描述设备型号的字符串
 * 返回值	:0表示成功,负值表示失败,-EINVAL表示参数是不支持的类型
 **********************************************************************************************/
int set_devtype_str(char *type)
{
	GTSeriesDVSR 	*dvsr=NULL;
	dictionary      		*ini=NULL;
	FILE				*fp=NULL;
	char				*ptr=NULL;
	if(type==NULL)
		return -EINVAL;
	dvsr=get_dvsr_by_typestr(type);
	if(dvsr==NULL)
		return -EINVAL;
	ini=iniparser_load_lockfile(DEVINFO_PARA_FILE,1,&fp);
	if(ini==NULL)
	{
                printf("init_devinfo() cannot parse ini file file [%s]", DEVINFO_PARA_FILE);
                return -ENOENT ;
        }

	ptr=iniparser_getstring(ini,"devinfo:devtypestring","NULL");
	gtloginfo("devinfo:devtypestring %s->%s",ptr,type);
	iniparser_setstr(ini,"devinfo:devtypestring",type);

	
	ptr=iniparser_getstring(ini,"devinfo:devtype","-1");
	gtloginfo("devinfo:devtypestring %d->%d",atoi(ptr),conv_dev_str2type(type));
	iniparser_setint(ini,"devinfo:devtype",conv_dev_str2type(type));
	save_inidict_file(DEVINFO_PARA_FILE,ini,&fp);
	iniparser_freedict(ini);
	return 0;	
}
예제 #6
0
/**********************************************************************************************
 * 函数名	:set_devid_str()
 * 功能	:应用程序调用设置设备的guid值,字符串格式
 * 输入	:id_str:字符串表示的设备guid值
 * 输出 	:
 * 返回值	:0表示成功 负值表示出错 -EINVAL表示输入参数格式不对
  **********************************************************************************************/
int set_devid_str(char *id_str)
{

	char				guid_temp[DEV_GUID_BYTE*4]; 
	struct GT_GUID 	guid;
	dictionary      		*ini=NULL;
	char 			*pstr=NULL;
	FILE 			*fp=NULL;
	
	if(id_str==NULL)
		return -EINVAL;
	guid=hex2guid(id_str);
	guid2hex(guid,guid_temp);
	if(strncasecmp(guid_temp,id_str,DEV_GUID_BYTE*2)!=0)
		return -EINVAL;	//GUID值非法
	ini=iniparser_load_lockfile(DEVINFO_PARA_FILE,1,&fp);
	if(ini==NULL)
	{
                printf("init_devinfo() cannot parse ini file file [%s]", DEVINFO_PARA_FILE);
                return -ENOENT ;
        }
	memcpy((void*)info.guid,(void*)&guid,DEV_GUID_BYTE);
	sprintf(info.guid_str,"%s",guid_temp);
	
	pstr=iniparser_getstring(ini,"devinfo:devguid","NULL");
	gtloginfo("devinfo:devguid %s->%s\n",pstr,guid_temp);
	iniparser_setstr(ini,"devinfo:devguid",guid_temp);	
	save_inidict_file(DEVINFO_PARA_FILE,ini,&fp);
	iniparser_freedict(ini);
	return 0;	
}
예제 #7
0
파일: INI.cpp 프로젝트: PATRONAS/xlloop
void INI::ExpandVariables(dictionary* ini)
{
	char tmp[4096];
	for(int i = 0; i < ini->size; i++) {
		char* key = ini->key[i];
		char* value = ini->val[i];
		int size = ExpandEnvironmentStrings(value, tmp, 4096);
		if(size == 0) {
			Log::Warning("Could not expand variable: %s", value);
		}
		iniparser_setstr(ini, key, tmp);
	}
}
예제 #8
0
void ttscpVoiceDialog::accept()
{
  QByteArray ba;
  
   tts.stopf();
  //tts.stop();
 
  dictionary * ini = iniparser_load("qenix.ini"); //Must deallocate manualy
  if (ini==NULL)
  {
  iniparser_freedict(ini);
  fprintf(stderr, "cannot parse file [%s]", "qenix.ini");
  return;
  }
	iniparser_dump(ini, stderr);
 
  tts.setInit_f(spinF->value());
  ba = QByteArray::number(spinF->value());
  iniparser_setstr(ini, "ttscp:init_f", ba.data());
  
  tts.setInit_i(spinI->value());
  ba = QByteArray::number(spinI->value());
  iniparser_setstr(ini, "ttscp:init_i", ba.data());
  
  tts.setInit_t(spinT->value());
  ba = QByteArray::number(spinT->value());
  iniparser_setstr(ini, "ttscp:init_t", ba.data());
  
  //msgbox(QString(t));
  
	FILE *fw;
	fw = fopen("qenix.ini", "wb+");
	
	iniparser_dump_ini(ini, fw);
	fclose(fw);
  iniparser_freedict(ini);
    
  done(Accepted);
}
예제 #9
0
파일: debug_log.c 프로젝트: ifzz/libcdf
/*init socket*/
void log_print_init(debugger_t *debugger)
{
	debug_log_prive_t *log_priv = &debugger->priv.log;
	FILE *fp;
	dictionary *d = debugger->d;;
	char *file_name;
	char default_log_name[] = "dbg_log.txt";

	printf("debug log init\n");
	file_name = iniparser_getstr(d, (char *)"log:log_file_name");
	if(file_name){
		memcpy(log_priv->log_file_name,file_name,strlen(file_name));
	}else{
		memcpy(log_priv->log_file_name,default_log_name,strlen(default_log_name));
		iniparser_setstr(d, (char *)"Log", NULL); 
		iniparser_setstr(d, (char *)"Log:log_file_name",log_priv->log_file_name);

		FILE *f = fopen(debugger->ini_file_name, "w");
		iniparser_dump_ini(d, f);
		fclose(f);
	}

	fp = fopen(log_priv->log_file_name,"ab+");
	if(fp == NULL)
	{
		perror("log file fopen()");
		exit(1);
	}
	log_priv->fp = fp;

	/*
	 *pthread_mutex_init(&log_priv->log_file_lock,NULL);
	 */
	printf("run at here.\n");
	sync_lock_init(&log_priv->log_file_lock,debugger->lock_type);
	printf("debug log init end\n");
}
예제 #10
0
static void
setIniString (IniDictionary *dictionary,
	      const char    *section,
	      const char    *entry,
	      const char    *value)
{
    char *sectionName;

    asprintf (&sectionName, "%s:%s", section, entry);

    if (!iniparser_find_entry (dictionary, (char*) section))
	iniparser_add_entry (dictionary, (char*) section, NULL, NULL);

    iniparser_setstr (dictionary, sectionName, (char*) value);

    free (sectionName);
}
예제 #11
0
파일: INI.cpp 프로젝트: PATRONAS/xlloop
dictionary* INI::LoadIniFile(HINSTANCE hInstance, LPSTR inifile)
{
	dictionary* ini = NULL;

	// First attempt to load INI from exe
	HRSRC hi = FindResource(hInstance, MAKEINTRESOURCE(1), RT_INI_FILE);
	if(hi) {
		HGLOBAL hg = LoadResource(hInstance, hi);
		PBYTE pb = (PBYTE) LockResource(hg);
		DWORD* pd = (DWORD*) pb;
		if(*pd == INI_RES_MAGIC) {
			ini = iniparser_load((char *) &pb[RES_MAGIC_SIZE], true);	
			if(!ini) {
				Log::Warning("Could not load embedded INI file");
			}
		}
	}

	// Check if we have already loaded an embedded INI file - if so 
	// then we only need to load and merge the INI file (if present)
	if(ini && iniparser_getboolean(ini, ALLOW_INI_OVERRIDE, 1)) {
		dictionary* ini2 = iniparser_load(inifile);
		if(ini2) {
			for(int i = 0; i < ini2->n; i++) {
				char* key = ini2->key[i];
				char* value = ini2->val[i];
				iniparser_setstr(ini, key, value);
			}		
			iniparser_freedict(ini2);
		}
	} else if(!ini) {
		ini = iniparser_load(inifile);
		if(ini == NULL) {
			Log::Error("Could not load INI file: %s", inifile);
			return NULL;
		}
	}

	// Expand environment variables
	ExpandVariables(ini);

	// Now check if we have an external file to load
	char* iniFileLocation = iniparser_getstr(ini, INI_FILE_LOCATION);
	if(iniFileLocation) {
		Log::Info("Loading INI keys from file location: %s", iniFileLocation);
		dictionary* ini3 = iniparser_load(iniFileLocation);
		if(ini3) {
			for(int i = 0; i < ini3->n; i++) {
				char* key = ini3->key[i];
				char* value = ini3->val[i];
				iniparser_setstr(ini, key, value);
			}		
			iniparser_freedict(ini3);
		} else {
			Log::Warning("Could not load INI keys from file: %s", iniFileLocation);
		}
	}

	// Attempt to parse registry location to include keys if present
	ParseRegistryKeys(ini);

	iniparser_setstr(ini, MODULE_INI, inifile);

	// Add module name to ini
	TCHAR filename[MAX_PATH], filedir[MAX_PATH];
	GetModuleFileName(hInstance, filename, MAX_PATH);
	iniparser_setstr(ini, MODULE_NAME, filename);

	// strip off filename to get module directory
	GetFileDirectory(filename, filedir);
	iniparser_setstr(ini, MODULE_DIR, filedir);

	// stip off filename to get ini directory
	GetFileDirectory(inifile, filedir);
	iniparser_setstr(ini, INI_DIR, filedir);

	// Log init
	Log::Init(hInstance, iniparser_getstr(ini, LOG_FILE), iniparser_getstr(ini, LOG_LEVEL), ini);
	Log::Info("Module Name: %s", filename);
	Log::Info("Module INI: %s", inifile);
	Log::Info("Module Dir: %s", filedir);
	Log::Info("INI Dir: %s", filedir);

	// Store a reference to be used by JNI functions
	g_ini = ini;

	return ini;
}
예제 #12
0
파일: INI.cpp 프로젝트: PATRONAS/xlloop
void INI::ParseRegistryKeys(dictionary* ini)
{
	// Now check if we have a registry location to load from
	char* iniRegistryLocation = iniparser_getstr(ini, INI_REGISTRY_LOCATION);
	if(!iniRegistryLocation) {
		return;
	}

	Log::Info("Loading INI keys from registry: %s", iniRegistryLocation);

	// find root key
	int len = strlen(iniRegistryLocation);
	int slash = 0;
	while(slash < len && iniRegistryLocation[slash] != '\\')
		slash++;

	if(slash == len) {
		Log::Warning("Unable to parse registry location (%s) - keys not included", iniRegistryLocation);
		return;
	}

	HKEY hKey = 0;
	char* rootKey = strdup(iniRegistryLocation);
	rootKey[slash] = 0;
	if(strcmp(rootKey, "HKEY_LOCAL_MACHINE") == 0) {
		hKey = HKEY_LOCAL_MACHINE;
	} else if(strcmp(rootKey, "HKEY_CURRENT_USER") == 0) {
		hKey = HKEY_CURRENT_USER;
	} else if(strcmp(rootKey, "HKEY_CLASSES_ROOT") == 0) {
		hKey = HKEY_CLASSES_ROOT;
	} else {
		Log::Warning("Unrecognized registry root key: %s", rootKey);
		free(rootKey);
		return;
	}
	free(rootKey);

	HKEY subKey;
	if(RegOpenKeyEx(hKey, &iniRegistryLocation[slash+1], 0, KEY_READ, &subKey) != ERROR_SUCCESS) {
		Log::Warning("Unable to open registry location (%s)", iniRegistryLocation);
		return;
	}

	DWORD index = 0;
	char name[MAX_PATH + 2];
	char data[4096];
	DWORD type;
	DWORD nameLen = MAX_PATH;
	DWORD dataLen = 4096;
	name[0] = ':';
	while(RegEnumValue(subKey, index, &name[1], &nameLen, NULL, &type, (LPBYTE) data, &dataLen) == ERROR_SUCCESS) {
		bool hasNamespace = StrContains(&name[1], ':');
		char* key = hasNamespace ? &name[1] : name;
		if(type == REG_DWORD) {
			DWORD val = *((LPDWORD)data);
			sprintf(data, "%d", val);
			iniparser_setstr(ini, key, data);
		} else if(type == REG_SZ && dataLen > 1) {
			iniparser_setstr(ini, key, data);
		}
		nameLen = MAX_PATH;
		dataLen = 4096;
		index++;
	}
}
예제 #13
0
/**********************************************************************************************
 * 函数名	:init_devinfo()
 * 功能	:初始化设备信息
 * 输入	:无
 * 返回值	:0表示正常,负值表示出错
 * 注		:应用程序在刚启动的时候需要调用这个函数从/conf/devinfo.ini中读取系统信息
 *			如果/conf/devinfo.ini不存在,则把设备信息设置成初始值,并返回-1
  **********************************************************************************************/
int init_devinfo(void)
{
	dictionary      *ini=NULL;
    	char *pstr=NULL;
    	int status;
	struct GT_GUID guid;
	int num;
//	struct tm *ptime=NULL;
//	time_t ctime;
	FILE *fp=NULL;
	int  write_file_flag=0;
	
	
	if(init_flag)
		return 0;
	init_flag=1;
	memset((void*)&info,0,sizeof(devinfo_struct));
	ini=iniparser_load_lockfile(DEVINFO_PARA_FILE,1,&fp);
	if(ini==NULL)
	{
		
                printf("init_devinfo() cannot parse ini file file [%s]", DEVINFO_PARA_FILE);
                gtlogerr("init_devinfo() cannot parse ini file file [%s]", DEVINFO_PARA_FILE);
                return -1 ;
        }
       // iniparser_dump_ini(ini,stdout); //将ini文件内容显示在屏幕上,实际使用时没有用,应去掉
	pstr=iniparser_getstring(ini,"devinfo:devguid",def_dev_guid);
	guid=hex2guid(pstr);
	memcpy((char*)info.guid,(char*)(&guid),sizeof(guid));
	guid2hex(guid,info.guid_str);
	
	//设备型号字符串
	pstr=iniparser_getstring(ini,"devinfo:devtypestring",T_GTIP2004_STR);
	info.dvsr=get_dvsr_by_typestr(pstr);
	if(info.dvsr==NULL)
		info.dvsr=get_dvsr_by_typestr(T_GTIP2004_STR);//默认为IP2004

	//设备型号代码
	num=iniparser_getint(ini,"devinfo:devtype",-1);
	if(num!=conv_dev_str2type(pstr))	//pstr存放型号字符串
	{
		iniparser_setint(ini,"devinfo:devtype",conv_dev_str2type(pstr));
		write_file_flag=1;
	}
	

	if(fix_devinfo_file(ini,info.dvsr)==1)
		write_file_flag=1;

	pstr=iniparser_getstring(ini,"devinfo:batchseq","NULL");
	sprintf(info.batch_seq,"%s",pstr);

	pstr=iniparser_getstring(ini,"devinfo:cpuboard","NULL");
	sprintf(info.board_seq,"%s",pstr);
	//	ctime=time(NULL); //	ptime=localtime(&ctime);	//	memcpy((void*)&info.lv_fac_time,(void *)ptime,sizeof(info.lv_fac_time));


	info.lv_fac_time.tm_year=iniparser_getint(ini,"leave_fac:year",2000)-1900;
	info.lv_fac_time.tm_mon=iniparser_getint(ini,"leave_fac:mon",1)-1;
	info.lv_fac_time.tm_mday=iniparser_getint(ini,"leave_fac:day",1);
	info.lv_fac_time.tm_hour=iniparser_getint(ini,"leave_fac:hour",0);
	info.lv_fac_time.tm_min=iniparser_getint(ini,"leave_fac:min",0);
	info.lv_fac_time.tm_sec=iniparser_getint(ini,"leave_fac:sec",0);	
	info.lfc_flag=iniparser_getint(ini,"leave_fac:lfc_flag",-1);

	num=iniparser_getint(ini,"resource:disk_capacity",-1);
	info.disk_capacity=num;
	if(info.disk_capacity<0)
	{
		iniparser_setstr(ini,"resource:disk_capacity","0");
		write_file_flag=1;		
	}	

	if(write_file_flag)
		save_inidict_file(DEVINFO_PARA_FILE,ini,&fp);
	else
	{
		if(fp!=NULL)
		{
			unlock_file(fileno(fp));
			fsync(fileno(fp));
			fclose(fp);
		}	
	}

	iniparser_freedict(ini);
	return 0;
}