|
dscrd
Discord C library
|
#include <jansson.h>#include <stddef.h>#include <stdalign.h>#include <stdbool.h>
Go to the source code of this file.
Data Structures | |
| struct | RestResp_s |
| Rest Response structure. More... | |
| struct | jsonToStruct_element_s |
| jsonToStruct element structure More... | |
| struct | jsonToStruct_element_custom_s |
| struct | jsonToStruct_custom_s |
| jsonToStruct_custom structure More... | |
| struct | jsonToStruct_s |
| jsonToStruct structure (array) More... | |
Macros | |
| #define | PTR(X, Y) ((X *) Y) |
| #define | NO_GATEWAY_RET() if(!dscrd_has_gateway()){dscrd_error_set ("This library has no gateway support."); return -1;} |
| #define | NO_GATEWAY_RET_P() if(!dscrd_has_gateway()){dscrd_error_set ("This library has no gateway support."); return NULL;} |
| #define | JTS_STRINGIFY(x) #x |
| #define | JTS_TOSTRING(x) JTS_STRINGIFY(x) |
| #define | JTS_NAME(x) jts_ ##x |
| #define | JTS_CUST_NAME(x) jts_ext_ ##x |
| #define | JTS_CHAR 0 |
| #define | JTS_CHARP 1 |
| #define | JTS_INT 2 |
| #define | JTS_UCHAR 3 |
| #define | JTS_CHARPP 4 |
| #define | JTS_CUST 7 |
| #define | JTS_BOOL 8 |
| #define | JTS_INTP 9 |
| #define | JTS_FLOAT 10 |
| #define | JTS_FLOATP 11 |
| #define | JTS_DOUBLE 12 |
| #define | JTS_DOUBLEP 13 |
| #define | JTS_ELEMENT_C(G, X, Y) |
| #define | JTS_ELEMENT(X, Y) |
| #define | JTS_ELEMENTT(G, X, Y) |
| #define | JTS_TYPE(T) |
| #define | JTS_T_D 0 |
| #define | JTS_T_P 1 |
| #define | JTS_T_PP 2 |
| #define | JTS_T_U 3 |
| #define | JTS_TYPE_P(P, T) |
| #define | JTS_STRINGIZE(arg) JTS_STRINGIZE1(arg) |
| #define | JTS_STRINGIZE1(arg) JTS_STRINGIZE2(arg) |
| #define | JTS_STRINGIZE2(arg) #arg |
| #define | JTS_CONCATENATE(arg1, arg2) JTS_CONCATENATE1(arg1, arg2) |
| #define | JTS_CONCATENATE1(arg1, arg2) JTS_CONCATENATE2(arg1, arg2) |
| #define | JTS_CONCATENATE2(arg1, arg2) arg1##arg2 |
| #define | JTS_E_FOR_EACH_1(what, x, y) what(x, y) |
| #define | JTS_E_FOR_EACH_2(what, x, y, ...) |
| #define | JTS_E_FOR_EACH_3(what, x, y, ...) |
| #define | JTS_E_FOR_EACH_4(what, x, y, ...) |
| #define | JTS_E_FOR_EACH_5(what, x, y, ...) |
| #define | JTS_E_FOR_EACH_6(what, x, y, ...) |
| #define | JTS_E_FOR_EACH_7(what, x, y, ...) |
| #define | JTS_E_FOR_EACH_8(what, x, y, ...) |
| #define | JTS_E_FOR_EACH_9(what, x, y, ...) |
| #define | JTS_E_FOR_EACH_10(what, x, y, ...) |
| #define | JTS_E_FOR_EACH_11(what, x, y, ...) |
| #define | JTS_E_FOR_EACH_12(what, x, y, ...) |
| #define | JTS_E_FOR_EACH_13(what, x, y, ...) |
| #define | JTS_E_FOR_EACH_14(what, x, y, ...) |
| #define | JTS_E_FOR_EACH_15(what, x, y, ...) |
| #define | JTS_E_FOR_EACH_16(what, x, y, ...) |
| #define | JTS_E_FOR_EACH_17(what, x, y, ...) |
| #define | JTS_E_FOR_EACH_18(what, x, y, ...) |
| #define | JTS_E_FOR_EACH_19(what, x, y, ...) |
| #define | JTS_E_FOR_EACH_20(what, x, y, ...) |
| #define | JTS_EX_FOR_EACH_2(what, g, x, y) what(g, x, y) |
| #define | JTS_EX_FOR_EACH_4(what, g, x, y, ...) |
| #define | JTS_EX_FOR_EACH_6(what, g, x, y, ...) |
| #define | JTS_EX_FOR_EACH_8(what, g, x, y, ...) |
| #define | JTS_PPNARG(...) JTS_PPNARG_(__VA_ARGS__,JTS_PPRSEQ_N()) |
| #define | JTS_PPNARG_(...) JTS_PPARG_N(__VA_ARGS__) |
| #define | JTS_PPARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, N, ...) N |
| #define | JTS_PPRSEQ_N() |
| #define | JTS_D(X, ...) |
| #define | JTS_D_EX(X, ...) |
| #define | JTS_E(X) extern jsonToStruct JTS_NAME(X); |
| #define | JTS_E_EX(X) extern jsonToStruct_custom JTS_CUST_NAME(X); |
| #define | JTS(X, Y) (X *) jts_structify (&JTS_NAME(X), Y, (jsonToStruct_custom *) 0) |
| #define | JTS_EX(X, Y) (X *) jts_structify (&JTS_NAME(X), Y, &JTS_CUST_NAME(X)) |
| #define | JTS_FREE(X, Y) jts_structify_reverse (&JTS_NAME(X), Y, (jsonToStruct_custom *) 0) |
| #define | JTS_EX_FREE(X, Y) jts_structify_reverse (&JTS_NAME(X), Y, &JTS_CUST_NAME(X)) |
| #define | STJ(X, Y) stj_jsonify (&JTS_NAME(X), Y) |
| #define | STJ_FREE(X) free(X) |
| #define | STJ_L(X, ...) stj_jsonify_list (&JTS_NAME(X), JTS_PPNARG(__VA_ARGS__)/2, __VA_ARGS__) |
Typedefs | |
| typedef enum dscrd_event_e | dscrd_event |
| typedef struct RestResp_s | RestResp |
| Rest Response structure. More... | |
| typedef struct jsonToStruct_element_s | jsonToStruct_element |
| jsonToStruct element structure More... | |
| typedef struct jsonToStruct_element_custom_s | jsonToStruct_element_custom |
| typedef struct jsonToStruct_custom_s | jsonToStruct_custom |
| jsonToStruct_custom structure More... | |
| typedef struct jsonToStruct_s | jsonToStruct |
| jsonToStruct structure (array) More... | |
Enumerations | |
| enum | dscrd_event_e { CREATE, DESTROY } |
| #define JTS | ( | X, | |
| Y | |||
| ) | (X *) jts_structify (&JTS_NAME(X), Y, (jsonToStruct_custom *) 0) |
Convert json data string into mentioned and predefined structure.
| X | Name of the datatype |
| Y | pointer to json data string |
| #define JTS_BOOL 8 |
| #define JTS_CHAR 0 |
| #define JTS_CHARP 1 |
| #define JTS_CHARPP 4 |
| #define JTS_CONCATENATE | ( | arg1, | |
| arg2 | |||
| ) | JTS_CONCATENATE1(arg1, arg2) |
| #define JTS_CONCATENATE1 | ( | arg1, | |
| arg2 | |||
| ) | JTS_CONCATENATE2(arg1, arg2) |
| #define JTS_CONCATENATE2 | ( | arg1, | |
| arg2 | |||
| ) | arg1##arg2 |
| #define JTS_CUST 7 |
| #define JTS_CUST_NAME | ( | x | ) | jts_ext_ ##x |
| #define JTS_D | ( | X, | |
| ... | |||
| ) |
Create new jsonToStruct data definition
| X | Name of the datatype |
| ... | list of datatype elements to process |
| #define JTS_D_EX | ( | X, | |
| ... | |||
| ) |
Create new jsonToStruct custom datatype definition
| X | Name of the datatype |
| ... | list of custom datatype elements in for of two: DATATYPE_NAME, DATATYPE |
| #define JTS_DOUBLE 12 |
| #define JTS_DOUBLEP 13 |
| #define JTS_E | ( | X | ) | extern jsonToStruct JTS_NAME(X); |
Reference exiting jsonToStruct data definition
| X | Name of the datatype |
| #define JTS_E_EX | ( | X | ) | extern jsonToStruct_custom JTS_CUST_NAME(X); |
Reference exiting jsonToStruct extention definition
| X | Name of the datatype |
| #define JTS_E_FOR_EACH_1 | ( | what, | |
| x, | |||
| y | |||
| ) | what(x, y) |
| #define JTS_E_FOR_EACH_10 | ( | what, | |
| x, | |||
| y, | |||
| ... | |||
| ) |
| #define JTS_E_FOR_EACH_11 | ( | what, | |
| x, | |||
| y, | |||
| ... | |||
| ) |
| #define JTS_E_FOR_EACH_12 | ( | what, | |
| x, | |||
| y, | |||
| ... | |||
| ) |
| #define JTS_E_FOR_EACH_13 | ( | what, | |
| x, | |||
| y, | |||
| ... | |||
| ) |
| #define JTS_E_FOR_EACH_14 | ( | what, | |
| x, | |||
| y, | |||
| ... | |||
| ) |
| #define JTS_E_FOR_EACH_15 | ( | what, | |
| x, | |||
| y, | |||
| ... | |||
| ) |
| #define JTS_E_FOR_EACH_16 | ( | what, | |
| x, | |||
| y, | |||
| ... | |||
| ) |
| #define JTS_E_FOR_EACH_17 | ( | what, | |
| x, | |||
| y, | |||
| ... | |||
| ) |
| #define JTS_E_FOR_EACH_18 | ( | what, | |
| x, | |||
| y, | |||
| ... | |||
| ) |
| #define JTS_E_FOR_EACH_19 | ( | what, | |
| x, | |||
| y, | |||
| ... | |||
| ) |
| #define JTS_E_FOR_EACH_2 | ( | what, | |
| x, | |||
| y, | |||
| ... | |||
| ) |
| #define JTS_E_FOR_EACH_20 | ( | what, | |
| x, | |||
| y, | |||
| ... | |||
| ) |
| #define JTS_E_FOR_EACH_3 | ( | what, | |
| x, | |||
| y, | |||
| ... | |||
| ) |
| #define JTS_E_FOR_EACH_4 | ( | what, | |
| x, | |||
| y, | |||
| ... | |||
| ) |
| #define JTS_E_FOR_EACH_5 | ( | what, | |
| x, | |||
| y, | |||
| ... | |||
| ) |
| #define JTS_E_FOR_EACH_6 | ( | what, | |
| x, | |||
| y, | |||
| ... | |||
| ) |
| #define JTS_E_FOR_EACH_7 | ( | what, | |
| x, | |||
| y, | |||
| ... | |||
| ) |
| #define JTS_E_FOR_EACH_8 | ( | what, | |
| x, | |||
| y, | |||
| ... | |||
| ) |
| #define JTS_E_FOR_EACH_9 | ( | what, | |
| x, | |||
| y, | |||
| ... | |||
| ) |
| #define JTS_ELEMENT | ( | X, | |
| Y | |||
| ) |
| #define JTS_ELEMENT_C | ( | G, | |
| X, | |||
| Y | |||
| ) |
| #define JTS_ELEMENTT | ( | G, | |
| X, | |||
| Y | |||
| ) |
| #define JTS_EX | ( | X, | |
| Y | |||
| ) | (X *) jts_structify (&JTS_NAME(X), Y, &JTS_CUST_NAME(X)) |
Convert json data string into mentioned and predefined structure. In comparison to JTS() this function requires that given datatype has its extention defined (see JTS_D_EX())
| X | Name of the datatype |
| Y | pointer to json data string |
| #define JTS_EX_FOR_EACH_2 | ( | what, | |
| g, | |||
| x, | |||
| y | |||
| ) | what(g, x, y) |
| #define JTS_EX_FOR_EACH_4 | ( | what, | |
| g, | |||
| x, | |||
| y, | |||
| ... | |||
| ) |
| #define JTS_EX_FOR_EACH_6 | ( | what, | |
| g, | |||
| x, | |||
| y, | |||
| ... | |||
| ) |
| #define JTS_EX_FOR_EACH_8 | ( | what, | |
| g, | |||
| x, | |||
| y, | |||
| ... | |||
| ) |
| #define JTS_EX_FREE | ( | X, | |
| Y | |||
| ) | jts_structify_reverse (&JTS_NAME(X), Y, &JTS_CUST_NAME(X)) |
| #define JTS_FLOAT 10 |
| #define JTS_FLOATP 11 |
| #define JTS_FREE | ( | X, | |
| Y | |||
| ) | jts_structify_reverse (&JTS_NAME(X), Y, (jsonToStruct_custom *) 0) |
Free data allocated by JTS().
| X | Name of the datatype |
| Y | pointer to datatype |
| #define JTS_INT 2 |
| #define JTS_INTP 9 |
| #define JTS_NAME | ( | x | ) | jts_ ##x |
| #define JTS_PPARG_N | ( | _1, | |
| _2, | |||
| _3, | |||
| _4, | |||
| _5, | |||
| _6, | |||
| _7, | |||
| _8, | |||
| _9, | |||
| _10, | |||
| _11, | |||
| _12, | |||
| _13, | |||
| _14, | |||
| _15, | |||
| _16, | |||
| _17, | |||
| _18, | |||
| _19, | |||
| _20, | |||
| _21, | |||
| _22, | |||
| _23, | |||
| _24, | |||
| _25, | |||
| _26, | |||
| _27, | |||
| _28, | |||
| _29, | |||
| _30, | |||
| _31, | |||
| _32, | |||
| _33, | |||
| _34, | |||
| _35, | |||
| _36, | |||
| _37, | |||
| _38, | |||
| _39, | |||
| _40, | |||
| _41, | |||
| _42, | |||
| _43, | |||
| _44, | |||
| _45, | |||
| _46, | |||
| _47, | |||
| _48, | |||
| _49, | |||
| _50, | |||
| _51, | |||
| _52, | |||
| _53, | |||
| _54, | |||
| _55, | |||
| _56, | |||
| _57, | |||
| _58, | |||
| _59, | |||
| _60, | |||
| _61, | |||
| _62, | |||
| _63, | |||
| N, | |||
| ... | |||
| ) | N |
| #define JTS_PPNARG | ( | ... | ) | JTS_PPNARG_(__VA_ARGS__,JTS_PPRSEQ_N()) |
| #define JTS_PPNARG_ | ( | ... | ) | JTS_PPARG_N(__VA_ARGS__) |
| #define JTS_PPRSEQ_N | ( | ) |
| #define JTS_STRINGIFY | ( | x | ) | #x |
| #define JTS_STRINGIZE | ( | arg | ) | JTS_STRINGIZE1(arg) |
| #define JTS_STRINGIZE1 | ( | arg | ) | JTS_STRINGIZE2(arg) |
| #define JTS_STRINGIZE2 | ( | arg | ) | #arg |
| #define JTS_T_D 0 |
| #define JTS_T_P 1 |
| #define JTS_T_PP 2 |
| #define JTS_T_U 3 |
| #define JTS_TOSTRING | ( | x | ) | JTS_STRINGIFY(x) |
| #define JTS_TYPE | ( | T | ) |
| #define JTS_TYPE_P | ( | P, | |
| T | |||
| ) |
| #define JTS_UCHAR 3 |
| #define NO_GATEWAY_RET | ( | ) | if(!dscrd_has_gateway()){dscrd_error_set ("This library has no gateway support."); return -1;} |
| #define NO_GATEWAY_RET_P | ( | ) | if(!dscrd_has_gateway()){dscrd_error_set ("This library has no gateway support."); return NULL;} |
| #define PTR | ( | X, | |
| Y | |||
| ) | ((X *) Y) |
Dereference void pointer
| X | pointer type |
| Y | pointer name |
| #define STJ | ( | X, | |
| Y | |||
| ) | stj_jsonify (&JTS_NAME(X), Y) |
Converts pointer of previously defined datatype into json datastring.
| X | Name of the datatype |
| Y | Pointer to the datatype |
| #define STJ_FREE | ( | X | ) | free(X) |
| #define STJ_L | ( | X, | |
| ... | |||
| ) | stj_jsonify_list (&JTS_NAME(X), JTS_PPNARG(__VA_ARGS__)/2, __VA_ARGS__) |
| typedef enum dscrd_event_e dscrd_event |
| typedef struct jsonToStruct_s jsonToStruct |
jsonToStruct structure (array)
| typedef struct jsonToStruct_custom_s jsonToStruct_custom |
jsonToStruct_custom structure
Here goes all external definitions.
| typedef struct jsonToStruct_element_s jsonToStruct_element |
jsonToStruct element structure
| typedef struct jsonToStruct_element_custom_s jsonToStruct_element_custom |
| typedef struct RestResp_s RestResp |
Rest Response structure.
Previously used RestResponse directly from rest-client-c library but now it's made API independent.
| enum dscrd_event_e |
| void DiscordGateway_callback_remove | ( | void * | gateway, |
| int | i | ||
| ) |
| void DiscordGateway_close | ( | DiscordClient * | client | ) |
| void* DiscordGateway_open | ( | DiscordClient * | client | ) |
| void DiscordGateway_send | ( | DiscordClient * | client, |
| const char * | message | ||
| ) |
| void dscrd_client_process | ( | DiscordClient * | client, |
| dscrd_type | type, | ||
| int | event | ||
| ) |
Process client for specified event like object creation or deletion. Currently this is used for:
| client | Discord session, can be NULL |
| type | dscrd_type of event |
| event | dscrd_event, for now either CREATE or DESTROY |
| void dscrd_error_set | ( | const char * | fmt, |
| ... | |||
| ) |
Sets formatted data to error string. (printf format)
| fmt | string with or without format specifiers |
| ... | sequence of additional arguments |
| void dscrd_error_set_detailed | ( | const char * | fmt, |
| ... | |||
| ) |
Prefixes current error with given formatted data. (printf format)
| fmt | string with or without format specifiers |
| ... | sequence of additional arguments |
| void dscrd_rest_error_parse | ( | int | code, |
| const char * | body | ||
| ) |
Process rest error response and set human readable message. Only called from rest.c when HTTP response is in 4XX row. At the time of writing only Bad Request (400) error is parsed.
| code | HTTP response code |
| body | raw response data |
| const char* dscrd_user_status_str | ( | int | status | ) |
todo
| void DscrdFile_data | ( | DscrdFile * | file | ) |
Ensures file data is loaded into memory.
| file | DscrdFile |
| void DscrdFile_data_base64 | ( | DscrdFile * | file | ) |
Ensures base64 file data is loaded into memory.
| file | DscrdFile |
| void DscrdFile_data_enc | ( | DscrdFile * | file | ) |
Ensures encoded file data is loaded into memory.
| file | DscrdFile |
| int is_DscrdFile_real | ( | DscrdFile * | file | ) |
Checks if DscrdFile is an existent file.
| file | DscrdFile |
| DiscordChannelList* json_DiscordChannelList | ( | DiscordClient * | client, |
| char * | json | ||
| ) |
| DiscordGuild** json_DiscordGuilds | ( | DiscordClient * | client, |
| char * | json | ||
| ) |
| void* json_discordobject | ( | DiscordClient * | client, |
| dscrd_type | type, | ||
| char * | json | ||
| ) |
Parse json string into object based on given dscrd_type
| client | Discord session |
| type | dscrd_type object |
| json | json string |
| WebhookList* json_WebhookList | ( | DiscordClient * | client, |
| char * | json | ||
| ) |
Parse json string into WebhookList object
| client | Discord session |
| json | json string |
| JTS_E | ( | DiscordUser | ) |
| JTS_E | ( | Webhook | ) |
| JTS_E | ( | DiscordChannel | ) |
| JTS_E | ( | DiscordGuild | ) |
| JTS_E | ( | DiscordChannelList | ) |
| JTS_E | ( | DiscordMessage | ) |
| JTS_E_EX | ( | Webhook | ) |
| JTS_E_EX | ( | DiscordChannelList | ) |
| JTS_E_EX | ( | DiscordMessage | ) |
| void* jts_structify | ( | const jsonToStruct * | jts, |
| const char * | json_data, | ||
| jsonToStruct_custom * | customdef | ||
| ) |
| void* jts_structify_jp | ( | const jsonToStruct * | jts, |
| json_t * | root, | ||
| jsonToStruct_custom * | customdef | ||
| ) |
| void jts_structify_reverse | ( | const jsonToStruct * | jts, |
| void * | structure, | ||
| jsonToStruct_custom * | customdef | ||
| ) |
| RestResp* Rest_call | ( | DiscordClient * | client, |
| const char * | path, | ||
| unsigned char | method, | ||
| const char * | body | ||
| ) |
Makes a REST call. Returned pointer has to be freed with Rest_call_free.
| client | DiscordClient session |
| path | API path |
| method | HTTP method, one of http_method |
| body | data to send |
| void Rest_call_free | ( | RestResp * | res | ) |
Frees pointer allocated by Rest_call.
| res | Rest response structure (RestResp) |
| void Rest_free | ( | void * | rest | ) |
Frees pointer allocated by Rest_init.
| rest | Rest library access pointer |
| void* Rest_init | ( | const char * | host, |
| int | port | ||
| ) |
Allocates Rest library access pointer.
| host | address of the host to connect |
| port | port to connect |
| char* stj_jsonify | ( | const jsonToStruct * | jts, |
| void * | ptr | ||
| ) |
| char* stj_jsonify_list | ( | const jsonToStruct * | jts, |
| int | num, | ||
| ... | |||
| ) |
1.8.13