diff --git a/src/hyper.h b/src/hyper.h index 49277f8..b430beb 100644 --- a/src/hyper.h +++ b/src/hyper.h @@ -66,6 +66,12 @@ struct hyper_win_size { uint64_t seq; }; +struct hyper_writter { + char *id; + char *file; + char *data; +}; + struct hyper_ctl { int efd; struct hyper_event sig; diff --git a/src/init.c b/src/init.c index e45b0bd..fc3e56e 100644 --- a/src/init.c +++ b/src/init.c @@ -762,6 +762,16 @@ static int hyper_start_pod(char *json, int length) return 0; } +static int hyper_cmd_write_file(char *json, int length) +{ + return 0; +} + +static int hyper_cmd_read_file(char *json, int length) +{ + return 0; +} + static void hyper_cleanup_shared(struct hyper_pod *pod) { if (pod->tag == NULL) { @@ -941,6 +951,13 @@ static int hyper_channel_handle(struct hyper_event *de, uint32_t len) case EXECCMD: ret = hyper_exec_cmd((char *)buf->data + 8, len - 8); break; + case WRITEFILE: + ret = hyper_cmd_write_file((char *)buf->data + 8, len - 8); + break; + case READFILE: + hyper_cmd_read_file((char *)buf->data + 8, len - 8); + /* hyperstart will send ACK message with file context */ + return 0; case PING: case GETPOD: break; diff --git a/src/parse.c b/src/parse.c index f29e888..cf7e38d 100644 --- a/src/parse.c +++ b/src/parse.c @@ -632,3 +632,62 @@ fail: exec = NULL; goto out; } + +int hyper_parse_write_file(struct hyper_writter *writter, char *json, int length) +{ + int i, n, ret = 0; + + jsmn_parser p; + int toks_num = 10; + jsmntok_t *toks = NULL; + + toks = calloc(toks_num, sizeof(jsmntok_t)); + + jsmn_init(&p); + n = jsmn_parse(&p, json, length, toks, toks_num); + if (n < 0) { + fprintf(stdout, "jsmn parse failed, n is %d\n", n); + ret = -1; + goto out; + } + + for (i = 0; i < n; i++) { + jsmntok_t *t = &toks[i]; + + if (t->type != JSMN_STRING) + continue; + + if (json_token_streq(json, t, "container")) { + if (i++ == n) + goto fail; + + writter->id = strdup(json_token_str(json, &toks[i])); + fprintf(stdout, "writefile get container %s\n", writter->id); + } else if (json_token_streq(json, t, "file")) { + if (i++ == n) + goto fail; + + writter->file = strdup(json_token_str(json, &toks[i])); + fprintf(stdout, "writefile get file %s\n", writter->file); + } else if (json_token_streq(json, t, "data")) { + if (i++ == n) + goto fail; + + writter->data = strdup(json_token_str(json, &toks[i])); + fprintf(stdout, "writefile get data %s\n", writter->data); + } else { + fprintf(stdout, "in writefile incorrect %s\n", json_token_str(json, &toks[i])); + } + } + +out: + free(toks); + return ret; +fail: + free(writter->id); + free(writter->file); + free(writter->data); + + ret = -1; + goto out; +} diff --git a/src/parse.h b/src/parse.h index 7b41ba0..4b93b41 100644 --- a/src/parse.h +++ b/src/parse.h @@ -9,5 +9,6 @@ struct hyper_exec *hyper_parse_execcmd(char *json, int length); char *json_token_str(char *js, jsmntok_t *t); int json_token_streq(char *js, jsmntok_t *t, char *s); int hyper_parse_winsize(struct hyper_win_size *ws, char *json, int length); +int hyper_parse_write_file(struct hyper_writter *writter, char *json, int length); #endif