/** * load_loal_error: * Used by loal_from_file to handle errors while loading. **/ static LoAL* load_loal_error(FILE* fp, LoAL* loal, AVPL* curr, int linenum, const gchar* fmt, ...) { va_list list; gchar* desc; LoAL* ret = NULL; gchar* err; va_start( list, fmt ); desc = g_strdup_vprintf(fmt, list); va_end( list ); err = g_strdup_printf("Error Loading LoAL from file: in %s at line: %i, %s",loal->name,linenum,desc); ret = new_loal(err); g_free(desc); g_free(err); if (fp) fclose(fp); if (loal) delete_loal(loal,TRUE,TRUE); if (curr) delete_avpl(curr,TRUE); return ret; }
/** * loal_from_file: * @param filename the file containing a loals text representation. * * Given a filename it will attempt to load a loal containing a copy of * the avpls represented in the file. * * Return value: if successful a pointer to the new populated loal, else NULL. * **/ extern LoAL* loal_from_file(gchar* filename) { FILE *fp = NULL; gchar c; int i = 0; guint32 linenum = 1; gchar linenum_buf[MAX_ITEM_LEN]; gchar name[MAX_ITEM_LEN]; gchar value[MAX_ITEM_LEN]; gchar op = '?'; LoAL *loal = new_loal(filename); AVPL* curr = NULL; AVP* avp; enum _load_loal_states { START, BEFORE_NAME, IN_NAME, IN_VALUE, MY_IGNORE } state; #ifndef _WIN32 if (! getuid()) { return load_loal_error(fp,loal,curr,linenum,"MATE Will not run as root"); } #endif state = START; if (( fp = ws_fopen(filename,"r") )) { while(( c = (gchar) fgetc(fp) )){ if ( feof(fp) ) { if ( ferror(fp) ) { report_read_failure(filename,errno); return load_loal_error(fp,loal,curr,linenum,"Error while reading '%f'",filename); } break; } if ( c == '\n' ) { linenum++; } if ( i >= MAX_ITEM_LEN - 1 ) { return load_loal_error(fp,loal,curr,linenum,"Maximum item length exceeded"); } switch(state) { case MY_IGNORE: switch (c) { case '\n': state = START; i = 0; continue; default: continue; } case START: switch (c) { case ' ': case '\t': /* ignore whitespace at line start */ continue; case '\n': /* ignore empty lines */ i = 0; continue; case AVP_NAME_CHAR: state = IN_NAME; i = 0; name[i++] = c; name[i] = '\0'; g_snprintf(linenum_buf,sizeof(linenum_buf),"%s:%u",filename,linenum); curr = new_avpl(linenum_buf); continue; case '#': state = MY_IGNORE; continue; default: return load_loal_error(fp,loal,curr,linenum,"expecting name got: '%c'",c); } case BEFORE_NAME: i = 0; name[0] = '\0'; switch (c) { case '\\': c = (gchar) fgetc(fp); if (c != '\n') ungetc(c,fp); continue; case ' ': case '\t': continue; case AVP_NAME_CHAR: state = IN_NAME; name[i++] = c; name[i] = '\0'; continue; case '\n': loal_append(loal,curr); state = START; continue; default: return load_loal_error(fp,loal,curr,linenum,"expecting name got: '%c'",c); } case IN_NAME: switch (c) { case ';': state = BEFORE_NAME; op = '?'; name[i] = '\0'; value[0] = '\0'; i = 0; avp = new_avp(name,value,op); if (! insert_avp(curr,avp) ) { delete_avp(avp); } continue; case AVP_OP_CHAR: name[i] = '\0'; i = 0; op = c; state = IN_VALUE; continue; case AVP_NAME_CHAR: name[i++] = c; continue; case '\n': return load_loal_error(fp,loal,curr,linenum,"operator expected found new line"); default: return load_loal_error(fp,loal,curr,linenum,"name or match operator expected found '%c'",c); } case IN_VALUE: switch (c) { case '\\': value[i++] = (gchar) fgetc(fp); continue; case ';': state = BEFORE_NAME; value[i] = '\0'; i = 0; avp = new_avp(name,value,op); if (! insert_avp(curr,avp) ) { delete_avp(avp); } continue; case '\n': return load_loal_error(fp,loal,curr,linenum,"';' expected found new line"); default: value[i++] = c; continue; } } } fclose (fp); return loal; } else { report_open_failure(filename,errno,FALSE); return load_loal_error(NULL,loal,NULL,0,"Cannot Open file '%s'",filename); } }
static void analyze_gog_config(gpointer k _U_, gpointer v, gpointer p _U_) { mate_cfg_gog* cfg = v; void* avp_cookie; void* avpl_cookie; AVP* avp; AVPL* avpl; AVPL* gopkey_avpl; AVPL* key_avps; LoAL* gog_keys = NULL; hf_register_info hfri = { NULL, {NULL, NULL, FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL}}; gint* ett; /* create the hf array for this gog */ hfri.p_id = &(cfg->hfid); hfri.hfinfo.name = g_strdup(cfg->name); hfri.hfinfo.abbrev = g_strdup_printf("mate.%s",cfg->name); hfri.hfinfo.blurb = g_strdup_printf("%s Id",cfg->name); hfri.hfinfo.type = FT_UINT32; hfri.hfinfo.display = BASE_DEC; g_array_append_val(matecfg->hfrs,hfri); hfri.p_id = &(cfg->hfid_gog_num_of_gops); hfri.hfinfo.name = "number of GOPs"; hfri.hfinfo.abbrev = g_strdup_printf("mate.%s.NumOfGops",cfg->name); hfri.hfinfo.type = FT_UINT32; hfri.hfinfo.display = BASE_DEC; hfri.hfinfo.blurb = g_strdup_printf("Number of GOPs assigned to this %s",cfg->name); g_array_append_val(matecfg->hfrs,hfri); hfri.p_id = &(cfg->hfid_gog_gopstart); hfri.hfinfo.name = "GopStart frame"; hfri.hfinfo.abbrev = g_strdup_printf("mate.%s.GopStart",cfg->name); hfri.hfinfo.type = FT_FRAMENUM; hfri.hfinfo.display = BASE_NONE; hfri.hfinfo.blurb = g_strdup("The start frame of a GOP"); g_array_append_val(matecfg->hfrs,hfri); hfri.p_id = &(cfg->hfid_gog_gopstop); hfri.hfinfo.name = "GopStop frame"; hfri.hfinfo.abbrev = g_strdup_printf("mate.%s.GopStop",cfg->name); hfri.hfinfo.type = FT_FRAMENUM; hfri.hfinfo.display = BASE_NONE; hfri.hfinfo.blurb = g_strdup("The stop frame of a GOP"); g_array_append_val(matecfg->hfrs,hfri); hfri.p_id = &(cfg->hfid_start_time); hfri.hfinfo.name = g_strdup_printf("%s start time",cfg->name); hfri.hfinfo.abbrev = g_strdup_printf("mate.%s.StartTime",cfg->name); hfri.hfinfo.type = FT_FLOAT; hfri.hfinfo.blurb = g_strdup_printf("Seconds passed since the beginning of capture to the start of this %s",cfg->name); g_array_append_val(matecfg->hfrs,hfri); hfri.p_id = &(cfg->hfid_last_time); hfri.hfinfo.name = g_strdup_printf("%s duration",cfg->name); hfri.hfinfo.abbrev = g_strdup_printf("mate.%s.Duration",cfg->name); hfri.hfinfo.blurb = g_strdup_printf("Time passed between the start of this %s and the last pdu assigned to it",cfg->name); g_array_append_val(matecfg->hfrs,hfri); /* this might become mate.gogname.gopname */ hfri.p_id = &(cfg->hfid_gog_gop); hfri.hfinfo.name = "a GOP"; hfri.hfinfo.abbrev = g_strdup_printf("mate.%s.Gop",cfg->name); hfri.hfinfo.type = FT_STRING; hfri.hfinfo.display = BASE_NONE; hfri.hfinfo.blurb = g_strdup_printf("a GOPs assigned to this %s",cfg->name); g_array_append_val(matecfg->hfrs,hfri); /* index the keys of gog for every gop and insert the avps of the keys to the hfarray */ key_avps = new_avpl(""); avpl_cookie = NULL; while (( avpl = get_next_avpl(cfg->keys,&avpl_cookie) )) { if (! ( gog_keys = g_hash_table_lookup(matecfg->gogs_by_gopname,avpl->name))) { gog_keys = new_loal(avpl->name); g_hash_table_insert(matecfg->gogs_by_gopname,gog_keys->name,gog_keys); } gopkey_avpl = new_avpl_from_avpl(cfg->name, avpl, TRUE); loal_append(gog_keys,gopkey_avpl); avp_cookie = NULL; while (( avp = get_next_avp(avpl,&avp_cookie) )) { if (! g_hash_table_lookup(cfg->my_hfids,avp->n)) { new_attr_hfri(cfg->name,cfg->my_hfids,avp->n); insert_avp(key_avps,avp); } } } /* insert the extra avps to the hfarray */ avp_cookie = NULL; while (( avp = get_next_avp(cfg->extra,&avp_cookie) )) { if (! g_hash_table_lookup(cfg->my_hfids,avp->n)) { new_attr_hfri(cfg->name,cfg->my_hfids,avp->n); } } /* every key_avp ios an extra as well. one day every Member will have its own extras */ merge_avpl(cfg->extra,key_avps,TRUE); analyze_transform_hfrs(cfg->name,cfg->transforms,cfg->my_hfids); ett = &cfg->ett; g_array_append_val(matecfg->ett,ett); ett = &cfg->ett_attr; g_array_append_val(matecfg->ett,ett); ett = &cfg->ett_children; g_array_append_val(matecfg->ett,ett); ett = &cfg->ett_times; g_array_append_val(matecfg->ett,ett); ett = &cfg->ett_gog_gop; g_array_append_val(matecfg->ett,ett); }