struct auth_cfg_st *auth_cfg_create(void) { int ret, i; mutex_init(&s_auth_cfg.auth_cfg_mutex); spin_lock_init(&s_auth_cfg.lock); s_auth_cfg.bypass = 1; s_auth_cfg.ap = ap_create(); s_auth_cfg.ap3rd = ap_3rd_create(); for (i = 0; i < sizeof(s_attri_item) / sizeof(struct attri_item); i++) { ret = sysfs_create_file(&THIS_MODULE->mkobj.kobj, &s_attri_item[i].item.attr); if (ret) { logerr("sysfs_create_file %d fail\n", i); goto error_flag; } s_attri_item[i].init = 1; } return &s_auth_cfg; error_flag: for (i = 0; i < sizeof(s_attri_item) / sizeof(struct attri_item); i++) { if (s_attri_item[i].init) { sysfs_remove_file(&THIS_MODULE->mkobj.kobj, &s_attri_item[i].item.attr); s_attri_item[i].init = 0; } } ap_destroy(s_auth_cfg.ap); mutex_destroy(&s_auth_cfg.auth_cfg_mutex); return NULL; }
void auth_cfg_destroy(struct auth_cfg_st *acfg) { int i; for (i = 0; i < sizeof(s_attri_item) / sizeof(struct attri_item); i++) { if (s_attri_item[i].init) { sysfs_remove_file(&THIS_MODULE->mkobj.kobj, &s_attri_item[i].item.attr); s_attri_item[i].init = 0; } } ap_destroy(acfg->ap); ap_3rd_destroy(acfg->ap3rd); mutex_destroy(acfg->auth_cfg_mutex); }
/* * this thread listens to incoming_wdp list * and then routs messages to proper wapbox */ static void wdp_to_wapboxes(void *arg) { List *route_info; AddrPar *ap; Boxc *conn; Msg *msg; int i; gwlist_add_producer(flow_threads); gwlist_add_producer(wapbox_list); route_info = gwlist_create(); while(bb_status != BB_DEAD) { gwlist_consume(suspended); /* block here if suspended */ if ((msg = gwlist_consume(incoming_wdp)) == NULL) break; gw_assert(msg_type(msg) == wdp_datagram); conn = route_msg(route_info, msg); if (conn == NULL) { warning(0, "Cannot route message, discard it"); msg_destroy(msg); continue; } gwlist_produce(conn->incoming, msg); } debug("bb", 0, "wdp_to_wapboxes: destroying lists"); while((ap = gwlist_extract_first(route_info)) != NULL) ap_destroy(ap); gw_assert(gwlist_len(route_info) == 0); gwlist_destroy(route_info, NULL); gwlist_lock(wapbox_list); for(i=0; i < gwlist_len(wapbox_list); i++) { conn = gwlist_get(wapbox_list, i); gwlist_remove_producer(conn->incoming); conn->alive = 0; } gwlist_unlock(wapbox_list); gwlist_remove_producer(wapbox_list); gwlist_remove_producer(flow_threads); }
void strpool_cleanup(StrPool *p) { int i; if(!p) return; for(i = 0; i < DEREF(p->dict,n_elts); ++i) { HashNode *n = p->dict->elts + i; if(!n->key) continue; if(!str_in_block(p,n->key)) continue; free(n->key); } for(i = 0; i < ap_size(&p->strblocks); ++i) free(p->strblocks[i]); ap_destroy(&p->strblocks,NULL); free_safe(p->dict); p->dict = 0; }
static Boxc *route_msg(List *route_info, Msg *msg) { AddrPar *ap; Boxc *conn, *best; int i, b, len; ap = gwlist_search(route_info, msg, cmp_route); if (ap == NULL) { debug("bb.boxc", 0, "Did not find previous routing info for WDP, " "generating new"); route: if (gwlist_len(wapbox_list) == 0) return NULL; gwlist_lock(wapbox_list); /* take random wapbox from list, and then check all wapboxes * and select the one with lowest load level - if tied, the first * one */ len = gwlist_len(wapbox_list); b = gw_rand() % len; best = gwlist_get(wapbox_list, b); for(i = 0; i < gwlist_len(wapbox_list); i++) { conn = gwlist_get(wapbox_list, (i+b) % len); if (conn != NULL && best != NULL) if (conn->load < best->load) best = conn; } if (best == NULL) { warning(0, "wapbox_list empty!"); gwlist_unlock(wapbox_list); return NULL; } conn = best; conn->load++; /* simulate new client until we get new values */ ap = gw_malloc(sizeof(AddrPar)); ap->address = octstr_duplicate(msg->wdp_datagram.source_address); ap->port = msg->wdp_datagram.source_port; ap->wapboxid = conn->id; gwlist_produce(route_info, ap); gwlist_unlock(wapbox_list); } else conn = gwlist_search(wapbox_list, ap, cmp_boxc); if (conn == NULL) { /* routing failed; wapbox has disappeared! * ..remove routing info and re-route */ debug("bb.boxc", 0, "Old wapbox has disappeared, re-routing"); gwlist_delete_equal(route_info, ap); ap_destroy(ap); goto route; } return conn; }