Beispiel #1
0
static def_t *
get_operand_def (expr_t *expr, operand_t *op)
{
	if (!op)
		return 0;
	switch (op->op_type) {
		case op_def:
			return op->o.def;
		case op_value:
			return get_value_def (op->o.value, op->type);
		case op_label:
			op->type = ev_short;
			zero_def.type = &type_short;
			return &zero_def;	//FIXME
		case op_temp:
			while (op->o.tempop.alias)
				op = op->o.tempop.alias;
			if (!op->o.tempop.def)
				op->o.tempop.def = temp_def (op->type, op->size);
			return op->o.tempop.def;
		case op_alias:
			return get_operand_def (expr, op->o.alias);
	}
	return 0;
}
//this function requires a init_config_file before to work properly
void store_config(char *section, struct config_handle a_conf_handle){
    //for the moment, only modem is supported
    char *module;
    char *tmp;

    module = get_value_def(section,"module","UNDEFINED",&a_conf_handle);
    if (strcmp(module,"modem")){
        //for the moment, only modem is valid, code to removed when more modules are managed
        LOGE("extra configuration not supported for : %s\n",module);
        return;
    }else{
        LOGI("storing configuration : %s\n",section);
        //pconfig INIT
        pconfig newconf = malloc(sizeof(struct config));
        if(!newconf) {
            LOGE("%s: newconf malloc failed\n", __FUNCTION__);
            return;
        }
        newconf->next   = NULL;
        newconf->eventname = NULL;
        newconf->matching_pattern = NULL;
        //TO IMPROVE replace harcoded value with array in parameter
        //Event name
        tmp = get_value(section,"eventname",&a_conf_handle);
        if (tmp){
            newconf->eventname = malloc(strlen(tmp)+1);/* add 1 for \0 */
            if(!newconf->eventname) {
                LOGE("%s:malloc failed\n", __FUNCTION__);
                free_config(newconf);
                return;
            }
            strncpy(newconf->eventname,tmp,strlen(tmp));
            newconf->eventname[strlen(tmp)]= '\0';
        }else{
            LOGE("wrong configuration for %s on %s \n",section,"eventname");
            free_config(newconf);
            return;
        }
        //matching_pattern
        tmp = get_value(section,"matching_pattern",&a_conf_handle);
        if (tmp){
            newconf->matching_pattern = malloc(strlen(tmp)+1);/* add 1 for \0 */
            if(!newconf->matching_pattern) {
                LOGE("%s: matching pattern malloc failed\n", __FUNCTION__);
                free_config(newconf);
                return;
            }
            strncpy(newconf->matching_pattern,tmp,strlen(tmp));
            newconf->matching_pattern[strlen(tmp)]= '\0';
        }else{
            LOGE("wrong configuration for %s on %s \n",section,"matching_pattern");
            free_config(newconf);
            return;
        }
        //type
        tmp = get_value_def(section,"type","file",&a_conf_handle);
        if (tmp){
            if (!strcmp(tmp,"dir")){
                newconf->type = 1;
            }else{
                newconf->type = 0;
            }
        }else{
            LOGE("wrong configuration for %s on %s \n",section,"type");
            free_config(newconf);
            return;
        }
        //path
        tmp = get_value(section,"path_trigger",&a_conf_handle);
        if (tmp){
            snprintf(newconf->path, sizeof(newconf->path), "%s", tmp);
            LOGI("path loaded :  %s \n",newconf->path);
        }else{
            LOGW("missing configuration for %s on %s \n",section,"path_trigger");
            //path is not mandatory, config is still valid
        }
        //path_linked
        tmp = get_value(section,"path_linked",&a_conf_handle);
        if (tmp){
            snprintf(newconf->path_linked, sizeof(newconf->path_linked), "%s", tmp);
            LOGI("path_linked loaded :  %s \n",newconf->path_linked);
        }else{
        //path_linked is not mandatory, config is still valid
            newconf->path_linked[0] = '\0';
        }

        //event_class
        tmp = get_value_def(section,"event_class","CRASH",&a_conf_handle);
        if (tmp){
            if (!strcmp(tmp,"CRASH")){
                newconf->event_class = 0;
            }else if (!strcmp(tmp,"ERROR")){
                newconf->event_class = 1;
            }else if (!strcmp(tmp,"INFO")){
                newconf->event_class = 2;
            }else{
                newconf->event_class = 0;
            }
        }else{
            //default value is CRASH
            newconf->event_class = 0;
        }
        if (g_first_modem_config==NULL){
            g_first_modem_config = newconf;
        }else{
            g_current_modem_config->next = newconf;
        }
        g_current_modem_config = newconf;
    }
}