Ejemplo n.º 1
0
void Settings::load(const void* _data, uint32_t _len)
{
	if (NULL != m_ini)
	{
		ini_destroy(INI_T(m_ini) );
	}

	if (NULL == _data)
	{
		m_ini = ini_create(m_allocator);
	}
	else
	{
		m_ini = ini_load( (const char*)_data, _len, m_allocator);
	}
}
Ejemplo n.º 2
0
int ini_load_from_buffer(char *content, ini_context_t *context)
{
    int result;

    if ((result=ini_init_context(context)) != 0) {
        return result;
    }

    result = ini_do_load_from_buffer(content, context);
    if (result == 0) {
        ini_sort_items(context);
    }
    else {
        ini_destroy(context);
    }

    return result;
}
Ejemplo n.º 3
0
int ini_load_from_file(const char *filename, ini_context_t *context)
{
    int result;
    char *last_ptr;
    char full_filename[PATH_MAX];
    char old_cwd[PATH_MAX];

    memset(old_cwd, 0, sizeof(old_cwd));
    if (strncasecmp(filename, "http://", 7) != 0) {
        last_ptr = strrchr(filename, '/');
        if (last_ptr != NULL) {
            char path[256];
            int len;

            if (getcwd(old_cwd, sizeof(old_cwd)) == NULL) {
                fprintf(stderr, "file: "__FILE__", line: %d, " 
                        "getcwd fail, errno: %d, " 
                        "error info: %s", 
                        __LINE__, errno, strerror(errno));
                *old_cwd = '\0';
            }

            len = last_ptr - filename;
            if (len > 0) {
                if (len >= sizeof(path)) {
                    len = sizeof(path) - 1;
                }
                memcpy(path, filename, len);
                *(path + len) = '\0';
                if (chdir(path) != 0) {
                    fprintf(stderr, "file: "__FILE__", line: %d, "
                            "chdir to the path of conf " 
                            "file: %s fail, errno: %d, " 
                            "error info: %s", 
                            __LINE__, filename, 
                            errno, strerror(errno));
                    return errno != 0 ? errno : ENOENT;
                }
            }
        }
    }

    if (*filename != '/' && *old_cwd != '\0') {
        snprintf(full_filename, sizeof(full_filename), "%s/%s", 
                old_cwd, filename);
    }
    else {
        snprintf(full_filename, sizeof(full_filename),"%s",filename);
    }

    if ((result=ini_init_context(context)) != 0) {
        return result;
    }

    result = ini_do_load_from_file(full_filename, context);
    if (result == 0) {
        ini_sort_items(context);
    }
    else {
        ini_destroy(context);
    }

    if (*old_cwd != '\0' && chdir(old_cwd) != 0) {
        fprintf(stderr, "file: "__FILE__", line: %d, " 
                "chdir to old path: %s fail, " 
                "errno: %d, error info: %s", 
                __LINE__, old_cwd, errno, strerror(errno));
        return errno != 0 ? errno : ENOENT;
    }

    return result;
}
Ejemplo n.º 4
0
Settings::~Settings()
{
	ini_destroy(INI_T(m_ini) );
}
Ejemplo n.º 5
0
  static bool loadZum1(std::string const& dataIn)
  {
    // Remove the header data
    const std::string data = dataIn.substr(5);

    createDefaultEmpty();
    currentDoc().width_ = 0;
    currentDoc().height_ = 0;

    ini_t * ini = ini_load(data.c_str(), nullptr);

    { // Load columns section
      const int columnsSection = ini_find_section(ini, "columns", 0);
      if (columnsSection != INI_NOT_FOUND)
      {
        const int columnsCount = ini_property_count(ini, columnsSection);
        for (int i = 0; i < columnsCount; ++i)
        {
          const int col = Index::strToColumn(std::string(ini_property_name(ini, columnsSection, i)));
          const int width = std::atoi(ini_property_value(ini, columnsSection, i));

          currentDoc().columnWidth_[col] = width;
        }
      }      
    }

    { // Load data section
      const int dataSection = ini_find_section(ini, "data", 0);
      if (dataSection == INI_NOT_FOUND)
      {
        logError("Could not locate the data section in the document");
        ini_destroy(ini);
        return false;
      }

      const int dataCount = ini_property_count(ini, dataSection);
      
      for (int i = 0; i < dataCount; ++i)
      {
        const Index idx = Index::fromStr(std::string(ini_property_name(ini, dataSection, i)));
        const std::string value = ini_property_value(ini, dataSection, i);

        setText(idx, value);
      }
    }

    { // Load format section
      const int formatSection = ini_find_section(ini, "format", 0);
      if (formatSection != INI_NOT_FOUND)
      {
        const int formatCount = ini_property_count(ini, formatSection);
        for (int i = 0; i < formatCount; ++i)
        {
          const Index idx = Index::fromStr(std::string(ini_property_name(ini, formatSection, i)));
          const std::string value = ini_property_value(ini, formatSection, i);

          getCell(idx).format = parseFormat(value);
        }
      }
    }

    ini_destroy(ini);

    evaluateDocument();
    return true;
  }
Ejemplo n.º 6
0
int32_t SearcherWorkerFactory::initilize(const char *path) 
{
    ini_context_t cfg;
    const ini_section_t *grp = NULL;
    const char *val = NULL;
    const char *seconf = NULL;
    uint32_t nval = 0;
    int32_t ret = 0;
    if (_ready) {
        return KS_SUCCESS;
    }
    if (!_server)
    {
        TERR("initialize _server error.");
        return KS_EFAILED;
    }
    _server->_type = FRAMEWORK::srv_type_searcher;
    ret = ini_load_from_file(path, &cfg);
    if (unlikely(ret != 0)) {
        TERR("initialize SearcherWorkerFactory by `%s' error.", 
                SAFE_STRING(path));
        return KS_EFAILED;
    }
    grp = &cfg.global;
    if (unlikely(!grp)) {
        TERR("invalid config file `%s' for SearcherWorkerFactory.",
                SAFE_STRING(path));
        ini_destroy(&cfg);
        return KS_EFAILED;
    }
    //获得搜索xml文件句柄
    val = ini_get_str_value1(grp, "module_config_path");
    if (val && (val[0] != '\0')) {
        FILE *fp = NULL;
        if ((fp = fopen(val, "r")) == NULL) {
            TERR("模块配置文件 %s 打开出错, 文件可能不存在.\n", val);
            ini_destroy(&cfg);
            return KS_EFAILED;
        }
        _pXMLTree = mxmlLoadFile(NULL, fp, MXML_NO_CALLBACK);
        if (_pXMLTree == NULL) {
            TERR("模块配置文件 %s 格式有错, 请修正您的配置文件.\n", val);
            fclose(fp);
            ini_destroy(&cfg);
            return KS_EFAILED;
        }
        fclose(fp);
    }
    else {
        TERR("search module config path is null");
        ini_destroy(&cfg);
        return KS_EFAILED;
    }
    //各个处理模块的初始化工作
    if (index_lib::init(_pXMLTree) != KS_SUCCESS) {
        TERR("init index lib failed!");
        ini_destroy(&cfg);
        return KS_EFAILED;
    }
    if (_qrewiter.init(_pXMLTree) != KS_SUCCESS){
        TERR("init query rewriter failed!");
        ini_destroy(&cfg);
        return KS_EFAILED;
    }
    if (_qp.init(_pXMLTree) != KS_SUCCESS){
        TERR("init query parser failed!");
        ini_destroy(&cfg);
        return KS_EFAILED;
    }
    if (_is.init(_pXMLTree) != KS_SUCCESS){
        TERR("init index searcher failed!");
        ini_destroy(&cfg);
        return KS_EFAILED;
    }
    if (_stat.init(_pXMLTree) != KS_SUCCESS){
        TWARN("init statistic failed!");
    }
    //get default value of format type
    _ofmt_type = get_outfmt_type(_pXMLTree);
    //get sort config
    val = ini_get_str_value1(grp, "sort_config_path");
    if (val && (val[0] != '\0')) {
        if (_sort.init(val) != KS_SUCCESS) {
            TERR("init sort failed! path = %s\n", val);
            ini_destroy(&cfg);
            return KS_EFAILED;
        }
    }
    else {
        TERR("sort config file is error!");
        ini_destroy(&cfg);
        return KS_EFAILED;
    }
    val = ini_get_str_value1(grp, "update_config_path");
    if (val && (val[0] != '\0')) {
        _pIndexUpdater = new UPDATE::IndexUpdater;
        int32_t nRes = -1;
        if ((nRes = _pIndexUpdater->init(val)) != 0) {
            TERR("init IndexUpdater failed! errno=%d", nRes);
        }
        else if (pthread_create(&_updateTid, NULL, UPDATE::Updater::start, _pIndexUpdater) != 0) {
            TERR("start updater thread failed!");
            ini_destroy(&cfg);
            return KS_EFAILED;
        }
    }
    else {
        TERR("update config path is null");
    }

    //获得detail_module.xml文件句柄
    val = ini_get_str_value1(grp, "detail_module_config_path");
    if (val && (val[0] != '\0')) {
        FILE *fp = NULL;
        if ((fp = fopen(val, "r")) == NULL) {
            TERR("模块配置文件 %s 打开出错, 文件可能不存在.\n", val);
            ini_destroy(&cfg);
            return KS_EFAILED;
        }
        _pXMLTreeDetail= mxmlLoadFile(NULL, fp, MXML_NO_CALLBACK);
        if (_pXMLTreeDetail == NULL) {
            TERR("模块配置文件 %s 格式有错, 请修正您的配置文件.\n", val);
            fclose(fp);
            ini_destroy(&cfg);
            return KS_EFAILED;
        }
        fclose(fp);
        _detail = true;
    }
    else {
        _detail = false;
    }

    if(_detail)
    {
		//初始化detail各模块
    	if(di_detail_init(_pXMLTreeDetail)!=KS_SUCCESS){
    		TERR("di_detail_init failed!");
    		ini_destroy(&cfg);
    		return KS_EFAILED;
    	}
    }

    ini_destroy(&cfg);

    _ready = true;
    return KS_SUCCESS;
}