This commit is contained in:
Tom Stellard 2020-12-30 19:12:24 -08:00
parent 11b7057891
commit 6f43a62563
5 changed files with 53 additions and 1 deletions

View File

@ -87,7 +87,7 @@ add_executable(bygfoot src/bet.c src/bet.h src/finance.h src/fixture.h
src/xml_lg_commentary.c src/xml_mmatches.c src/xml_name.c
src/xml_news.c src/xml_strategy.c src/xml_team.c src/youth_academy.c
src/zip/zip.c src/zip/zip.h src/zip/unzip.c src/zip/unzip.h
src/bygfoot.c src/backend_filesystem.c src/json_serialize.c ${JSON_FILES})
src/bygfoot.c src/backend_filesystem.c src/json_serialize.c src/cgi.c ${JSON_FILES})
# Some gtk headers use deprecated glib features, so disable this warning
# since we can't do anything about it.

View File

@ -207,6 +207,7 @@ typedef struct
typedef struct {
gchar *json_filename;
gboolean is_cgi;
} CommandLineArgs;

35
src/cgi.c Normal file
View File

@ -0,0 +1,35 @@
#include <json-c/json_object.h>
#include <stdio.h>
#include "bygfoot_struct.h"
#include "json_interface.h"
/* country */
#define URI_COMPONENT_MAX_LEN 7
#define DATA_MAX_LEN 256
#if 0
static struct json_object *
read_data()
{
struct json_tokener *tokener = json_tokener_new();
}
#endif
int bygfoot_cgi_main(Bygfoot *bygfoot)
{
const char uri_separator = '/';
const gchar *path_info = g_getenv("PATH_INFO");
if (!path_info || path_info[0] != uri_separator) {
fprintf(stderr, "Error parsing PATH_INFO");
return 1;
}
path_info++;
if (g_str_has_prefix(path_info, "country")) {
struct json_object *country_list_obj =
bygfoot_json_call_get_countries(bygfoot, NULL);
printf("%s", json_object_to_json_string(country_list_obj));
return 0;
}
return 1;
}

6
src/cgi.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef CGI_H
#define CGI_H
int bygfoot_cgi_main(Bygfoot *bygfoot);
#endif

View File

@ -34,6 +34,7 @@
#include "bet_struct.h"
#include "bygfoot_struct.h"
#include "cgi.h"
#include "debug.h"
#include "file.h"
#include "free.h"
@ -83,6 +84,8 @@ main_parse_frontend_backend_cl_arguments(gint *argc, gchar ***argv, CommandLineA
{ "json", 0, 0, G_OPTION_ARG_FILENAME, &args->json_filename,
"JSON file containing commands to run. bygfoot will run the "
"commands in this file and then exit", "FILE"},
{ "cgi", 0, 0, G_OPTION_ARG_NONE, &args->is_cgi,
"Start bygfoot in cgi mode", NULL },
{NULL}
};
@ -464,6 +467,13 @@ main (gint argc, gchar *argv[])
memset(&cl_args, 0, sizeof(cl_args));
main_parse_frontend_backend_cl_arguments(&argc, &argv, &cl_args);
if (cl_args.is_cgi) {
bygfoot_init(&bygfoot, BYGFOOT_FRONTEND_CONSOLE, BYGFOOT_BACKEND_FILESYSTEM);
main_init(&argc, &argv, &bygfoot);
validate_country_files(&bygfoot);
return bygfoot_cgi_main(&bygfoot);
}
if (cl_args.json_filename) {
bygfoot_init(&bygfoot, BYGFOOT_FRONTEND_CONSOLE, BYGFOOT_BACKEND_FILESYSTEM);
main_init(&argc, &argv, &bygfoot);