agoo 2.5.5 → 2.5.6
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of agoo might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +1 -1
- data/ext/agoo/agoo.c +4 -3
- data/ext/agoo/atomic.h +120 -0
- data/ext/agoo/bind.c +52 -52
- data/ext/agoo/bind.h +13 -13
- data/ext/agoo/con.c +499 -481
- data/ext/agoo/con.h +47 -39
- data/ext/agoo/debug.c +42 -42
- data/ext/agoo/debug.h +1 -1
- data/ext/agoo/doc.c +17 -17
- data/ext/agoo/doc.h +12 -12
- data/ext/agoo/err.c +18 -18
- data/ext/agoo/err.h +27 -27
- data/ext/agoo/error_stream.c +9 -9
- data/ext/agoo/extconf.rb +3 -0
- data/ext/agoo/gqlintro.c +43 -43
- data/ext/agoo/gqlintro.h +1 -1
- data/ext/agoo/gqlvalue.c +131 -131
- data/ext/agoo/gqlvalue.h +32 -32
- data/ext/agoo/graphql.c +158 -158
- data/ext/agoo/graphql.h +34 -33
- data/ext/agoo/hook.c +15 -14
- data/ext/agoo/hook.h +18 -14
- data/ext/agoo/http.c +14 -14
- data/ext/agoo/http.h +4 -4
- data/ext/agoo/kinds.h +5 -5
- data/ext/agoo/log.c +232 -224
- data/ext/agoo/log.h +93 -93
- data/ext/agoo/method.h +17 -17
- data/ext/agoo/page.c +88 -86
- data/ext/agoo/page.h +21 -21
- data/ext/agoo/pub.c +36 -36
- data/ext/agoo/pub.h +23 -23
- data/ext/agoo/queue.c +37 -38
- data/ext/agoo/queue.h +20 -19
- data/ext/agoo/rack_logger.c +13 -13
- data/ext/agoo/ready.c +357 -0
- data/ext/agoo/ready.h +41 -0
- data/ext/agoo/req.c +11 -11
- data/ext/agoo/req.h +30 -31
- data/ext/agoo/request.c +46 -46
- data/ext/agoo/request.h +2 -2
- data/ext/agoo/res.c +40 -18
- data/ext/agoo/res.h +14 -14
- data/ext/agoo/response.c +6 -6
- data/ext/agoo/response.h +9 -9
- data/ext/agoo/rhook.c +3 -3
- data/ext/agoo/rhook.h +1 -1
- data/ext/agoo/rlog.c +47 -42
- data/ext/agoo/rlog.h +0 -1
- data/ext/agoo/rresponse.c +33 -33
- data/ext/agoo/rresponse.h +1 -1
- data/ext/agoo/rserver.c +184 -175
- data/ext/agoo/rserver.h +2 -2
- data/ext/agoo/rupgraded.c +41 -41
- data/ext/agoo/rupgraded.h +3 -3
- data/ext/agoo/sdl.c +80 -80
- data/ext/agoo/sdl.h +1 -1
- data/ext/agoo/seg.h +2 -2
- data/ext/agoo/server.c +143 -117
- data/ext/agoo/server.h +43 -42
- data/ext/agoo/sse.c +7 -7
- data/ext/agoo/sse.h +4 -4
- data/ext/agoo/subject.c +5 -5
- data/ext/agoo/subject.h +6 -6
- data/ext/agoo/text.c +21 -21
- data/ext/agoo/text.h +14 -13
- data/ext/agoo/upgraded.c +41 -40
- data/ext/agoo/upgraded.h +41 -40
- data/ext/agoo/websocket.c +42 -42
- data/ext/agoo/websocket.h +16 -16
- data/lib/agoo/version.rb +1 -1
- data/test/static_test.rb +2 -0
- metadata +5 -5
- data/ext/agoo/log_queue.h +0 -30
- data/ext/agoo/sub.c +0 -111
- data/ext/agoo/sub.h +0 -36
data/ext/agoo/gqlvalue.h
CHANGED
@@ -18,19 +18,19 @@ typedef struct _gqlLink {
|
|
18
18
|
} *gqlLink;
|
19
19
|
|
20
20
|
typedef struct _gqlValue {
|
21
|
-
struct _gqlType
|
21
|
+
struct _gqlType *type;
|
22
22
|
union {
|
23
|
-
char
|
24
|
-
int32_t
|
25
|
-
int64_t
|
26
|
-
double
|
27
|
-
bool
|
28
|
-
int64_t
|
29
|
-
char
|
30
|
-
char
|
23
|
+
char *url;
|
24
|
+
int32_t i;
|
25
|
+
int64_t i64;
|
26
|
+
double f;
|
27
|
+
bool b;
|
28
|
+
int64_t time;
|
29
|
+
char *str;
|
30
|
+
char str16[16];
|
31
31
|
struct {
|
32
|
-
uint64_t
|
33
|
-
uint64_t
|
32
|
+
uint64_t hi;
|
33
|
+
uint64_t lo;
|
34
34
|
} uuid;
|
35
35
|
struct {
|
36
36
|
struct _gqlLink *members; // linked list for List and Object types
|
@@ -39,41 +39,41 @@ typedef struct _gqlValue {
|
|
39
39
|
};
|
40
40
|
} *gqlValue;
|
41
41
|
|
42
|
-
extern int gql_value_init(
|
42
|
+
extern int gql_value_init(agooErr err);
|
43
43
|
|
44
44
|
extern void gql_value_destroy(gqlValue value);
|
45
45
|
|
46
|
-
extern gqlValue gql_int_create(
|
47
|
-
extern gqlValue gql_i64_create(
|
48
|
-
extern gqlValue gql_string_create(
|
49
|
-
extern gqlValue gql_url_create(
|
50
|
-
extern gqlValue gql_bool_create(
|
51
|
-
extern gqlValue gql_float_create(
|
52
|
-
extern gqlValue gql_time_create(
|
53
|
-
extern gqlValue gql_time_str_create(
|
54
|
-
extern gqlValue gql_uuid_create(
|
55
|
-
extern gqlValue gql_uuid_str_create(
|
56
|
-
extern gqlValue gql_null_create(
|
57
|
-
extern gqlValue gql_list_create(
|
58
|
-
extern gqlValue gql_object_create(
|
46
|
+
extern gqlValue gql_int_create(agooErr err, int32_t i);
|
47
|
+
extern gqlValue gql_i64_create(agooErr err, int64_t i);
|
48
|
+
extern gqlValue gql_string_create(agooErr err, const char *str, int len);
|
49
|
+
extern gqlValue gql_url_create(agooErr err, const char *url, int len);
|
50
|
+
extern gqlValue gql_bool_create(agooErr err, bool b);
|
51
|
+
extern gqlValue gql_float_create(agooErr err, double f);
|
52
|
+
extern gqlValue gql_time_create(agooErr err, int64_t t);
|
53
|
+
extern gqlValue gql_time_str_create(agooErr err, const char *str, int len);
|
54
|
+
extern gqlValue gql_uuid_create(agooErr err, uint64_t hi, uint64_t lo);
|
55
|
+
extern gqlValue gql_uuid_str_create(agooErr err, const char *str, int len);
|
56
|
+
extern gqlValue gql_null_create(agooErr err);
|
57
|
+
extern gqlValue gql_list_create(agooErr err, struct _gqlType *itemType);
|
58
|
+
extern gqlValue gql_object_create(agooErr err);
|
59
59
|
|
60
|
-
extern int gql_list_append(
|
61
|
-
extern int gql_list_preend(
|
62
|
-
extern int gql_object_set(
|
60
|
+
extern int gql_list_append(agooErr err, gqlValue list, gqlValue item);
|
61
|
+
extern int gql_list_preend(agooErr err, gqlValue list, gqlValue item);
|
62
|
+
extern int gql_object_set(agooErr err, gqlValue obj, const char *key, gqlValue item);
|
63
63
|
|
64
64
|
extern void gql_int_set(gqlValue value, int32_t i);
|
65
65
|
extern void gql_i64_set(gqlValue value, int64_t i);
|
66
66
|
extern void gql_string_set(gqlValue value, const char *str, int len);
|
67
|
-
extern int gql_url_set(
|
67
|
+
extern int gql_url_set(agooErr err, gqlValue value, const char *url, int len);
|
68
68
|
extern void gql_bool_set(gqlValue value, bool b);
|
69
69
|
extern void gql_float_set(gqlValue value, double f);
|
70
70
|
extern void gql_time_set(gqlValue value, int64_t t);
|
71
|
-
extern int gql_time_str_set(
|
71
|
+
extern int gql_time_str_set(agooErr err, gqlValue value, const char *str, int len);
|
72
72
|
extern void gql_uuid_set(gqlValue value, uint64_t hi, uint64_t lo);
|
73
|
-
extern int gql_uuid_str_set(
|
73
|
+
extern int gql_uuid_str_set(agooErr err, gqlValue value, const char *str, int len);
|
74
74
|
extern void gql_null_set(gqlValue value);
|
75
75
|
|
76
|
-
extern
|
76
|
+
extern agooText gql_value_json(agooText text, gqlValue value, int indent, int depth);
|
77
77
|
|
78
78
|
extern struct _gqlType gql_null_type;
|
79
79
|
extern struct _gqlType gql_int_type;
|
data/ext/agoo/graphql.c
CHANGED
@@ -15,8 +15,8 @@
|
|
15
15
|
#define BUCKET_MASK 63
|
16
16
|
#define BAD_NAME (uint64_t)-1
|
17
17
|
|
18
|
-
typedef struct
|
19
|
-
struct
|
18
|
+
typedef struct _slot {
|
19
|
+
struct _slot *next;
|
20
20
|
gqlType type;
|
21
21
|
uint64_t hash;
|
22
22
|
} *Slot;
|
@@ -187,11 +187,11 @@ gql_directive_get(const char *name) {
|
|
187
187
|
}
|
188
188
|
|
189
189
|
int
|
190
|
-
gql_type_set(
|
190
|
+
gql_type_set(agooErr err, gqlType type) {
|
191
191
|
uint64_t h = calc_hash(type->name);
|
192
192
|
|
193
193
|
if (h <= 0) {
|
194
|
-
return
|
194
|
+
return agoo_err_set(err, AGOO_ERR_ARG, "%s is not a valid GraphQL type name.", type->name);
|
195
195
|
} else {
|
196
196
|
Slot *bucket = get_bucketp(h);
|
197
197
|
Slot s;
|
@@ -200,11 +200,11 @@ gql_type_set(Err err, gqlType type) {
|
|
200
200
|
if (h == s->hash && 0 == strcmp(s->type->name, type->name)) {
|
201
201
|
type_destroy(s->type);
|
202
202
|
s->type = type;
|
203
|
-
return
|
203
|
+
return AGOO_ERR_OK;
|
204
204
|
}
|
205
205
|
}
|
206
|
-
if (NULL == (s = (Slot)malloc(sizeof(struct
|
207
|
-
return
|
206
|
+
if (NULL == (s = (Slot)malloc(sizeof(struct _slot)))) {
|
207
|
+
return agoo_err_set(err, AGOO_ERR_MEMORY, "Failed to allocation memory for a GraphQL type.");
|
208
208
|
}
|
209
209
|
DEBUG_ALLOC(mem_graphql_slot, s);
|
210
210
|
s->hash = h;
|
@@ -212,7 +212,7 @@ gql_type_set(Err err, gqlType type) {
|
|
212
212
|
s->next = *bucket;
|
213
213
|
*bucket = s;
|
214
214
|
}
|
215
|
-
return
|
215
|
+
return AGOO_ERR_OK;
|
216
216
|
}
|
217
217
|
|
218
218
|
static void
|
@@ -242,11 +242,11 @@ type_remove(gqlType type) {
|
|
242
242
|
}
|
243
243
|
|
244
244
|
int
|
245
|
-
gql_init(
|
245
|
+
gql_init(agooErr err) {
|
246
246
|
memset(buckets, 0, sizeof(buckets));
|
247
247
|
|
248
|
-
if (
|
249
|
-
|
248
|
+
if (AGOO_ERR_OK != gql_value_init(err) ||
|
249
|
+
AGOO_ERR_OK != gql_intro_init(err)) {
|
250
250
|
|
251
251
|
return err->code;
|
252
252
|
}
|
@@ -261,7 +261,7 @@ gql_init(Err err) {
|
|
261
261
|
|
262
262
|
return err->code;
|
263
263
|
}
|
264
|
-
return
|
264
|
+
return AGOO_ERR_OK;
|
265
265
|
}
|
266
266
|
|
267
267
|
void
|
@@ -291,11 +291,11 @@ gql_destroy() {
|
|
291
291
|
}
|
292
292
|
|
293
293
|
static gqlType
|
294
|
-
type_create(
|
294
|
+
type_create(agooErr err, const char *name, const char *desc, int dlen, bool locked) {
|
295
295
|
gqlType type = (gqlType)malloc(sizeof(struct _gqlType));
|
296
296
|
|
297
297
|
if (NULL == type) {
|
298
|
-
|
298
|
+
agoo_err_set(err, AGOO_ERR_MEMORY, "Failed to allocation memory for a GraphQL Type.");
|
299
299
|
} else {
|
300
300
|
DEBUG_ALLOC(mem_graphql_type, type);
|
301
301
|
type->name = strdup(name);
|
@@ -312,7 +312,7 @@ type_create(Err err, const char *name, const char *desc, int dlen, bool locked)
|
|
312
312
|
type->core = false;
|
313
313
|
type->dir = NULL;
|
314
314
|
|
315
|
-
if (
|
315
|
+
if (AGOO_ERR_OK != gql_type_set(err, type)) {
|
316
316
|
gql_type_destroy(type);
|
317
317
|
type = NULL;
|
318
318
|
}
|
@@ -320,20 +320,20 @@ type_create(Err err, const char *name, const char *desc, int dlen, bool locked)
|
|
320
320
|
return type;
|
321
321
|
}
|
322
322
|
|
323
|
-
|
324
|
-
gql_object_to_json(
|
323
|
+
agooText
|
324
|
+
gql_object_to_json(agooText text, gqlValue value, int indent, int depth) {
|
325
325
|
// TBD
|
326
326
|
return text;
|
327
327
|
}
|
328
328
|
|
329
|
-
|
330
|
-
gql_object_to_graphql(
|
329
|
+
agooText
|
330
|
+
gql_object_to_graphql(agooText text, gqlValue value, int indent, int depth) {
|
331
331
|
// TBD
|
332
332
|
return text;
|
333
333
|
}
|
334
334
|
|
335
335
|
gqlType
|
336
|
-
gql_type_create(
|
336
|
+
gql_type_create(agooErr err, const char *name, const char *desc, int dlen, bool locked, gqlType *interfaces) {
|
337
337
|
gqlType type = type_create(err, name, desc, dlen, locked);
|
338
338
|
|
339
339
|
if (NULL != type) {
|
@@ -351,7 +351,7 @@ gql_type_create(Err err, const char *name, const char *desc, int dlen, bool lock
|
|
351
351
|
}
|
352
352
|
if (0 < cnt) {
|
353
353
|
if (NULL == (type->interfaces = (gqlType*)malloc(sizeof(gqlType) * (cnt + 1)))) {
|
354
|
-
|
354
|
+
agoo_err_set(err, AGOO_ERR_MEMORY, "Failed to allocation memory for a GraphQL type interfaces.");
|
355
355
|
free(type);
|
356
356
|
return NULL;
|
357
357
|
}
|
@@ -366,7 +366,7 @@ gql_type_create(Err err, const char *name, const char *desc, int dlen, bool lock
|
|
366
366
|
}
|
367
367
|
|
368
368
|
gqlField
|
369
|
-
gql_type_field(
|
369
|
+
gql_type_field(agooErr err,
|
370
370
|
gqlType type,
|
371
371
|
const char *name,
|
372
372
|
gqlType return_type,
|
@@ -378,7 +378,7 @@ gql_type_field(Err err,
|
|
378
378
|
gqlField f = (gqlField)malloc(sizeof(struct _gqlField));
|
379
379
|
|
380
380
|
if (NULL == f) {
|
381
|
-
|
381
|
+
agoo_err_set(err, AGOO_ERR_MEMORY, "Failed to allocation memory for a GraphQL field.");
|
382
382
|
} else {
|
383
383
|
DEBUG_ALLOC(mem_graphql_field, f);
|
384
384
|
f->next = NULL;
|
@@ -411,7 +411,7 @@ gql_type_field(Err err,
|
|
411
411
|
}
|
412
412
|
|
413
413
|
gqlArg
|
414
|
-
gql_field_arg(
|
414
|
+
gql_field_arg(agooErr err,
|
415
415
|
gqlField field,
|
416
416
|
const char *name,
|
417
417
|
gqlType type,
|
@@ -421,7 +421,7 @@ gql_field_arg(Err err,
|
|
421
421
|
gqlArg a = (gqlArg)malloc(sizeof(struct _gqlArg));
|
422
422
|
|
423
423
|
if (NULL == a) {
|
424
|
-
|
424
|
+
agoo_err_set(err, AGOO_ERR_MEMORY, "Failed to allocation memory for a GraphQL field argument.");
|
425
425
|
} else {
|
426
426
|
DEBUG_ALLOC(mem_graphql_arg, a);
|
427
427
|
a->next = NULL;
|
@@ -448,14 +448,14 @@ gql_field_arg(Err err,
|
|
448
448
|
return a;
|
449
449
|
}
|
450
450
|
|
451
|
-
|
452
|
-
gql_union_to_json(
|
451
|
+
agooText
|
452
|
+
gql_union_to_json(agooText text, gqlValue value, int indent, int depth) {
|
453
453
|
// TBD
|
454
454
|
return text;
|
455
455
|
}
|
456
456
|
|
457
457
|
gqlType
|
458
|
-
gql_union_create(
|
458
|
+
gql_union_create(agooErr err, const char *name, const char *desc, int dlen, bool locked) {
|
459
459
|
gqlType type = type_create(err, name, desc, dlen, locked);
|
460
460
|
|
461
461
|
if (NULL != type) {
|
@@ -467,11 +467,11 @@ gql_union_create(Err err, const char *name, const char *desc, int dlen, bool loc
|
|
467
467
|
}
|
468
468
|
|
469
469
|
int
|
470
|
-
gql_union_add(
|
470
|
+
gql_union_add(agooErr err, gqlType type, const char *name, int len) {
|
471
471
|
gqlTypeLink link = (gqlTypeLink)malloc(sizeof(gqlTypeLink));
|
472
472
|
|
473
473
|
if (NULL == link) {
|
474
|
-
|
474
|
+
agoo_err_set(err, AGOO_ERR_MEMORY, "Failed to allocation memory for a GraphQL Union value.");
|
475
475
|
}
|
476
476
|
if (0 >= len) {
|
477
477
|
len = (int)strlen(name);
|
@@ -488,17 +488,17 @@ gql_union_add(Err err, gqlType type, const char *name, int len) {
|
|
488
488
|
link->next = NULL;
|
489
489
|
last->next = link;
|
490
490
|
}
|
491
|
-
return
|
491
|
+
return AGOO_ERR_OK;
|
492
492
|
}
|
493
493
|
|
494
|
-
|
495
|
-
gql_enum_to_json(
|
494
|
+
agooText
|
495
|
+
gql_enum_to_json(agooText text, gqlValue value, int indent, int depth) {
|
496
496
|
// TBD
|
497
497
|
return text;
|
498
498
|
}
|
499
499
|
|
500
500
|
gqlType
|
501
|
-
gql_enum_create(
|
501
|
+
gql_enum_create(agooErr err, const char *name, const char *desc, int dlen, bool locked) {
|
502
502
|
gqlType type = type_create(err, name, desc, dlen, locked);
|
503
503
|
|
504
504
|
if (NULL != type) {
|
@@ -510,11 +510,11 @@ gql_enum_create(Err err, const char *name, const char *desc, int dlen, bool lock
|
|
510
510
|
}
|
511
511
|
|
512
512
|
int
|
513
|
-
gql_enum_add(
|
513
|
+
gql_enum_add(agooErr err, gqlType type, const char *value, int len) {
|
514
514
|
gqlStrLink link = (gqlStrLink)malloc(sizeof(gqlStrLink));
|
515
515
|
|
516
516
|
if (NULL == link) {
|
517
|
-
|
517
|
+
agoo_err_set(err, AGOO_ERR_MEMORY, "Failed to allocation memory for a GraphQL Enum value.");
|
518
518
|
}
|
519
519
|
if (0 >= len) {
|
520
520
|
len = (int)strlen(value);
|
@@ -523,15 +523,15 @@ gql_enum_add(Err err, gqlType type, const char *value, int len) {
|
|
523
523
|
type->choices = link;
|
524
524
|
link->str = strndup(value, len);
|
525
525
|
|
526
|
-
return
|
526
|
+
return AGOO_ERR_OK;
|
527
527
|
}
|
528
528
|
|
529
529
|
int
|
530
|
-
gql_enum_append(
|
530
|
+
gql_enum_append(agooErr err, gqlType type, const char *value, int len) {
|
531
531
|
gqlStrLink link = (gqlStrLink)malloc(sizeof(gqlStrLink));
|
532
532
|
|
533
533
|
if (NULL == link) {
|
534
|
-
|
534
|
+
agoo_err_set(err, AGOO_ERR_MEMORY, "Failed to allocation memory for a GraphQL Enum value.");
|
535
535
|
}
|
536
536
|
if (0 >= len) {
|
537
537
|
len = (int)strlen(value);
|
@@ -548,17 +548,17 @@ gql_enum_append(Err err, gqlType type, const char *value, int len) {
|
|
548
548
|
link->next = NULL;
|
549
549
|
last->next = link;
|
550
550
|
}
|
551
|
-
return
|
551
|
+
return AGOO_ERR_OK;
|
552
552
|
}
|
553
553
|
|
554
|
-
static
|
555
|
-
fragment_to_json(
|
554
|
+
static agooText
|
555
|
+
fragment_to_json(agooText text, gqlValue value, int indent, int depth) {
|
556
556
|
// TBD
|
557
557
|
return text;
|
558
558
|
}
|
559
559
|
|
560
560
|
gqlType
|
561
|
-
gql_fragment_create(
|
561
|
+
gql_fragment_create(agooErr err, const char *name, const char *desc, int dlen, bool locked, gqlType on) {
|
562
562
|
gqlType type = type_create(err, name, desc, dlen, locked);
|
563
563
|
|
564
564
|
if (NULL != type) {
|
@@ -570,14 +570,14 @@ gql_fragment_create(Err err, const char *name, const char *desc, int dlen, bool
|
|
570
570
|
return type;
|
571
571
|
}
|
572
572
|
|
573
|
-
static
|
574
|
-
input_to_json(
|
573
|
+
static agooText
|
574
|
+
input_to_json(agooText text, gqlValue value, int indent, int depth) {
|
575
575
|
// TBD
|
576
576
|
return text;
|
577
577
|
}
|
578
578
|
|
579
579
|
gqlType
|
580
|
-
gql_input_create(
|
580
|
+
gql_input_create(agooErr err, const char *name, const char *desc, int dlen, bool locked) {
|
581
581
|
gqlType type = type_create(err, name, desc, dlen, locked);
|
582
582
|
|
583
583
|
if (NULL != type) {
|
@@ -588,14 +588,14 @@ gql_input_create(Err err, const char *name, const char *desc, int dlen, bool loc
|
|
588
588
|
return type;
|
589
589
|
}
|
590
590
|
|
591
|
-
static
|
592
|
-
interface_to_json(
|
591
|
+
static agooText
|
592
|
+
interface_to_json(agooText text, gqlValue value, int indent, int depth) {
|
593
593
|
// TBD
|
594
594
|
return text;
|
595
595
|
}
|
596
596
|
|
597
597
|
gqlType
|
598
|
-
gql_interface_create(
|
598
|
+
gql_interface_create(agooErr err, const char *name, const char *desc, int dlen, bool locked) {
|
599
599
|
gqlType type = type_create(err, name, desc, dlen, locked);
|
600
600
|
|
601
601
|
if (NULL != type) {
|
@@ -606,21 +606,21 @@ gql_interface_create(Err err, const char *name, const char *desc, int dlen, bool
|
|
606
606
|
return type;
|
607
607
|
}
|
608
608
|
|
609
|
-
static
|
610
|
-
scalar_to_json(
|
609
|
+
static agooText
|
610
|
+
scalar_to_json(agooText text, gqlValue value, int indent, int depth) {
|
611
611
|
if (NULL == value->str) {
|
612
|
-
text =
|
612
|
+
text = agoo_text_append(text, "null", 4);
|
613
613
|
} else {
|
614
|
-
text =
|
615
|
-
text =
|
616
|
-
text =
|
614
|
+
text = agoo_text_append(text, "\"", 1);
|
615
|
+
text = agoo_text_append(text, value->str, -1);
|
616
|
+
text = agoo_text_append(text, "\"", 1);
|
617
617
|
}
|
618
618
|
return text;
|
619
619
|
}
|
620
620
|
|
621
621
|
// Create a scalar type that will be represented as a string.
|
622
622
|
gqlType
|
623
|
-
gql_scalar_create(
|
623
|
+
gql_scalar_create(agooErr err, const char *name, const char *desc, int dlen, bool locked) {
|
624
624
|
gqlType type = type_create(err, name, desc, dlen, locked);
|
625
625
|
|
626
626
|
if (NULL != type) {
|
@@ -633,11 +633,11 @@ gql_scalar_create(Err err, const char *name, const char *desc, int dlen, bool lo
|
|
633
633
|
}
|
634
634
|
|
635
635
|
gqlDir
|
636
|
-
gql_directive_create(
|
636
|
+
gql_directive_create(agooErr err, const char *name, const char *desc, int dlen, bool locked) {
|
637
637
|
gqlDir dir;
|
638
638
|
|
639
639
|
if (NULL == (dir = (gqlDir)malloc(sizeof(struct _gqlDir)))) {
|
640
|
-
|
640
|
+
agoo_err_set(err, AGOO_ERR_MEMORY, "Failed to allocation memory for a GraphQL directive.");
|
641
641
|
return NULL;
|
642
642
|
}
|
643
643
|
DEBUG_ALLOC(mem_graphql_directive, dir);
|
@@ -660,7 +660,7 @@ gql_directive_create(Err err, const char *name, const char *desc, int dlen, bool
|
|
660
660
|
}
|
661
661
|
|
662
662
|
gqlArg
|
663
|
-
gql_dir_arg(
|
663
|
+
gql_dir_arg(agooErr err,
|
664
664
|
gqlDir dir,
|
665
665
|
const char *name,
|
666
666
|
const char *type_name,
|
@@ -672,7 +672,7 @@ gql_dir_arg(Err err,
|
|
672
672
|
gqlArg a = (gqlArg)malloc(sizeof(struct _gqlArg));
|
673
673
|
|
674
674
|
if (NULL == a) {
|
675
|
-
|
675
|
+
agoo_err_set(err, AGOO_ERR_MEMORY, "Failed to allocation memory for a GraphQL directive argument.");
|
676
676
|
} else {
|
677
677
|
DEBUG_ALLOC(mem_graphql_arg, a);
|
678
678
|
a->next = NULL;
|
@@ -703,12 +703,12 @@ gql_dir_arg(Err err,
|
|
703
703
|
}
|
704
704
|
|
705
705
|
int
|
706
|
-
gql_directive_on(
|
706
|
+
gql_directive_on(agooErr err, gqlDir d, const char *on, int len) {
|
707
707
|
gqlStrLink link = (gqlStrLink)malloc(sizeof(gqlStrLink));
|
708
708
|
gqlStrLink loc;
|
709
709
|
|
710
710
|
if (NULL == link) {
|
711
|
-
|
711
|
+
agoo_err_set(err, AGOO_ERR_MEMORY, "Failed to allocation memory for a GraphQL directive location.");
|
712
712
|
}
|
713
713
|
if (0 >= len) {
|
714
714
|
len = (int)strlen(on);
|
@@ -724,7 +724,7 @@ gql_directive_on(Err err, gqlDir d, const char *on, int len) {
|
|
724
724
|
}
|
725
725
|
link->str = strndup(on, len);
|
726
726
|
|
727
|
-
return
|
727
|
+
return AGOO_ERR_OK;
|
728
728
|
}
|
729
729
|
|
730
730
|
void
|
@@ -747,20 +747,20 @@ desc_len(const char *desc) {
|
|
747
747
|
return (int)(d - desc) * special;
|
748
748
|
}
|
749
749
|
|
750
|
-
static
|
751
|
-
desc_sdl(
|
750
|
+
static agooText
|
751
|
+
desc_sdl(agooText text, const char *desc, int indent) {
|
752
752
|
if (NULL != desc) {
|
753
753
|
int cnt = desc_len(desc);
|
754
754
|
|
755
755
|
if (0 < indent) {
|
756
|
-
text =
|
756
|
+
text = agoo_text_append(text, spaces, indent);
|
757
757
|
}
|
758
758
|
if (0 <= cnt) {
|
759
|
-
text =
|
760
|
-
text =
|
761
|
-
text =
|
759
|
+
text = agoo_text_append(text, "\"", 1);
|
760
|
+
text = agoo_text_append(text, desc, cnt);
|
761
|
+
text = agoo_text_append(text, "\"\n", 2);
|
762
762
|
} else {
|
763
|
-
text =
|
763
|
+
text = agoo_text_append(text, "\"\"\"\n", 4);
|
764
764
|
if (0 < indent) {
|
765
765
|
const char *start = desc;
|
766
766
|
const char *d = desc;
|
@@ -772,94 +772,94 @@ desc_sdl(Text text, const char *desc, int indent) {
|
|
772
772
|
if ('\n' == *d) {
|
773
773
|
d++;
|
774
774
|
}
|
775
|
-
text =
|
776
|
-
text =
|
777
|
-
text =
|
775
|
+
text = agoo_text_append(text, spaces, indent);
|
776
|
+
text = agoo_text_append(text, start, len);
|
777
|
+
text = agoo_text_append(text, "\n", 1);
|
778
778
|
start = d;
|
779
779
|
} else if ('\n' == *d) {
|
780
|
-
text =
|
781
|
-
text =
|
782
|
-
text =
|
780
|
+
text = agoo_text_append(text, spaces, indent);
|
781
|
+
text = agoo_text_append(text, start, (int)(d - start));
|
782
|
+
text = agoo_text_append(text, "\n", 1);
|
783
783
|
d++;
|
784
784
|
start = d;
|
785
785
|
}
|
786
786
|
}
|
787
|
-
text =
|
788
|
-
text =
|
787
|
+
text = agoo_text_append(text, spaces, indent);
|
788
|
+
text = agoo_text_append(text, start, (int)(d - start));
|
789
789
|
} else {
|
790
|
-
text =
|
790
|
+
text = agoo_text_append(text, desc, -1);
|
791
791
|
}
|
792
792
|
if (0 < indent) {
|
793
|
-
text =
|
794
|
-
text =
|
795
|
-
text =
|
793
|
+
text = agoo_text_append(text, "\n", 1);
|
794
|
+
text = agoo_text_append(text, spaces, indent);
|
795
|
+
text = agoo_text_append(text, "\"\"\"\n", 4);
|
796
796
|
} else {
|
797
|
-
text =
|
797
|
+
text = agoo_text_append(text, "\n\"\"\"\n", 5);
|
798
798
|
}
|
799
799
|
}
|
800
800
|
}
|
801
801
|
return text;
|
802
802
|
}
|
803
803
|
|
804
|
-
static
|
805
|
-
arg_sdl(
|
804
|
+
static agooText
|
805
|
+
arg_sdl(agooText text, gqlArg a, bool with_desc, bool last) {
|
806
806
|
if (with_desc) {
|
807
807
|
text = desc_sdl(text, a->desc, 4);
|
808
808
|
}
|
809
|
-
text =
|
809
|
+
text = agoo_text_append(text, a->name, -1);
|
810
810
|
if (a->required) {
|
811
|
-
text =
|
811
|
+
text = agoo_text_append(text, "!: ", 3);
|
812
812
|
} else {
|
813
|
-
text =
|
813
|
+
text = agoo_text_append(text, ": ", 2);
|
814
814
|
}
|
815
|
-
text =
|
815
|
+
text = agoo_text_append(text, a->type_name, -1);
|
816
816
|
if (NULL != a->default_value) {
|
817
|
-
text =
|
817
|
+
text = agoo_text_append(text, " = ", 3);
|
818
818
|
text = gql_value_json(text, a->default_value, 0, 0);
|
819
819
|
}
|
820
820
|
if (!last) {
|
821
|
-
text =
|
821
|
+
text = agoo_text_append(text, ", ", 2);
|
822
822
|
}
|
823
823
|
return text;
|
824
824
|
}
|
825
825
|
|
826
|
-
static
|
827
|
-
field_sdl(
|
826
|
+
static agooText
|
827
|
+
field_sdl(agooText text, gqlField f, bool with_desc) {
|
828
828
|
if (with_desc) {
|
829
829
|
text = desc_sdl(text, f->desc, 2);
|
830
830
|
}
|
831
|
-
text =
|
832
|
-
text =
|
831
|
+
text = agoo_text_append(text, " ", 2);
|
832
|
+
text = agoo_text_append(text, f->name, -1);
|
833
833
|
if (NULL != f->args) {
|
834
834
|
gqlArg a;
|
835
835
|
|
836
|
-
text =
|
836
|
+
text = agoo_text_append(text, "(", 1);
|
837
837
|
for (a = f->args; NULL != a; a = a->next) {
|
838
838
|
text = arg_sdl(text, a, with_desc, NULL == a->next);
|
839
839
|
}
|
840
|
-
text =
|
840
|
+
text = agoo_text_append(text, ")", 1);
|
841
841
|
}
|
842
|
-
text =
|
842
|
+
text = agoo_text_append(text, ": ", 2);
|
843
843
|
if (f->list) {
|
844
|
-
text =
|
845
|
-
text =
|
844
|
+
text = agoo_text_append(text, "[", 1);
|
845
|
+
text = agoo_text_append(text, f->type->name, -1);
|
846
846
|
if (f->not_empty) {
|
847
|
-
text =
|
847
|
+
text = agoo_text_append(text, "!", 1);
|
848
848
|
}
|
849
|
-
text =
|
849
|
+
text = agoo_text_append(text, "]", 1);
|
850
850
|
} else {
|
851
|
-
text =
|
851
|
+
text = agoo_text_append(text, f->type->name, -1);
|
852
852
|
}
|
853
853
|
if (f->required) {
|
854
|
-
text =
|
854
|
+
text = agoo_text_append(text, "!", 1);
|
855
855
|
}
|
856
|
-
text =
|
856
|
+
text = agoo_text_append(text, "\n", 1);
|
857
857
|
|
858
858
|
return text;
|
859
859
|
}
|
860
860
|
|
861
|
-
|
862
|
-
gql_type_sdl(
|
861
|
+
agooText
|
862
|
+
gql_type_sdl(agooText text, gqlType type, bool with_desc) {
|
863
863
|
if (with_desc) {
|
864
864
|
desc_sdl(text, type->desc, 0);
|
865
865
|
}
|
@@ -868,36 +868,36 @@ gql_type_sdl(Text text, gqlType type, bool with_desc) {
|
|
868
868
|
case GQL_FRAG: {
|
869
869
|
gqlField f;
|
870
870
|
|
871
|
-
text =
|
872
|
-
text =
|
871
|
+
text = agoo_text_append(text, "type ", 5);
|
872
|
+
text = agoo_text_append(text, type->name, -1);
|
873
873
|
if (NULL != type->interfaces) {
|
874
874
|
gqlType *tp = type->interfaces;
|
875
875
|
|
876
|
-
text =
|
876
|
+
text = agoo_text_append(text, " implements ", 12);
|
877
877
|
for (; NULL != *tp; tp++) {
|
878
|
-
text =
|
878
|
+
text = agoo_text_append(text, (*tp)->name, -1);
|
879
879
|
if (NULL != *(tp + 1)) {
|
880
|
-
text =
|
880
|
+
text = agoo_text_append(text, ", ", 2);
|
881
881
|
}
|
882
882
|
}
|
883
883
|
}
|
884
|
-
text =
|
884
|
+
text = agoo_text_append(text, " {\n", 3);
|
885
885
|
for (f = type->fields; NULL != f; f = f->next) {
|
886
886
|
text = field_sdl(text, f, with_desc);
|
887
887
|
}
|
888
|
-
text =
|
888
|
+
text = agoo_text_append(text, "}\n", 2);
|
889
889
|
break;
|
890
890
|
}
|
891
891
|
case GQL_UNION: {
|
892
892
|
gqlTypeLink link;
|
893
893
|
|
894
|
-
text =
|
895
|
-
text =
|
896
|
-
text =
|
894
|
+
text = agoo_text_append(text, "union ", 6);
|
895
|
+
text = agoo_text_append(text, type->name, -1);
|
896
|
+
text = agoo_text_append(text, " = ", 3);
|
897
897
|
for (link = type->types; NULL != link; link = link->next) {
|
898
|
-
text =
|
898
|
+
text = agoo_text_append(text, link->name, -1);
|
899
899
|
if (NULL != link->next) {
|
900
|
-
text =
|
900
|
+
text = agoo_text_append(text, " | ", 3);
|
901
901
|
}
|
902
902
|
}
|
903
903
|
break;
|
@@ -905,45 +905,45 @@ gql_type_sdl(Text text, gqlType type, bool with_desc) {
|
|
905
905
|
case GQL_ENUM: {
|
906
906
|
gqlStrLink link;;
|
907
907
|
|
908
|
-
text =
|
909
|
-
text =
|
910
|
-
text =
|
908
|
+
text = agoo_text_append(text, "enum ", 5);
|
909
|
+
text = agoo_text_append(text, type->name, -1);
|
910
|
+
text = agoo_text_append(text, " {\n", 3);
|
911
911
|
for (link = type->choices; NULL != link; link = link->next) {
|
912
|
-
text =
|
913
|
-
text =
|
914
|
-
text =
|
912
|
+
text = agoo_text_append(text, " ", 2);
|
913
|
+
text = agoo_text_append(text, link->str, -1);
|
914
|
+
text = agoo_text_append(text, "\n", 1);
|
915
915
|
}
|
916
|
-
text =
|
916
|
+
text = agoo_text_append(text, "}\n", 2);
|
917
917
|
break;
|
918
918
|
}
|
919
919
|
case GQL_SCALAR:
|
920
|
-
text =
|
921
|
-
text =
|
922
|
-
text =
|
920
|
+
text = agoo_text_append(text, "scalar ", 7);
|
921
|
+
text = agoo_text_append(text, type->name, -1);
|
922
|
+
text = agoo_text_append(text, "\n", 1);
|
923
923
|
break;
|
924
924
|
case GQL_INTERFACE: {
|
925
925
|
gqlField f;
|
926
926
|
|
927
|
-
text =
|
928
|
-
text =
|
929
|
-
text =
|
927
|
+
text = agoo_text_append(text, "interface ", 10);
|
928
|
+
text = agoo_text_append(text, type->name, -1);
|
929
|
+
text = agoo_text_append(text, " {\n", 3);
|
930
930
|
|
931
931
|
for (f = type->fields; NULL != f; f = f->next) {
|
932
932
|
text = field_sdl(text, f, with_desc);
|
933
933
|
}
|
934
|
-
text =
|
934
|
+
text = agoo_text_append(text, "}\n", 2);
|
935
935
|
break;
|
936
936
|
}
|
937
937
|
case GQL_INPUT: {
|
938
938
|
gqlField f;
|
939
939
|
|
940
|
-
text =
|
941
|
-
text =
|
942
|
-
text =
|
940
|
+
text = agoo_text_append(text, "input ", 6);
|
941
|
+
text = agoo_text_append(text, type->name, -1);
|
942
|
+
text = agoo_text_append(text, " {\n", 3);
|
943
943
|
for (f = type->fields; NULL != f; f = f->next) {
|
944
944
|
text = field_sdl(text, f, with_desc);
|
945
945
|
}
|
946
|
-
text =
|
946
|
+
text = agoo_text_append(text, "}\n", 2);
|
947
947
|
break;
|
948
948
|
}
|
949
949
|
default:
|
@@ -952,29 +952,29 @@ gql_type_sdl(Text text, gqlType type, bool with_desc) {
|
|
952
952
|
return text;
|
953
953
|
}
|
954
954
|
|
955
|
-
|
956
|
-
gql_directive_sdl(
|
955
|
+
agooText
|
956
|
+
gql_directive_sdl(agooText text, gqlDir d, bool with_desc) {
|
957
957
|
gqlStrLink link;
|
958
958
|
|
959
959
|
if (with_desc) {
|
960
960
|
text = desc_sdl(text, d->desc, 0);
|
961
961
|
}
|
962
|
-
text =
|
963
|
-
text =
|
962
|
+
text = agoo_text_append(text, "directive @", 11);
|
963
|
+
text = agoo_text_append(text, d->name, -1);
|
964
964
|
if (NULL != d->args) {
|
965
965
|
gqlArg a;
|
966
966
|
|
967
|
-
text =
|
967
|
+
text = agoo_text_append(text, "(", 1);
|
968
968
|
for (a = d->args; NULL != a; a = a->next) {
|
969
969
|
text = arg_sdl(text, a, with_desc, NULL == a->next);
|
970
970
|
}
|
971
|
-
text =
|
971
|
+
text = agoo_text_append(text, ")", 1);
|
972
972
|
}
|
973
|
-
text =
|
973
|
+
text = agoo_text_append(text, " on ", 4);
|
974
974
|
for (link = d->locs; NULL != link; link = link->next) {
|
975
|
-
text =
|
975
|
+
text = agoo_text_append(text, link->str, -1);
|
976
976
|
if (NULL != link->next) {
|
977
|
-
text =
|
977
|
+
text = agoo_text_append(text, " | ", 3);
|
978
978
|
}
|
979
979
|
}
|
980
980
|
return text;
|
@@ -997,8 +997,8 @@ type_cmp(const void *v0, const void *v1) {
|
|
997
997
|
return t0->kind - t1->kind;
|
998
998
|
}
|
999
999
|
|
1000
|
-
|
1001
|
-
gql_schema_sdl(
|
1000
|
+
agooText
|
1001
|
+
gql_schema_sdl(agooText text, bool with_desc, bool all) {
|
1002
1002
|
Slot *bucket;
|
1003
1003
|
Slot s;
|
1004
1004
|
gqlType type;
|
@@ -1032,44 +1032,44 @@ gql_schema_sdl(Text text, bool with_desc, bool all) {
|
|
1032
1032
|
for (i = 0, tp = types; i < cnt; i++, tp++) {
|
1033
1033
|
text = gql_type_sdl(text, *tp, with_desc);
|
1034
1034
|
if (i < cnt - 1) {
|
1035
|
-
text =
|
1035
|
+
text = agoo_text_append(text, "\n", 1);
|
1036
1036
|
}
|
1037
1037
|
}
|
1038
1038
|
}
|
1039
1039
|
for (d = directives; NULL != d; d = d->next) {
|
1040
|
-
text =
|
1040
|
+
text = agoo_text_append(text, "\n", 1);
|
1041
1041
|
text = gql_directive_sdl(text, d, with_desc);
|
1042
|
-
text =
|
1042
|
+
text = agoo_text_append(text, "\n", 1);
|
1043
1043
|
}
|
1044
1044
|
return text;
|
1045
1045
|
}
|
1046
1046
|
|
1047
1047
|
void
|
1048
|
-
gql_dump_hook(
|
1048
|
+
gql_dump_hook(agooReq req) {
|
1049
1049
|
char buf[256];
|
1050
1050
|
int cnt;
|
1051
|
-
|
1051
|
+
agooText text = agoo_text_allocate(4094);
|
1052
1052
|
bool all = false;
|
1053
1053
|
bool with_desc = true;
|
1054
1054
|
int vlen;
|
1055
|
-
const char *s =
|
1055
|
+
const char *s = agoo_req_query_value(req, "all", 3, &vlen);
|
1056
1056
|
|
1057
1057
|
if (NULL != s && 4 == vlen && 0 == strncasecmp("true", s, 4)) {
|
1058
1058
|
all = true;
|
1059
1059
|
}
|
1060
|
-
s =
|
1060
|
+
s = agoo_req_query_value(req, "with_desc", 9, &vlen);
|
1061
1061
|
|
1062
1062
|
if (NULL != s && 5 == vlen && 0 == strncasecmp("false", s, 5)) {
|
1063
1063
|
with_desc = false;
|
1064
1064
|
}
|
1065
1065
|
text = gql_schema_sdl(text, with_desc, all);
|
1066
1066
|
cnt = snprintf(buf, sizeof(buf), "HTTP/1.1 200 Okay\r\nContent-Type: application/graphql\r\nContent-Length: %ld\r\n\r\n", text->len);
|
1067
|
-
text =
|
1068
|
-
|
1067
|
+
text = agoo_text_prepend(text, buf, cnt);
|
1068
|
+
agoo_res_set_message(req->res, text);
|
1069
1069
|
}
|
1070
1070
|
|
1071
1071
|
void
|
1072
|
-
gql_eval_hook(
|
1072
|
+
gql_eval_hook(agooReq req) {
|
1073
1073
|
// TBD detect introspection
|
1074
1074
|
// start resolving by callout to some global handler as needed
|
1075
1075
|
// pass target, field, args
|