dscrd
Discord C library
dscrd_i.h
Go to the documentation of this file.
1 /*
2  * dscrd: Discord C library
3  * Copyright (C) 2018 Jakub Wasylków
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 // This file was autogenerated by gen_dscrd_i_h.sh.
20 
21 // todo
22 typedef enum dscrd_event_e {
24 } dscrd_event;
25 
27 const char * dscrd_user_status_str (int status);
28 
39 void dscrd_client_process (DiscordClient *client, dscrd_type type, int event);
40 
49 void dscrd_rest_error_parse (int code, const char * body);
50 
57 void dscrd_error_set (const char* fmt, ...);
58 
65 void dscrd_error_set_detailed (const char* fmt, ...);
66 
73 #define PTR(X,Y) ((X *) Y)
74 
75 #define NO_GATEWAY_RET() if(!dscrd_has_gateway()){dscrd_error_set ("This library has no gateway support."); return -1;}
76 
77 #define NO_GATEWAY_RET_P() if(!dscrd_has_gateway()){dscrd_error_set ("This library has no gateway support."); return NULL;}
78 
79 
80 
86 void DscrdFile_data (DscrdFile *file);
87 
93 void DscrdFile_data_base64 (DscrdFile *file);
94 
100 void DscrdFile_data_enc (DscrdFile *file);
101 
110 int is_DscrdFile_real (DscrdFile *file);
111 
112 
121 void * json_discordobject (DiscordClient *client, dscrd_type type, char *json);
122 
131 WebhookList * json_WebhookList (DiscordClient * client, char *json);
132 
133 
134 DiscordGuild ** json_DiscordGuilds (DiscordClient * client, char *json);
135 
137 
138 
139 // todo
140 void * DiscordGateway_open (DiscordClient *client);
141 
142 // todo
143 void DiscordGateway_close (DiscordClient *client);
144 
145 void DiscordGateway_send (DiscordClient *client, const char *message);
146 
147 void DiscordGateway_callback_remove (void *gateway, int i);
148 
149 
150 
156 typedef struct RestResp_s {
158  char http_status[255];
161  // include headers in this structure? for now not needed
163  char *body;
168 
172  void *api_data;
173 } RestResp;
174 
180 void * Rest_init (const char *host, int port);
181 
186 void Rest_free (void * rest);
187 
198 RestResp * Rest_call (DiscordClient *client, const char * path, unsigned char method, const char * body);
199 
204 void Rest_call_free (RestResp *res);
205 
206 
207 #ifndef json_t
208 #include <jansson.h>
209 #endif
210 
211 #define JTS_STRINGIFY(x) #x
212 #define JTS_TOSTRING(x) JTS_STRINGIFY(x)
213 #define JTS_NAME(x) jts_ ##x
214 #define JTS_CUST_NAME(x) jts_ext_ ##x
215 #ifndef offsetof
216 #include <stddef.h>
217 #endif
218 #ifndef alignof
219 #include <stdalign.h>
220 #endif
221 #ifndef bool
222 #include <stdbool.h>
223 #endif
224 //struct jsonToStruct_element_s;
225 struct jsonToStruct_s;
226 
231 typedef struct jsonToStruct_element_s {
232  const char *name;
233  const size_t offset;
234  const size_t align;
235  const int data_type;
236  const int size;
237  const int pp;
238  const struct jsonToStruct_s * jts_cust;
240 
242  const char *name;
243  const int size;
244  const int pointer_type;
245  const struct jsonToStruct_s * jts_cust;
246  const int pp;
248 
254 typedef struct jsonToStruct_custom_s {
257 
258 
263 typedef struct jsonToStruct_s {
267  const int data_size;
268 
269  const char *name;
270 } jsonToStruct;
271 
272 #define JTS_CHAR 0 // unable to detect with gcc (for now)
273 #define JTS_CHARP 1 // character pointer
274 #define JTS_INT 2
275 #define JTS_UCHAR 3
276 #define JTS_CHARPP 4
277 //#define JTS_DUP 5
278 //#define JTS_DU 6
279 #define JTS_CUST 7
280 #define JTS_BOOL 8
281 #define JTS_INTP 9
282 #define JTS_FLOAT 10
283 #define JTS_FLOATP 11
284 #define JTS_DOUBLE 12
285 #define JTS_DOUBLEP 13
286 
287 // name, type
288 #define JTS_ELEMENT_C(G, X, Y) \
289  &(jsonToStruct_element_custom) { \
290  .name = (const char *) JTS_TOSTRING(X), \
291  .pointer_type = JTS_TYPE_P(Y, ((G *)0)->X), \
292  .jts_cust = & JTS_NAME(Y), \
293  .pp = JTS_TYPE_P(Y, ((G *)0)->X) \
294  },
295 
296 #define JTS_ELEMENT(X, Y) \
297  &(jsonToStruct_element) { \
298  .name = JTS_TOSTRING(Y), \
299  .offset = offsetof(X, Y), \
300  .align = alignof(((X *)0)->Y), \
301  .size = sizeof( ((X *)0)->Y), \
302  .data_type = JTS_TYPE(((X *)0)->Y) \
303  },
304 
305 #define JTS_ELEMENTT(G, X, Y) \
306  &(jsonToStruct_element) { \
307  .name = JTS_TOSTRING(Y), \
308  .offset = offsetof(X, Y), \
309  .size = sizeof( ((X *)0)->Y), \
310  .data_type = JTS_TYPE(((X *)0)->Y), \
311  .pp = JTS_TYPE_P( ((G *)0)->X) \
312  },
313 
314 #define JTS_TYPE(T) _Generic( (T), \
315  char: JTS_CHAR, \
316  char *: JTS_CHARP, \
317  int: JTS_INT, \
318  unsigned char: JTS_UCHAR, \
319  char **: JTS_CHARPP, \
320  bool: JTS_BOOL, \
321  int *: JTS_INTP, \
322  float: JTS_FLOAT, \
323  float*: JTS_FLOATP,\
324  double: JTS_DOUBLE, \
325  double*: JTS_DOUBLEP,\
326  default: JTS_CUST)
327 
328 #define JTS_T_D 0
329 #define JTS_T_P 1
330 #define JTS_T_PP 2
331 #define JTS_T_U 3
332 
333 #define JTS_TYPE_P(P,T) _Generic( (T), \
334  P: JTS_T_D, \
335  P *: JTS_T_P, \
336  P **: JTS_T_PP, \
337  default: JTS_T_U)
338 
339 #define JTS_STRINGIZE(arg) JTS_STRINGIZE1(arg)
340 #define JTS_STRINGIZE1(arg) JTS_STRINGIZE2(arg)
341 #define JTS_STRINGIZE2(arg) #arg
342 
343 #define JTS_CONCATENATE(arg1, arg2) JTS_CONCATENATE1(arg1, arg2)
344 #define JTS_CONCATENATE1(arg1, arg2) JTS_CONCATENATE2(arg1, arg2)
345 #define JTS_CONCATENATE2(arg1, arg2) arg1##arg2
346 
347 #define JTS_E_FOR_EACH_1(what, x, y)\
348  what(x, y)
349 #define JTS_E_FOR_EACH_2(what, x, y, ...)\
350  what(x, y)\
351  JTS_E_FOR_EACH_1(what, x, __VA_ARGS__)
352 #define JTS_E_FOR_EACH_3(what, x, y, ...)\
353  what(x, y)\
354  JTS_E_FOR_EACH_2(what, x, __VA_ARGS__)
355 #define JTS_E_FOR_EACH_4(what, x, y, ...)\
356  what(x,y)\
357  JTS_E_FOR_EACH_3(what, x, __VA_ARGS__)
358 #define JTS_E_FOR_EACH_5(what, x, y, ...)\
359  what(x, y)\
360  JTS_E_FOR_EACH_4(what, x, __VA_ARGS__)
361 #define JTS_E_FOR_EACH_6(what, x, y, ...)\
362  what(x, y)\
363  JTS_E_FOR_EACH_5(what, x, __VA_ARGS__)
364 #define JTS_E_FOR_EACH_7(what, x, y, ...)\
365  what(x, y)\
366  JTS_E_FOR_EACH_6(what, x, __VA_ARGS__)
367 #define JTS_E_FOR_EACH_8(what, x, y, ...)\
368  what(x, y)\
369  JTS_E_FOR_EACH_7(what, x, __VA_ARGS__)
370 #define JTS_E_FOR_EACH_9(what, x, y, ...)\
371  what(x, y)\
372  JTS_E_FOR_EACH_8(what, x, __VA_ARGS__)
373 #define JTS_E_FOR_EACH_10(what, x, y, ...)\
374  what(x, y)\
375  JTS_E_FOR_EACH_9(what, x, __VA_ARGS__)
376 #define JTS_E_FOR_EACH_11(what, x, y, ...)\
377  what(x, y)\
378  JTS_E_FOR_EACH_10(what, x, __VA_ARGS__)
379 #define JTS_E_FOR_EACH_12(what, x, y, ...)\
380  what(x, y)\
381  JTS_E_FOR_EACH_11(what, x, __VA_ARGS__)
382 #define JTS_E_FOR_EACH_13(what, x, y, ...)\
383  what(x, y)\
384  JTS_E_FOR_EACH_12(what, x, __VA_ARGS__)
385 #define JTS_E_FOR_EACH_14(what, x, y, ...)\
386  what(x, y)\
387  JTS_E_FOR_EACH_13(what, x, __VA_ARGS__)
388 #define JTS_E_FOR_EACH_15(what, x, y, ...)\
389  what(x, y)\
390  JTS_E_FOR_EACH_14(what, x, __VA_ARGS__)
391 #define JTS_E_FOR_EACH_16(what, x, y, ...)\
392  what(x, y)\
393  JTS_E_FOR_EACH_15(what, x, __VA_ARGS__)
394 #define JTS_E_FOR_EACH_17(what, x, y, ...)\
395  what(x, y)\
396  JTS_E_FOR_EACH_16(what, x, __VA_ARGS__)
397 #define JTS_E_FOR_EACH_18(what, x, y, ...)\
398  what(x, y)\
399  JTS_E_FOR_EACH_17(what, x, __VA_ARGS__)
400 #define JTS_E_FOR_EACH_19(what, x, y, ...)\
401  what(x, y)\
402  JTS_E_FOR_EACH_18(what, x, __VA_ARGS__)
403 #define JTS_E_FOR_EACH_20(what, x, y, ...)\
404  what(x, y)\
405  JTS_E_FOR_EACH_19(what, x, __VA_ARGS__)
406 
407 
408 
409 #define JTS_EX_FOR_EACH_2(what, g, x, y)\
410  what(g, x, y)
411  //JTS_EX_FOR_EACH_1(what, __VA_ARGS__)
412 #define JTS_EX_FOR_EACH_4(what, g, x, y, ...)\
413  what(g, x,y)\
414  JTS_EX_FOR_EACH_2(what, g, __VA_ARGS__)
415 #define JTS_EX_FOR_EACH_6(what, g, x, y, ...)\
416  what(g, x, y)\
417  JTS_EX_FOR_EACH_4(what, g, __VA_ARGS__)
418 #define JTS_EX_FOR_EACH_8(what, g, x, y, ...)\
419  what(g, x, y)\
420  JTS_EX_FOR_EACH_6(what, g, __VA_ARGS__)
421 
422 
423 #define JTS_PPNARG(...) \
424  JTS_PPNARG_(__VA_ARGS__,JTS_PPRSEQ_N())
425 #define JTS_PPNARG_(...) \
426  JTS_PPARG_N(__VA_ARGS__)
427 #define JTS_PPARG_N( \
428  _1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \
429  _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
430  _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
431  _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
432  _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
433  _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
434  _61,_62,_63,N,...) N
435 #define JTS_PPRSEQ_N() \
436  63,62,61,60, \
437  59,58,57,56,55,54,53,52,51,50, \
438  49,48,47,46,45,44,43,42,41,40, \
439  39,38,37,36,35,34,33,32,31,30, \
440  29,28,27,26,25,24,23,22,21,20, \
441  19,18,17,16,15,14,13,12,11,10, \
442  9,8,7,6,5,4,3,2,1,0
443 
444 
445 void * jts_structify_jp (const jsonToStruct *jts, json_t *root, jsonToStruct_custom *customdef);
446 
447 void * jts_structify (const jsonToStruct *jts, const char *json_data, jsonToStruct_custom *customdef);
448 
449 void jts_structify_reverse (const jsonToStruct *jts, void *structure, jsonToStruct_custom *customdef);
450 
451 char * stj_jsonify (const jsonToStruct *jts, void *ptr);
452 
453 char * stj_jsonify_list (const jsonToStruct *jts, int num, ...);
454 
455 
456 #ifndef json_t
457 #include <jansson.h>
458 #endif
459 
460 #ifndef JTS_E_FOR_EACH_1
461 #error "include jts_b.h before jts.h"
462 #endif
463 
470 #define JTS_D(X, ...) jsonToStruct JTS_NAME(X) = { \
471  (const jsonToStruct_element *[]) {JTS_CONCATENATE(JTS_E_FOR_EACH_, JTS_PPNARG(__VA_ARGS__)) (JTS_ELEMENT, X, __VA_ARGS__) NULL }, \
472  sizeof(X),\
473  JTS_TOSTRING(X)\
474 };
475 
483 #define JTS_D_EX(X, ...) jsonToStruct_custom JTS_CUST_NAME(X) = { \
484  (const jsonToStruct_element_custom *[]) {JTS_CONCATENATE(JTS_EX_FOR_EACH_, JTS_PPNARG(__VA_ARGS__)) (JTS_ELEMENT_C, X, __VA_ARGS__) NULL } \
485 }
486 
492 #define JTS_E(X) extern jsonToStruct JTS_NAME(X);
493 
499 #define JTS_E_EX(X) extern jsonToStruct_custom JTS_CUST_NAME(X);
500 
511 #define JTS(X,Y) (X *) jts_structify (&JTS_NAME(X), Y, (jsonToStruct_custom *) 0)
512 
523 #define JTS_EX(X,Y) (X *) jts_structify (&JTS_NAME(X), Y, &JTS_CUST_NAME(X))
524 
533 #define JTS_FREE(X,Y) jts_structify_reverse (&JTS_NAME(X), Y, (jsonToStruct_custom *) 0)
534 
543 #define JTS_EX_FREE(X,Y) jts_structify_reverse (&JTS_NAME(X), Y, &JTS_CUST_NAME(X))
544 
545 
556 #define STJ(X, Y) stj_jsonify (&JTS_NAME(X), Y)
557 
565 #define STJ_FREE(X) free(X)
566 
579 #define STJ_L(X,...) stj_jsonify_list (&JTS_NAME(X), JTS_PPNARG(__VA_ARGS__)/2, __VA_ARGS__)
580 
581 
583 
584 JTS_E(Webhook);
585 
587 
589 
591 
593 
595 
597 
599 
const int data_type
Definition: dscrd_i.h:235
Definition: dscrd_i.h:23
const struct jsonToStruct_s * jts_cust
Definition: dscrd_i.h:238
void dscrd_error_set_detailed(const char *fmt,...)
char * body
response body
Definition: dscrd_i.h:163
int is_DscrdFile_real(DscrdFile *file)
Discord file wrapper.
Definition: dscrd.h:765
void DiscordGateway_close(DiscordClient *client)
DiscordClient * discord_client
pointer DiscordClient of this response
Definition: dscrd_i.h:170
#define JTS_E(X)
Definition: dscrd_i.h:492
void DscrdFile_data(DscrdFile *file)
void dscrd_rest_error_parse(int code, const char *body)
void * DiscordGateway_open(DiscordClient *client)
const int pp
Definition: dscrd_i.h:237
const int pointer_type
Definition: dscrd_i.h:244
void Rest_free(void *rest)
void DiscordGateway_callback_remove(void *gateway, int i)
Discord channel.
Definition: dscrd.h:619
Discord user.
Definition: dscrd.h:297
enum dscrd_event_e dscrd_event
void DscrdFile_data_base64(DscrdFile *file)
void * Rest_init(const char *host, int port)
char http_status[255]
HTTP status response (if any), for example "BAD REQUEST".
Definition: dscrd_i.h:158
Definition: dscrd.h:806
char * stj_jsonify(const jsonToStruct *jts, void *ptr)
Discord guild.
Definition: dscrd.h:505
void DscrdFile_data_enc(DscrdFile *file)
enum dscrd_type_e dscrd_type
Discord datatypes.
#define JTS_E_EX(X)
Definition: dscrd_i.h:499
char * stj_jsonify_list(const jsonToStruct *jts, int num,...)
Rest Response structure.
Definition: dscrd_i.h:156
dscrd_event_e
Definition: dscrd_i.h:22
const char * name
Definition: dscrd_i.h:269
const jsonToStruct_element_custom ** a
Definition: dscrd_i.h:255
DiscordChannelList * json_DiscordChannelList(DiscordClient *client, char *json)
void * jts_structify(const jsonToStruct *jts, const char *json_data, jsonToStruct_custom *customdef)
WebhookList structure.
Definition: dscrd.h:913
const jsonToStruct_element ** a
array to jsonToStruct elements (jsonToStruct_element_s)
Definition: dscrd_i.h:265
WebhookList * json_WebhookList(DiscordClient *client, char *json)
const char * name
Definition: dscrd_i.h:242
void Rest_call_free(RestResp *res)
void dscrd_error_set(const char *fmt,...)
const int size
Definition: dscrd_i.h:236
void dscrd_client_process(DiscordClient *client, dscrd_type type, int event)
int content_length
length of response body
Definition: dscrd_i.h:167
Definition: dscrd_i.h:23
struct jsonToStruct_custom_s jsonToStruct_custom
jsonToStruct_custom structure
DiscordGuild ** json_DiscordGuilds(DiscordClient *client, char *json)
const int size
Definition: dscrd_i.h:243
const size_t offset
Definition: dscrd_i.h:233
const struct jsonToStruct_s * jts_cust
Definition: dscrd_i.h:245
const char * name
Definition: dscrd_i.h:232
struct jsonToStruct_s jsonToStruct
jsonToStruct structure (array)
struct jsonToStruct_element_s jsonToStruct_element
jsonToStruct element structure
const int data_size
size of data
Definition: dscrd_i.h:267
Definition: dscrd_i.h:241
char * content_type
body&#39;s content type (if body), for example "application/json"
Definition: dscrd_i.h:165
void * json_discordobject(DiscordClient *client, dscrd_type type, char *json)
const int pp
Definition: dscrd_i.h:246
jsonToStruct_custom structure
Definition: dscrd_i.h:254
void * jts_structify_jp(const jsonToStruct *jts, json_t *root, jsonToStruct_custom *customdef)
int http_code
HTTP code response, for example 404 (Not Found)
Definition: dscrd_i.h:160
struct RestResp_s RestResp
Rest Response structure.
struct jsonToStruct_element_custom_s jsonToStruct_element_custom
Webhook structure.
Definition: dscrd.h:882
jsonToStruct structure (array)
Definition: dscrd_i.h:263
const char * dscrd_user_status_str(int status)
todo
Definition: dscrd.h:649
void DiscordGateway_send(DiscordClient *client, const char *message)
RestResp * Rest_call(DiscordClient *client, const char *path, unsigned char method, const char *body)
void * api_data
private pointer
Definition: dscrd_i.h:172
jsonToStruct element structure
Definition: dscrd_i.h:231
const size_t align
Definition: dscrd_i.h:234
Discord session.
Definition: dscrd.h:366
void jts_structify_reverse(const jsonToStruct *jts, void *structure, jsonToStruct_custom *customdef)