int redis_load_conf() { Ul_confdata *pconf; pconf=ul_initconf(DEFAULT_CONF_NUM); if(!pconf) { printf("\n[Fatal Error] init config file error! \n"); return FAIL; } memset(&redis_conf,0,sizeof(redis_conf)); strcpy(redis_conf.confpath,DEFAULT_CONFPATH_REDIS); strcpy(redis_conf.conffile,DEFAULT_CONFFILE_REDIS); int ret=ul_readconf(redis_conf.confpath,redis_conf.conffile,pconf); if(ret<0){ printf("\n[Fatal Error] load config file error! path[%s] file[%s] \n",redis_conf.confpath,redis_conf.conffile); return FAIL; } if (ul_getconfstr(pconf, "ip", redis_conf.redis_conf.ip)) { printf("Conf: redis server ip: %s\n",redis_conf.redis_conf.ip); ul_writelog(UL_LOG_NOTICE, "Conf: redis server ip: %s", redis_conf.redis_conf.ip); } else { strcpy( redis_conf.redis_conf.ip,DEFAULT_REDIS_SERVER_IP); ul_writelog(UL_LOG_NOTICE, "Conf: redis server ip is: %s DEFAULT", DEFAULT_REDIS_SERVER_IP); } if (ul_getconfint(pconf, "port",&( redis_conf.redis_conf.port))) { ul_writelog(UL_LOG_NOTICE, "Conf: redis port: %d", redis_conf.redis_conf.port); } else { redis_conf.redis_conf.port = DEFAULT_REDIS_PORT; ul_writelog(UL_LOG_NOTICE, "Conf: redis port is: %d DEFAULT", DEFAULT_REDIS_PORT); } if (ul_getconfint(pconf, "conn_timeout",(int *)&( redis_conf.redis_conf.conn_timeout.tv_sec))) { ul_writelog(UL_LOG_NOTICE, "Conf: redis conn_timeout: %d", redis_conf.redis_conf.conn_timeout.tv_sec); } else { redis_conf.redis_conf.conn_timeout.tv_sec = DEFAULT_CONN_TIMEOUT; ul_writelog(UL_LOG_NOTICE, "Conf: redis conn_timeout is: %d DEFAULT", DEFAULT_CONN_TIMEOUT); } if (ul_getconfint(pconf, "rdwr_timeout",(int *)&( redis_conf.redis_conf.rdwr_timeout.tv_sec))) { ul_writelog(UL_LOG_NOTICE, "Conf: redis rdwr_timeout: %d", redis_conf.redis_conf.rdwr_timeout.tv_sec); } else { redis_conf.redis_conf.rdwr_timeout.tv_sec = DEFAULT_RDWR_TIMEOUT; ul_writelog(UL_LOG_NOTICE, "Conf: redis rdwr_timeout is: %d DEFAULT", DEFAULT_RDWR_TIMEOUT); } ul_freeconf(pconf); pconf=NULL; return OK; }
int GetAddr::init(const char* path,const char* file) { Ul_confdata *pconf; pconf = ul_initconf(CONF_NUM); int ret; ret = ul_readconf(path, file, pconf); if (ret < 0) { FATAL_LOG_NLP("load config file error!"); return -1; } char buf[100]; string loc_map_dict; ul_getconfstr(pconf, "loc_map_path", buf); loc_map_dict=buf; string adcode_map_dict; ul_getconfstr(pconf, "adcode_map_path", buf); adcode_map_dict=buf; string suffix_dict; ul_getconfstr(pconf, "suffix_path", buf); suffix_dict=buf; string extendMap_dict; ul_getconfstr(pconf, "extend_dict_path", buf); extendMap_dict=buf; ul_freeconf(pconf); ifstream fin1; fin1.open(loc_map_dict.c_str()); if( !fin1 ) { FATAL_LOG_NLP("open loc_map_dict failed"); return -1; } ifstream fin2; fin2.open(adcode_map_dict.c_str()); if( !fin2 ) { FATAL_LOG_NLP("open adcode_map_dict failed"); return -1; } ifstream fin3; fin3.open(suffix_dict.c_str()); if( !fin3 ) { FATAL_LOG_NLP("open suffix_dict failed"); return -1; } ifstream fin4; fin4.open(extendMap_dict.c_str()); if( !fin4 ) { FATAL_LOG_NLP("open extendMap_dict failed, errno:%d, dir:%s", errno, extendMap_dict.c_str()); return -1; } tree = init_trie_tree(); if(!tree) { FATAL_LOG_NLP("init_trie_tree failed"); return -1; } string line; string word_1,word_2; string pattern = "\t"; string::size_type pos = 0; trie_node *node; while(getline(fin1,line)) { pos = line.find(pattern); if (pos != -1) { word_1 = line.substr(0,pos); node = add_word(tree, word_1.c_str()); if(!node) { FATAL_LOG_NLP("add_word failed"); return -1; } ++node->preq; } } while(getline(fin2,line)) { pos = line.find(pattern); if (pos != -1) { word_2 = line.substr(pos+1,line.length()); node = add_word(tree, word_2.c_str()); if(!node) { FATAL_LOG_NLP("add_word failed"); return -1; } ++node->preq; } } while(getline(fin3,line)) { filter_dict.push_back(line); } while(getline(fin4,line)) { pos = line.find(pattern); if (pos != -1) { word_1 = line.substr(0,pos); node = add_word(tree, word_1.c_str()); if(!node) { FATAL_LOG_NLP("add_word failed"); return -1; } ++node->preq; } } fin1.close(); fin2.close(); fin3.close(); fin4.close(); return 0; }