ccndumpnames.c

Go to the documentation of this file.
00001 /**
00002  * @file ccndumpnames.c
00003  *
00004  * Dumps names of everything quickly retrievable to stdout
00005  *
00006  * A CCNx command-line utility.
00007  *
00008  * Copyright (C) 2008-2010 Palo Alto Research Center, Inc.
00009  *
00010  * This work is free software; you can redistribute it and/or modify it under
00011  * the terms of the GNU General Public License version 2 as published by the
00012  * Free Software Foundation.
00013  * This work is distributed in the hope that it will be useful, but WITHOUT ANY
00014  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
00016  * for more details. You should have received a copy of the GNU General Public
00017  * License along with this program; if not, write to the
00018  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
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  * This is a temporary interface, don't even bother to put it in a header file.
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 }
Generated on Fri May 13 16:27:01 2011 for Content-Centric Networking in C by  doxygen 1.6.3