| 48 | } |
| 49 | |
| 50 | int |
| 51 | cmdline_parse_string(cmdline_parse_token_hdr_t *tk, const char *buf, void *res, |
| 52 | unsigned ressize) |
| 53 | { |
| 54 | struct cmdline_token_string *tk2; |
| 55 | struct cmdline_token_string_data *sd; |
| 56 | unsigned int token_len; |
| 57 | const char *str; |
| 58 | |
| 59 | if (res && ressize < STR_TOKEN_SIZE) |
| 60 | return -1; |
| 61 | |
| 62 | if (!tk || !buf || ! *buf) |
| 63 | return -1; |
| 64 | |
| 65 | tk2 = (struct cmdline_token_string *)tk; |
| 66 | |
| 67 | sd = &tk2->string_data; |
| 68 | |
| 69 | /* fixed string (known single token) */ |
| 70 | if ((sd->str != NULL) && (strcmp(sd->str, TOKEN_STRING_MULTI) != 0)) { |
| 71 | str = sd->str; |
| 72 | do { |
| 73 | token_len = get_token_len(str); |
| 74 | |
| 75 | /* if token is too big... */ |
| 76 | if (token_len >= STR_TOKEN_SIZE - 1) { |
| 77 | continue; |
| 78 | } |
| 79 | |
| 80 | if ( strncmp(buf, str, token_len) ) { |
| 81 | continue; |
| 82 | } |
| 83 | |
| 84 | if ( !cmdline_isendoftoken(*(buf+token_len)) ) { |
| 85 | continue; |
| 86 | } |
| 87 | |
| 88 | break; |
| 89 | } while ( (str = get_next_token(str)) != NULL ); |
| 90 | |
| 91 | if (!str) |
| 92 | return -1; |
| 93 | } |
| 94 | /* multi string */ |
| 95 | else if (sd->str != NULL) { |
| 96 | if (ressize < STR_MULTI_TOKEN_SIZE) |
| 97 | return -1; |
| 98 | |
| 99 | token_len = 0; |
| 100 | while (!cmdline_isendofcommand(buf[token_len]) && |
| 101 | token_len < (STR_MULTI_TOKEN_SIZE - 1)) |
| 102 | token_len++; |
| 103 | |
| 104 | /* return if token too long */ |
| 105 | if (token_len >= (STR_MULTI_TOKEN_SIZE - 1)) |
| 106 | return -1; |
| 107 | } |