parse dns from pod file

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
This commit is contained in:
Gao feng
2015-08-27 22:42:57 +08:00
parent 01f07fb952
commit 04a501edb7
2 changed files with 34 additions and 0 deletions
+2
View File
@@ -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;
+32
View File
@@ -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]));