Skip to content
Snippets Groups Projects
Commit 3c73d07e authored by Cenk Gündoğan's avatar Cenk Gündoğan Committed by GitHub
Browse files

Merge pull request #7026 from smlng/shell/ccn_lite_cmd_fixup

shell: fix _ccnl_content command
parents 2e0133d1 f40e7077
No related branches found
No related tags found
No related merge requests found
...@@ -84,37 +84,35 @@ static void _content_usage(char *argv) ...@@ -84,37 +84,35 @@ static void _content_usage(char *argv)
int _ccnl_content(int argc, char **argv) int _ccnl_content(int argc, char **argv)
{ {
char *body = (char*) _default_content;
int arg_len = strlen(_default_content) + 1;
int offs = CCNL_MAX_PACKET_SIZE;
if (argc < 2) { if (argc < 2) {
_content_usage(argv[0]); _content_usage(argv[0]);
return -1; 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) { if (argc > 2) {
char buf[BUF_SIZE]; unsigned pos = 0;
char *buf_ptr = buf; for (int i = 2; (i < argc) && (pos < BUF_SIZE); ++i) {
for (int i = 2; (i < argc) && (buf_ptr < (buf + BUF_SIZE)); i++) {
if (i > 2) {
*(buf_ptr++) = ' ';
}
arg_len = strlen(argv[i]); arg_len = strlen(argv[i]);
if ((buf_ptr + arg_len) > (buf + BUF_SIZE)) { if ((pos + arg_len) > BUF_SIZE) {
arg_len = (buf + BUF_SIZE) - buf_ptr; arg_len = BUF_SIZE - pos;
} }
strncpy(buf_ptr, argv[i], arg_len); strncpy(&buf[pos], argv[i], arg_len);
buf_ptr += arg_len; pos += arg_len;
/* increment pos _after_ adding ' ' */
buf[pos++] = ' ';
} }
*buf_ptr = '\0'; /* decrement pos _before_ to overwrite last ' ' with '\0' */
buf[--pos] = '\0';
body = buf; body = buf;
arg_len = strlen(body);
} }
arg_len = strlen(body);
int suite = CCNL_SUITE_NDNTLV; struct ccnl_prefix_s *prefix = ccnl_URItoPrefix(argv[1], CCNL_SUITE_NDNTLV, NULL, NULL);
int offs = CCNL_MAX_PACKET_SIZE;
struct ccnl_prefix_s *prefix = ccnl_URItoPrefix(argv[1], suite, NULL, NULL);
arg_len = ccnl_ndntlv_prependContent(prefix, (unsigned char*) body, arg_len, NULL, NULL, &offs, _out); arg_len = ccnl_ndntlv_prependContent(prefix, (unsigned char*) body, arg_len, NULL, NULL, &offs, _out);
free_prefix(prefix); free_prefix(prefix);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment