diff --git a/src/hyper.h b/src/hyper.h index c4d4e99..9ed204b 100644 --- a/src/hyper.h +++ b/src/hyper.h @@ -36,6 +36,7 @@ struct hyper_pod { struct hyper_container *c; struct hyper_interface *iface; struct hyper_route *rt; + char **dns; struct list_head pe_head; struct list_head ce_head; char *hostname; @@ -45,6 +46,7 @@ struct hyper_pod { uint32_t i_num; uint32_t r_num; uint32_t e_num; + uint32_t d_num; uint32_t type; uint32_t code; uint32_t remains; diff --git a/src/parse.c b/src/parse.c index 6662e37..f29e888 100644 --- a/src/parse.c +++ b/src/parse.c @@ -384,6 +384,32 @@ static int hyper_parse_routes(struct hyper_pod *pod, char *json, jsmntok_t *toks return i; } +static int hyper_parse_dns(struct hyper_pod *pod, char *json, jsmntok_t *toks) +{ + int i = 1, j; + + if (toks[i].type != JSMN_ARRAY) { + fprintf(stdout, "Dns format incorrect\n"); + return -1; + } + + pod->d_num = toks[i].size; + fprintf(stdout, "dns count %d\n", pod->d_num); + pod->dns = calloc(pod->d_num, sizeof(*pod->dns)); + + if (pod->dns == NULL) { + fprintf(stdout, "alloc memory for container failed\n"); + return -1; + } + + for (j = 0; j < pod->d_num; j++) { + pod->dns[j] = strdup(json_token_str(json, &toks[++i])); + fprintf(stdout, "pod dns %d: %s\n", j, pod->dns[j]); + } + + return i; +} + int hyper_parse_pod(struct hyper_pod *pod, char *json, int length) { int i, n, next = -1; @@ -436,6 +462,12 @@ realloc: if (next < 0) goto out; + i += next; + } else if (json_token_streq(json, t, "dns") && t->size == 1) { + next = hyper_parse_dns(pod, json, t); + if (next < 0) + goto out; + i += next; } else if (json_token_streq(json, t, "shareDir") && t->size == 1) { pod->tag = strdup(json_token_str(json, &toks[++i]));