Beispiel #1
0
void load_config() {
    char *value;
    char msg[100];
    msg[0] = 0;

    /* ini_r is a structure that holds state to make this reader
     * reentrant */
    struct read_ini *ini_r = NULL;

    /* "test.ini" will be parsed into "ini" */

    char* root = (*SYS_RootDir)();
    char filename[100];
    filename[0] = 0;
    strcat(filename, root);
    strcat(filename, "\\PlugIns\\");
    strcat(filename, "saveall.ini");
    struct ini *ini = read_ini(&ini_r, filename);

    /* pretty printing of ini structure */
    ini_pp(ini);

    /* retrieve a value */
    value = ini_get_value(ini, "section", "basedir");
    if(value != NULL) {
        strcat(msg, "value is\n");
        strcat(msg, value);
        strcpy(basedir, value);
//		ShowMessage(msg);
    } else {
//		ShowMessage("cannot get key");
    }

    /* free memory */
    destroy_ini(ini);
    cleanup_readini(ini_r);
}
Beispiel #2
0
/** 
 *@brief  获取配置
 *@return success 0 failed -1
 */
int get_config()
{
	//读取配置文件内的配置
	int fd;
	char buf[1024];
	if( init_ini(CONFIG_FILE_NAME, &fd, buf, 1024) ){
		return -1;
	}
	if( get_ini(buf, "sql_name", cgv_sql_name) ){
		return -1;
	}
	if( get_ini(buf, "sql_user", cgv_sql_user) ){
		return -1;
	}
	if( get_ini(buf, "sql_pass", cgv_sql_pass) ){
		return -1;
	}
	if( get_ini(buf, "report_addr", cgv_report_addr) ){
		return -1;
	}
	char temp[32];
	if( get_ini(buf, "report_port", temp) ){
		return -1;
	}
	cgv_report_port = atoi( temp );
	if( get_ini(buf, "authenticate_port", temp) ){
		return -1;
	}
	cgv_authenticate_port = atoi( temp );
	destroy_ini( fd );

	//打印配置文件中读取的配置
	xyprintf(0, "** O(∩ _∩ )O ~~ Get config of config file is success!");
	xyprintf(0, "sql_name = %s\n\
			sql_user = %s\n\
			sql_pass = %s",
			cgv_sql_name, cgv_sql_user, cgv_sql_pass);
	xyprintf(0, "report_addr = %s\n\
			report_port = %u\n\
			authenticate_port = %u\n",
			cgv_report_addr, cgv_report_port, cgv_authenticate_port);


	//获取数据库内的配置内容
	wt_sql_handle *handle = malloc(sizeof(wt_sql_handle));
	memset(handle, 0, sizeof(wt_sql_handle));
	
	if( wt_sql_init(handle, cgv_sql_name, cgv_sql_user, cgv_sql_pass) ){			//数据库初始化
		xyprintf(0, "SQL_INIT_ERROR:%s %s %d -- Datebase connect error!", __func__, __FILE__, __LINE__);
		goto ERR;
	}
    
	if( wt_sql_get_gg(handle) ){
		goto STR_ERR;
	}
	if( wt_sql_get_gg2(handle) ){
		goto STR_ERR;
	}
    if( wt_sql_get_other(handle) ){
		goto STR_ERR;
	}
    if( wt_sql_get_white(handle) ){
		goto STR_ERR;
	}
    if( wt_sql_get_weixin(handle) ){
		goto STR_ERR;
	}
    if( wt_sql_get_upurl(handle) ){
		goto STR_ERR;
	}

	wt_sql_destroy(handle);
	free(handle);
	return 0;

STR_ERR:
	wt_sql_destroy(handle);
	free(handle);
ERR:
	return -1;
}