basicparsetest.c

Go to the documentation of this file.
00001 /**
00002  * @file basicparsetest.c
00003  * 
00004  * A CCNx test program.
00005  *
00006  * Copyright (C) 2009 Palo Alto Research Center, Inc.
00007  *
00008  * This work is free software; you can redistribute it and/or modify it under
00009  * the terms of the GNU General Public License version 2 as published by the
00010  * Free Software Foundation.
00011  * This work is distributed in the hope that it will be useful, but WITHOUT ANY
00012  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
00014  * for more details. You should have received a copy of the GNU General Public
00015  * License along with this program; if not, write to the
00016  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  */
00019 
00020 #include <stddef.h>
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <unistd.h>
00025 
00026 #include <ccn/ccn.h>
00027 #include <ccn/charbuf.h>
00028 #include <ccn/coding.h>
00029 #include <ccn/face_mgmt.h>
00030 #include <ccn/sockcreate.h>
00031 #include <ccn/reg_mgmt.h>
00032 #include <ccn/header.h>
00033 
00034 /**
00035  * This is for testing.
00036  *
00037  * Reads ccnb-encoded data from stdin and 
00038  * tries parsing with various parsers, and when successful turns
00039  * the result back into ccnb and tests for goodness.
00040  *
00041  */
00042 int
00043 main (int argc, char **argv)
00044 {
00045     unsigned char buf[8800];
00046     ssize_t size;
00047     struct ccn_face_instance *face_instance;
00048     struct ccn_forwarding_entry *forwarding_entry;
00049     struct ccn_header *header;
00050     int res = 1;
00051     struct ccn_charbuf *c = ccn_charbuf_create();
00052     int i;
00053     struct ccn_parsed_interest parsed_interest = {0};
00054     struct ccn_parsed_interest *pi = &parsed_interest;
00055     
00056     size = read(0, buf, sizeof(buf));
00057     if (size < 0)
00058         exit(0);
00059     
00060     face_instance = ccn_face_instance_parse(buf, size);
00061     if (face_instance != NULL) {
00062         printf("face_instance OK\n");
00063         c->length = 0;
00064         res = ccnb_append_face_instance(c, face_instance);
00065         if (res != 0)
00066             printf("face_instance append failed\n");
00067         if (memcmp(buf, c->buf, c->length) != 0)
00068             printf("face_instance mismatch\n");
00069         ccn_face_instance_destroy(&face_instance);
00070         face_instance = ccn_face_instance_parse(c->buf, c->length);
00071         if (face_instance == NULL) {
00072             printf("face_instance reparse failed\n");
00073             res = 1;
00074         }
00075     }
00076     ccn_face_instance_destroy(&face_instance);
00077     
00078     forwarding_entry = ccn_forwarding_entry_parse(buf, size);
00079     if (forwarding_entry != NULL) {
00080         printf("forwarding_entry OK\n");
00081         c->length = 0;
00082         res = ccnb_append_forwarding_entry(c, forwarding_entry);
00083         if (res != 0)
00084             printf("forwarding_entry append failed\n");
00085         if (memcmp(buf, c->buf, c->length) != 0)
00086             printf("forwarding_entry mismatch\n");
00087         ccn_forwarding_entry_destroy(&forwarding_entry);
00088         forwarding_entry = ccn_forwarding_entry_parse(c->buf, c->length);
00089         if (forwarding_entry == NULL) {
00090             printf("forwarding_entry reparse failed\n");
00091             res = 1;
00092         }
00093     }
00094     ccn_forwarding_entry_destroy(&forwarding_entry);
00095     
00096     header = ccn_header_parse(buf, size);
00097     if (header != NULL) {
00098         printf("header OK\n");
00099         c->length = 0;
00100         res = ccnb_append_header(c, header);
00101         if (res != 0)
00102             printf("header append failed\n");
00103         if (memcmp(buf, c->buf, c->length) != 0)
00104             printf("header mismatch\n");
00105         ccn_header_destroy(&header);
00106         header = ccn_header_parse(c->buf, c->length);
00107         if (header == NULL) {
00108             printf("header reparse failed\n");
00109             res = 1;
00110         }
00111     }
00112     ccn_header_destroy(&header);
00113 
00114     i = ccn_parse_interest(buf, size, pi, NULL);
00115     if (i >= 0) {
00116         res = 0;
00117         printf("interest OK lifetime %jd (%d seconds)\n",
00118                ccn_interest_lifetime(buf, pi),
00119                ccn_interest_lifetime_seconds(buf, pi));
00120     }
00121 
00122     if (res != 0) {
00123         printf("URP\n");
00124     }
00125     exit(res);
00126 }
Generated on Fri May 13 16:27:02 2011 for Content-Centric Networking in C by  doxygen 1.6.3