/* remove node form list */ void list_remove_data(List * L, void * data) { List *p, *tmpcell; p = list_find_prev( L , data ); if ( !list_is_last( p ) ) { /* data is found; delete it */ tmpcell = p->next; p->next = tmpcell->next; /* Bypass deleted cell */ free( tmpcell ); } else { if ( L->next == NULL ) { L->data = NULL; return; } else { /*swap 1st and 2st*/ p = list_get_first_entry( L ); tmpcell = p->next; p->data = tmpcell->data; if (!p->next->next) p->next = NULL; else p->next = tmpcell->next; free( tmpcell ); } } }
List *list_get_entry( List *list, void * data) { List *list_entry; list_entry = list_get_first_entry(list); while (list_entry) { if ( list_entry->data == data ) return list_entry; list_entry = list_get_next_entry( list_entry ); } return NULL; }
void config_list_dump(calipso_config_t *config) { int i = 1; conf_ctx_t *conf; config = list_get_first_entry( config ); while ( config !=NULL ) { conf = list_get_entry_value( config ); printf("%4d. %-20s => %-40s @ %s\n", i, conf->option, conf->value, conf->block); config = list_get_next_entry( config ); i++; } }
void calipso_hook_dump(int hook) { void *p; int i = 0; List *hook_ptr; List *list_entry; hook_ptr = calipso_get_m_hook(hook); list_entry = list_get_first_entry(hook_ptr); while (list_entry != NULL) { p = list_get_entry_value(list_entry); printf("<[%d] nr_hook [%s], h_addr: %p>\n", i, get_hook_byid(hook), p); list_entry = list_get_next_entry(list_entry); i++; } }
static int mod_http_init_config(calipso_config_t * config) { struct http_conf_ctx * ctx = NULL; for(config = list_get_first_entry( config ); config != NULL; config = list_get_next_entry( config )) { conf_ctx_t *c = list_get_entry_value( config ); if(c && c->block) { if(!strcasecmp(c->block, CONF_BLOCK_CTX)) { int state = config_get_state_ctx(c); /* lazzy loading */ if(CTX_BLOCK_BEGIN == state) { if(!ctx) { ctx = xmalloc(sizeof(*ctx)); config_parse_run(ctx, NULL, NULL); } } if(CTX_BLOCK_END == state) { mod_http_init_server_ctx(ctx); if(ctx) { free(ctx); ctx = NULL; } } if(ctx) { config_parse_run(ctx, c->option, c->value); } } } } if(ctx) { free(ctx); ctx=NULL; } return CPO_OK; }
const char *config_get_option(calipso_config_t *config, const char *opt , const char *section) { conf_ctx_t *cfg; config = list_get_first_entry( config ); while ( config ) { cfg = list_get_entry_value(config); if(!section) { if (!OPTCMP( cfg->option , opt) ) { return (const char *)cfg->value; } } else if(cfg->block) { if (!OPTCMP(cfg->block, section) && !OPTCMP( cfg->option , opt)) { return (const char *)cfg->value; } } config = list_get_next_entry( config ); } return (NULL); }
void config_unalloc(calipso_config_t * config) { conf_ctx_t *c; calipso_config_t * p; config = list_get_first_entry( config ); p = config; while ( config !=NULL ) { c = list_get_entry_value( config ); if(c) { if(c->block) free(c->block); if(c->option) free(c->option); if(c->value); free(c->value); free(c); } config = list_get_next_entry( config ); } list_delete( p ); free(p); }
int calipso_trigger_hook(int hook, ...) { int ret; List *p; List *list_entry; calipso_client_t *client; calipso_request_t *request; va_list ap; va_start(ap, hook); p = calipso_get_m_hook(hook); if (/* p->size == 0 && */p == NULL && hook != HOOK_REPLY) { va_end(ap); TRACE("BUG: bad hook\n"); return (0); } //printf("TODO: triger hook: %d %p\n",hook,p); switch (hook) { case HOOK_LOAD_DYNAMIC: case HOOK_CONFIGURE: case HOOK_INIT: case HOOK_CHROOT: case HOOK_PRIVILEGES: case HOOK_END: list_entry = list_get_first_entry(p); while (list_entry) { if (list_entry->data) ((int (*)(void)) list_get_entry_value(list_entry))(); list_entry = list_get_next_entry(list_entry); } break; case HOOK_CONNECT: case HOOK_DISCONNECT: list_entry = list_get_first_entry(p); client = va_arg(ap, calipso_client_t *); while (list_entry) { if (list_entry->data) ((int (*)(calipso_client_t *)) list_get_entry_value(list_entry))( client); list_entry = list_get_next_entry(list_entry); } break; case HOOK_REQUEST: case HOOK_TRANSLATE: case HOOK_RESOURCE: case HOOK_MIME: case HOOK_LOG: list_entry = list_get_first_entry(p); request = va_arg(ap, calipso_request_t *); while (list_entry) { if (list_entry->data) ((int (*)(calipso_request_t *)) list_get_entry_value(list_entry))( request); list_entry = list_get_next_entry(list_entry); } break; case HOOK_ACCESS_CHECK: list_entry = list_get_first_entry(p); request = va_arg(ap, calipso_request_t *); /* NEEDS_FIX - no need to loop through all callbacks if one fails */ while (list_entry) { if (list_entry->data) ((int (*)(calipso_request_t *)) list_get_entry_value(list_entry))( request); list_entry = list_get_next_entry(list_entry); } break; case HOOK_REPLY: request = va_arg(ap, calipso_request_t *); ret = calipso_request_handler(request); va_end(ap); return (ret); } //!switch va_end(ap); return CPO_OK; }