int ml_unregister_cbr(const char* event, cbr_func cbr) { ASSERT(event != NULL && cbr != NULL); LOCK(ml_cbr_lock); struct cbr_record * record = find_record(event, 0); int retval = -1; int count = 0; if (record == NULL) { dbg_printf("Unknown event %s\n", event); retval = -1; goto end; } struct cbr_node * current = record->first; struct cbr_node * prev = NULL; while(current != NULL) { if(current->cbr == cbr) { if(prev == NULL) { record->first = current->next; //TODO: Possibile optimization: remove record if current->next is NULL } else { prev->next = current->next; } current->cbr = NULL; current->next = NULL; count++; } prev = current; current = current->next; } retval = 0; end: dbg_printf("Removed %d CBRs\n", count); UNLOCK(ml_cbr_lock); return retval; }
// Search the array of phone records for a number void search_records(PhoneRecord records[], size_t count) { Name name; char answer = 'n'; do { name = read_name(); int index = 0; bool first = true; while((index = find_record(records, index, count, &name)) >= 0) { if(first) { printf_s("The numbers for %s %s are:\n", name.firstname, name.secondname); first = false; } printf_s("%s\n", records[index++].number); if(index >= count) break; } if(first) printf_s("No numbers found for %s %s.\n", name.firstname, name.secondname); printf_s("\nDo you want to search for another name (y or n)? "); scanf_s(" %c" , &answer, sizeof(answer)); }while(tolower(answer) == 'y'); }
static DBusMessage *update_xml_record(DBusConnection *conn, DBusMessage *msg, struct service_adapter *serv_adapter) { struct record_data *user_record; sdp_record_t *sdp_record; const char *record; dbus_uint32_t handle; int len; if (dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &handle, DBUS_TYPE_STRING, &record, DBUS_TYPE_INVALID) == FALSE) return NULL; len = (record ? strlen(record) : 0); if (len == 0) return btd_error_invalid_args(msg); user_record = find_record(serv_adapter, handle, dbus_message_get_sender(msg)); if (!user_record) return btd_error_not_available(msg); sdp_record = sdp_xml_parse_record(record, len); if (!sdp_record) { error("Parsing of XML service record failed"); return btd_error_failed(msg, "Parsing of XML service record failed"); } return update_record(conn, msg, serv_adapter, handle, sdp_record); }
std::vector<std::string> find_all(std::vector<std::string> names) { auto db = Database::get(); std::vector<std::string> result; for (auto& name : names) result.push_back(db.find_record(name)); return result; }
static command_status_t record_delete(COMMAND_ARGS) { domain_t *d; record_t *match; bool request_success; domain_record_argument_t *args; args = (domain_record_argument_t *) arg; assert(NULL != args->domain); assert(NULL != args->record); if ((request_success = (COMMAND_SUCCESS == get_domain_records(args->domain, &d, FALSE, error)))) { #if 0 // what was the goal? If true, it is more the domain which does not exist! if (!hashtable_get(domains, argv[0], &d)) { error_set(error, WARN, "Domain '%s' doesn't have any record named '%s'\n", argv[0], argv[3]); return COMMAND_FAILURE; } #endif { size_t matches; matches = find_record(d->records, args->record, &match); switch (matches) { case 1: { if (!confirm(mainopts, _("Confirm deletion of '%s.%s'"), match->name, args->domain)) { return COMMAND_SUCCESS; // yeah, success because user canceled it } break; } case 0: error_set(error, INFO, "No record match '%s'", args->record); return COMMAND_SUCCESS; default: error_set(error, WARN, "Abort, more than one record match '%s'", args->record); return COMMAND_FAILURE; } } { request_t *req; // request req = request_new(REQUEST_FLAG_SIGN, HTTP_DELETE, NULL, error, API_BASE_URL "/domain/zone/%s/record/%" PRIu32, args->domain, match->id); request_success = request_execute(req, RESPONSE_IGNORE, NULL, error); request_destroy(req); // result if (request_success) { hashtable_quick_delete(d->records, match->id, NULL, TRUE); ask_for_refresh(RELAY_COMMAND_ARGS); } } } return request_success ? COMMAND_SUCCESS : COMMAND_FAILURE; }
void debug_cbr_tree(const char * event) { ASSERT(event != NULL); LOCK(ml_cbr_lock); struct cbr_record * record = find_record(event, 0); struct cbr_node * node = record->first; while (node != NULL) { dbg_printf("P:%d\tCBR@0x%x\n", node->priority, (void*)node->cbr); node = node->next; } UNLOCK(ml_cbr_lock); }
static int read_packet(AVFormatContext *s, AVPacket *pkt) { AnmDemuxContext *anm = s->priv_data; ByteIOContext *pb = s->pb; Page *p; int tmp, record_size; if (url_feof(s->pb)) return AVERROR(EIO); if (anm->page < 0) return 0; repeat: p = &anm->pt[anm->page]; /* parse page header */ if (anm->record < 0) { url_fseek(pb, anm->page_table_offset + MAX_PAGES*6 + (anm->page<<16), SEEK_SET); url_fskip(pb, 8 + 2*p->nb_records); anm->record = 0; } /* if we have fetched all records in this page, then find the next page and repeat */ if (anm->record >= p->nb_records) { anm->page = find_record(anm, p->base_record + p->nb_records); if (anm->page < 0) return anm->page; anm->record = -1; goto repeat; } /* fetch record size */ tmp = url_ftell(pb); url_fseek(pb, anm->page_table_offset + MAX_PAGES*6 + (anm->page<<16) + 8 + anm->record * 2, SEEK_SET); record_size = get_le16(pb); url_fseek(pb, tmp, SEEK_SET); /* fetch record */ pkt->size = av_get_packet(s->pb, pkt, record_size); if (pkt->size < 0) return pkt->size; if (p->base_record + anm->record == 0) pkt->flags |= PKT_FLAG_KEY; anm->record++; return 0; }
void ml_notify_cbr(const char * event, void * data) { ASSERT(event != NULL); LOCK(ml_cbr_lock); struct cbr_record * record = find_record(event, 0); if (record == NULL) { return; } struct cbr_node * call = record->first; while (call != NULL) { if (call->cbr != NULL) { if (call->cbr(event, data) == ML_CBR_STOP) { break; } } call = call->next; } UNLOCK(ml_cbr_lock); }
static int remove_record(DBusConnection *conn, const char *sender, struct service_adapter *serv_adapter, dbus_uint32_t handle) { struct record_data *user_record; DBG("remove record 0x%x", handle); user_record = find_record(serv_adapter, handle, sender); if (!user_record) return -1; DBG("listner_id %d", user_record->listener_id); g_dbus_remove_watch(conn, user_record->listener_id); exit_callback(conn, user_record); return 0; }
std::string cache_read() { PROFILE_FUNC(); std::string data; PROFILE_START(action_find); // Starts new action which will be inner to ACTION_READ bool found = find_record(); PROFILE_STOP(action_find); if (!found) { PROFILE_BLOCK(load_from_disk); data = read_from_disk(); put_into_cache(data); return data; // Here all action guards are destructed and actions are correctly finished } data = load_from_cache(); return data; }
int ml_register_cbr(const char * event, cbr_func cbr, unsigned int prio) { ASSERT(event != NULL && cbr != NULL); int retval = -1; LOCK(ml_cbr_lock); ml_unregister_cbr(event, cbr); struct cbr_record * record = find_record(event, 1); if (record == NULL) { struct cbr_record_arena * new_arena = expand_cbr_record_pool(); if (new_arena == NULL || &(new_arena->pool[0]) == NULL) { retval = -1; goto end; } else { record = &(new_arena->pool[0]); } } retval = insert_cbr(record, cbr, prio); end: UNLOCK(ml_cbr_lock); return retval; }
/* find a measurement record by name, * creating it if necessary. */ static struct measure_record *give_record(id_proto) { /* try and find it in list */ int i_found = find_record(id_pass); if (i_found != -1) { return records[i_found]; } /* not found, create it. just append it to the list. * by just enlarging the list, it also creates the list, if necessary. */ record_len++; records = realloc(records, record_len * sizeof(struct measure_record *)); /* create the entry itself */ struct measure_record *r = malloc(sizeof(struct measure_record)); r->name1 = name1; r->name2 = name2; r->accum = 0; records[record_len-1] = r; return r; }
void init_node(const char* p_name) { struct tw_hostent* p_host; char* pa; int i; // pthread_mutex_lock(&mutex); if(find_record(p_name) == 1) { //printf("find a url:%s\n", p_name); p_host = (struct tw_hostent*)malloc(sizeof(struct tw_hostent)); memcpy(p_host->name, p_name, 30); memcpy(p_host->file, p_name, 30); if ((pa = strchr(p_name, '.')) != NULL) { memcpy(p_host->key_word, pa + 1, 30); } p_host->is_dns = 0; p_host->is_url = 0; p_host->prev = NULL; p_host->next = NULL; p_host->id = head.sum; p_host->first = 0; hostent_index[p_host->id] = p_host; for (i = 0; i < 100; i++) { p_host->ip[i] = malloc(4); } p_host->dns = NULL; query_dns(p_host); join_list(&p_host); } // pthread_mutex_unlock(&mutex); return; }
static void append_envvar(const char *name, const char *val) { envvar_t *record; char *p; record = find_record(name); if(record == NULL) { set_envvar(name, val); return; } p = realloc(record->val, strlen(record->val) + strlen(val) + 1); if(p == NULL) { text_buffer_add("Not enough memory"); return; } record->val = p; strcat(record->val, val); env_set(name, record->val); }
static int read_header(AVFormatContext *s, AVFormatParameters *ap) { AnmDemuxContext *anm = s->priv_data; ByteIOContext *pb = s->pb; AVStream *st; int i, ret; url_fskip(pb, 4); /* magic number */ if (get_le16(pb) != MAX_PAGES) { av_log_ask_for_sample(s, "max_pages != " AV_STRINGIFY(MAX_PAGES) "\n"); return AVERROR_INVALIDDATA; } anm->nb_pages = get_le16(pb); anm->nb_records = get_le32(pb); url_fskip(pb, 2); /* max records per page */ anm->page_table_offset = get_le16(pb); if (get_le32(pb) != ANIM_TAG) return AVERROR_INVALIDDATA; /* video stream */ st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_ANM; st->codec->codec_tag = 0; /* no fourcc */ st->codec->width = get_le16(pb); st->codec->height = get_le16(pb); if (get_byte(pb) != 0) goto invalid; url_fskip(pb, 1); /* frame rate multiplier info */ /* ignore last delta record (used for looping) */ if (get_byte(pb)) /* has_last_delta */ anm->nb_records = FFMAX(anm->nb_records - 1, 0); url_fskip(pb, 1); /* last_delta_valid */ if (get_byte(pb) != 0) goto invalid; if (get_byte(pb) != 1) goto invalid; url_fskip(pb, 1); /* other recs per frame */ if (get_byte(pb) != 1) goto invalid; url_fskip(pb, 32); /* record_types */ st->nb_frames = get_le32(pb); av_set_pts_info(st, 64, 1, get_le16(pb)); url_fskip(pb, 58); /* color cycling and palette data */ st->codec->extradata_size = 16*8 + 4*256; st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); if (!st->codec->extradata) { ret = AVERROR(ENOMEM); goto close_and_return; } ret = get_buffer(pb, st->codec->extradata, st->codec->extradata_size); if (ret < 0) goto close_and_return; /* read page table */ ret = url_fseek(pb, anm->page_table_offset, SEEK_SET); if (ret < 0) goto close_and_return; for (i = 0; i < MAX_PAGES; i++) { Page *p = &anm->pt[i]; p->base_record = get_le16(pb); p->nb_records = get_le16(pb); p->size = get_le16(pb); } /* find page of first frame */ anm->page = find_record(anm, 0); if (anm->page < 0) { ret = anm->page; goto close_and_return; } anm->record = -1; return 0; invalid: av_log_ask_for_sample(s, NULL); ret = AVERROR_INVALIDDATA; close_and_return: av_close_input_stream(s); return ret; }
const char * local_getenv(const char *envname) { envvar_t *record = find_record(envname); return (record == NULL || record->removed) ? "" : record->val; }
int unlet_variables(const char *cmd) { int error = 0; assert(initialized); while(*cmd != '\0') { envvar_t *record; char name[VAR_NAME_MAX + 1]; char *p; int envvar = 1; /* check if its environment variable */ if(*cmd != '$') envvar = 0; else cmd++; /* copy variable name */ p = name; while(*cmd != '\0' && char_is_one_of(ENV_VAR_NAME_CHARS, *cmd) && p - name < sizeof(name) - 1) *p++ = *cmd++; *p = '\0'; if(*cmd != '\0' && !isspace(*cmd)) { text_buffer_add("Trailing characters"); error++; break; } cmd = skip_whitespace(cmd); /* currently we support only environment variables */ if(!envvar) { text_buffer_addf("%s: %s", "Unsupported variable type", name); cmd = skip_non_whitespace(cmd); error++; continue; } /* test for empty variable name */ if(name[0] == '\0') { text_buffer_addf("%s: %s", "Unsupported variable name", "empty name"); error++; continue; } record = find_record(name); if(record == NULL || record->removed) { text_buffer_addf("%s: %s", "No such variable", name); error++; continue; } if(record->from_parent) record->removed = 1; else free_record(record); env_remove(name); } return error; }
static int read_header(AVFormatContext *s) { AnmDemuxContext *anm = s->priv_data; AVIOContext *pb = s->pb; AVStream *st; int i, ret; avio_skip(pb, 4); /* magic number */ if (avio_rl16(pb) != MAX_PAGES) { avpriv_request_sample(s, "max_pages != " AV_STRINGIFY(MAX_PAGES)); return AVERROR_PATCHWELCOME; } anm->nb_pages = avio_rl16(pb); anm->nb_records = avio_rl32(pb); avio_skip(pb, 2); /* max records per page */ anm->page_table_offset = avio_rl16(pb); if (avio_rl32(pb) != ANIM_TAG) return AVERROR_INVALIDDATA; /* video stream */ st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = AV_CODEC_ID_ANM; st->codec->codec_tag = 0; /* no fourcc */ st->codec->width = avio_rl16(pb); st->codec->height = avio_rl16(pb); if (avio_r8(pb) != 0) goto invalid; avio_skip(pb, 1); /* frame rate multiplier info */ /* ignore last delta record (used for looping) */ if (avio_r8(pb)) /* has_last_delta */ anm->nb_records = FFMAX(anm->nb_records - 1, 0); avio_skip(pb, 1); /* last_delta_valid */ if (avio_r8(pb) != 0) goto invalid; if (avio_r8(pb) != 1) goto invalid; avio_skip(pb, 1); /* other recs per frame */ if (avio_r8(pb) != 1) goto invalid; avio_skip(pb, 32); /* record_types */ st->nb_frames = avio_rl32(pb); avpriv_set_pts_info(st, 64, 1, avio_rl16(pb)); avio_skip(pb, 58); /* color cycling and palette data */ st->codec->extradata_size = 16*8 + 4*256; st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); if (!st->codec->extradata) { return AVERROR(ENOMEM); } ret = avio_read(pb, st->codec->extradata, st->codec->extradata_size); if (ret < 0) return ret; /* read page table */ ret = avio_seek(pb, anm->page_table_offset, SEEK_SET); if (ret < 0) return ret; for (i = 0; i < MAX_PAGES; i++) { Page *p = &anm->pt[i]; p->base_record = avio_rl16(pb); p->nb_records = avio_rl16(pb); p->size = avio_rl16(pb); } /* find page of first frame */ anm->page = find_record(anm, 0); if (anm->page < 0) { return anm->page; } anm->record = -1; return 0; invalid: avpriv_request_sample(s, "Invalid header element"); return AVERROR_PATCHWELCOME; }
/* and initialize some things */ void check_rc(char *use_output) { struct structure *s; struct output *o; struct record *r,*fr; struct field *f; struct lookup *l; int several_records = 0; int errors = 0; int ordinal; int field_count_first; int var_field_found; char num[64]; s = structure; o = output; if(s == NULL) { errors++; fprintf(stderr,"%s: No structure definitions in rc-file\n",program); } while(s != NULL) { if(use_output != NULL) { free(s->output_name); s->output_name = xstrdup(use_output); } if(s->output_name == NULL) { s->output_name = DEFAULT_OUTPUT; } s->o = search_output(s->output_name); s->max_record_len = 0; if(s->o == NULL) errors++; r = s->r; if(r == NULL) { errors++; fprintf(stderr,"%s: No records in structure \'%s\'\n",program,s->name); } else { several_records = r->next != NULL ? 1 : 0; } if(s->quote && s->type[0] == SEPARATED) { if(s->quote == s->type[1]) { errors++; fprintf(stderr,"%s: Quotation and separator cannot be the same character, structure \'%s\'\n",program,s->name); } } if(s->header && s->type[0] != SEPARATED) { errors++; fprintf(stderr,"%s: Headers are valid only in separated input, structure \'%s\'\n",program,s->name); } field_count_first = 0; while(r != NULL) { if(r->output_name == NULL || use_output != NULL) { if(r->output_name != NULL) free(r->output_name); r->output_name = s->output_name; r->o = s->o; } else { r->o = search_output(r->output_name); if(r->o == NULL) errors++; } if(several_records && s->type[0] == BINARY && r->i == NULL) { errors++; fprintf(stderr,"%s: Every record in a binary multi-record structure must have an id, structure \'%s\', record \'%s\'\n",program,s->name,r->name); } if(r->fields_from != NULL) { if(r->f != NULL) { errors++; fprintf(stderr,"%s: field and fields-from are mutually exclusive, structure \'%s\', record \'%s\'\n",program,s->name,r->name); } fr = find_record(s,r->fields_from); if(fr != NULL) { r->f = fr->f; } else { errors++; fprintf(stderr,"%s: No record named as '\%s\' in structure \'%s\'\n",program,r->fields_from,s->name); } } f = r->f; if(f == NULL) { errors++; fprintf(stderr,"%s: No fields in record \'%s\'\n",program,r->name); } r->length = 0; ordinal = 1; var_field_found = 0; while(f != NULL) { if(s->type[0] == FIXED_LENGTH || s->type[0] == BINARY) { if (r->length_field_name != NULL && strcmp(r->length_field_name,f->name) == 0) r->length_field = f; if (r->var_field_name != NULL && strcmp(r->var_field_name,f->name) == 0) { f->length = 0; f->var_length = 1; } f->position = r->length; f->bposition = r->length; r->length += f->length; } else { f->position = ordinal; r->length++; if(s->header) { if(r == s->r) { field_count_first++; } } } if(!s->header && f->name == NULL) { sprintf(num,"%d",ordinal); f->name = xstrdup(num); } if(s->type[0] == BINARY && f->length < 1) { if((r->length_field != NULL && var_field_found) || !r->length_field_name) { errors++; fprintf(stderr,"%s: The field \'%s\' must have length in binary structure \'%s\' record \'%s\'\n",program ,f->name,s->name,r->name); } var_field_found = 1; } if(s->type[0] == FIXED_LENGTH && f->length < 1) { if(f->next) /* last field can have length 0 */ { if(r->length_field != NULL && var_field_found) { errors++; fprintf(stderr,"%s: The field \'%s\' must have length in fixed length structure \'%s\' record \'%s\'\n",program,f->name,s->name,r->name); } var_field_found = 1; } else { if(r->length_field == NULL) r->arb_length = 1; } } if(f->lookup_table_name != NULL) { l = lookup; while(l != NULL && f->lookup == NULL) { if(strcmp(l->name,f->lookup_table_name) == 0) { f->lookup = l; } l = l->next; } if(f->lookup == NULL) { errors++; fprintf(stderr,"%s: No lookup table named as '%s'\n",program,f->lookup_table_name); } } if(f->output_name != NULL && use_output == NULL) { f->o = search_output(f->output_name); if(f->o == NULL) errors++; if(f->o == raw) { errors++; fprintf(stderr,"%s: Field cannot have output \'raw\', field \'%s\'\n",program,f->name); } } if(f->pipe_name != NULL) { f->p = search_pipe(f->pipe_name); if(f->p == NULL) { errors++; fprintf(stderr,"%s: No filter named as '%s'\n",program,f->pipe_name); } } f = f->next; ordinal++; } if (r->length_field_name != NULL && !r->length_field) { errors++; fprintf(stderr,"%s: Record \'%s\' does not contain length field '\%s\'\n",program,r->name,r->length_field_name); } if(r->length < 1 && s->type[0] == BINARY) { errors++; fprintf(stderr,"%s: Record \'%s\' in structure \'%s\' must have length\n",program,r->name,s->name); } if(r->length > s->max_record_len) s->max_record_len = r->length; if(s->type[0] == BINARY && s->max_record_len > max_binary_record_length) max_binary_record_length = s->max_record_len; if(s->header && r->length != field_count_first) { errors++; fprintf(stderr,"%s: All records in separated structure with header must have equal count of fields, structure \'%s\'\n",program,s->name); } r = r->next; } s = s->next; }
int unlet_variables(const char *cmd) { int error = 0; assert(initialized); while(*cmd != '\0') { var_t *record; char name[VAR_NAME_MAX + 1]; char *p; int envvar = 1; /* check if its environment variable */ if(*cmd != '$') envvar = 0; else cmd++; /* copy variable name */ p = name; while(*cmd != '\0' && !isspace(*cmd) && *cmd != '=' && p - name < sizeof(name) - 1) *p++ = *cmd++; *p = '\0'; /* skip spaces */ while(isspace(*cmd)) cmd++; /* currently we support only environment variables */ if(!envvar) { print_msg(1, "Unsupported variable type", name); /* skip non-spaces */ while(*cmd != '\0' && !isspace(*cmd)) cmd++; error++; continue; } /* test for empty variable name */ if(name[0] == '\0') { print_msg(1, "Unsupported variable name", "empty name"); error++; continue; } record = find_record(name); if(record == NULL || record->removed) { print_msg(1, "No such variable", name); error++; continue; } if(record->from_parent) record->removed = 1; else free_record(record); env_remove(name); } return error; }
static DBusMessage *request_authorization(DBusConnection *conn, DBusMessage *msg, void *data) { struct record_data *user_record; struct service_adapter *serv_adapter = data; sdp_record_t *record; sdp_list_t *services; const char *sender; dbus_uint32_t handle; const char *address; struct pending_auth *auth; char uuid_str[MAX_LEN_UUID_STR]; uuid_t *uuid, *uuid128; bdaddr_t src; if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, DBUS_TYPE_UINT32, &handle, DBUS_TYPE_INVALID) == FALSE) return NULL; sender = dbus_message_get_sender(msg); if (find_pending_by_sender(serv_adapter, sender)) return btd_error_does_not_exist(msg); user_record = find_record(serv_adapter, handle, sender); if (!user_record) { user_record = find_record(serv_adapter_any, handle, sender); if (!user_record) return btd_error_not_authorized(msg); } record = sdp_record_find(user_record->handle); if (record == NULL) return btd_error_not_authorized(msg); if (sdp_get_service_classes(record, &services) < 0) { sdp_record_free(record); return btd_error_not_authorized(msg); } if (services == NULL) return btd_error_not_authorized(msg); uuid = services->data; uuid128 = sdp_uuid_to_uuid128(uuid); sdp_list_free(services, bt_free); if (sdp_uuid2strn(uuid128, uuid_str, MAX_LEN_UUID_STR) < 0) { bt_free(uuid128); return btd_error_not_authorized(msg); } bt_free(uuid128); auth = g_new0(struct pending_auth, 1); auth->msg = dbus_message_ref(msg); auth->conn = dbus_connection_ref(connection); auth->sender = user_record->sender; memcpy(auth->uuid, uuid_str, MAX_LEN_UUID_STR); str2ba(address, &auth->dst); serv_adapter->pending_list = g_slist_append(serv_adapter->pending_list, auth); auth = next_pending(serv_adapter); if (auth == NULL) return btd_error_does_not_exist(msg); if (serv_adapter->adapter) adapter_get_address(serv_adapter->adapter, &src); else bacpy(&src, BDADDR_ANY); if (btd_request_authorization(&src, &auth->dst, auth->uuid, auth_cb, serv_adapter) < 0) { serv_adapter->pending_list = g_slist_remove(serv_adapter->pending_list, auth); g_free(auth); return btd_error_not_authorized(msg); } return NULL; }
// arguments: [ttl <int>] [name <string>] [target <string>] // (in any order) // if we change record's name (subDomain), we need to update records cache static command_status_t record_update(COMMAND_ARGS) { domain_t *d; record_t *r; bool success; domain_record_argument_t *args; USED(mainopts); args = (domain_record_argument_t *) arg; assert(NULL != args->domain); assert(NULL != args->record); if ((success = (COMMAND_SUCCESS == get_domain_records(args->domain, &d, FALSE, error)))) { json_document_t *reqdoc; size_t matches; matches = find_record(d->records, args->record, &r); switch (matches) { case 1: // NOP : OK break; case 0: error_set(error, WARN, "Abort, no record match '%s'", args->record); return COMMAND_FAILURE; default: error_set(error, WARN, "Abort, more than one record match '%s'", args->record); return COMMAND_FAILURE; } // data { json_value_t root; reqdoc = json_document_new(); root = json_object(); if (NULL != args->value) { json_object_set_property(root, "target", json_string(args->value)); } if (NULL != args->name) { json_object_set_property(root, "subDomain", json_string(args->name)); } json_object_set_property(root, "ttl", json_integer(args->ttl)); json_document_set_root(reqdoc, root); } // request { request_t *req; req = request_new(REQUEST_FLAG_SIGN | REQUEST_FLAG_JSON, HTTP_PUT, reqdoc, error, API_BASE_URL "/domain/zone/%s/record/%" PRIu32, args->domain, r->id); success = request_execute(req, RESPONSE_IGNORE, NULL, error); request_destroy(req); json_document_destroy(reqdoc); } if (success) { if (NULL != args->value) { FREE(r, target); r->target = strdup(args->value); } if (NULL != args->name) { FREE(r, name); r->name = strdup(args->name); } r->ttl = args->ttl; ask_for_refresh(RELAY_COMMAND_ARGS); } } // debug("request update of %s.%s to %s.%s with TTL = %" PRIu32 " and value = '%s'", args->record, args->domain, args->name, args->domain, args->ttl, args->value); return COMMAND_SUCCESS; }