/* * (udp|tcp) host [port [mcastttl [mcastif]]] */ int ccndc_create(struct ccndc_data *self, int check_only, const char *cmd_orig) { int ret_code = -1; char *cmd, *cmd_token; char *cmd_proto = NULL; char *cmd_host = NULL; char *cmd_port = NULL; char *cmd_mcastttl = NULL; char *cmd_mcastif = NULL; struct ccn_face_instance *face = NULL; struct ccn_face_instance *newface = NULL; if (cmd_orig == NULL) { ccndc_warn(__LINE__, "command error\n"); return -1; } cmd = strdup(cmd_orig); if (cmd == NULL) { ccndc_warn(__LINE__, "Cannot allocate memory for copy of the command\n"); return -1; } cmd_token = cmd; GET_NEXT_TOKEN(cmd_token, cmd_proto); GET_NEXT_TOKEN(cmd_token, cmd_host); GET_NEXT_TOKEN(cmd_token, cmd_port); GET_NEXT_TOKEN(cmd_token, cmd_mcastttl); GET_NEXT_TOKEN(cmd_token, cmd_mcastif); // perform sanity checking face = parse_ccn_face_instance(self, cmd_proto, cmd_host, cmd_port, cmd_mcastttl, cmd_mcastif, self->lifetime); if (face == NULL) goto Cleanup; if (!check_only) { newface = ccndc_do_face_action(self, "newface", face); if (newface == NULL) { ccndc_warn(__LINE__, "Cannot create/lookup face"); goto Cleanup; } ccn_face_instance_destroy(&newface); } ret_code = 0; Cleanup: ccn_face_instance_destroy(&face); free(cmd); return (ret_code); }
int ccndc_destroyface(struct ccndc_data *self, int check_only, const char *cmd_orig) { int ret_code = 0; char *cmd, *cmd_token; char *cmd_faceid = NULL; struct ccn_face_instance *face; struct ccn_face_instance *newface; if (cmd_orig == NULL) { ccndc_warn(__LINE__, "command error\n"); return -1; } cmd = strdup(cmd_orig); if (cmd == NULL) { ccndc_warn(__LINE__, "Cannot allocate memory for copy of the command\n"); return -1; } cmd_token = cmd; GET_NEXT_TOKEN(cmd_token, cmd_faceid); face = parse_ccn_face_instance_from_face(self, cmd_faceid); if (face == NULL) { ret_code = -1; } if (ret_code == 0 && check_only == 0) { newface = ccndc_do_face_action(self, "destroyface", face); if (newface == NULL) { ccndc_warn(__LINE__, "Cannot destroy face %d or the face does not exist\n", face->faceid); } ccn_face_instance_destroy(&newface); } ccn_face_instance_destroy(&face); free(cmd); return ret_code; }
/* * uri (udp|tcp) host [port [flags [mcastttl [mcastif]]]]) * uri face faceid */ int ccndc_renew(struct ccndc_data *self, int check_only, const char *cmd_orig) { int ret_code = -1; char *cmd, *cmd_token; char *cmd_uri = NULL; char *cmd_proto = NULL; char *cmd_host = NULL; char *cmd_port = NULL; char *cmd_flags = NULL; char *cmd_mcastttl = NULL; char *cmd_mcastif = NULL; struct ccn_face_instance *face = NULL; struct ccn_face_instance *newface = NULL; struct ccn_forwarding_entry *prefix = NULL; if (cmd_orig == NULL) { ccndc_warn(__LINE__, "command error\n"); return -1; } cmd = strdup(cmd_orig); if (cmd == NULL) { ccndc_warn(__LINE__, "Cannot allocate memory for copy of the command\n"); return -1; } cmd_token = cmd; GET_NEXT_TOKEN(cmd_token, cmd_uri); GET_NEXT_TOKEN(cmd_token, cmd_proto); GET_NEXT_TOKEN(cmd_token, cmd_host); GET_NEXT_TOKEN(cmd_token, cmd_port); GET_NEXT_TOKEN(cmd_token, cmd_flags); GET_NEXT_TOKEN(cmd_token, cmd_mcastttl); GET_NEXT_TOKEN(cmd_token, cmd_mcastif); // perform sanity checking face = parse_ccn_face_instance(self, cmd_proto, cmd_host, cmd_port, cmd_mcastttl, cmd_mcastif, (~0U) >> 1); prefix = parse_ccn_forwarding_entry(self, cmd_uri, cmd_flags, self->lifetime); if (face == NULL || prefix == NULL) goto Cleanup; if (!check_only) { // look up the old face ("queryface" would be useful) newface = ccndc_do_face_action(self, "newface", face); if (newface == NULL) { ccndc_warn(__LINE__, "Cannot create/lookup face"); goto Cleanup; } face->faceid = newface->faceid; ccn_face_instance_destroy(&newface); // destroy the old face newface = ccndc_do_face_action(self, "destroyface", face); if (newface == NULL) { ccndc_warn(__LINE__, "Cannot destroy face %d or the face does not exist\n", face->faceid); goto Cleanup; } ccn_face_instance_destroy(&newface); // recreate the face newface = ccndc_do_face_action(self, "newface", face); if (newface == NULL) { ccndc_warn(__LINE__, "Cannot create/lookup face"); goto Cleanup; } prefix->faceid = newface->faceid; ccn_face_instance_destroy(&newface); // and add the prefix to it ret_code = ccndc_do_prefix_action(self, "prefixreg", prefix); if (ret_code < 0) { ccndc_warn(__LINE__, "Cannot register prefix [%s]\n", cmd_uri); goto Cleanup; } } ret_code = 0; Cleanup: ccn_face_instance_destroy(&face); ccn_forwarding_entry_destroy(&prefix); free(cmd); return (ret_code); }
/* * (udp|tcp) host [port [mcastttl [mcastif]]] */ int ccndc_destroy(struct ccndc_data *self, int check_only, const char *cmd_orig) { int ret_code = -1; char *cmd, *cmd_token; char *cmd_proto = NULL; char *cmd_host = NULL; char *cmd_port = NULL; char *cmd_mcastttl = NULL; char *cmd_mcastif = NULL; struct ccn_face_instance *face = NULL; struct ccn_face_instance *newface = NULL; if (cmd_orig == NULL) { ccndc_warn(__LINE__, "command error\n"); return -1; } cmd = strdup(cmd_orig); if (cmd == NULL) { ccndc_warn(__LINE__, "Cannot allocate memory for copy of the command\n"); return -1; } cmd_token = cmd; GET_NEXT_TOKEN(cmd_token, cmd_proto); GET_NEXT_TOKEN(cmd_token, cmd_host); GET_NEXT_TOKEN(cmd_token, cmd_port); GET_NEXT_TOKEN(cmd_token, cmd_mcastttl); GET_NEXT_TOKEN(cmd_token, cmd_mcastif); // perform sanity checking face = parse_ccn_face_instance(self, cmd_proto, cmd_host, cmd_port, cmd_mcastttl, cmd_mcastif, (~0U) >> 1); if (face == NULL) goto Cleanup; if (!check_only) { // TODO: should use queryface when implemented if (0 != strcasecmp(cmd_proto, "face")) { newface = ccndc_do_face_action(self, "newface", face); if (newface == NULL) { ccndc_warn(__LINE__, "Cannot create/lookup face"); goto Cleanup; } face->faceid = newface->faceid; ccn_face_instance_destroy(&newface); } newface = ccndc_do_face_action(self, "destroyface", face); if (newface == NULL) { ccndc_warn(__LINE__, "Cannot destroy face %d or the face does not exist\n", face->faceid); goto Cleanup; } ccn_face_instance_destroy(&newface); } ret_code = 0; Cleanup: ccn_face_instance_destroy(&face); free(cmd); return ret_code; }
int ccndc_del(struct ccndc_data *self, int check_only, const char *cmd_orig) { int ret_code = -1; char *cmd, *cmd_token; char *cmd_uri = NULL; char *cmd_proto = NULL; char *cmd_host = NULL; char *cmd_port = NULL; char *cmd_flags = NULL; char *cmd_mcastttl = NULL; char *cmd_mcastif = NULL; struct ccn_face_instance *face = NULL; struct ccn_face_instance *newface = NULL; struct ccn_forwarding_entry *prefix = NULL; if (cmd_orig == NULL) { ccndc_warn(__LINE__, "command error\n"); return -1; } cmd = strdup(cmd_orig); if (cmd == NULL) { ccndc_warn(__LINE__, "Cannot allocate memory for copy of the command\n"); return -1; } cmd_token = cmd; GET_NEXT_TOKEN(cmd_token, cmd_uri); GET_NEXT_TOKEN(cmd_token, cmd_proto); GET_NEXT_TOKEN(cmd_token, cmd_host); GET_NEXT_TOKEN(cmd_token, cmd_port); GET_NEXT_TOKEN(cmd_token, cmd_flags); GET_NEXT_TOKEN(cmd_token, cmd_mcastttl); GET_NEXT_TOKEN(cmd_token, cmd_mcastif); face = parse_ccn_face_instance(self, cmd_proto, cmd_host, cmd_port, cmd_mcastttl, cmd_mcastif, (~0U) >> 1); prefix = parse_ccn_forwarding_entry(self, cmd_uri, cmd_flags, (~0U) >> 1); if (face == NULL || prefix == NULL) goto Cleanup; if (!check_only) { if (0 != strcasecmp(cmd_proto, "face")) { newface = ccndc_do_face_action(self, "newface", face); if (newface == NULL) { ccndc_warn(__LINE__, "Cannot create/lookup face"); goto Cleanup; } prefix->faceid = newface->faceid; ccn_face_instance_destroy(&newface); } else { prefix->faceid = face->faceid; } ret_code = ccndc_do_prefix_action(self, "unreg", prefix); if (ret_code < 0) { ccndc_warn(__LINE__, "Cannot unregister prefix [%s]\n", cmd_uri); goto Cleanup; } } ret_code = 0; Cleanup: ccn_face_instance_destroy(&face); ccn_forwarding_entry_destroy(&prefix); free(cmd); return (ret_code); }
GNOKII_API gn_error gn_file_phonebook_raw_parse(gn_phonebook_entry *entry, char *line) { char memory_type_char[3]; char number[GN_PHONEBOOK_NUMBER_MAX_LENGTH]; int length, o, offset = 0; gn_error error = GN_ERR_NONE; memset(entry, 0, sizeof(gn_phonebook_entry)); length = strlen(line); entry->empty = true; memory_type_char[2] = 0; GET_NEXT_TOKEN(); switch (o) { case 0: return GN_ERR_WRONGDATAFORMAT; case 1: /* empty name: this is a request to delete the entry */ break; default: break; } STORE_TOKEN(entry->name); offset += o; BUG(offset >= length); GET_NEXT_TOKEN(); switch (o) { case 0: return GN_ERR_WRONGDATAFORMAT; default: break; } STORE_TOKEN(entry->number); offset += o; BUG(offset >= length); GET_NEXT_TOKEN(); switch (o) { case 3: break; default: return GN_ERR_WRONGDATAFORMAT; } STORE_TOKEN(memory_type_char); offset += o; BUG(offset >= length); entry->memory_type = gn_str2memory_type(memory_type_char); /* We can store addressbook entries only in ME or SM (or ON on some models) */ if (entry->memory_type != GN_MT_ME && entry->memory_type != GN_MT_SM && entry->memory_type != GN_MT_ON) { return GN_ERR_INVALIDMEMORYTYPE; } BUG(offset >= length); memset(number, 0, sizeof(number)); GET_NEXT_TOKEN(); STORE_TOKEN(number); switch (o) { case 0: return GN_ERR_WRONGDATAFORMAT; case 1: entry->location = 0; break; default: entry->location = atoi(number); break; } offset += o; BUG(offset >= length); memset(number, 0, sizeof(number)); GET_NEXT_TOKEN(); STORE_TOKEN(number); switch (o) { case 0: return GN_ERR_WRONGDATAFORMAT; case 1: entry->caller_group = 0; break; default: entry->caller_group = atoi(number); break; } offset += o; entry->empty = false; for (entry->subentries_count = 0; offset < length; entry->subentries_count++) { if (entry->subentries_count == GN_PHONEBOOK_SUBENTRIES_MAX_NUMBER) { fprintf(stderr, _("Formatting error: too many subentries\n")); error = GN_ERR_WRONGDATAFORMAT; goto endloop; } memset(number, 0, sizeof(number)); GET_NEXT_TOKEN(); STORE_TOKEN(number); switch (o) { case 0: fprintf(stderr, _("Formatting error: unknown error while reading subentry type\n")); error = GN_ERR_WRONGDATAFORMAT; goto endloop; case 1: fprintf(stderr, _("Formatting error: empty entry type\n")); entry->subentries[entry->subentries_count].entry_type = 0; break; default: entry->subentries[entry->subentries_count].entry_type = atoi(number); break; } offset += o; if (offset > length) { fprintf(stderr, _("Formatting error: subentry has only entry type field\n")); break; } memset(number, 0, sizeof(number)); GET_NEXT_TOKEN(); STORE_TOKEN(number); switch (o) { case 0: fprintf(stderr, _("Formatting error: unknown error while reading subentry number type\n")); error = GN_ERR_WRONGDATAFORMAT; goto endloop; case 1: fprintf(stderr, _("Formatting error: empty number type\n")); entry->subentries[entry->subentries_count].number_type = 0; /* Number type is required with Number entry type */ if (entry->subentries[entry->subentries_count].entry_type == GN_PHONEBOOK_ENTRY_Number) { error = GN_ERR_WRONGDATAFORMAT; goto endloop; } break; default: entry->subentries[entry->subentries_count].number_type = atoi(number); break; } offset += o; if (offset > length) { fprintf(stderr, _("Formatting error: subentry has only entry and number type fields\n")); break; } memset(number, 0, sizeof(number)); GET_NEXT_TOKEN(); STORE_TOKEN(number); switch (o) { case 0: fprintf(stderr, _("Formatting error: unknown error while reading subentry id\n")); error = GN_ERR_WRONGDATAFORMAT; goto endloop; case 1: fprintf(stderr, _("Formatting error: empty id\n")); entry->subentries[entry->subentries_count].id = 0; break; default: entry->subentries[entry->subentries_count].id = atoi(number); break; } offset += o; if (offset > length) { fprintf(stderr, _("Formatting error: subentry has only entry and number type fields\n")); break; } GET_NEXT_TOKEN(); switch (entry->subentries[entry->subentries_count].entry_type) { case GN_PHONEBOOK_ENTRY_Date: case GN_PHONEBOOK_ENTRY_Birthday: entry->subentries[entry->subentries_count].data.date.year = local_atoi(line + offset, 4); entry->subentries[entry->subentries_count].data.date.month = local_atoi(line + offset + 4, 2); entry->subentries[entry->subentries_count].data.date.day = local_atoi(line + offset + 6, 2); entry->subentries[entry->subentries_count].data.date.hour = local_atoi(line + offset + 8, 2); entry->subentries[entry->subentries_count].data.date.minute = local_atoi(line + offset + 10, 2); entry->subentries[entry->subentries_count].data.date.second = local_atoi(line + offset + 12, 2); break; case GN_PHONEBOOK_ENTRY_ExtGroup: entry->subentries[entry->subentries_count].data.id = local_atoi(line + offset, 3); break; default: STORE_TOKEN(entry->subentries[entry->subentries_count].data.number); break; } switch (o) { case 0: fprintf(stderr, _("Formatting error: unknown error while reading subentry contents\n")); error = GN_ERR_WRONGDATAFORMAT; goto endloop; case 1: fprintf(stderr, _("Formatting error: empty subentry contents\n")); break; default: break; } offset += o; } endloop: /* Fake subentry: this is to send other exports (like from 6110) to 7110 */ if (!entry->subentries_count) { entry->subentries[entry->subentries_count].entry_type = GN_PHONEBOOK_ENTRY_Number; entry->subentries[entry->subentries_count].number_type = GN_PHONEBOOK_NUMBER_General; entry->subentries[entry->subentries_count].id = 2; snprintf(entry->subentries[entry->subentries_count].data.number, sizeof(entry->subentries[entry->subentries_count].data.number), "%s", entry->number); entry->subentries_count = 1; } return error; }