/* * 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); }
int ccndc_srv(struct ccndc_data *self, const unsigned char *domain, size_t domain_size) { char *proto = NULL; char *host = NULL; int port = 0; char port_str[10]; struct ccn_charbuf *uri; struct ccn_charbuf *uri_auto; struct ccn_face_instance *face; struct ccn_face_instance *newface; struct ccn_forwarding_entry *prefix; struct ccn_forwarding_entry *prefix_auto; int res; res = ccndc_query_srv(domain, domain_size, &host, &port, &proto); if (res < 0) { return -1; } uri = ccn_charbuf_create(); ccn_charbuf_append_string(uri, "ccnx:/"); if (domain_size != 0) { ccn_uri_append_percentescaped(uri, domain, domain_size); } snprintf (port_str, sizeof(port_str), "%d", port); /* now process the results */ /* pflhead, lineno=0, "add" "ccnx:/asdfasdf.com/" "tcp|udp", host, portstring, NULL NULL NULL */ ccndc_note(__LINE__, " >>> trying: add %s %s %s %s <<<\n", ccn_charbuf_as_string(uri), proto, host, port_str); face = parse_ccn_face_instance(self, proto, host, port_str, NULL, NULL, (~0U) >> 1); prefix = parse_ccn_forwarding_entry(self, ccn_charbuf_as_string(uri), NULL, self->lifetime); if (face == NULL || prefix == NULL) { res = -1; goto Cleanup; } // crazy operation // First. "Create" face, which will do nothing if face already exists // Second. Destroy the face // Third. Create face for real newface = ccndc_do_face_action(self, "newface", face); if (newface == NULL) { ccndc_warn(__LINE__, "Cannot create/lookup face"); res = -1; 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"); } else { ccn_face_instance_destroy(&newface); } newface = ccndc_do_face_action(self, "newface", face); if (newface == NULL) { ccndc_warn(__LINE__, "Cannot create/lookup face"); res = -1; goto Cleanup; } prefix->faceid = newface->faceid; ccn_face_instance_destroy(&newface); res = ccndc_do_prefix_action(self, "prefixreg", prefix); if (res < 0) { ccndc_warn(__LINE__, "Cannot register prefix [%s]\n", ccn_charbuf_as_string(uri)); } uri_auto = ccn_charbuf_create(); ccn_charbuf_append_string(uri_auto, "ccnx:/autoconf-route"); prefix_auto = parse_ccn_forwarding_entry(self, ccn_charbuf_as_string(uri_auto), NULL, self->lifetime); if (prefix_auto == NULL) { res = -1; goto Cleanup; } prefix_auto->faceid = prefix->faceid; res = ccndc_do_prefix_action(self, "prefixreg", prefix_auto); if (res < 0) { ccndc_warn(__LINE__, "Cannot register prefix_auto [%s]\n", ccn_charbuf_as_string(uri_auto)); } Cleanup: free(host); ccn_charbuf_destroy(&uri); ccn_charbuf_destroy(&uri_auto); ccn_face_instance_destroy(&face); ccn_forwarding_entry_destroy(&prefix); ccn_forwarding_entry_destroy(&prefix_auto); return res; }
/* * uri (udp|tcp) host [port [flags [mcastttl [mcastif]]]]) * uri face faceid */ int ccndc_add(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); printf("cmd_uri:\t%s\ncmd_proto:\t%s\ncmd_host:\t%s\ncmd_port:\t%s\ncmd_flags:\t%s\ncmd_mcastttl:\t%s\ncmd_mcastif:\t%s\n", cmd_uri, cmd_proto, cmd_host, cmd_port, cmd_flags, cmd_mcastttl, 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; printf("face->action: %s\nface->descr->address: %s\nface->descr.source_addr: %s\n", face->action, face->descr.address, face->descr.source_address); if (!check_only) { if (0 != strcasecmp(cmd_proto, "face")) { newface = ccndc_do_face_action(self, "newface", face); printf("newface: %p\n", newface); 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, "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); }