mirror of
https://github.com/clearlinux/hyperstart.git
synced 2026-09-03 20:21:47 +00:00
introduce hyper_parse_write_file
Signed-off-by: Gao feng <omarapazanadi@gmail.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
+17
@@ -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;
|
||||
|
||||
+59
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user