void reg_tm_cback(struct cell *t, int type, struct tmcb_params *ps) { reg_tm_cb_t *cb_param; int statuscode = 0; int ret; time_t now; struct reg_tm_cback_data tm_cback_data; if(ps==NULL || ps->rpl==NULL) { LM_ERR("wrong ps parameter\n"); return; } if(ps->param==NULL || *ps->param==NULL) { LM_ERR("null callback parameter\n"); return; } cb_param = (reg_tm_cb_t *)*ps->param; if(cb_param->uac == NULL) { LM_ERR("null record\n"); return; } statuscode = ps->code; now = time(0); LM_DBG("tm [%p] notification cb for %s [%d] reply at [%d]\n", t, (ps->rpl==FAKED_REPLY)?"FAKED_REPLY":"", statuscode, (unsigned int)now); if(statuscode<200) return; /* Initialize slinkedl run traversal data */ tm_cback_data.t = t; tm_cback_data.ps = ps; tm_cback_data.cb_param = cb_param; tm_cback_data.now = now; lock_get(®_htable[cb_param->hash_index].lock); ret = slinkedl_traverse(reg_htable[cb_param->hash_index].p_list, &run_reg_tm_cback, (void*)&tm_cback_data, NULL); lock_release(®_htable[cb_param->hash_index].lock); if (ret==0) { LM_ERR("record [%p] not found on hash index [%d]\n", cb_param->uac, cb_param->hash_index); } return; }
/** * Performs lookup values for given keys. * For GET requests, we will use the libmicrohttpd's * internal API: MHD_lookup_connection_value(). * For POST requests, we will retrieve the value from * the slinkedl_list that was created and populated by * the post_iterator(). * * @param connection Pointer to the MHD_Connection * @param key The key for which we need to retrieve * the value. * @param con_cls This is a pointer to the slinkedl_list * that was passed back and forth via * several callback between the application * and the libmicrohttpd library. * @param val Pointer to the value that we are looking * for. */ void httpd_lookup_arg(void *connection, const char *key, void *con_cls, str *val) { slinkedl_list_t *list = (slinkedl_list_t*)con_cls; if (val) { if (list==NULL) { val->s = (char *)MHD_lookup_connection_value( (struct MHD_Connection *)connection, MHD_GET_ARGUMENT_KIND, key); if (val->s) val->len = strlen(val->s); else val->len = 0; } else { slinkedl_traverse(list, &httpd_get_val, (void *)key, val); } } else { LM_ERR("NULL holder for requested val\n"); } return; }
static struct mi_root* mi_reg_list(struct mi_root* cmd, void* param) { struct mi_root *rpl_tree; int i, ret; rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN); if (rpl_tree==NULL) return NULL; for(i=0; i<reg_hsize; i++) { lock_get(®_htable[i].lock); ret = slinkedl_traverse(reg_htable[i].p_list, &run_mi_reg_list, (void*)rpl_tree, NULL); lock_release(®_htable[i].lock); if (ret<0) { LM_ERR("Unable to create reply\n"); free_mi_tree(rpl_tree); return NULL; } } return rpl_tree; }
void timer_check(unsigned int ticks, void* param) { unsigned int i=hash_index; char *p; int len, ret; time_t now; str str_now = {NULL, 0}; struct timer_check_data t_check_data; now = time(0); p = int2str((unsigned long)(time(0)), &len); if (p && len>0) { str_now.s = (char *)pkg_malloc(len); if (str_now.s) { memcpy(str_now.s, p, len); str_now.len = len; } else { LM_ERR("oom\n"); return; } } /* Initialize slinkedl run traversal data */ t_check_data.now = now; t_check_data.s_now = &str_now; LM_DBG("checking ... [%d] on htable[%d]\n", (unsigned int)now, i); lock_get(®_htable[i].lock); ret = slinkedl_traverse(reg_htable[i].p_list, &run_timer_check, (void*)&t_check_data, NULL); if (ret<0) LM_CRIT("Unexpected return code %d\n", ret); lock_release(®_htable[i].lock); if (str_now.s) {pkg_free(str_now.s);} hash_index = (++i)%reg_hsize; return; }