int acl_initialize(struct hub_config* config, struct acl_handle* handle) { int ret; memset(handle, 0, sizeof(struct acl_handle)); handle->users = list_create(); handle->users_denied = list_create(); handle->users_banned = list_create(); handle->cids = list_create(); handle->networks = list_create(); handle->nat_override = list_create(); if (!handle->users || !handle->cids || !handle->networks || !handle->users_denied || !handle->users_banned || !handle->nat_override) { LOG_FATAL("acl_initialize: Out of memory"); list_destroy(handle->users); list_destroy(handle->users_denied); list_destroy(handle->users_banned); list_destroy(handle->cids); list_destroy(handle->networks); list_destroy(handle->nat_override); return -1; } if (config) { if (!*config->file_acl) return 0; ret = file_read_lines(config->file_acl, handle, &acl_parse_line); if (ret == -1) return -1; } return 0; }
int plugin_initialize(struct hub_config* config, struct uhub_plugins* handle) { int ret; handle->loaded = list_create(); if (!handle->loaded) return -1; if (config) { if (!*config->file_plugins) return 0; ret = file_read_lines(config->file_plugins, handle, &plugin_parse_line); if (ret == -1) return -1; } return 0; }
int read_config(const char* file, struct hub_config* config, int allow_missing) { int ret; memset(config, 0, sizeof(struct hub_config)); config_defaults(config); ret = file_read_lines(file, config, &config_parse_line); if (ret < 0) { if (allow_missing && ret == -2) { LOG_DUMP("Using default configuration."); } else { return -1; } } return 0; }
static struct acl_data* load_acl(const char* config, struct plugin_handle* handle) { struct acl_data* data = parse_config(config); if (!data) return 0; if (!data->file || !*data->file) { free_acl(data); data = 0; set_error_message(handle, "No configuration file given, missing \"file=<filename>\" configuration option."); return 0; } if (file_read_lines(data->file, data->users, &parse_line) == -1) { fprintf(stderr, "Unable to load %s\n", data->file); set_error_message(handle, "Unable to load file"); } return data; }
int plugin_initialize(struct hub_config* config, struct hub_info* hub) { int ret; hub->plugins->loaded = list_create(); if (!hub->plugins->loaded) return -1; if (config) { if (!*config->file_plugins) return 0; ret = file_read_lines(config->file_plugins, hub, &plugin_parse_line); if (ret == -1) { list_clear(hub->plugins->loaded, hub_free); list_destroy(hub->plugins->loaded); hub->plugins->loaded = 0; return -1; } } return 0; }
void _op_obj_import(void) { t_context *C=ctx_get(); char *filename=C->event->standby_string; if(filename) { // init list OBJECTS=lst_new("lst"); // parse file t_file *file = file_new(filename); free(C->event->standby_string); //C->event->standby_function=NULL; C->event->callback=NULL; file_read(file); file_read_lines(file); //parse words t_link *link; t_link *l; t_word *word; for(link=file->lines->first;link;link=link->next) { t_line *line = link->data; line_read_words(line); } // parse tokens int object_start; int line_object; int is_face; //int tot_object; int tot_vert; int tot_face; int tot_tri; int tot_quad; int tot_indice; char *object_name; //tot_object=0; tot_face=0; tot_quad=0; tot_tri=0; object_start=0; for(link=file->lines->first;link;link=link->next) { // LINE t_line *line = link->data; // RESET is_face=0; for(l=line->words->first;l;l=l->next) { // WORD word=l->data; if(word_equal(word,"o")) { if(object_start) { obj_add(object_name,tot_vert,tot_face,tot_quad,tot_tri); tot_vert=0; tot_face=0; tot_quad=0; tot_tri=0; free(object_name); } else { object_start=1; } tot_vert=0; line_object=1; } else if(line_object) { object_name=(char *)malloc(sizeof(char)*(strlen(word->data)+1)); strcpy(object_name,word->data); line_object=0; } else if(word_equal(word,"v")) { tot_vert++; } else if(word_equal(word,"f")) { tot_face++; is_face=1; tot_indice=0; } else if(is_face) { tot_indice++; } else if(word_equal(word,"usemtl")) { } else if(word_equal(word,"s")) { } } if(is_face) { if(tot_indice==4) { tot_quad++; } else { tot_tri++; } } } // add last object obj_add(object_name,tot_vert,tot_face,tot_quad,tot_tri); // vars int is_data=0; int indice_vertex=0; int indice_face=0; int cursor_tri=0; int cursor_quad=0; int global_cursor=0; int tmp_global_cursor=0; int face[4]; object_start=0; t_token_type token; t_link *link_object; t_obj *obj; for(link=file->lines->first;link;link=link->next) { // LINE t_line *line = link->data; // reset is_data=0; indice_face=0; for(l=line->words->first;l;l=l->next) { // WORD word=l->data; if(word_equal(word,"o")) { token=token_object; if(object_start) { if(link_object->next) link_object=link_object->next; obj=link_object->data; // global cursor global_cursor+=tmp_global_cursor; tmp_global_cursor=obj->tot_vert; } //first else { link_object=OBJECTS->first; obj=link_object->data; object_start=1; tmp_global_cursor=obj->tot_vert; } indice_vertex=0; indice_face=0; cursor_tri=0; cursor_quad=0; } else if(word_equal(word,"v")) { token=token_vertex; } else if(word_equal(word,"f")) { token=token_face; } else if(word_equal(word,"usemtl")) { token=token_material; } else if(word_equal(word,"s")) { token=token_unknown; } else { is_data=1; } if(is_data) { if(token==token_vertex) { obj->verts[indice_vertex]=atof(word->data); indice_vertex++; } else if(token==token_face) { face[indice_face]=atoi(word->data); indice_face++; } } } // store face indice if(token==token_face) { int i; if(indice_face==3) { for(i=0;i<3;i++) { obj->tris[cursor_tri]=face[i]-global_cursor-1; cursor_tri++; } } else { for(i=0;i<4;i++) { obj->quads[cursor_quad]=face[i]-global_cursor-1; cursor_quad++; } } } } // add objects to scene C->scene->store=1; for(link=OBJECTS->first;link;link=link->next) { t_obj *obj = link->data; // new mesh t_node *node_mesh=mesh_make( obj->name, //"me_obj", obj->tot_vert, obj->tot_face, obj->tot_quad, obj->tot_tri, obj->verts, obj->quads, obj->tris); // new object t_node *node_object=object_add("mesh",obj->name); // link t_object *object=node_object->data; object->cls->link(object,node_mesh); } C->scene->store=0; // free obj for(link=OBJECTS->first;link;link=link->next) { t_obj *obj = link->data; obj_free(obj); } } }