void NCDValue_Free (NCDValue *o) { switch (o->type) { case NCDVALUE_STRING: { free(o->string); } break; case NCDVALUE_LIST: { LinkedList1Node *n; while (n = LinkedList1_GetFirst(&o->list)) { struct NCDValue__list_element *e = UPPER_OBJECT(n, struct NCDValue__list_element, list_node); NCDValue_Free(&e->v); LinkedList1_Remove(&o->list, &e->list_node); free(e); } } break; case NCDVALUE_MAP: { LinkedList1Node *n; while (n = LinkedList1_GetFirst(&o->map_list)) { struct NCDValue__map_element *e = UPPER_OBJECT(n, struct NCDValue__map_element, list_node); LinkedList1_Remove(&o->map_list, &e->list_node); NCDValue_Free(&e->key); NCDValue_Free(&e->val); free(e); } } break; case NCDVALUE_VAR: { free(o->var_name); } break; case NCDVALUE_INVOC: { NCDValue_Free(o->invoc_arg); NCDValue_Free(o->invoc_func); free(o->invoc_arg); free(o->invoc_func); } break; default: ASSERT(0); } }
static void free_frame (FragmentProtoAssembler *o, struct FragmentProtoAssembler_frame *frame) { // remove from used list LinkedList1_Remove(&o->frames_used, &frame->list_node); // remove from used tree FPAFramesTree_Remove(&o->frames_used_tree, 0, frame); // append to free list LinkedList1_Append(&o->frames_free, &frame->list_node); }
void BPending_Free (BPending *o) { DebugCounter_Decrement(&o->g->pending_ctr); DebugObject_Free(&o->d_obj); // remove from jobs list if (o->pending) { LinkedList1_Remove(&o->g->jobs, &o->pending_node); } }
static void remove_dns_entry (struct instance *o, struct dns_entry *entry) { // remove from list LinkedList1_Remove(&o->entries, &entry->list_node); // free line free(entry->line); // free entry free(entry); }
void BPending_Unset (BPending *o) { DebugObject_Access(&o->d_obj); if (o->pending) { // remove from jobs list LinkedList1_Remove(&o->g->jobs, &o->pending_node); // set not pending o->pending = 0; } }
void DPReceivePeer_Free (DPReceivePeer *o) { DebugObject_Free(&o->d_obj); DebugCounter_Free(&o->d_receivers_ctr); ASSERT(!o->dp_sink) // remove from peers list LinkedList1_Remove(&o->device->peers_list, &o->list_node); // free relay sink DPRelaySink_Free(&o->relay_sink); // free relay source DPRelaySource_Free(&o->relay_source); }
void BPending_Set (BPending *o) { DebugObject_Access(&o->d_obj); // remove from jobs list if (o->pending) { LinkedList1_Remove(&o->g->jobs, &o->pending_node); } // insert to jobs list LinkedList1_Append(&o->g->jobs, &o->pending_node); // set pending o->pending = 1; }
static void func_die (void *vo) { struct instance *o = vo; struct global *g = ModuleGlobal(o->i); // remove from instances LinkedList1_Remove(&g->instances, &o->instances_node); // set servers set_servers(g); // free servers remove_entries(o); NCDModuleInst_Backend_Dead(o->i); }
static void schedule (PacketPassFifoQueue *o) { ASSERT(!o->freeing) ASSERT(!o->sending_flow) ASSERT(!LinkedList1_IsEmpty(&o->waiting_flows_list)) ASSERT(!BPending_IsSet(&o->schedule_job)) // get first waiting flow PacketPassFifoQueueFlow *flow = UPPER_OBJECT(LinkedList1_GetFirst(&o->waiting_flows_list), PacketPassFifoQueueFlow, waiting_flows_list_node); ASSERT(flow->queue == o) ASSERT(flow->is_waiting) // remove it from queue LinkedList1_Remove(&o->waiting_flows_list, &flow->waiting_flows_list_node); flow->is_waiting = 0; // send PacketPassInterface_Sender_Send(o->output, flow->waiting_data, flow->waiting_len); o->sending_flow = flow; }
void PacketPassFifoQueueFlow_Free (PacketPassFifoQueueFlow *o) { PacketPassFifoQueue *queue = o->queue; DebugObject_Free(&o->d_obj); DebugCounter_Decrement(&queue->d_flows_ctr); ASSERT(queue->freeing || o != queue->sending_flow) // remove from sending flow if (o == queue->sending_flow) { queue->sending_flow = NULL; } // remove from waiting flows list if (o->is_waiting) { LinkedList1_Remove(&queue->waiting_flows_list, &o->waiting_flows_list_node); } // free input PacketPassInterface_Free(&o->input); }
void BPendingGroup_ExecuteJob (BPendingGroup *g) { ASSERT(!LinkedList1_IsEmpty(&g->jobs)) DebugObject_Access(&g->d_obj); // get a job LinkedList1Node *node = LinkedList1_GetLast(&g->jobs); BPending *p = UPPER_OBJECT(node, BPending, pending_node); ASSERT(p->pending) // remove from jobs list LinkedList1_Remove(&g->jobs, &p->pending_node); // set not pending p->pending = 0; // execute job p->handler(p->user); return; }
static void func_new_resolvconf (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params) { struct global *g = ModuleGlobal(i); struct instance *o = vo; o->i = i; // init servers list LinkedList1_Init(&o->entries); // get arguments NCDValRef lines_arg; NCDValRef priority_arg; if (!NCDVal_ListRead(params->args, 2, &lines_arg, &priority_arg)) { ModuleLog(o->i, BLOG_ERROR, "wrong arity"); goto fail1; } if (!NCDVal_IsList(lines_arg) || !NCDVal_IsString(priority_arg)) { ModuleLog(o->i, BLOG_ERROR, "wrong type"); goto fail1; } uintmax_t priority; if (!ncd_read_uintmax(priority_arg, &priority) || priority > INT_MAX) { ModuleLog(o->i, BLOG_ERROR, "wrong priority"); goto fail1; } // read lines size_t count = NCDVal_ListCount(lines_arg); for (size_t j = 0; j < count; j++) { int loop_failed = 1; NCDValRef line = NCDVal_ListGet(lines_arg, j); if (!NCDVal_IsList(line) || NCDVal_ListCount(line) != 2) { ModuleLog(o->i, BLOG_ERROR, "lines element is not a list with two elements"); goto loop_fail0; } NCDValRef type = NCDVal_ListGet(line, 0); NCDValRef value = NCDVal_ListGet(line, 1); if (!NCDVal_IsStringNoNulls(type) || !NCDVal_IsStringNoNulls(value)) { ModuleLog(o->i, BLOG_ERROR, "wrong type of type or value"); goto loop_fail0; } NCDValNullTermString type_nts; if (!NCDVal_StringNullTerminate(type, &type_nts)) { ModuleLog(o->i, BLOG_ERROR, "NCDVal_StringNullTerminate failed"); goto loop_fail0; } NCDValNullTermString value_nts; if (!NCDVal_StringNullTerminate(value, &value_nts)) { ModuleLog(o->i, BLOG_ERROR, "NCDVal_StringNullTerminate failed"); goto loop_fail1; } if (!add_dns_entry(o, type_nts.data, value_nts.data, priority)) { ModuleLog(o->i, BLOG_ERROR, "failed to add dns entry"); goto loop_fail2; } loop_failed = 0; loop_fail2: NCDValNullTermString_Free(&value_nts); loop_fail1: NCDValNullTermString_Free(&type_nts); loop_fail0: if (loop_failed) { goto fail1; } } // add to instances LinkedList1_Append(&g->instances, &o->instances_node); // set servers if (!set_servers(g)) { ModuleLog(o->i, BLOG_ERROR, "failed to set DNS servers"); goto fail2; } // signal up NCDModuleInst_Backend_Up(o->i); return; fail2: LinkedList1_Remove(&g->instances, &o->instances_node); fail1: remove_entries(o); NCDModuleInst_Backend_DeadError(i); }
static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params) { struct global *g = ModuleGlobal(i); struct instance *o = vo; o->i = i; // init servers list LinkedList1_Init(&o->entries); // get arguments NCDValRef servers_arg; NCDValRef priority_arg; if (!NCDVal_ListRead(params->args, 2, &servers_arg, &priority_arg)) { ModuleLog(o->i, BLOG_ERROR, "wrong arity"); goto fail1; } if (!NCDVal_IsList(servers_arg) || !NCDVal_IsString(priority_arg)) { ModuleLog(o->i, BLOG_ERROR, "wrong type"); goto fail1; } uintmax_t priority; if (!ncd_read_uintmax(priority_arg, &priority) || priority > INT_MAX) { ModuleLog(o->i, BLOG_ERROR, "wrong priority"); goto fail1; } // read servers size_t count = NCDVal_ListCount(servers_arg); for (size_t j = 0; j < count; j++) { NCDValRef server_arg = NCDVal_ListGet(servers_arg, j); if (!NCDVal_IsString(server_arg)) { ModuleLog(o->i, BLOG_ERROR, "wrong type"); goto fail1; } uint32_t addr; if (!ipaddr_parse_ipv4_addr_bin((char *)NCDVal_StringData(server_arg), NCDVal_StringLength(server_arg), &addr)) { ModuleLog(o->i, BLOG_ERROR, "wrong addr"); goto fail1; } char addr_str[IPADDR_PRINT_MAX]; ipaddr_print_addr(addr, addr_str); if (!add_dns_entry(o, "nameserver", addr_str, priority)) { ModuleLog(o->i, BLOG_ERROR, "failed to add dns entry"); goto fail1; } } // add to instances LinkedList1_Append(&g->instances, &o->instances_node); // set servers if (!set_servers(g)) { ModuleLog(o->i, BLOG_ERROR, "failed to set DNS servers"); goto fail2; } // signal up NCDModuleInst_Backend_Up(o->i); return; fail2: LinkedList1_Remove(&g->instances, &o->instances_node); fail1: remove_entries(o); NCDModuleInst_Backend_DeadError(i); }