-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
56e10a4
commit f0763ac
Showing
16 changed files
with
723 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
from utils.tools import nested_lookup | ||
|
||
|
||
RUNTIME_FAMILIES = ["nodejs", "ruby", "jvm", "dotnet", "go", "php", "python"] | ||
RUNTIME_FAMILIES = ["nodejs", "ruby", "jvm", "dotnet", "go", "php", "python", "cpp"] | ||
|
||
|
||
@bug(context.library == "[email protected]", reason="APMRP-360") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#include <fcntl.h> | ||
#include <microhttpd.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <signal.h> | ||
#include <stdio.h> | ||
#include <sys/stat.h> | ||
|
||
#define PORT 7778 | ||
|
||
static struct MHD_Daemon *daemon_; | ||
|
||
static ssize_t read_data(void *cls, uint64_t pos, char *buf, size_t max) { | ||
int fd = (int)(uintptr_t)cls; | ||
ssize_t num_read = read(fd, buf, max); | ||
if (num_read == 0) { | ||
return -1; | ||
} | ||
if (num_read < 0) { | ||
return -2; | ||
} | ||
return num_read; | ||
} | ||
static void close_fd(void *cls) { | ||
close((int)(uintptr_t)cls); | ||
} | ||
|
||
static enum MHD_Result answer_to_connection(void *cls, struct MHD_Connection *connection, | ||
const char *url, const char *method, | ||
const char *version, const char *upload_data, | ||
size_t *upload_data_size, void **con_cls) | ||
{ | ||
const char *status_str = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "status"); | ||
const char *value = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "value"); | ||
|
||
if (strcmp(url, "/read_file") == 0) { | ||
const char *val = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "file"); | ||
if (!val) { | ||
return MHD_NO; | ||
} | ||
|
||
const int fd = open(val, O_RDONLY); | ||
if (fd < 0) { | ||
return MHD_NO; | ||
} | ||
|
||
struct stat st; | ||
if (fstat(fd, &st) != 0) { | ||
close(fd); | ||
return MHD_NO; | ||
} | ||
const size_t file_size = st.st_size; | ||
|
||
struct MHD_Response *response; | ||
if (file_size == 0) { | ||
response = MHD_create_response_from_callback(-1, 512, read_data, (void*)(uintptr_t)fd, close_fd); | ||
} else { | ||
response = MHD_create_response_from_fd((uint64_t)file_size, fd); | ||
} | ||
|
||
MHD_add_response_header(response, "Content-Type", "application/octet-stream"); | ||
int ret = MHD_queue_response(connection, 200, response); | ||
MHD_destroy_response(response); | ||
return ret; | ||
} | ||
|
||
if (strcmp(url, "/content") != 0 || !status_str || !value) | ||
return MHD_NO; // Only respond to the correct URL and if all parameters are present | ||
|
||
int status_code = atoi(status_str); | ||
if (status_code <= 0) | ||
return MHD_NO; // Ensure the status code is a valid positive integer | ||
|
||
const char *page = value; | ||
struct MHD_Response *response = MHD_create_response_from_buffer(strlen(page), (void*)page, MHD_RESPMEM_MUST_COPY); | ||
MHD_add_response_header(response, "Content-Type", "text/html"); | ||
|
||
int ret = MHD_queue_response(connection, status_code, response); | ||
MHD_destroy_response(response); | ||
return ret; | ||
} | ||
|
||
void stop_server(int signum) | ||
{ | ||
if (daemon_) | ||
{ | ||
MHD_stop_daemon(daemon_); | ||
daemon_ = NULL; | ||
printf("Server has been stopped.\n"); | ||
} | ||
exit(0); | ||
} | ||
|
||
int main() | ||
{ | ||
struct sigaction action; | ||
memset(&action, 0, sizeof(struct sigaction)); | ||
action.sa_handler = stop_server; | ||
sigaction(SIGINT, &action, NULL); // Handle SIGINT | ||
sigaction(SIGTERM, &action, NULL); // Handle SIGTERM | ||
|
||
daemon_ = MHD_start_daemon(MHD_USE_INTERNAL_POLLING_THREAD, PORT, NULL, NULL, | ||
&answer_to_connection, NULL, MHD_OPTION_END); | ||
if (!daemon_) | ||
{ | ||
fprintf(stderr, "Failed to start the daemon.\n"); | ||
return 1; | ||
} | ||
|
||
printf("Server running on port %d\n", PORT); | ||
pause(); // Wait for signals | ||
|
||
return 0; | ||
} |
Oops, something went wrong.