Pharos 0.7.23
Modern Web Framework & Web App Hosting Service.
Loading...
Searching...
No Matches
native_spawn_argv.c
Go to the documentation of this file.
1/**
2 * @file
3 * @brief Builds the argv vector used to launch an app entrypoint for an incoming HTTP request.
4 */
5
6#include "native_spawn_argv.h"
7
8#include <stddef.h>
9
10static int push_argv_value(char *argv_list[], size_t argv_capacity, size_t *argc_io, char *value) {
11 if (argv_list == NULL || argc_io == NULL) {
12 return 69;
13 }
14 if (*argc_io + 1 >= argv_capacity) {
15 return 69;
16 }
17 argv_list[*argc_io] = value;
18 (*argc_io)++;
19 return 0;
20}
21
23 const AppRuntime *app,
24 const char *request_method,
25 const char *request_target,
26 const char *request_cookie,
27 const char *request_headers,
28 const char *request_content_type,
29 const char *request_body,
30 int request_is_multipart,
31 const char *temp_body_path,
32 char *argv_list[],
33 size_t argv_capacity,
34 size_t *argc_out
35) {
36 size_t argc = 0;
37 if (argc_out != NULL) {
38 *argc_out = 0;
39 }
40 if (app == NULL || argv_list == NULL || argc_out == NULL || argv_capacity == 0) {
41 return 69;
42 }
43 if (app->compiled_entrypoint == NULL || app->build_dir == NULL || request_method == NULL || request_target == NULL) {
44 return 69;
45 }
46 if (push_argv_value(argv_list, argv_capacity, &argc, app->compiled_entrypoint) != 0) {
47 return 69;
48 }
49 if ((app->build_dir != NULL && app->build_dir[0] != '\0' &&
50 (push_argv_value(argv_list, argv_capacity, &argc, "--build-dir") != 0 ||
51 push_argv_value(argv_list, argv_capacity, &argc, app->build_dir) != 0)) ||
52 (app->state_path != NULL && app->state_path[0] != '\0' &&
53 (push_argv_value(argv_list, argv_capacity, &argc, "--state-path") != 0 ||
54 push_argv_value(argv_list, argv_capacity, &argc, app->state_path) != 0)) ||
55 (app->base_path != NULL &&
56 (push_argv_value(argv_list, argv_capacity, &argc, "--base-path") != 0 ||
57 push_argv_value(argv_list, argv_capacity, &argc, app->base_path) != 0)) ||
58 (app->log_path != NULL && app->log_path[0] != '\0' &&
59 (push_argv_value(argv_list, argv_capacity, &argc, "--log-path") != 0 ||
60 push_argv_value(argv_list, argv_capacity, &argc, app->log_path) != 0)) ||
61 (app->debug != NULL && app->debug[0] != '\0' &&
62 (push_argv_value(argv_list, argv_capacity, &argc, "--debug") != 0 ||
63 push_argv_value(argv_list, argv_capacity, &argc, app->debug) != 0)) ||
64 push_argv_value(argv_list, argv_capacity, &argc, "--request") != 0 ||
65 push_argv_value(argv_list, argv_capacity, &argc, (char *)request_method) != 0 ||
66 push_argv_value(argv_list, argv_capacity, &argc, (char *)request_target) != 0 ||
67 push_argv_value(argv_list, argv_capacity, &argc, "--cookie") != 0 ||
68 push_argv_value(argv_list, argv_capacity, &argc, (char *)(request_cookie != NULL ? request_cookie : "")) != 0 ||
69 push_argv_value(argv_list, argv_capacity, &argc, "--headers") != 0 ||
70 push_argv_value(argv_list, argv_capacity, &argc, (char *)(request_headers != NULL ? request_headers : "")) != 0 ||
71 push_argv_value(argv_list, argv_capacity, &argc, "--content-type") != 0 ||
72 push_argv_value(argv_list, argv_capacity, &argc, (char *)(request_content_type != NULL ? request_content_type : "application/x-www-form-urlencoded")) != 0) {
73 return 69;
74 }
75 if (temp_body_path != NULL && temp_body_path[0] != '\0') {
76 if (push_argv_value(argv_list, argv_capacity, &argc, "--body-file") != 0 ||
77 push_argv_value(argv_list, argv_capacity, &argc, (char *)temp_body_path) != 0) {
78 return 69;
79 }
80 }
81 (void)request_body;
82 (void)request_is_multipart;
83 if (argc >= argv_capacity) {
84 return 69;
85 }
86 argv_list[argc] = NULL;
87 *argc_out = argc;
88 return 0;
89}
int build_native_app_request_argv(const AppRuntime *app, const char *request_method, const char *request_target, const char *request_cookie, const char *request_headers, const char *request_content_type, const char *request_body, int request_is_multipart, const char *temp_body_path, char *argv_list[], size_t argv_capacity, size_t *argc_out)
Builds the argv vector used to execute one compiled app request.
static int push_argv_value(char *argv_list[], size_t argv_capacity, size_t *argc_io, char *value)
Declares argv construction helpers for spawned app requests.
Loaded runtime metadata for one Pharos app artifact.