From cbf31be73b9936ed2e266961978169616b704d9f Mon Sep 17 00:00:00 2001 From: Iwan Timmer Date: Sun, 11 Jun 2017 18:14:32 +0200 Subject: [PATCH] Add debug option to show http traffic --- docs/README.pod | 4 ++++ libgamestream/client.c | 4 ++-- libgamestream/client.h | 2 +- libgamestream/http.c | 12 +++++++++++- libgamestream/http.h | 2 +- src/config.c | 4 ++++ src/main.c | 3 ++- 7 files changed, 25 insertions(+), 6 deletions(-) diff --git a/docs/README.pod b/docs/README.pod index 8491a35..3fbd621 100644 --- a/docs/README.pod +++ b/docs/README.pod @@ -145,6 +145,10 @@ Try streaming if GFE version is unsupported Enable verbose output +=item B<-debug> + +Enable verbose and debug output + =item B<-input> [I] Enable the I device. diff --git a/libgamestream/client.c b/libgamestream/client.c index 4e4179d..eff1d64 100644 --- a/libgamestream/client.c +++ b/libgamestream/client.c @@ -727,7 +727,7 @@ int gs_quit_app(PSERVER_DATA server) { return ret; } -int gs_init(PSERVER_DATA server, char *address, const char *keyDirectory) { +int gs_init(PSERVER_DATA server, char *address, const char *keyDirectory, int log_level) { mkdirtree(keyDirectory); if (load_unique_id(keyDirectory) != GS_OK) return GS_FAILED; @@ -735,7 +735,7 @@ int gs_init(PSERVER_DATA server, char *address, const char *keyDirectory) { if (load_cert(keyDirectory)) return GS_FAILED; - http_init(keyDirectory); + http_init(keyDirectory, log_level); LiInitializeServerInformation(&server->serverInfo); server->serverInfo.address = address; diff --git a/libgamestream/client.h b/libgamestream/client.h index 5591d70..ae0971d 100644 --- a/libgamestream/client.h +++ b/libgamestream/client.h @@ -40,7 +40,7 @@ typedef struct _SERVER_DATA { SERVER_INFORMATION serverInfo; } SERVER_DATA, *PSERVER_DATA; -int gs_init(PSERVER_DATA server, char* address, const char *keyDirectory); +int gs_init(PSERVER_DATA server, char* address, const char *keyDirectory, int logLevel); int gs_start_app(PSERVER_DATA server, PSTREAM_CONFIGURATION config, int appId, bool sops, bool localaudio); int gs_applist(PSERVER_DATA server, PAPP_LIST *app_list); int gs_unpair(PSERVER_DATA server); diff --git a/libgamestream/http.c b/libgamestream/http.c index 757deb5..c8f9bf1 100644 --- a/libgamestream/http.c +++ b/libgamestream/http.c @@ -20,6 +20,7 @@ #include "http.h" #include "errors.h" +#include #include #include @@ -28,6 +29,8 @@ static CURL *curl; static const char *pCertFile = "./client.pem"; static const char *pKeyFile = "./key.pem"; +static bool debug; + static size_t _write_curl(void *contents, size_t size, size_t nmemb, void *userp) { size_t realsize = size * nmemb; @@ -44,8 +47,9 @@ static size_t _write_curl(void *contents, size_t size, size_t nmemb, void *userp return realsize; } -int http_init(const char* keyDirectory) { +int http_init(const char* keyDirectory, int logLevel) { curl = curl_easy_init(); + debug = logLevel >= 2; if (!curl) return GS_FAILED; @@ -73,6 +77,9 @@ int http_request(char* url, PHTTP_DATA data) { curl_easy_setopt(curl, CURLOPT_WRITEDATA, data); curl_easy_setopt(curl, CURLOPT_URL, url); + if (debug) + printf("Request %s\n", url); + if (data->size > 0) { free(data->memory); data->memory = malloc(1); @@ -89,6 +96,9 @@ int http_request(char* url, PHTTP_DATA data) { } else if (data->memory == NULL) { return GS_OUT_OF_MEMORY; } + + if (debug) + printf("Response:\n%s\n\n", data->memory); return GS_OK; } diff --git a/libgamestream/http.h b/libgamestream/http.h index be28344..f06ace1 100644 --- a/libgamestream/http.h +++ b/libgamestream/http.h @@ -29,7 +29,7 @@ typedef struct _HTTP_DATA { size_t size; } HTTP_DATA, *PHTTP_DATA; -int http_init(const char* keyDirectory); +int http_init(const char* keyDirectory, int logLevel); PHTTP_DATA http_create_data(); int http_request(char* url, PHTTP_DATA data); void http_free_data(PHTTP_DATA data); diff --git a/src/config.c b/src/config.c index 545fcf9..db7aaa9 100644 --- a/src/config.c +++ b/src/config.c @@ -64,6 +64,7 @@ static struct option long_options[] = { {"codec", required_argument, NULL, 'x'}, {"unsupported", no_argument, NULL, 'y'}, {"verbose", no_argument, NULL, 'z'}, + {"debug", no_argument, NULL, 'Z'}, {0, 0, 0, 0}, }; @@ -207,6 +208,9 @@ static void parse_argument(int c, char* value, PCONFIGURATION config) { case 'z': config->debug_level = 1; break; + case 'Z': + config->debug_level = 2; + break; case 1: if (config->action == NULL) config->action = value; diff --git a/src/main.c b/src/main.c index b1b7745..e565280 100644 --- a/src/main.c +++ b/src/main.c @@ -142,6 +142,7 @@ static void help() { printf("\t-config \tLoad configuration file\n"); printf("\t-save \t\tSave configuration file\n"); printf("\t-verbose\t\tEnable verbose output\n"); + printf("\t-debug\t\t\tEnable verbose and debug output\n"); printf("\n Streaming options\n\n"); printf("\t-720\t\t\tUse 1280x720 resolution [default]\n"); printf("\t-1080\t\t\tUse 1920x1080 resolution\n"); @@ -215,7 +216,7 @@ int main(int argc, char* argv[]) { printf("Connect to %s...\n", config.address); int ret; - if ((ret = gs_init(&server, config.address, config.key_dir)) == GS_OUT_OF_MEMORY) { + if ((ret = gs_init(&server, config.address, config.key_dir, config.debug_level)) == GS_OUT_OF_MEMORY) { fprintf(stderr, "Not enough memory\n"); exit(-1); } else if (ret == GS_INVALID) {