ccndumpnames.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 #include <string.h>
00025 #include <unistd.h>
00026
00027 #include <ccn/ccn.h>
00028 #include <ccn/charbuf.h>
00029 #include <ccn/uri.h>
00030
00031
00032
00033
00034 void
00035 ccn_dump_names(struct ccn *h, struct ccn_charbuf *name_prefix, int local_scope, int allow_stale);
00036
00037 static void
00038 usage(const char *progname)
00039 {
00040 fprintf(stderr,
00041 "%s [-a] [uri]\n"
00042 " Dumps names of everything quickly retrievable\n"
00043 " -a - allow stale data\n",
00044 progname);
00045 exit(1);
00046 }
00047
00048 int
00049 main(int argc, char **argv)
00050 {
00051 struct ccn *ccn = NULL;
00052 struct ccn_charbuf *c = NULL;
00053 int allow_stale = 0;
00054 int opt;
00055 int res;
00056
00057 while ((opt = getopt(argc, argv, "ha")) != -1) {
00058 switch (opt) {
00059 case 'a':
00060 allow_stale = 1;
00061 break;
00062 case 'h':
00063 default:
00064 usage(argv[0]);
00065 }
00066 }
00067
00068 ccn = ccn_create();
00069 if (ccn_connect(ccn, NULL) == -1) {
00070 perror("Could not connect to ccnd");
00071 exit(1);
00072 }
00073 c = ccn_charbuf_create();
00074 if (argv[optind] == NULL)
00075 ccn_name_init(c);
00076 else {
00077 res = ccn_name_from_uri(c, argv[optind]);
00078 if (res < 0) {
00079 fprintf(stderr, "%s: bad ccn URI: %s\n", argv[0], argv[optind]);
00080 exit(1);
00081 }
00082 if (argv[optind+1] != NULL)
00083 fprintf(stderr, "%s warning: extra arguments ignored\n", argv[0]);
00084 }
00085 ccn_dump_names(ccn, c, 1, allow_stale);
00086 exit(0);
00087 }