struct t_gui_hotlist * gui_hotlist_add (struct t_gui_buffer *buffer, enum t_gui_hotlist_priority priority, struct timeval *creation_time) { struct t_gui_hotlist *new_hotlist, *ptr_hotlist; int i, count[GUI_HOTLIST_NUM_PRIORITIES]; const char *away; if (!buffer || !gui_add_hotlist) return NULL; /* do not add core buffer if upgrading */ if (weechat_upgrading && (buffer == gui_buffer_search_main ())) return NULL; /* do not add buffer if it is displayed and away is not set */ away = hashtable_get (buffer->local_variables, "away"); if ((buffer->num_displayed > 0) && ((!away || !away[0]) || !CONFIG_BOOLEAN(config_look_hotlist_add_buffer_if_away))) return NULL; if (priority > GUI_HOTLIST_MAX) priority = GUI_HOTLIST_MAX; /* check if priority is OK according to buffer notify level value */ if (!gui_hotlist_check_buffer_notify (buffer, priority)) return NULL; /* init count */ for (i = 0; i < GUI_HOTLIST_NUM_PRIORITIES; i++) { count[i] = 0; } ptr_hotlist = gui_hotlist_search (gui_hotlist, buffer); if (ptr_hotlist) { /* return if priority is greater or equal than the one to add */ if (ptr_hotlist->priority >= priority) { ptr_hotlist->count[priority]++; gui_hotlist_changed_signal (); return ptr_hotlist; } /* * if buffer is present with lower priority: save counts, remove it * and go on */ memcpy (count, ptr_hotlist->count, sizeof (ptr_hotlist->count)); gui_hotlist_free (&gui_hotlist, &last_gui_hotlist, ptr_hotlist); } new_hotlist = malloc (sizeof (*new_hotlist)); if (!new_hotlist) { log_printf (_("Error: not enough memory to add a buffer to " "hotlist")); return NULL; } new_hotlist->priority = priority; if (creation_time) { memcpy (&(new_hotlist->creation_time), creation_time, sizeof (*creation_time)); } else gettimeofday (&(new_hotlist->creation_time), NULL); new_hotlist->buffer = buffer; memcpy (new_hotlist->count, count, sizeof (new_hotlist->count)); new_hotlist->count[priority]++; new_hotlist->next_hotlist = NULL; new_hotlist->prev_hotlist = NULL; gui_hotlist_add_hotlist (&gui_hotlist, &last_gui_hotlist, new_hotlist); gui_hotlist_changed_signal (); return new_hotlist; }
//----------------------------------------------------------------------------- rlc_union_t* rrc_rlc_add_rlc ( const module_id_t enb_mod_idP, const module_id_t ue_mod_idP, const frame_t frameP, const eNB_flag_t enb_flagP, const srb_flag_t srb_flagP, const MBMS_flag_t MBMS_flagP, const rb_id_t rb_idP, const logical_chan_id_t chan_idP, const rlc_mode_t rlc_modeP) { //----------------------------------------------------------------------------- hash_key_t key = HASHTABLE_QUESTIONABLE_KEY_VALUE; hashtable_rc_t h_rc; rlc_union_t *rlc_union_p = NULL; #ifdef Rel10 rlc_mbms_id_t *mbms_id_p = NULL; logical_chan_id_t lcid = 0; #endif #ifdef OAI_EMU if (enb_flagP) { AssertFatal ((enb_mod_idP >= oai_emulation.info.first_enb_local) && (oai_emulation.info.nb_enb_local > 0), "eNB module id is too low (%u/%d)!\n", enb_mod_idP, oai_emulation.info.first_enb_local); AssertFatal ((enb_mod_idP < (oai_emulation.info.first_enb_local + oai_emulation.info.nb_enb_local)) && (oai_emulation.info.nb_enb_local > 0), "eNB module id is too high (%u/%d)!\n", enb_mod_idP, oai_emulation.info.first_enb_local + oai_emulation.info.nb_enb_local); AssertFatal (ue_mod_idP < NB_UE_INST, "UE module id is too high (%u/%d)!\n", ue_mod_idP, oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); } else { AssertFatal (ue_mod_idP < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local), "UE module id is too high (%u/%d)!\n", ue_mod_idP, oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); AssertFatal (ue_mod_idP >= oai_emulation.info.first_ue_local, "UE module id is too low (%u/%d)!\n", ue_mod_idP, oai_emulation.info.first_ue_local); } #endif if (MBMS_flagP == FALSE) { AssertFatal (rb_idP < NB_RB_MAX, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MAX); AssertFatal (chan_idP < RLC_MAX_LC, "LC id is too high (%u/%d)!\n", chan_idP, RLC_MAX_LC); } #ifdef Rel10 if (MBMS_flagP == TRUE) { if (enb_flagP) { lcid = rlc_mbms_enb_get_lcid_by_rb_id(enb_mod_idP,rb_idP); LOG_I(RLC, "[Frame %05u] lcid %d = rlc_mbms_enb_get_lcid_by_rb_id(enb_mod_idP %u, rb_idP %u)\n", frameP,lcid, enb_mod_idP, rb_idP); mbms_id_p = &rlc_mbms_lcid2service_session_id_eNB[enb_mod_idP][lcid]; //LG 2014-04-15rlc_mbms_lcid2service_session_id_eNB[enb_mod_idP][lcid].service_id = 0; //LG 2014-04-15rlc_mbms_lcid2service_session_id_eNB[enb_mod_idP][lcid].session_id = 0; //LG 2014-04-15rlc_mbms_rbid2lcid_eNB[enb_mod_idP][rb_idP] = RLC_LC_UNALLOCATED; } else { lcid = rlc_mbms_ue_get_lcid_by_rb_id(ue_mod_idP,rb_idP); mbms_id_p = &rlc_mbms_lcid2service_session_id_ue[ue_mod_idP][lcid]; //LG 2014-04-15rlc_mbms_lcid2service_session_id_eNB[ue_mod_idP][lcid].service_id = 0; //LG 2014-04-15rlc_mbms_lcid2service_session_id_eNB[ue_mod_idP][lcid].session_id = 0; //LG 2014-04-15rlc_mbms_rbid2lcid_ue[ue_mod_idP][rb_idP] = RLC_LC_UNALLOCATED; } key = RLC_COLL_KEY_MBMS_VALUE(enb_mod_idP, ue_mod_idP, enb_flagP, mbms_id_p->service_id, mbms_id_p->session_id); } else #endif { key = RLC_COLL_KEY_VALUE(enb_mod_idP, ue_mod_idP, enb_flagP, rb_idP, srb_flagP); } h_rc = hashtable_get(rlc_coll_p, key, (void**)&rlc_union_p); if (h_rc == HASH_TABLE_OK) { LOG_W(RLC, "[Frame %05u][%s][RLC_RRC][INST %u/%u][%s %u] rrc_rlc_add_rlc , already exist %s\n", frameP, (enb_flagP) ? "eNB" : "UE", enb_mod_idP, ue_mod_idP, (srb_flagP) ? "SRB" : "DRB", rb_idP, (srb_flagP) ? "SRB" : "DRB"); AssertFatal(rlc_union_p->mode == rlc_modeP, "Error rrc_rlc_add_rlc , already exist but RLC mode differ"); return rlc_union_p; } else if (h_rc == HASH_TABLE_KEY_NOT_EXISTS) { rlc_union_p = calloc(1, sizeof(rlc_union_t)); h_rc = hashtable_insert(rlc_coll_p, key, rlc_union_p); if (h_rc == HASH_TABLE_OK) { #ifdef Rel10 if (MBMS_flagP == TRUE) { LOG_I(RLC, "[Frame %05u][%s][RLC_RRC][INST %u/%u] RLC service id %u session id %u rrc_rlc_add_rlc\n", frameP, (enb_flagP) ? "eNB" : "UE", enb_mod_idP, ue_mod_idP, mbms_id_p->service_id, mbms_id_p->session_id); } else #endif { LOG_I(RLC, "[Frame %05u][%s][RLC_RRC][INST %u/%u][%s %u] rrc_rlc_add_rlc %s\n", frameP, (enb_flagP) ? "eNB" : "UE", enb_mod_idP, ue_mod_idP, (srb_flagP) ? "SRB" : "DRB", rb_idP, (srb_flagP) ? "SRB" : "DRB"); } rlc_union_p->mode = rlc_modeP; return rlc_union_p; } else { LOG_E(RLC, "[Frame %05u][%s][RLC_RRC][INST %u/%u][%s %u] rrc_rlc_add_rlc FAILED %s\n", frameP, (enb_flagP) ? "eNB" : "UE", enb_mod_idP, ue_mod_idP, (srb_flagP) ? "SRB" : "DRB", rb_idP, (srb_flagP) ? "SRB" : "DRB"); free(rlc_union_p); rlc_union_p = NULL; return NULL; } } else { LOG_E(RLC, "[Frame %05u][%s][RLC_RRC][INST %u/%u][%s %u] rrc_rlc_add_rlc , INTERNAL ERROR %s\n", frameP, (enb_flagP) ? "eNB" : "UE", enb_mod_idP, ue_mod_idP, (srb_flagP) ? "SRB" : "DRB", rb_idP, (srb_flagP) ? "SRB" : "DRB"); } return NULL; }
int hdata_set (struct t_hdata *hdata, void *pointer, const char *name, const char *value) { struct t_hdata_var *var; char **ptr_string, *error; long number; long unsigned int ptr; int rc; if (!hdata->update_pending) return 0; var = hashtable_get (hdata->hash_var, name); if (!var) return 0; if (!var->update_allowed) return 0; switch (var->type) { case WEECHAT_HDATA_OTHER: break; case WEECHAT_HDATA_CHAR: *((char *)(pointer + var->offset)) = (value) ? value[0] : '\0'; return 1; break; case WEECHAT_HDATA_INTEGER: error = NULL; number = strtol (value, &error, 10); if (error && !error[0]) { *((int *)(pointer + var->offset)) = (int)number; return 1; } break; case WEECHAT_HDATA_LONG: error = NULL; number = strtol (value, &error, 10); if (error && !error[0]) { *((long *)(pointer + var->offset)) = number; return 1; } break; case WEECHAT_HDATA_STRING: ptr_string = (char **)(pointer + var->offset); if (*ptr_string) free (*ptr_string); *ptr_string = (value) ? strdup (value) : NULL; return 1; break; case WEECHAT_HDATA_SHARED_STRING: ptr_string = (char **)(pointer + var->offset); if (*ptr_string) string_shared_free (*ptr_string); *ptr_string = (value) ? (char *)string_shared_get (value) : NULL; return 1; break; case WEECHAT_HDATA_POINTER: rc = sscanf (value, "%lx", &ptr); if ((rc != EOF) && (rc != 0)) { *((void **)(pointer + var->offset)) = (void *)ptr; return 1; } break; case WEECHAT_HDATA_TIME: error = NULL; number = strtol (value, &error, 10); if (error && !error[0]) { *((time_t *)(pointer + var->offset)) = (time_t)number; return 1; } break; case WEECHAT_HDATA_HASHTABLE: break; } return 0; }
//----------------------------------------------------------------------------- rlc_op_status_t rrc_rlc_remove_rlc ( const protocol_ctxt_t* const ctxt_pP, const srb_flag_t srb_flagP, const MBMS_flag_t MBMS_flagP, const rb_id_t rb_idP) { //----------------------------------------------------------------------------- logical_chan_id_t lcid = 0; hash_key_t key = HASHTABLE_NOT_A_KEY_VALUE; hashtable_rc_t h_rc; rlc_union_t *rlc_union_p = NULL; #ifdef Rel10 rlc_mbms_id_t *mbms_id_p = NULL; #endif #ifdef OAI_EMU CHECK_CTXT_ARGS(ctxt_pP) #endif #ifdef Rel10 if (MBMS_flagP == TRUE) { if (ctxt_pP->enb_flag) { lcid = rlc_mbms_enb_get_lcid_by_rb_id(ctxt_pP->module_id,rb_idP); mbms_id_p = &rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lcid]; rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lcid].service_id = 0; rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lcid].session_id = 0; rlc_mbms_rbid2lcid_ue[ctxt_pP->module_id][rb_idP] = RLC_LC_UNALLOCATED; } else { lcid = rlc_mbms_ue_get_lcid_by_rb_id(ctxt_pP->module_id,rb_idP); mbms_id_p = &rlc_mbms_lcid2service_session_id_ue[ctxt_pP->module_id][lcid]; rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lcid].service_id = 0; rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lcid].session_id = 0; rlc_mbms_rbid2lcid_ue[ctxt_pP->module_id][rb_idP] = RLC_LC_UNALLOCATED; } key = RLC_COLL_KEY_MBMS_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, mbms_id_p->service_id, mbms_id_p->session_id); } else #endif { key = RLC_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP); } AssertFatal (rb_idP < NB_RB_MAX, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MAX); h_rc = hashtable_get(rlc_coll_p, key, (void**)&rlc_union_p); if (h_rc == HASH_TABLE_OK) { h_rc = hashtable_remove(rlc_coll_p, key); LOG_D(RLC, PROTOCOL_CTXT_FMT"[%s %u] RELEASED %s\n", PROTOCOL_CTXT_ARGS(ctxt_pP), (srb_flagP) ? "SRB" : "DRB", rb_idP, (srb_flagP) ? "SRB" : "DRB"); } else if (h_rc == HASH_TABLE_KEY_NOT_EXISTS) { LOG_D(RLC, PROTOCOL_CTXT_FMT"[%s %u] RELEASE : RLC NOT FOUND %s\n", PROTOCOL_CTXT_ARGS(ctxt_pP), (srb_flagP) ? "SRB" : "DRB", rb_idP, (srb_flagP) ? "SRB" : "DRB"); } else { LOG_E(RLC, PROTOCOL_CTXT_FMT"[%s %u] RELEASE : INTERNAL ERROR %s\n", PROTOCOL_CTXT_ARGS(ctxt_pP), (srb_flagP) ? "SRB" : "DRB", rb_idP, (srb_flagP) ? "SRB" : "DRB"); } return RLC_OP_STATUS_OK; }
//----------------------------------------------------------------------------- rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t * const ctxt_pP, const SRB_ToAddModList_t * const srb2add_listP, const DRB_ToAddModList_t * const drb2add_listP, const DRB_ToReleaseList_t * const drb2release_listP #if defined(Rel10) ,const PMCH_InfoList_r9_t * const pmch_InfoList_r9_pP #endif ) { //----------------------------------------------------------------------------- rb_id_t rb_id = 0; logical_chan_id_t lc_id = 0; DRB_Identity_t drb_id = 0; DRB_Identity_t* pdrb_id = NULL; long int cnt = 0; const SRB_ToAddMod_t *srb_toaddmod_p = NULL; const DRB_ToAddMod_t *drb_toaddmod_p = NULL; rlc_union_t *rlc_union_p = NULL; hash_key_t key = HASHTABLE_NOT_A_KEY_VALUE; hashtable_rc_t h_rc; #if defined(Rel10) int i, j; MBMS_SessionInfoList_r9_t *mbms_SessionInfoList_r9_p = NULL; MBMS_SessionInfo_r9_t *MBMS_SessionInfo_p = NULL; mbms_session_id_t mbms_session_id; mbms_service_id_t mbms_service_id; DL_UM_RLC_t dl_um_rlc; #endif LOG_D(RLC, PROTOCOL_CTXT_FMT" CONFIG REQ ASN1 \n", PROTOCOL_CTXT_ARGS(ctxt_pP)); #ifdef OAI_EMU CHECK_CTXT_ARGS(ctxt_pP) #endif if (srb2add_listP != NULL) { for (cnt=0; cnt<srb2add_listP->list.count; cnt++) { rb_id = srb2add_listP->list.array[cnt]->srb_Identity; lc_id = rb_id + 2; LOG_D(RLC, "Adding SRB %d, rb_id %d\n",srb2add_listP->list.array[cnt]->srb_Identity,rb_id); srb_toaddmod_p = srb2add_listP->list.array[cnt]; if (srb_toaddmod_p->rlc_Config) { switch (srb_toaddmod_p->rlc_Config->present) { case SRB_ToAddMod__rlc_Config_PR_NOTHING: break; case SRB_ToAddMod__rlc_Config_PR_explicitValue: switch (srb_toaddmod_p->rlc_Config->choice.explicitValue.present) { case RLC_Config_PR_NOTHING: break; case RLC_Config_PR_am: if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, rb_id, lc_id, RLC_MODE_AM) != NULL) { config_req_rlc_am_asn1 ( ctxt_pP, SRB_FLAG_YES, &srb_toaddmod_p->rlc_Config->choice.explicitValue.choice.am, rb_id); } else { LOG_E(RLC, PROTOCOL_CTXT_FMT" ERROR IN ALLOCATING SRB %d \n", PROTOCOL_CTXT_ARGS(ctxt_pP), rb_id); } break; case RLC_Config_PR_um_Bi_Directional: if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, rb_id, lc_id, RLC_MODE_UM) != NULL) { config_req_rlc_um_asn1( ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, UNUSED_PARAM_MBMS_SESSION_ID, UNUSED_PARAM_MBMS_SERVICE_ID, &srb_toaddmod_p->rlc_Config->choice.explicitValue.choice.um_Bi_Directional.ul_UM_RLC, &srb_toaddmod_p->rlc_Config->choice.explicitValue.choice.um_Bi_Directional.dl_UM_RLC, rb_id); } else { LOG_E(RLC, PROTOCOL_CTXT_FMT" ERROR IN ALLOCATING SRB %d \n", PROTOCOL_CTXT_ARGS(ctxt_pP), rb_id); } break; case RLC_Config_PR_um_Uni_Directional_UL: if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, rb_id, lc_id, RLC_MODE_UM) != NULL) { config_req_rlc_um_asn1( ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, UNUSED_PARAM_MBMS_SESSION_ID, UNUSED_PARAM_MBMS_SERVICE_ID, &srb_toaddmod_p->rlc_Config->choice.explicitValue.choice.um_Uni_Directional_UL.ul_UM_RLC, NULL, rb_id); } else { LOG_E(RLC, PROTOCOL_CTXT_FMT" ERROR IN ALLOCATING SRB %d \n", PROTOCOL_CTXT_ARGS(ctxt_pP), rb_id); } break; case RLC_Config_PR_um_Uni_Directional_DL: if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, rb_id, lc_id, RLC_MODE_UM) != NULL) { config_req_rlc_um_asn1( ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, UNUSED_PARAM_MBMS_SESSION_ID, UNUSED_PARAM_MBMS_SERVICE_ID, NULL, &srb_toaddmod_p->rlc_Config->choice.explicitValue.choice.um_Uni_Directional_DL.dl_UM_RLC, rb_id); } else { LOG_E(RLC, PROTOCOL_CTXT_FMT" ERROR IN ALLOCATING SRB %d \n", PROTOCOL_CTXT_ARGS(ctxt_pP), rb_id); } break; default: LOG_E(RLC, PROTOCOL_CTXT_FMT" UNKNOWN RLC CONFIG %d \n", PROTOCOL_CTXT_ARGS(ctxt_pP), srb_toaddmod_p->rlc_Config->choice.explicitValue.present); break; } break; case SRB_ToAddMod__rlc_Config_PR_defaultValue: #warning TO DO SRB_ToAddMod__rlc_Config_PR_defaultValue if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, rb_id, lc_id, RLC_MODE_UM) != NULL) { config_req_rlc_um_asn1( ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, UNUSED_PARAM_MBMS_SESSION_ID, UNUSED_PARAM_MBMS_SERVICE_ID, NULL, // TO DO DEFAULT CONFIG NULL, // TO DO DEFAULT CONFIG rb_id); } else { LOG_D(RLC, PROTOCOL_CTXT_FMT" ERROR IN ALLOCATING SRB %d \n", PROTOCOL_CTXT_ARGS(ctxt_pP), rb_id); } break; default: ; } } } } if (drb2add_listP != NULL) { for (cnt=0; cnt<drb2add_listP->list.count; cnt++) { drb_toaddmod_p = drb2add_listP->list.array[cnt]; drb_id = drb_toaddmod_p->drb_Identity; lc_id = drb_id + 2; LOG_D(RLC, "Adding DRB %d, lc_id %d\n",drb_id,lc_id); if (drb_toaddmod_p->rlc_Config) { switch (drb_toaddmod_p->rlc_Config->present) { case RLC_Config_PR_NOTHING: break; case RLC_Config_PR_am: if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_NO, MBMS_FLAG_NO, drb_id, lc_id, RLC_MODE_AM) != NULL) { config_req_rlc_am_asn1 ( ctxt_pP, SRB_FLAG_NO, &drb_toaddmod_p->rlc_Config->choice.am, drb_id); } break; case RLC_Config_PR_um_Bi_Directional: if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_NO, MBMS_FLAG_NO, drb_id, lc_id, RLC_MODE_UM) != NULL) { config_req_rlc_um_asn1( ctxt_pP, SRB_FLAG_NO, MBMS_FLAG_NO, UNUSED_PARAM_MBMS_SESSION_ID, UNUSED_PARAM_MBMS_SERVICE_ID, &drb_toaddmod_p->rlc_Config->choice.um_Bi_Directional.ul_UM_RLC, &drb_toaddmod_p->rlc_Config->choice.um_Bi_Directional.dl_UM_RLC, drb_id); } break; case RLC_Config_PR_um_Uni_Directional_UL: if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_NO, MBMS_FLAG_NO, drb_id, lc_id, RLC_MODE_UM) != NULL) { config_req_rlc_um_asn1( ctxt_pP, SRB_FLAG_NO, MBMS_FLAG_NO, UNUSED_PARAM_MBMS_SESSION_ID, UNUSED_PARAM_MBMS_SERVICE_ID, &drb_toaddmod_p->rlc_Config->choice.um_Uni_Directional_UL.ul_UM_RLC, NULL, drb_id); } break; case RLC_Config_PR_um_Uni_Directional_DL: if (rrc_rlc_add_rlc (ctxt_pP, SRB_FLAG_NO, MBMS_FLAG_NO, drb_id, lc_id, RLC_MODE_UM) != NULL) { config_req_rlc_um_asn1( ctxt_pP, SRB_FLAG_NO, MBMS_FLAG_NO, UNUSED_PARAM_MBMS_SESSION_ID, UNUSED_PARAM_MBMS_SERVICE_ID, NULL, &drb_toaddmod_p->rlc_Config->choice.um_Uni_Directional_DL.dl_UM_RLC, drb_id); } break; default: LOG_W(RLC, PROTOCOL_CTXT_FMT"[RB %u] unknown drb_toaddmod_p->rlc_Config->present \n", PROTOCOL_CTXT_ARGS(ctxt_pP), drb_id); } } } } if (drb2release_listP != NULL) { for (cnt=0; cnt<drb2release_listP->list.count; cnt++) { pdrb_id = drb2release_listP->list.array[cnt]; rrc_rlc_remove_rlc( ctxt_pP, SRB_FLAG_NO, MBMS_FLAG_NO, *pdrb_id); } } #if defined(Rel10) if (pmch_InfoList_r9_pP != NULL) { for (i=0; i<pmch_InfoList_r9_pP->list.count; i++) { mbms_SessionInfoList_r9_p = &(pmch_InfoList_r9_pP->list.array[i]->mbms_SessionInfoList_r9); for (j=0; j<mbms_SessionInfoList_r9_p->list.count; j++) { MBMS_SessionInfo_p = mbms_SessionInfoList_r9_p->list.array[j]; mbms_session_id = MBMS_SessionInfo_p->sessionId_r9->buf[0]; lc_id = mbms_session_id; mbms_service_id = MBMS_SessionInfo_p->tmgi_r9.serviceId_r9.buf[2]; //serviceId is 3-octet string // can set the mch_id = i if (ctxt_pP->enb_flag) { rb_id = (mbms_service_id * maxSessionPerPMCH ) + mbms_session_id;//+ (maxDRB + 3) * MAX_MOBILES_PER_ENB; // 1 rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lc_id].service_id = mbms_service_id; rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lc_id].session_id = mbms_session_id; rlc_mbms_enb_set_lcid_by_rb_id(ctxt_pP->module_id,rb_id,lc_id); } else { rb_id = (mbms_service_id * maxSessionPerPMCH ) + mbms_session_id; // + (maxDRB + 3); // 15 rlc_mbms_lcid2service_session_id_ue[ctxt_pP->module_id][lc_id].service_id = mbms_service_id; rlc_mbms_lcid2service_session_id_ue[ctxt_pP->module_id][lc_id].session_id = mbms_session_id; rlc_mbms_ue_set_lcid_by_rb_id(ctxt_pP->module_id,rb_id,lc_id); } key = RLC_COLL_KEY_MBMS_VALUE(ctxt_pP->module_id, ctxt_pP->module_id, ctxt_pP->enb_flag, mbms_service_id, mbms_session_id); h_rc = hashtable_get(rlc_coll_p, key, (void**)&rlc_union_p); if (h_rc == HASH_TABLE_KEY_NOT_EXISTS) { rlc_union_p = rrc_rlc_add_rlc ( ctxt_pP, SRB_FLAG_NO, MBMS_FLAG_YES, rb_id, lc_id, RLC_MODE_UM); AssertFatal(rlc_union_p != NULL, "ADD MBMS RLC UM FAILED"); } LOG_D(RLC, PROTOCOL_CTXT_FMT" CONFIG REQ MBMS ASN1 LC ID %u RB ID %u SESSION ID %u SERVICE ID %u\n", PROTOCOL_CTXT_ARGS(ctxt_pP), lc_id, rb_id, mbms_session_id, mbms_service_id ); dl_um_rlc.sn_FieldLength = SN_FieldLength_size5; dl_um_rlc.t_Reordering = T_Reordering_ms0; config_req_rlc_um_asn1 ( ctxt_pP, SRB_FLAG_NO, MBMS_FLAG_YES, mbms_session_id, mbms_service_id, NULL, &dl_um_rlc, rb_id); } } } #endif LOG_D(RLC, PROTOCOL_CTXT_FMT" CONFIG REQ ASN1 END \n", PROTOCOL_CTXT_ARGS(ctxt_pP)); return RLC_OP_STATUS_OK; }
char * eval_hdata_get_value (struct t_hdata *hdata, void *pointer, const char *path) { char *value, *old_value, *var_name, str_value[128], *pos; const char *ptr_value, *hdata_name; int type; struct t_hashtable *hashtable; value = NULL; var_name = NULL; /* NULL pointer? return empty string */ if (!pointer) return strdup (""); /* no path? just return current pointer as string */ if (!path || !path[0]) { snprintf (str_value, sizeof (str_value), "0x%lx", (long unsigned int)pointer); return strdup (str_value); } /* * look for name of hdata, for example in "window.buffer.full_name", the * hdata name is "window" */ pos = strchr (path, '.'); if (pos > path) var_name = string_strndup (path, pos - path); else var_name = strdup (path); if (!var_name) goto end; /* search type of variable in hdata */ type = hdata_get_var_type (hdata, var_name); if (type < 0) goto end; /* build a string with the value or variable */ switch (type) { case WEECHAT_HDATA_CHAR: snprintf (str_value, sizeof (str_value), "%c", hdata_char (hdata, pointer, var_name)); value = strdup (str_value); break; case WEECHAT_HDATA_INTEGER: snprintf (str_value, sizeof (str_value), "%d", hdata_integer (hdata, pointer, var_name)); value = strdup (str_value); break; case WEECHAT_HDATA_LONG: snprintf (str_value, sizeof (str_value), "%ld", hdata_long (hdata, pointer, var_name)); value = strdup (str_value); break; case WEECHAT_HDATA_STRING: case WEECHAT_HDATA_SHARED_STRING: ptr_value = hdata_string (hdata, pointer, var_name); value = (ptr_value) ? strdup (ptr_value) : NULL; break; case WEECHAT_HDATA_POINTER: pointer = hdata_pointer (hdata, pointer, var_name); snprintf (str_value, sizeof (str_value), "0x%lx", (long unsigned int)pointer); value = strdup (str_value); break; case WEECHAT_HDATA_TIME: snprintf (str_value, sizeof (str_value), "%ld", (long)hdata_time (hdata, pointer, var_name)); value = strdup (str_value); break; case WEECHAT_HDATA_HASHTABLE: pointer = hdata_hashtable (hdata, pointer, var_name); if (pos) { /* * for a hashtable, if there is a "." after name of hdata, * get the value for this key in hashtable */ hashtable = pointer; ptr_value = hashtable_get (hashtable, pos + 1); if (ptr_value) { switch (hashtable->type_values) { case HASHTABLE_INTEGER: snprintf (str_value, sizeof (str_value), "%d", *((int *)ptr_value)); value = strdup (str_value); break; case HASHTABLE_STRING: value = strdup (ptr_value); break; case HASHTABLE_POINTER: case HASHTABLE_BUFFER: snprintf (str_value, sizeof (str_value), "0x%lx", (long unsigned int)ptr_value); value = strdup (str_value); break; case HASHTABLE_TIME: snprintf (str_value, sizeof (str_value), "%ld", (long)(*((time_t *)ptr_value))); value = strdup (str_value); break; case HASHTABLE_NUM_TYPES: break; } } } else { snprintf (str_value, sizeof (str_value), "0x%lx", (long unsigned int)pointer); value = strdup (str_value); } break; } /* * if we are on a pointer and that something else is in path (after "."), * go on with this pointer and remaining path */ if ((type == WEECHAT_HDATA_POINTER) && pos) { hdata_name = hdata_get_var_hdata (hdata, var_name); if (!hdata_name) goto end; hdata = hook_hdata_get (NULL, hdata_name); old_value = value; value = eval_hdata_get_value (hdata, pointer, (pos) ? pos + 1 : NULL); if (old_value) free (old_value); } end: if (var_name) free (var_name); return value; }
int main(int argc, const char **argv) { hashtable_p table = NULL; int size = START_CAPACITY; float best_utilization = 0.0; float tmp_utilization = 0.0; (void)argc; (void)argv; pdebug(DEBUG_INFO,"Starting hashtable tests."); set_debug_level(DEBUG_SPEW); /* create a hashtable */ pdebug(DEBUG_INFO,"Creating hashtable with at least capacity %d.", START_CAPACITY); table = hashtable_create(START_CAPACITY); assert(table != NULL); assert(hashtable_capacity(table) >= START_CAPACITY); assert(hashtable_entries(table) == 0); size = hashtable_capacity(table); /* insert tests. */ for(int i=1; i <= INSERT_ENTRIES; i++) { int rc = hashtable_put(table, i, (void*)(intptr_t)i); assert(rc == PLCTAG_STATUS_OK); if(hashtable_capacity(table) != size) { pdebug(DEBUG_INFO, "Hashtable expanded from %d entries to %d entries after inserting %d entries.", size, hashtable_capacity(table), hashtable_entries(table)); size = hashtable_capacity(table); } } tmp_utilization = (float)(hashtable_entries(table))/(float)(hashtable_capacity(table)); pdebug(DEBUG_INFO, "Current table utilization %f%%", tmp_utilization*100.0); if(tmp_utilization > best_utilization) { best_utilization = tmp_utilization; } assert(hashtable_entries(table) == INSERT_ENTRIES); pdebug(DEBUG_INFO, "Hash table has correct number of used entries, %d.", hashtable_entries(table)); pdebug(DEBUG_INFO, "Hashtable using %d entries of %d entries capacity.", hashtable_entries(table), hashtable_capacity(table)); /* retrieval tests. */ pdebug(DEBUG_INFO, "Running retrieval tests."); for(int i=INSERT_ENTRIES; i > 0; i--) { void *res = hashtable_get(table, i); assert(res != NULL); assert(i == (int)(intptr_t)res); } /* insert + delete tests. */ pdebug(DEBUG_INFO, "Running combined insert and delete tests."); for(int i=INSERT_ENTRIES+1; i < (INSERT_ENTRIES*2); i++) { int rc = hashtable_put(table, i, (void*)(intptr_t)i); void *res = NULL; assert(rc == PLCTAG_STATUS_OK); res = hashtable_remove(table, (i - INSERT_ENTRIES)); assert((i - INSERT_ENTRIES) == (int)(intptr_t)res); } assert(hashtable_entries(table) == INSERT_ENTRIES); pdebug(DEBUG_INFO, "Hash table has correct number of used entries, %d.", hashtable_entries(table)); tmp_utilization = (float)(hashtable_entries(table))/(float)(hashtable_capacity(table)); pdebug(DEBUG_INFO, "Current table utilization %f%%", tmp_utilization*100.0); if(tmp_utilization > best_utilization) { best_utilization = tmp_utilization; } pdebug(DEBUG_INFO, "Best table utilization %f%%", best_utilization*100.0); hashtable_destroy(table); pdebug(DEBUG_INFO, "Done."); }
int _read(t_ext2* ext2,int fd, void* buf,u32 count) { struct t_process_context* current_process_context; u32 i; u32 block_offset; u32 first_inode_block; u32 first_data_offset; u32 last_inode_block; u32 inode_block; u32 lba; u32 indirect_lba; u32 allocated_indirect_block; u32 sector_count; u32 byte_to_read; u32 byte_read; u32 byte_count; t_inode* inode; char* iob_indirect_block; char* iob_data_block; byte_read=0; byte_to_read=count; iob_indirect_block=kmalloc(BLOCK_SIZE); iob_data_block=kmalloc(BLOCK_SIZE); CURRENT_PROCESS_CONTEXT(current_process_context) inode=hashtable_get(current_process_context->file_desc,fd); if (inode==NULL) { return -1; } first_inode_block=inode->file_offset/BLOCK_SIZE; first_data_offset=inode->file_offset%BLOCK_SIZE; last_inode_block=(inode->file_offset+count)/BLOCK_SIZE; allocated_indirect_block=0; for (i=first_inode_block;i<=last_inode_block;i++) { if (i>11) { if (!allocated_indirect_block) { indirect_lba=FROM_BLOCK_TO_LBA(inode->i_block[12]); sector_count=BLOCK_SIZE/SECTOR_SIZE; READ(sector_count,indirect_lba,iob_indirect_block); allocated_indirect_block=1; } READ_DWORD(&iob_indirect_block[4*(i-12)],inode_block); lba=FROM_BLOCK_TO_LBA(inode_block); } else { lba=FROM_BLOCK_TO_LBA(inode->i_block[i]); } if (byte_to_read>=BLOCK_SIZE) { byte_count=BLOCK_SIZE; byte_to_read-=BLOCK_SIZE; } else { byte_count=byte_to_read; byte_to_read=0; } sector_count=BLOCK_SIZE/SECTOR_SIZE; READ(sector_count,lba,iob_data_block); kmemcpy(buf,iob_data_block+first_data_offset,byte_count); inode->file_offset+=byte_count; buf+=byte_count; byte_read+=byte_count; } kfree(iob_indirect_block); kfree(iob_data_block); return byte_read; }
exchange_type_t *lookup_exchange_type(amqp_bytes_t name) { exchange_type_t *t = NULL; hashtable_get(&all_exchange_types, name, (void **) &t); return t; }
int gui_chat_hsignal_quote_line_cb (void *data, const char *signal, struct t_hashtable *hashtable) { const char *time, *prefix, *message, *date, *nick, *tags; unsigned int length_time, length_prefix, length_message, length; char *str, *ptr_str_time, *custom_nick_prefix; static char str_time[128]; struct tm local_time; int tags_count, i, custom_nick_ok = 0; char **tags_array; /* make C compiler happy */ (void) data; if (!gui_current_window->buffer->input) return WEECHAT_RC_OK; if (strstr(signal, "time")) { if (!CONFIG_STRING(config_look_quote_time_format) || !CONFIG_STRING(config_look_quote_time_format)[0]) time = hashtable_get (hashtable, "_chat_line_time"); else { date = hashtable_get (hashtable, "_chat_line_date"); if (date && date[0] && strptime (date, "%s", &local_time) && mktime(&local_time) != 0) { str_time[0] = '\0'; strftime (str_time, sizeof (str_time), CONFIG_STRING(config_look_quote_time_format), &local_time); length_time = strlen(str_time); ptr_str_time = malloc (length_time); strncpy (ptr_str_time, str_time, length_time); time = ptr_str_time; } else time = NULL; } } else time = NULL; prefix = (strstr (signal, "prefix")) ? hashtable_get (hashtable, "_chat_line_prefix") : NULL; message = hashtable_get (hashtable, "_chat_line_message"); if (!message) return WEECHAT_RC_OK; length_time = (time) ? strlen (time) : 0; length_prefix = (prefix) ? strlen (prefix) : 0; length_message = strlen (message); nick = hashtable_get (hashtable, "_chat_line_nick"); tags = hashtable_get (hashtable, "_chat_line_tags"); if (prefix && nick && nick[0] && CONFIG_STRING(config_look_quote_nick_format) && CONFIG_STRING(config_look_quote_nick_format)[0]) { tags_array = string_split (tags, ",", 0, 0, &tags_count); if (tags_array) { for (i = 0; i < tags_count; i++) { if (!strcmp (tags_array[i], "irc_privmsg")) custom_nick_ok = 1; else if (!strcmp (tags_array[i], "irc_action")) { custom_nick_ok = 0; break; } } string_free_split(tags_array); if (custom_nick_ok) { custom_nick_prefix = malloc (255); length_prefix = snprintf (custom_nick_prefix, sizeof (custom_nick_prefix), CONFIG_STRING(config_look_quote_nick_format), nick); if (length_prefix >= sizeof (custom_nick_prefix)) { custom_nick_prefix = realloc (custom_nick_prefix, length_prefix + 1); snprintf (custom_nick_prefix, length_prefix, CONFIG_STRING(config_look_quote_nick_format), nick); } } } } length = length_time + 1 + length_prefix + 1 + strlen (CONFIG_STRING(config_look_prefix_suffix)) + 1 + length_message + 1 + 1; str = malloc (length); if (str) { if (custom_nick_ok) { snprintf (str, length, "%s%s%s%s%s ", (time) ? time : "", (time) ? " " : "", (prefix) ? custom_nick_prefix : "", (prefix) ? " " : "", message); } else { snprintf (str, length, "%s%s%s%s%s%s%s ", (time) ? time : "", (time && !(prefix && prefix[0] == ' ')) ? " " : "", (prefix) ? prefix : "", (prefix && prefix[0]) ? " " : "", ((time || prefix) && CONFIG_BOOLEAN(config_look_quote_show_prefix_suffix)) ? CONFIG_STRING(config_look_prefix_suffix) : "", ((time || prefix) && CONFIG_BOOLEAN(config_look_quote_show_prefix_suffix) && CONFIG_STRING(config_look_prefix_suffix) && CONFIG_STRING(config_look_prefix_suffix)[0]) ? " " : "", message); } gui_input_insert_string (gui_current_window->buffer, str, -1); gui_input_text_changed_modifier_and_signal (gui_current_window->buffer, 1, /* save undo */ 1); /* stop completion */ free (str); } return WEECHAT_RC_OK; }
int _write(t_ext2* ext2,int fd, const void *buf,u32 count) { u32 i; u32 first_inode_block; u32 first_data_offset; u32 last_inode_block; u32 last_data_offset; u32 inode_block; u32 lba; u32 indirect_lba; u32 indirect_old_lba; u32 sector_count; u32 byte_to_read; u32 byte_read; u32 byte_count; u32 load_block; u32 update_indirct_block; t_inode* inode; char* iob_data_block; char* iob_indirect_block; u32 update_indirect_block; u32 byte_written; u32 byte_to_write; iob_data_block=kmalloc(BLOCK_SIZE); iob_indirect_block=kmalloc(BLOCK_SIZE); kfillmem(iob_data_block,0,BLOCK_SIZE); kfillmem(iob_indirect_block,0,BLOCK_SIZE); update_indirect_block=FALSE; byte_written=0; inode=hashtable_get(((struct t_process_context*)system.process_info->current_process)->file_desc,fd); first_inode_block=inode->file_offset/BLOCK_SIZE; first_data_offset=inode->file_offset%BLOCK_SIZE; last_inode_block=(inode->file_offset+count)/BLOCK_SIZE; last_data_offset=(inode->file_offset+count)%BLOCK_SIZE; byte_to_write=count; if (last_inode_block>=12) { if (inode->i_block[12]==0) { inode->i_block[12]=alloc_indirect_block(ext2,inode); } else { sector_count=BLOCK_SIZE/SECTOR_SIZE; READ(sector_count,inode->i_block[12],iob_indirect_block); } } for (i=first_inode_block;i<=last_inode_block;i++) { if ((i==first_inode_block && first_data_offset!=0) || (i==last_inode_block && last_data_offset!=0)) { load_block=1; if (i>12) { if (iob_indirect_block[i-12]==0) { iob_indirect_block[i-12]=alloc_block(ext2,inode,i); load_block=0; update_indirect_block=TRUE; } lba=iob_indirect_block[i-12]; } else { if (inode->i_block[i]==0) { inode->i_block[i]=alloc_block(ext2,inode,i); load_block=0; } lba=inode->i_block[i]; } if (load_block) { sector_count=BLOCK_SIZE/SECTOR_SIZE; _read_28_ata(sector_count,lba,iob_data_block); if (i==first_inode_block) { iob_data_block+=first_data_offset; byte_count=BLOCK_SIZE-first_data_offset; byte_to_write-=byte_count; } else if (i==last_inode_block) { byte_count=last_data_offset; byte_to_write-=byte_count; } } } else { byte_count=BLOCK_SIZE; byte_to_write-=BLOCK_SIZE; if (i>12) { if (iob_indirect_block[i-12]==0) { iob_indirect_block[i-12]=alloc_block(ext2,inode,i); update_indirect_block=TRUE; } lba=iob_indirect_block[i-12]; } else { if (inode->i_block[i]==0) { inode->i_block[i]=alloc_block(ext2,inode,i); } lba=inode->i_block[i]; } byte_count=BLOCK_SIZE; byte_to_write-=BLOCK_SIZE; } kmemcpy(iob_data_block,buf,byte_count); sector_count=BLOCK_SIZE/SECTOR_SIZE; WRITE(sector_count,lba,iob_data_block); inode->file_offset+=byte_count; buf+=byte_count; byte_written+=byte_count; } if (update_indirect_block) { WRITE(sector_count,inode->i_block[12],iob_indirect_block); } kfree(iob_data_block); kfree(iob_indirect_block); return byte_written; }
TEST(Hashtable, SetGetRemove) { struct t_hashtable *hashtable, *hashtable2; struct t_hashtable_item *item, *ptr_item, *ptr_item2; const char *str_key = HASHTABLE_TEST_KEY; const char *str_value = HASHTABLE_TEST_VALUE; const char *ptr_value; unsigned long long hash; int i; hashtable = hashtable_new (32, WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_STRING, &test_hashtable_hash_key_cb, &test_hashtable_keycmp_cb); LONGS_EQUAL(32, hashtable->size); LONGS_EQUAL(0, hashtable->items_count); /* invalid set of items */ POINTERS_EQUAL(NULL, hashtable_set_with_size (NULL, NULL, -1, NULL, -1)); POINTERS_EQUAL(NULL, hashtable_set_with_size (NULL, NULL, -1, NULL, -1)); /* add an item in hashtable with NULL value */ item = hashtable_set (hashtable, str_key, NULL); CHECK(item); LONGS_EQUAL(1, hashtable->items_count); STRCMP_EQUAL(str_key, (const char *)item->key); LONGS_EQUAL(strlen (str_key) + 1, item->key_size); POINTERS_EQUAL(NULL, item->value); LONGS_EQUAL(0, item->value_size); POINTERS_EQUAL(NULL, item->prev_item); POINTERS_EQUAL(NULL, item->next_item); /* set a string value for the same key */ item = hashtable_set (hashtable, str_key, str_value); CHECK(item); LONGS_EQUAL(1, hashtable->items_count); STRCMP_EQUAL(str_key, (const char *)item->key); LONGS_EQUAL(strlen (str_key) + 1, item->key_size); STRCMP_EQUAL(str_value, (const char *)item->value); LONGS_EQUAL(strlen (str_value) + 1, item->value_size); POINTERS_EQUAL(NULL, item->prev_item); POINTERS_EQUAL(NULL, item->next_item); /* get item */ item = hashtable_get_item (hashtable, str_key, &hash); CHECK(item); STRCMP_EQUAL(str_key, (const char *)item->key); STRCMP_EQUAL(str_value, (const char *)item->value); LONGS_EQUAL(2, hash); /* get value */ ptr_value = (const char *)hashtable_get (hashtable, str_key); CHECK(ptr_value); STRCMP_EQUAL(ptr_value, str_value); /* check if key is in hashtable */ LONGS_EQUAL(0, hashtable_has_key (hashtable, NULL)); LONGS_EQUAL(0, hashtable_has_key (hashtable, "")); LONGS_EQUAL(0, hashtable_has_key (hashtable, "xxx")); LONGS_EQUAL(1, hashtable_has_key (hashtable, str_key)); /* delete an item */ hashtable_remove (hashtable, str_key); LONGS_EQUAL(0, hashtable->items_count); /* add an item with size in hashtable */ item = hashtable_set_with_size (hashtable, str_key, strlen (str_key) + 1, str_value, strlen (str_value) + 1); CHECK(item); LONGS_EQUAL(1, hashtable->items_count); STRCMP_EQUAL(str_key, (const char *)item->key); LONGS_EQUAL(strlen (str_key) + 1, item->key_size); STRCMP_EQUAL(str_value, (const char *)item->value); LONGS_EQUAL(strlen (str_value) + 1, item->value_size); /* add another item */ hashtable_set (hashtable, "xxx", "zzz"); LONGS_EQUAL(2, hashtable->items_count); /* * test duplication of hashtable and check that duplicated content is * exactly the same as initial hashtable */ hashtable2 = hashtable_dup (hashtable); CHECK(hashtable2); LONGS_EQUAL(hashtable->size, hashtable2->size); LONGS_EQUAL(hashtable->items_count, hashtable2->items_count); for (i = 0; i < hashtable->size; i++) { if (hashtable->htable[i]) { ptr_item = hashtable->htable[i]; ptr_item2 = hashtable2->htable[i]; while (ptr_item && ptr_item2) { LONGS_EQUAL(ptr_item->key_size, ptr_item2->key_size); LONGS_EQUAL(ptr_item->value_size, ptr_item2->value_size); if (ptr_item->key) { STRCMP_EQUAL((const char *)ptr_item->key, (const char *)ptr_item2->key); } else { POINTERS_EQUAL(ptr_item->key, ptr_item2->key); } if (ptr_item->value) { STRCMP_EQUAL((const char *)ptr_item->value, (const char *)ptr_item2->value); } else { POINTERS_EQUAL(ptr_item->value, ptr_item2->value); } ptr_item = ptr_item->next_item; ptr_item2 = ptr_item2->next_item; CHECK((ptr_item && ptr_item2) || (!ptr_item && !ptr_item2)); } } else { POINTERS_EQUAL(hashtable->htable[i], hashtable2->htable[i]); } } /* remove all items */ hashtable_remove_all (hashtable); LONGS_EQUAL(0, hashtable->items_count); /* free hashtables */ hashtable_free (hashtable); hashtable_free (hashtable2); /* * create a hashtable with size 8, and add 6 items, * to check if many items with same hashed key work fine, * the expected htable inside hashtable is: * +-----+ * | 0 | * +-----+ * | 1 | * +-----+ * | 2 | --> "extensible" * +-----+ * | 3 | --> "fast" --> "light" * +-----+ * | 4 | * +-----+ * | 5 | --> "chat" * +-----+ * | 6 | --> "client" * +-----+ * | 7 | --> "weechat" * +-----+ */ hashtable = hashtable_new (8, WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_STRING, NULL, NULL); LONGS_EQUAL(8, hashtable->size); LONGS_EQUAL(0, hashtable->items_count); item = hashtable_set (hashtable, "weechat", NULL); CHECK(item); POINTERS_EQUAL(item, hashtable->htable[7]); item = hashtable_set (hashtable, "fast", NULL); CHECK(item); POINTERS_EQUAL(item, hashtable->htable[3]); item = hashtable_set (hashtable, "light", NULL); CHECK(item); POINTERS_EQUAL(item, hashtable->htable[3]->next_item); item = hashtable_set (hashtable, "extensible", NULL); CHECK(item); POINTERS_EQUAL(item, hashtable->htable[2]); item = hashtable_set (hashtable, "chat", NULL); CHECK(item); POINTERS_EQUAL(item, hashtable->htable[5]); item = hashtable_set (hashtable, "client", NULL); CHECK(item); POINTERS_EQUAL(item, hashtable->htable[6]); /* free hashtable */ hashtable_free (hashtable); }
int ddb_parse(const struct ts_header *header, const char *payload, uint32_t payload_len, struct demuxfs_data *priv) { struct ddb_table *current_ddb = NULL; struct ddb_table *ddb = (struct ddb_table *) calloc(1, sizeof(struct ddb_table)); assert(ddb); ddb->dentry = (struct dentry *) calloc(1, sizeof(struct dentry)); assert(ddb->dentry); /* Copy data up to the first loop entry */ int ret = psi_parse((struct psi_common_header *) ddb, payload, payload_len); if (ret < 0) { ddb_free(ddb); return 0; } ddb_check_header(ddb); /* Set hash key and check if there's already one version of this table in the hash */ ddb->dentry->inode = TS_PACKET_HASH_KEY(header, ddb); current_ddb = hashtable_get(priv->psi_tables, ddb->dentry->inode); /* Check whether we should keep processing this packet or not */ if (! ddb->current_next_indicator) { dprintf("ddb doesn't have current_next_indicator bit set, skipping it"); ddb_free(ddb); return 0; } /** DSM-CC Download Data Header */ struct dsmcc_download_data_header *data_header = &ddb->dsmcc_download_data_header; int j = dsmcc_parse_download_data_header(data_header, payload, 8); if (data_header->_dsmcc_type != 0x03 || data_header->_message_id != 0x1003) { ddb_free(ddb); return 0; } if (data_header->message_length < 5) { // XXX: expose header in the fs? if (data_header->message_length) dprintf("skipping message with len=%d", data_header->message_length); ddb_free(ddb); return 0; } /** DDB bits */ ddb->module_id = CONVERT_TO_16(payload[j], payload[j+1]); ddb->module_version = payload[j+2]; ddb->reserved = payload[j+3]; ddb->block_number = CONVERT_TO_16(payload[j+4], payload[j+5]); ddb->_block_data_size = data_header->message_length - data_header->adaptation_length - 6; if (! ddb->_block_data_size) { ddb_free(ddb); return 0; } if (ddb_block_number_already_parsed(current_ddb, ddb->module_id, ddb->block_number)) { ddb_free(ddb); return 0; } // TS_INFO("DDB parser: pid=%d, table_id=%#x, ddb->version_number=%#x, ddb->block_number=%d, module_id=%d, current=%p", // header->pid, ddb->table_id, ddb->version_number, ddb->block_number, ddb->module_id, current_ddb); /* Create filesystem entries for this table */ struct dentry *version_dentry = NULL; if (current_ddb) version_dentry = fsutils_get_current(current_ddb->dentry); else ddb_create_directory(header, ddb, &version_dentry, priv); uint16_t this_block_size = payload_len - (j+6) - 4; uint16_t this_block_start = j+6; if (this_block_size != ddb->_block_data_size) TS_WARNING("ddb->block_data_size=%d != this_block_size=%d", ddb->_block_data_size, this_block_size); /* Create individual block file */ struct dentry *module_dir = CREATE_DIRECTORY(version_dentry, "module_%02d", ddb->module_id); struct dentry *block_dentry = (struct dentry *) calloc(1, sizeof(struct dentry)); block_dentry->size = this_block_size; block_dentry->mode = S_IFREG | 0444; block_dentry->obj_type = OBJ_TYPE_FILE; block_dentry->contents = malloc(this_block_size); memcpy(block_dentry->contents, &payload[this_block_start], this_block_size); asprintf(&block_dentry->name, "block_%02d.bin", ddb->block_number); CREATE_COMMON(module_dir, block_dentry); xattr_add(block_dentry, XATTR_FORMAT, XATTR_FORMAT_BIN, strlen(XATTR_FORMAT_BIN), false); if (current_ddb) ddb_free(ddb); else hashtable_add(priv->psi_tables, ddb->dentry->inode, ddb, (hashtable_free_function_t) ddb_free); return 0; }
void config_req_rlc_um_asn1 ( const protocol_ctxt_t* const ctxt_pP, const srb_flag_t srb_flagP, const MBMS_flag_t mbms_flagP, const mbms_session_id_t mbms_session_idP, const mbms_service_id_t mbms_service_idP, const UL_UM_RLC_t * const ul_rlc_pP, const DL_UM_RLC_t * const dl_rlc_pP, const rb_id_t rb_idP) { uint32_t ul_sn_FieldLength = 0; uint32_t dl_sn_FieldLength = 0; uint32_t t_Reordering = 0; rlc_union_t *rlc_union_p = NULL; rlc_um_entity_t *rlc_p = NULL; hash_key_t key = RLC_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP); hashtable_rc_t h_rc; #if Rel10 if (mbms_flagP) { AssertFatal(dl_rlc_pP, "No RLC UM DL config"); AssertFatal(ul_rlc_pP == NULL, "RLC UM UL config present"); key = RLC_COLL_KEY_MBMS_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, mbms_service_idP, mbms_session_idP); h_rc = hashtable_get(rlc_coll_p, key, (void**)&rlc_union_p); AssertFatal (h_rc == HASH_TABLE_OK, "RLC NOT FOUND enb id %u rnti %i enb flag %u service id %u, session id %u", ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, mbms_service_idP, mbms_session_idP); rlc_p = &rlc_union_p->rlc.um; } else #endif { key = RLC_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP); h_rc = hashtable_get(rlc_coll_p, key, (void**)&rlc_union_p); AssertFatal (h_rc == HASH_TABLE_OK, "RLC NOT FOUND enb id %u ue id %i enb flag %u rb id %u, srb flag %u", ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP); rlc_p = &rlc_union_p->rlc.um; } //----------------------------------------------------------------------------- LOG_D(RLC, PROTOCOL_RLC_UM_CTXT_FMT" CONFIG_REQ timer_reordering=%dms sn_field_length= RB %u \n", PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,rlc_p), (dl_rlc_pP && dl_rlc_pP->t_Reordering<31)?t_Reordering_tab[dl_rlc_pP->t_Reordering]:-1, rb_idP); rlc_um_init(ctxt_pP, rlc_p); if (rlc_um_fsm_notify_event (ctxt_pP, rlc_p, RLC_UM_RECEIVE_CRLC_CONFIG_REQ_ENTER_DATA_TRANSFER_READY_STATE_EVENT)) { rlc_um_set_debug_infos(ctxt_pP,rlc_p, srb_flagP, rb_idP); if (ul_rlc_pP != NULL) { switch (ul_rlc_pP->sn_FieldLength) { case SN_FieldLength_size5: ul_sn_FieldLength = 5; break; case SN_FieldLength_size10: ul_sn_FieldLength = 10; break; default: LOG_E(RLC,PROTOCOL_RLC_UM_CTXT_FMT" [CONFIGURE] RB %u INVALID UL sn_FieldLength %d, RLC NOT CONFIGURED\n", PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,rlc_p), rlc_p->rb_id, ul_rlc_pP->sn_FieldLength); MSC_LOG_RX_DISCARDED_MESSAGE( (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE, (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RRC_ENB:MSC_RRC_UE, NULL, 0, MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" CONFIG-REQ UL sn_FieldLength %u", MSC_AS_TIME_ARGS(ctxt_pP), PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, rlc_p), ul_rlc_pP->sn_FieldLength); return; } } if (dl_rlc_pP != NULL) { switch (dl_rlc_pP->sn_FieldLength) { case SN_FieldLength_size5: dl_sn_FieldLength = 5; break; case SN_FieldLength_size10: dl_sn_FieldLength = 10; break; default: LOG_E(RLC,PROTOCOL_RLC_UM_CTXT_FMT" [CONFIGURE] RB %u INVALID DL sn_FieldLength %d, RLC NOT CONFIGURED\n", PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,rlc_p), rlc_p->rb_id, dl_rlc_pP->sn_FieldLength); MSC_LOG_RX_DISCARDED_MESSAGE( (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE, (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RRC_ENB:MSC_RRC_UE, NULL, 0, MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" CONFIG-REQ DL sn_FieldLength %u", MSC_AS_TIME_ARGS(ctxt_pP), PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, rlc_p), dl_rlc_pP->sn_FieldLength); return; } if (dl_rlc_pP->t_Reordering<T_Reordering_spare1) { t_Reordering = t_Reordering_tab[dl_rlc_pP->t_Reordering]; } else { LOG_E(RLC,PROTOCOL_RLC_UM_CTXT_FMT" [CONFIGURE] RB %u INVALID T_Reordering %d, RLC NOT CONFIGURED\n", PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,rlc_p), rlc_p->rb_id, dl_rlc_pP->t_Reordering); MSC_LOG_RX_DISCARDED_MESSAGE( (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE, (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RRC_ENB:MSC_RRC_UE, NULL, 0, MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" CONFIG-REQ t_Reord %u", MSC_AS_TIME_ARGS(ctxt_pP), PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, rlc_p), dl_rlc_pP->t_Reordering); return; } } if (ctxt_pP->enb_flag > 0) { rlc_um_configure(ctxt_pP,rlc_p, t_Reordering, ul_sn_FieldLength, dl_sn_FieldLength, mbms_flagP); MSC_LOG_RX_MESSAGE( (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE, (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RRC_ENB:MSC_RRC_UE, NULL, 0, MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" CONFIG-REQ t_Reord %u rx snfl %u tx snfl %u", MSC_AS_TIME_ARGS(ctxt_pP), PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, rlc_p), t_Reordering, ul_sn_FieldLength, dl_sn_FieldLength); } else { rlc_um_configure(ctxt_pP,rlc_p, t_Reordering, dl_sn_FieldLength, ul_sn_FieldLength, mbms_flagP); MSC_LOG_RX_MESSAGE( (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE, (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RRC_ENB:MSC_RRC_UE, NULL, 0, MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" CONFIG-REQ t_Reord %u rx snfl %u tx snfl %u", MSC_AS_TIME_ARGS(ctxt_pP), PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP, rlc_p), t_Reordering, dl_sn_FieldLength, ul_sn_FieldLength); } } }
int main(int argc, char **argv) { int *vals = (int *)GC_MALLOC(SIZE * sizeof(int)); int i; for(i=0;i<SIZE; i++) vals[i] = i; hashtable_t *tab = hashtable_create(1000001); clock_t start, diff; int msec; start = clock(); for(i=0; i<SIZE; i++) hashtable_put(tab, (void *)(vals[i]), (void *)(i*i)); diff = clock() - start; msec = diff * 1000 / CLOCKS_PER_SEC; printf("Put took %d seconds %d milliseconds\n", msec/1000, msec%1000); start = clock(); for(i=0; i<SIZE; i++) { hashtable_entry_t *b = hashtable_get(tab, (void *)(vals[i])); assert((int)(b->ptr) == i); assert((int)(b->value) == i*i); } assert(tab->count == SIZE); diff = clock() - start; msec = diff * 1000 / CLOCKS_PER_SEC; printf("Get took %d seconds %d milliseconds\n", msec/1000, msec%1000); start = clock(); hashtable_remove(tab, (void *)(vals[SIZE/2])); assert(tab->count == SIZE-1); diff = clock() - start; msec = diff * 1000 / CLOCKS_PER_SEC; printf("Remove took %d seconds %d milliseconds\n", msec/1000, msec%1000); assert(hashtable_get(tab, (void *)(vals[SIZE/2])) == NULL); hashtable_remove(tab, (void *)(vals[0])); hashtable_delete(tab); tab = hashtable_create(1000001); for(i=0; i<SIZE; i++) hashtable_put(tab, (void *)vals[i], (void *)(i*i)); hashtable_entry_t *entries = hashtable_entries(tab); while(entries) { assert((int)(entries->value) == (int)(entries->ptr) * (int)(entries->ptr)); entries = entries->next; } hashtable_delete(tab); //free(vals); }
static exchange_t *internal_lookup_exchange(vhost_t *vhost, amqp_bytes_t name) { exchange_t *result = NULL; hashtable_get(&vhost->exchanges, name, (void **) &result); return result; }
char * eval_replace_vars_cb (void *data, const char *text) { struct t_hashtable *pointers, *extra_vars; struct t_config_option *ptr_option; struct t_gui_buffer *ptr_buffer; char str_value[64], *value, *pos, *pos1, *pos2, *hdata_name, *list_name; char *tmp, *info_name, *hide_char, *hidden_string; const char *ptr_value, *ptr_arguments, *ptr_string; struct t_hdata *hdata; void *pointer; int i, length_hide_char, length, index; pointers = (struct t_hashtable *)(((void **)data)[0]); extra_vars = (struct t_hashtable *)(((void **)data)[1]); /* 1. look for var in hashtable "extra_vars" */ if (extra_vars) { ptr_value = hashtable_get (extra_vars, text); if (ptr_value) return strdup (ptr_value); } /* 2. convert escaped chars */ if (strncmp (text, "esc:", 4) == 0) return string_convert_escaped_chars (text + 4); if ((text[0] == '\\') && text[1] && (text[1] != '\\')) return string_convert_escaped_chars (text); /* 3. hide chars: replace all chars by a given char */ if (strncmp (text, "hide:", 5) == 0) { hidden_string = NULL; ptr_string = strchr (text + 5, (text[5] == ',') ? ';' : ','); if (!ptr_string) return strdup (""); hide_char = string_strndup (text + 5, ptr_string - text - 5); if (hide_char) { length_hide_char = strlen (hide_char); length = utf8_strlen (ptr_string + 1); hidden_string = malloc ((length * length_hide_char) + 1); if (hidden_string) { index = 0; for (i = 0; i < length; i++) { memcpy (hidden_string + index, hide_char, length_hide_char); index += length_hide_char; } hidden_string[length * length_hide_char] = '\0'; } free (hide_char); } return (hidden_string) ? hidden_string : strdup (""); } /* 4. look for a color */ if (strncmp (text, "color:", 6) == 0) { ptr_value = gui_color_get_custom (text + 6); return strdup ((ptr_value) ? ptr_value : ""); } /* 5. look for an info */ if (strncmp (text, "info:", 5) == 0) { ptr_value = NULL; ptr_arguments = strchr (text + 5, ','); if (ptr_arguments) { info_name = string_strndup (text + 5, ptr_arguments - text - 5); ptr_arguments++; } else info_name = strdup (text + 5); if (info_name) { ptr_value = hook_info_get (NULL, info_name, ptr_arguments); free (info_name); } return strdup ((ptr_value) ? ptr_value : ""); } /* 6. look for name of option: if found, return this value */ if (strncmp (text, "sec.data.", 9) == 0) { ptr_value = hashtable_get (secure_hashtable_data, text + 9); return strdup ((ptr_value) ? ptr_value : ""); } else { config_file_search_with_string (text, NULL, NULL, &ptr_option, NULL); if (ptr_option) { if (!ptr_option->value) return strdup (""); switch (ptr_option->type) { case CONFIG_OPTION_TYPE_BOOLEAN: return strdup (CONFIG_BOOLEAN(ptr_option) ? EVAL_STR_TRUE : EVAL_STR_FALSE); case CONFIG_OPTION_TYPE_INTEGER: if (ptr_option->string_values) return strdup (ptr_option->string_values[CONFIG_INTEGER(ptr_option)]); snprintf (str_value, sizeof (str_value), "%d", CONFIG_INTEGER(ptr_option)); return strdup (str_value); case CONFIG_OPTION_TYPE_STRING: return strdup (CONFIG_STRING(ptr_option)); case CONFIG_OPTION_TYPE_COLOR: return strdup (gui_color_get_name (CONFIG_COLOR(ptr_option))); case CONFIG_NUM_OPTION_TYPES: return strdup (""); } } } /* 7. look for local variable in buffer */ ptr_buffer = hashtable_get (pointers, "buffer"); if (ptr_buffer) { ptr_value = hashtable_get (ptr_buffer->local_variables, text); if (ptr_value) return strdup (ptr_value); } /* 8. look for hdata */ value = NULL; hdata_name = NULL; list_name = NULL; pointer = NULL; pos = strchr (text, '.'); if (pos > text) hdata_name = string_strndup (text, pos - text); else hdata_name = strdup (text); if (!hdata_name) goto end; pos1 = strchr (hdata_name, '['); if (pos1 > hdata_name) { pos2 = strchr (pos1 + 1, ']'); if (pos2 > pos1 + 1) { list_name = string_strndup (pos1 + 1, pos2 - pos1 - 1); } tmp = string_strndup (hdata_name, pos1 - hdata_name); if (tmp) { free (hdata_name); hdata_name = tmp; } } hdata = hook_hdata_get (NULL, hdata_name); if (!hdata) goto end; if (list_name) pointer = hdata_get_list (hdata, list_name); if (!pointer) { pointer = hashtable_get (pointers, hdata_name); if (!pointer) goto end; } value = eval_hdata_get_value (hdata, pointer, (pos) ? pos + 1 : NULL); end: if (hdata_name) free (hdata_name); if (list_name) free (list_name); return (value) ? value : strdup (""); }
void client_loop (int cfd) { char buffer[2048]; while (1) { ssize_t rd; if ((rd = read(cfd, buffer, 128)) <= 0) { perror("read()"); break; } if (memcmp(buffer, "scus", 4) == 0) { memcpy(buffer, "figur\n", 6); rd = 6; } else if (memcmp(buffer, "chiudi", 6) == 0) { break; } else if (memcmp(buffer, "put", 3) == 0) { printf("Byte letti %d\n", rd); char *key, *value; int k_len, v_len; key = buffer + 4; printf("key = %p\n",key); value = memchr(buffer + 4, ' ', rd - 4) +1; k_len =(value - key) - 1; v_len = rd - 4 - k_len - 1; printf("Key = "); stampa(key, k_len); printf("Value = "); stampa(value, v_len); /*int i_key; i_key = strtol(key, NULL, 10); printf("integer key = %d\n", i_key);*/ hashtable_insert(&db, key, value,k_len, v_len); log_insert(log_fd, key, value,k_len, v_len); memcpy(buffer, "storato\n", 8); rd = 8; } else if (memcmp(buffer, "get", 3) == 0) { char *g_key, *g_value; int g_key_len, v_len; g_key = buffer + 4; g_key_len = rd - 4; //ig_key = strtol(g_key, NULL, 10); g_value = hashtable_get(&db, g_key, g_key_len, &v_len); memcpy(buffer, g_value, v_len); memcpy(buffer + v_len, "\n", 1); rd = v_len + 1; } else if (memcmp(buffer, "GET", 3) == 0) { char xbuffer[4096]; read(cfd, xbuffer, sizeof(xbuffer)); memcpy(buffer, html, strlen(html)); rd = strlen(html); } else { memcpy(buffer + rd, "culo\n", 5); printf("il buffer %s\n", buffer); rd += 5; } if (write(cfd, buffer, rd) != rd) { perror("write()"); break; } } close(cfd); }
char * eval_expression (const char *expr, struct t_hashtable *pointers, struct t_hashtable *extra_vars, struct t_hashtable *options) { int condition, rc, pointers_allocated; char *value; const char *prefix, *suffix; const char *default_prefix = EVAL_DEFAULT_PREFIX; const char *default_suffix = EVAL_DEFAULT_SUFFIX; const char *ptr_value; struct t_gui_window *window; if (!expr) return NULL; condition = 0; pointers_allocated = 0; prefix = default_prefix; suffix = default_suffix; /* create hashtable pointers if it's NULL */ if (!pointers) { pointers = hashtable_new (32, WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_POINTER, NULL, NULL); if (!pointers) return NULL; pointers_allocated = 1; } /* * set window/buffer with pointer to current window/buffer * (if not already defined in the hashtable) */ if (gui_current_window) { if (!hashtable_has_key (pointers, "window")) hashtable_set (pointers, "window", gui_current_window); if (!hashtable_has_key (pointers, "buffer")) { window = (struct t_gui_window *)hashtable_get (pointers, "window"); if (window) hashtable_set (pointers, "buffer", window->buffer); } } /* read options */ if (options) { /* check the type of evaluation */ ptr_value = hashtable_get (options, "type"); if (ptr_value && (strcmp (ptr_value, "condition") == 0)) condition = 1; /* check for custom prefix */ ptr_value = hashtable_get (options, "prefix"); if (ptr_value && ptr_value[0]) prefix = ptr_value; /* check for custom suffix */ ptr_value = hashtable_get (options, "suffix"); if (ptr_value && ptr_value[0]) suffix = ptr_value; } /* evaluate expression */ if (condition) { /* evaluate as condition (return a boolean: "0" or "1") */ value = eval_expression_condition (expr, pointers, extra_vars, prefix, suffix); rc = eval_is_true (value); if (value) free (value); value = strdup ((rc) ? EVAL_STR_TRUE : EVAL_STR_FALSE); } else { /* only replace variables in expression */ value = eval_replace_vars (expr, pointers, extra_vars, prefix, suffix); } if (pointers_allocated) hashtable_free (pointers); return value; }
int weeurl_download (const char *url, struct t_hashtable *options) { CURL *curl; struct t_url_file url_file[2]; char *url_file_option[2] = { "file_in", "file_out" }; char *url_file_mode[2] = { "rb", "wb" }; CURLoption url_file_opt_func[2] = { CURLOPT_READFUNCTION, CURLOPT_WRITEFUNCTION }; CURLoption url_file_opt_data[2] = { CURLOPT_READDATA, CURLOPT_WRITEDATA }; void *url_file_opt_cb[2] = { &weeurl_read, &weeurl_write }; int rc, i; rc = 0; for (i = 0; i < 2; i++) { url_file[i].filename = NULL; url_file[i].stream = NULL; } if (!url || !url[0]) { rc = 1; goto end; } curl = curl_easy_init(); if (!curl) { rc = 3; goto end; } /* set default options */ curl_easy_setopt (curl, CURLOPT_URL, url); curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1L); /* set file in/out from options in hashtable */ if (options) { for (i = 0; i < 2; i++) { url_file[i].filename = hashtable_get (options, url_file_option[i]); if (url_file[i].filename) { url_file[i].stream = fopen (url_file[i].filename, url_file_mode[i]); if (!url_file[i].stream) { rc = 4; goto end; } curl_easy_setopt (curl, url_file_opt_func[i], url_file_opt_cb[i]); curl_easy_setopt (curl, url_file_opt_data[i], url_file[i].stream); } } } /* set other options in hashtable */ hashtable_map (options, &weeurl_option_map_cb, curl); /* perform action! */ if (curl_easy_perform (curl) != CURLE_OK) rc = 2; /* cleanup */ curl_easy_cleanup (curl); end: for (i = 0; i < 2; i++) { if (url_file[i].stream) fclose (url_file[i].stream); } return rc; }
void render_path(StyleMachine *m, Raster *raster, Path *p) { LinkNode *node; int min[2], max[2]; int x, y, found=0; float rgba[4] = {0, 0, 0, 0}; Style *style = (Style*) hashtable_get(&raster->styles, p->style); if (!style) { style = DEFAULT_STYLE; } m->style = style; m->code = style->code; m->codelen = style->codelen; min[0] = min[1] = INT_MAX; max[0] = max[1] = INT_MIN; for (node=p->segments.first; node; node=node->next) { PathSegment *s = node->data; min[0] = MIN2(min[0], s->v1->x); min[0] = MIN2(min[0], s->h1->x); min[0] = MIN2(min[0], s->h2->x); min[0] = MIN2(min[0], s->v2->x); min[1] = MIN2(min[1], s->v1->y); min[1] = MIN2(min[1], s->h1->y); min[1] = MIN2(min[1], s->h2->y); min[1] = MIN2(min[1], s->v2->y); max[0] = MAX2(max[0], s->v1->x); max[0] = MAX2(max[0], s->h1->x); max[0] = MAX2(max[0], s->h2->x); max[0] = MAX2(max[0], s->v2->x); max[1] = MAX2(max[1], s->v1->y); max[1] = MAX2(max[1], s->h1->y); max[1] = MAX2(max[1], s->h2->y); max[1] = MAX2(max[1], s->v2->y); found = 1; } if (!found || (min[0] == max[0] && min[1] == max[1])) { return; //path has no area } int w = raster->size[0], h = raster->size[1]; int outside[2] = {min[0]-100, min[1]-101}; //precache some calculations for (node=p->segments.first; node; node=node->next) { PathSegment *s = node->data; s->tmps.dxab = s->v1->x - s->v2->x; s->tmps.dyab = s->v1->y - s->v2->y; s->tmps.dxbc = s->v2->x - outside[0]; s->tmps.dybc = s->v2->y - outside[1]; } int miny=min[1], maxy=max[1]; int minx=min[0], maxx=max[0]; for (y = miny; y <= maxy; y++) { for (x = minx; x <= maxx; x++) { if (x < 0 || y < 0 || x >= w || y >= h) { continue; //XXX todo: better clipping } int ok = 1; int totisect = 0; for (node = p->segments.first; node; node=node->next) { PathSegment *s = (PathSegment*) node->data; s->tmps.dxcd = outside[0] - x; s->tmps.dycd = outside[1] - y; s->tmps.dxda = x - s->v1->x; s->tmps.dyda = y - s->v1->y; int w1 = -(s->tmps.dxbc*s->tmps.dycd+s->tmps.dxbc*s->tmps.dyda-s->tmps.dxcd*s->tmps.dybc-s->tmps.dxda*s->tmps.dybc) > 0.0; int w2 = -(s->tmps.dxbc*s->tmps.dyda+s->tmps.dxcd*s->tmps.dyda-s->tmps.dxda*s->tmps.dybc-s->tmps.dxda*s->tmps.dycd) > 0.0; int w3 = -(s->tmps.dxcd*s->tmps.dyda-s->tmps.dxda*s->tmps.dycd) > 0.0; int w4 = -(s->tmps.dxbc*s->tmps.dycd-s->tmps.dxcd*s->tmps.dybc) > 0.0; //do winding test totisect += !!(w1 != w2 && w3 != w4); ///isect_line(s->v1->x, s->v1->y, s->v2->x, s->v2->y, x, y, outside[0], outside[1]); } ok = (totisect & 1); if (!ok) { continue; } stylepixel(m, rgba, style, p->styleflag, p->styleargs, (float)x, (float)y, (float)x/(float)w, (float)y/(float)h); //rgba[0] = 1.0; //rgba[1] = 0.0; //rgba[1] = 0.0; //rgba[3] = 1.0; int idx = (y*raster->size[0] + x)*4; CLAMP(rgba[0], 0.0f, 1.0f); CLAMP(rgba[1], 0.0f, 1.0f); CLAMP(rgba[2], 0.0f, 1.0f); CLAMP(rgba[3], 0.0f, 1.0f); raster->buffer[idx] = (unsigned char)(rgba[0]*255.0f); raster->buffer[idx+1] = (unsigned char)(rgba[1]*255.0f); raster->buffer[idx+2] = (unsigned char)(rgba[2]*255.0f); raster->buffer[idx+3] = (unsigned char)(rgba[3]*255.0f); } } }
void GUIID_Table_GetID(const char* gui_name, unsigned int* pid) { hashtable_get(g_guid_table, gui_name, pid); }
//----------------------------------------------------------------------------- rlc_union_t* rrc_rlc_add_rlc ( const protocol_ctxt_t* const ctxt_pP, const srb_flag_t srb_flagP, const MBMS_flag_t MBMS_flagP, const rb_id_t rb_idP, const logical_chan_id_t chan_idP, const rlc_mode_t rlc_modeP) { //----------------------------------------------------------------------------- hash_key_t key = HASHTABLE_NOT_A_KEY_VALUE; hashtable_rc_t h_rc; rlc_union_t *rlc_union_p = NULL; #ifdef Rel10 rlc_mbms_id_t *mbms_id_p = NULL; logical_chan_id_t lcid = 0; #endif #ifdef OAI_EMU CHECK_CTXT_ARGS(ctxt_pP) #endif if (MBMS_flagP == FALSE) { AssertFatal (rb_idP < NB_RB_MAX, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MAX); AssertFatal (chan_idP < RLC_MAX_LC, "LC id is too high (%u/%d)!\n", chan_idP, RLC_MAX_LC); } #ifdef Rel10 if (MBMS_flagP == TRUE) { if (ctxt_pP->enb_flag) { lcid = rlc_mbms_enb_get_lcid_by_rb_id(ctxt_pP->module_id,rb_idP); mbms_id_p = &rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lcid]; //LG 2014-04-15rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lcid].service_id = 0; //LG 2014-04-15rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lcid].session_id = 0; //LG 2014-04-15rlc_mbms_rbid2lcid_eNB[ctxt_pP->module_id][rb_idP] = RLC_LC_UNALLOCATED; } else { lcid = rlc_mbms_ue_get_lcid_by_rb_id(ctxt_pP->module_id,rb_idP); mbms_id_p = &rlc_mbms_lcid2service_session_id_ue[ctxt_pP->module_id][lcid]; //LG 2014-04-15rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lcid].service_id = 0; //LG 2014-04-15rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][lcid].session_id = 0; //LG 2014-04-15rlc_mbms_rbid2lcid_ue[ctxt_pP->module_id][rb_idP] = RLC_LC_UNALLOCATED; } key = RLC_COLL_KEY_MBMS_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, mbms_id_p->service_id, mbms_id_p->session_id); } else #endif { key = RLC_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP); } h_rc = hashtable_get(rlc_coll_p, key, (void**)&rlc_union_p); if (h_rc == HASH_TABLE_OK) { LOG_W(RLC, PROTOCOL_CTXT_FMT"[%s %u] rrc_rlc_add_rlc , already exist %s\n", PROTOCOL_CTXT_ARGS(ctxt_pP), (srb_flagP) ? "SRB" : "DRB", rb_idP, (srb_flagP) ? "SRB" : "DRB"); AssertFatal(rlc_union_p->mode == rlc_modeP, "Error rrc_rlc_add_rlc , already exist but RLC mode differ"); return rlc_union_p; } else if (h_rc == HASH_TABLE_KEY_NOT_EXISTS) { rlc_union_p = calloc(1, sizeof(rlc_union_t)); h_rc = hashtable_insert(rlc_coll_p, key, rlc_union_p); if (h_rc == HASH_TABLE_OK) { #ifdef Rel10 if (MBMS_flagP == TRUE) { LOG_I(RLC, PROTOCOL_CTXT_FMT" RLC service id %u session id %u rrc_rlc_add_rlc\n", PROTOCOL_CTXT_ARGS(ctxt_pP), mbms_id_p->service_id, mbms_id_p->session_id); } else #endif { LOG_I(RLC, PROTOCOL_CTXT_FMT" [%s %u] rrc_rlc_add_rlc %s\n", PROTOCOL_CTXT_ARGS(ctxt_pP), (srb_flagP) ? "SRB" : "DRB", rb_idP, (srb_flagP) ? "SRB" : "DRB"); } rlc_union_p->mode = rlc_modeP; return rlc_union_p; } else { LOG_E(RLC, PROTOCOL_CTXT_FMT"[%s %u] rrc_rlc_add_rlc FAILED %s\n", PROTOCOL_CTXT_ARGS(ctxt_pP), (srb_flagP) ? "SRB" : "DRB", rb_idP, (srb_flagP) ? "SRB" : "DRB"); free(rlc_union_p); rlc_union_p = NULL; return NULL; } } else { LOG_E(RLC, PROTOCOL_CTXT_FMT"[%s %u] rrc_rlc_add_rlc , INTERNAL ERROR %s\n", PROTOCOL_CTXT_ARGS(ctxt_pP), (srb_flagP) ? "SRB" : "DRB", rb_idP, (srb_flagP) ? "SRB" : "DRB"); } return NULL; }
int hdata_get_var_array_size (struct t_hdata *hdata, void *pointer, const char *name) { struct t_hdata_var *var; const char *ptr_size; char *error; long value; int i, offset; void *ptr_value; if (!hdata || !name) return -1; var = hashtable_get (hdata->hash_var, name); if (!var) return -1; ptr_size = var->array_size; if (!ptr_size) return -1; if (strcmp (ptr_size, "*") == 0) { /* * automatic size: look for NULL in array * (this automatic size is possible only with pointers, so with * types: string, pointer, hashtable) */ if ((var->type == WEECHAT_HDATA_STRING) || (var->type == WEECHAT_HDATA_SHARED_STRING) || (var->type == WEECHAT_HDATA_POINTER) || (var->type == WEECHAT_HDATA_HASHTABLE)) { if (!(*((void **)(pointer + var->offset)))) return 0; i = 0; while (1) { ptr_value = NULL; switch (var->type) { case WEECHAT_HDATA_STRING: case WEECHAT_HDATA_SHARED_STRING: ptr_value = (*((char ***)(pointer + var->offset)))[i]; break; case WEECHAT_HDATA_POINTER: ptr_value = (*((void ***)(pointer + var->offset)))[i]; break; case WEECHAT_HDATA_HASHTABLE: ptr_value = (*((struct t_hashtable ***)(pointer + var->offset)))[i]; break; } if (!ptr_value) break; i++; } return i; } } else { /* fixed size: the size can be a name of variable or integer */ offset = hdata_get_var_offset (hdata, ptr_size); if (offset >= 0) { /* size is the name of a variable in hdata, read it */ switch (hdata_get_var_type (hdata, ptr_size)) { case WEECHAT_HDATA_CHAR: return (int)(*((char *)(pointer + offset))); case WEECHAT_HDATA_INTEGER: return *((int *)(pointer + offset)); case WEECHAT_HDATA_LONG: return (int)(*((long *)(pointer + offset))); default: break; } } else { /* check if the size is a valid integer */ error = NULL; value = strtol (ptr_size, &error, 10); if (error && !error[0]) return (int)value; } } return -1; }
void Map__contains(caStack* stack) { caValue* value = hashtable_get(circa_input(stack, 0), circa_input(stack, 1)); set_bool(circa_output(stack, 0), value != NULL); }
// returns 1 if no error int getopt_parse(getopt_t *gopt, int argc, char *argv[], int showErrors) { int okay = 1; int i; dgc_vector_t *toks = dgc_vector_create(argc+1); // take the input stream and chop it up into tokens for (i = 1; i < argc; i++) { char *arg = strdup(argv[i]); char *eq = strstr(arg, "="); // no equal sign? Push the whole thing. if (eq == NULL) { dgc_vector_add(toks, strdup(arg)); } else { // there was an equal sign. Push the part // before and after the equal sign char *val = &eq[1]; eq[0] = 0; dgc_vector_add(toks, arg); // if the part after the equal sign is // enclosed by quotation marks, strip them. if (val[0]=='\"') { int last = strlen(val) - 1; if (val[last]=='\"') val[last] = 0; dgc_vector_add(toks, &val[1]); } else { dgc_vector_add(toks, val); } } } // now loop over the elements and evaluate the arguments i = 0; while (i < dgc_vector_size(toks)) { char *tok = (char*) dgc_vector_get(toks, i); if (!strncmp(tok,"--", 2)) { char *optname = &tok[2]; getopt_option_t *goo = (getopt_option_t*) hashtable_get(gopt->lopts, optname); if (goo == NULL) { okay = 0; if (showErrors) printf("Unknown option --%s\n", optname); i++; continue; } if (goo->type == GOO_BOOL_TYPE) { if ((i+1) < dgc_vector_size(toks)) { char *val = (char*) dgc_vector_get(toks, i+1); if (!strcmp(val,"true")) { i+=2; goo->svalue = "true"; continue; } if (!strcmp(val,"false")) { i+=2; goo->svalue = "false"; continue; } } goo->svalue = "true"; i++; continue; } if (goo->type == GOO_STRING_TYPE) { if ((i+1) < dgc_vector_size(toks)) { char *val = (char*) dgc_vector_get(toks, i+1); i+=2; goo->svalue = strdup(val); continue; } okay = 0; if (showErrors) printf("Option %s requires a string argument.\n",optname); } } if (!strncmp(tok,"-",1) && strncmp(tok,"--",2)) { int len = strlen(tok); int pos; for (pos = 1; pos < len; pos++) { char sopt[2]; sopt[0] = tok[pos]; sopt[1] = 0; getopt_option_t *goo = (getopt_option_t*) hashtable_get(gopt->sopts, sopt); if (goo==NULL) { okay = 0; if (showErrors) printf("Unknown option -%c\n", tok[pos]); i++; continue; } if (goo->type == GOO_BOOL_TYPE) { goo->svalue = "true"; continue; } if (goo->type == GOO_STRING_TYPE) { if ((i+1) < dgc_vector_size(toks)) { char *val = (char*) dgc_vector_get(toks, i+1); if (val[0]=='-') { okay = 0; if (showErrors) printf("Ran out of arguments for option block %s\n", tok); } i++; goo->svalue=strdup(val); continue; } okay = 0; if (showErrors) printf("Option -%c requires a string argument.\n", tok[pos]); } } i++; continue; } // it's not an option-- it's an argument. dgc_vector_add(gopt->extraargs, tok); i++; } return okay; }