Skip to content

Commit

Permalink
feat: Add contest list
Browse files Browse the repository at this point in the history
Contest list
  • Loading branch information
ajami1331 authored Jan 5, 2025
2 parents 839092e + 808fc2a commit b165c0e
Show file tree
Hide file tree
Showing 19 changed files with 924 additions and 315 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ if(NOT curl_FOUND)
endif()
endif()

include_directories(${CMAKE_SOURCE_DIR}/lib/include)
file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/* lib/**/*.h lib/*.c)
include_directories(${CMAKE_SOURCE_DIR}/include)
file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/* lib/* include/*)
message("SOURCES: ${SOURCES}")
add_executable(${PROJECT_NAME} ${SOURCES})

target_link_libraries(${PROJECT_NAME} CURL::libcurl_static)
Expand Down
7 changes: 7 additions & 0 deletions include/announcement.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef ANNOUNCEMENT_H
#define ANNOUNCEMENT_H
#include <command.h>

struct command* init_announcement_command(void);

#endif // ANNOUNCEMENT_H
29 changes: 29 additions & 0 deletions include/client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef CLIENT_H
#define CLIENT_H

#include <curl/curl.h>
#include <sr_keychain.h>

#ifndef NDEBUG
#define TARGET_URL "http://judge_ui:8888"
#else
#define TARGET_URL "https://judge.eluminatis-of-lu.com"
#endif

#define target_url(x) TARGET_URL "/" x

struct response
{
char *memory;
size_t size;
};
extern struct response response_body;
extern CURL *curl;

void init_curl(void);
void cleanup_curl(void);
void print_cookies(void);
void save_cookies(void);
size_t noop_write_callback(char *ptr, size_t size, size_t nmemb, void *userdata);

#endif // CLIENT_H
17 changes: 17 additions & 0 deletions include/command.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef COMMAND_H
#define COMMAND_H

struct command
{
const char *name;
const char *desc;
const char *help;
struct command **sub;
int (*func)(struct command *cur, int argc, char **argv);
};

void print_help(struct command *cmd);
int print_help_and_traverse(struct command *cur, int argc, char **argv);
void cleanup_commands(struct command *cmd);

#endif // COMMAND_H
7 changes: 7 additions & 0 deletions include/contest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef CONTEST_H
#define CONTEST_H
#include <command.h>

struct command *init_contest_command(void);

#endif // CONTEST_H
File renamed without changes.
89 changes: 89 additions & 0 deletions include/kson.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* The MIT License
*
* Copyright (c) 2008- Attractive Chaos <attractor@live.co.uk>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef KSON_H
#define KSON_H

#include <string.h>

#define KSON_TYPE_NO_QUOTE 1
#define KSON_TYPE_SGL_QUOTE 2
#define KSON_TYPE_DBL_QUOTE 3
#define KSON_TYPE_BRACKET 4
#define KSON_TYPE_BRACE 5

#define KSON_OK 0
#define KSON_ERR_EXTRA_LEFT 1
#define KSON_ERR_EXTRA_RIGHT 2
#define KSON_ERR_NO_KEY 3

typedef struct kson_node_s {
unsigned long long type:3, n:61;
char *key;
union {
struct kson_node_s **child;
char *str;
} v;
} kson_node_t;

typedef struct {
long n_nodes;
kson_node_t *root;
} kson_t;

#ifdef __cplusplus
extern "C" {
#endif

kson_t *kson_parse(const char *json);
void kson_destroy(kson_t *kson);
const kson_node_t *kson_by_path(const kson_node_t *root, int path_len, ...);
void kson_format(const kson_node_t *root);

#ifdef __cplusplus
}
#endif

#define kson_is_internal(p) ((p)->type == KSON_TYPE_BRACKET || (p)->type == KSON_TYPE_BRACE)

static inline const kson_node_t *kson_by_key(const kson_node_t *p, const char *key)
{
long i;
if (!kson_is_internal(p)) return 0;
for (i = 0; i < (long)p->n; ++i) {
const kson_node_t *q = p->v.child[i];
if (q->key && strcmp(q->key, key) == 0)
return q;
}
return 0;
}

static inline const kson_node_t *kson_by_index(const kson_node_t *p, long i)
{
if (!kson_is_internal(p)) return 0;
return 0 <= i && i < (long)p->n? p->v.child[i] : 0;
}

#endif
7 changes: 7 additions & 0 deletions include/login.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef LOGIN_H
#define LOGIN_H
#include <command.h>

struct command *init_login_command(void);

#endif // LOGIN_H
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit b165c0e

Please sign in to comment.