void *hash_table_open(struct ci_lookup_table *table) { struct text_table_entry *e; struct text_table *text_table=file_table_open(table); if (!text_table) return NULL; /* build the hash table*/ ci_debug_printf(7, "Will build a hash for %d rows of data\n", text_table->rows); text_table->hash_table = ci_hash_build(text_table->rows, table->key_ops, table->allocator); if(!text_table->hash_table) { file_table_close(table); return NULL; } e=text_table->entries; while(e) { ci_hash_add(text_table->hash_table,e->key, e); e = e->next; } return text_table; }
void service(int client_socket) { struct xxx_connection *client; char *e; int eof; gfarm_int32_t request; char buffer[GFARM_INT32STRLEN]; client = file_table[client_socket].conn; e = xxx_proto_recv(client, 0, &eof, "i", &request); if (eof) { file_table_close(client_socket); return; } if (e != NULL) { gflog_warning("request number", e); return; } switch (request) { case GFJ_PROTO_LOCK_REGISTER: e = gfj_server_lock_register(client); break; case GFJ_PROTO_UNLOCK_REGISTER: e = gfj_server_unlock_register(client); break; case GFJ_PROTO_REGISTER: e = gfj_server_register(client_socket); break; case GFJ_PROTO_UNREGISTER: e = gfj_server_unregister(client_socket); break; case GFJ_PROTO_REGISTER_NODE: e = gfj_server_register_node(client); break; case GFJ_PROTO_LIST: e = gfj_server_list(client); break; case GFJ_PROTO_INFO: e = gfj_server_info(client); break; case GFJ_PROTO_HOSTINFO: e = gfj_server_hostinfo(client); break; default: sprintf(buffer, "%d", request); gflog_warning("unknown request", buffer); } if (e == NULL) e = xxx_proto_flush(client); if (e != NULL) file_table_close(client_socket); }
void regex_table_close(struct ci_lookup_table *table) { #ifdef HAVE_REGEX /*just call the file_table_close:*/ file_table_close(table); #else ci_debug_printf(1,"regex lookup tables are not supported on this system!\n"); return NULL; #endif }
void hash_table_close(struct ci_lookup_table *table) { struct text_table *text_table = (struct text_table *)table->data; if (text_table && text_table->hash_table) { /*destroy the hash table */ ci_hash_destroy(text_table->hash_table); text_table->hash_table = NULL; } /*... and then call the file_table_close:*/ file_table_close(table); }
int load_text_table(char *filename, struct ci_lookup_table *table) { FILE *f; struct text_table_entry *e, *l = NULL; int rows, ret; struct text_table *text_table = (struct text_table *)table->data; if ((f = fopen(filename, "r")) == NULL) { ci_debug_printf(1, "Error opening file: %s\n", filename); return 0; } rows = 0; if (text_table->entries != NULL) /*if table is not empty try to find the last element*/ for (l = text_table->entries; l->next != NULL; l = l->next); while(0 < (ret=read_row(f, table->cols, &e, table))) { if (e) { e->next = NULL; if(text_table->entries==NULL) { text_table->entries = e; l = e; } else { l->next = e; l = e; } } rows++; } fclose(f); if(ret==-1) { ci_debug_printf(1, "Error loading file table %s: parse error on line %d\n", filename, rows+1); file_table_close(table); return 0; } text_table->rows = rows; return 1; }