| 1089 | }; |
| 1090 | |
| 1091 | static int |
| 1092 | ng_bytearray_parse(const struct ng_parse_type *type, |
| 1093 | const char *s, int *off, const u_char *const start, |
| 1094 | u_char *const buf, int *buflen) |
| 1095 | { |
| 1096 | char *str; |
| 1097 | int toklen; |
| 1098 | int slen; |
| 1099 | |
| 1100 | /* We accept either an array of bytes or a string constant */ |
| 1101 | if ((str = ng_get_string_token(s, off, &toklen, &slen)) != NULL) { |
| 1102 | ng_parse_array_getLength_t *const getLength = type->info; |
| 1103 | int arraylen; |
| 1104 | |
| 1105 | arraylen = (*getLength)(type, start, buf); |
| 1106 | if (arraylen > *buflen) { |
| 1107 | free(str, M_NETGRAPH_PARSE); |
| 1108 | return (ERANGE); |
| 1109 | } |
| 1110 | if (slen > arraylen) { |
| 1111 | free(str, M_NETGRAPH_PARSE); |
| 1112 | return (E2BIG); |
| 1113 | } |
| 1114 | bcopy(str, buf, slen); |
| 1115 | bzero(buf + slen, arraylen - slen); |
| 1116 | free(str, M_NETGRAPH_PARSE); |
| 1117 | *off += toklen; |
| 1118 | *buflen = arraylen; |
| 1119 | return (0); |
| 1120 | } else { |
| 1121 | struct ng_parse_type subtype; |
| 1122 | |
| 1123 | subtype = ng_parse_bytearray_subtype; |
| 1124 | subtype.private = __DECONST(void *, type->info); |
| 1125 | return ng_array_parse(&subtype, s, off, start, buf, buflen); |
| 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | static int |
| 1130 | ng_bytearray_unparse(const struct ng_parse_type *type, |
nothing calls this directly
no test coverage detected