diff --git a/examples/ccn-lite-relay/README.md b/examples/ccn-lite-relay/README.md index d836a07e74..9fa19bff8b 100644 --- a/examples/ccn-lite-relay/README.md +++ b/examples/ccn-lite-relay/README.md @@ -15,12 +15,13 @@ RIOT provides three shell to interact with the CCN-Lite stack: If the second parameter is omitted, the Interest will be broadcasted. You may call it like this: `ccnl_int /riot/peter/schmerzl b6:e5:94:26:ab:da` -* `ccnl_cont` - generates and populates content. The command expects one - mandatory and one optional parameter. The first parameter - specifies the name of the content to be created, the second - parameter specifies the content itself. The second parameter - may include spaces, e.g. you can call: - `ccnl_cont /riot/peter/schmerzl Hello World! Hello RIOT!` +* `ccnl_cs` - dumps CS or generates and populates content. If the command is + called without parameters, it will print all content items in + the cache. Otherwise, the command expects two parameters. The + first parameter specifies the name of the content to be created, + the second parameter specifies the content itself. The second + parameter may include spaces, e.g. you can call: + `ccnl_cont /riot/peter/schmerzl Hello World! Hello RIOT!` * `ccnl_fib` - modifies the FIB or shows its current state. If the command is called without parameters, it will print the current state of the FIB. It can also be called with the action parameters `add` diff --git a/sys/shell/commands/sc_ccnl.c b/sys/shell/commands/sc_ccnl.c index 4e9d7369c0..e843624860 100644 --- a/sys/shell/commands/sc_ccnl.c +++ b/sys/shell/commands/sc_ccnl.c @@ -30,7 +30,6 @@ static unsigned char _int_buf[BUF_SIZE]; -static const char *_default_content = "Start the RIOT!"; static unsigned char _out[CCNL_MAX_PACKET_SIZE]; /* usage for open command */ @@ -75,44 +74,45 @@ int _ccnl_open(int argc, char **argv) static void _content_usage(char *argv) { - printf("usage: %s [content]\n" - "%% %s /riot/peter/schmerzl (default content)\n" + printf("usage: %s [URI] [content]\n" + "prints the CS if called without parameters:\n" "%% %s /riot/peter/schmerzl RIOT\n", - argv, argv, argv); + argv, argv); } int _ccnl_content(int argc, char **argv) { if (argc < 2) { + ccnl_cs_dump(&ccnl_relay); + return 0; + } + if (argc == 2) { _content_usage(argv[0]); return -1; } int arg_len; - char *body = (char*) _default_content; char buf[BUF_SIZE+1]; /* add one extra space to fit trailing '\0' */ - if (argc > 2) { - unsigned pos = 0; - for (int i = 2; (i < argc) && (pos < BUF_SIZE); ++i) { - arg_len = strlen(argv[i]); - if ((pos + arg_len) > BUF_SIZE) { - arg_len = BUF_SIZE - pos; - } - strncpy(&buf[pos], argv[i], arg_len); - pos += arg_len; - /* increment pos _after_ adding ' ' */ - buf[pos++] = ' '; + unsigned pos = 0; + for (int i = 2; (i < argc) && (pos < BUF_SIZE); ++i) { + arg_len = strlen(argv[i]); + if ((pos + arg_len) > BUF_SIZE) { + arg_len = BUF_SIZE - pos; } - /* decrement pos _before_ to overwrite last ' ' with '\0' */ - buf[--pos] = '\0'; - body = buf; + strncpy(&buf[pos], argv[i], arg_len); + pos += arg_len; + /* increment pos _after_ adding ' ' */ + buf[pos++] = ' '; } - arg_len = strlen(body); + /* decrement pos _before_ to overwrite last ' ' with '\0' */ + buf[--pos] = '\0'; + + arg_len = strlen(buf); struct ccnl_prefix_s *prefix = ccnl_URItoPrefix(argv[1], CCNL_SUITE_NDNTLV, NULL, NULL); int offs = CCNL_MAX_PACKET_SIZE; - arg_len = ccnl_ndntlv_prependContent(prefix, (unsigned char*) body, arg_len, NULL, NULL, &offs, _out); + arg_len = ccnl_ndntlv_prependContent(prefix, (unsigned char*) buf, arg_len, NULL, NULL, &offs, _out); ccnl_prefix_free(prefix); diff --git a/sys/shell/commands/shell_commands.c b/sys/shell/commands/shell_commands.c index f6e79d64c6..bb9a0684d8 100644 --- a/sys/shell/commands/shell_commands.c +++ b/sys/shell/commands/shell_commands.c @@ -213,7 +213,7 @@ const shell_command_t _shell_command_list[] = { #ifdef MODULE_CCN_LITE_UTILS { "ccnl_open", "opens an interface or socket", _ccnl_open }, { "ccnl_int", "sends an interest", _ccnl_interest }, - { "ccnl_cont", "create content and populated it", _ccnl_content }, + { "ccnl_cs", "shows CS or creates content and populates it", _ccnl_content }, { "ccnl_fib", "shows or modifies the CCN-Lite FIB", _ccnl_fib }, #endif #ifdef MODULE_SNTP