agoo 2.5.4 → 2.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of agoo might be problematic. Click here for more details.

Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/bin/agoo +3 -1
  4. data/ext/agoo/base64.h +3 -3
  5. data/ext/agoo/bind.c +1 -1
  6. data/ext/agoo/bind.h +3 -3
  7. data/ext/agoo/con.c +4 -2
  8. data/ext/agoo/con.h +3 -3
  9. data/ext/agoo/debug.c +7 -0
  10. data/ext/agoo/debug.h +13 -6
  11. data/ext/agoo/doc.c +159 -0
  12. data/ext/agoo/doc.h +34 -0
  13. data/ext/agoo/dtime.h +3 -3
  14. data/ext/agoo/err.h +3 -3
  15. data/ext/agoo/error_stream.h +3 -3
  16. data/ext/agoo/extconf.rb +1 -1
  17. data/ext/agoo/gqlintro.c +333 -0
  18. data/ext/agoo/gqlintro.h +10 -0
  19. data/ext/agoo/gqlvalue.c +1035 -0
  20. data/ext/agoo/gqlvalue.h +88 -0
  21. data/ext/agoo/graphql.c +1078 -0
  22. data/ext/agoo/graphql.h +198 -0
  23. data/ext/agoo/hook.c +2 -0
  24. data/ext/agoo/hook.h +4 -3
  25. data/ext/agoo/http.c +2 -1
  26. data/ext/agoo/http.h +3 -3
  27. data/ext/agoo/kinds.h +3 -3
  28. data/ext/agoo/log.h +3 -3
  29. data/ext/agoo/log_queue.h +3 -3
  30. data/ext/agoo/method.h +3 -3
  31. data/ext/agoo/page.h +3 -3
  32. data/ext/agoo/pub.h +3 -3
  33. data/ext/agoo/queue.h +3 -3
  34. data/ext/agoo/rack_logger.h +3 -3
  35. data/ext/agoo/req.c +2 -2
  36. data/ext/agoo/req.h +3 -3
  37. data/ext/agoo/request.h +3 -3
  38. data/ext/agoo/res.h +3 -3
  39. data/ext/agoo/response.h +3 -3
  40. data/ext/agoo/rhook.c +2 -2
  41. data/ext/agoo/rhook.h +4 -3
  42. data/ext/agoo/rlog.h +3 -3
  43. data/ext/agoo/rresponse.h +3 -3
  44. data/ext/agoo/rserver.c +64 -0
  45. data/ext/agoo/rserver.h +3 -3
  46. data/ext/agoo/rupgraded.c +1 -1
  47. data/ext/agoo/rupgraded.h +3 -3
  48. data/ext/agoo/sdl.c +334 -0
  49. data/ext/agoo/sdl.h +10 -0
  50. data/ext/agoo/seg.h +3 -3
  51. data/ext/agoo/server.c +3 -1
  52. data/ext/agoo/server.h +5 -4
  53. data/ext/agoo/sha1.h +3 -3
  54. data/ext/agoo/sse.h +3 -3
  55. data/ext/agoo/sub.h +3 -3
  56. data/ext/agoo/subject.h +3 -3
  57. data/ext/agoo/text.h +3 -3
  58. data/ext/agoo/upgraded.h +3 -3
  59. data/ext/agoo/websocket.h +3 -3
  60. data/lib/agoo/version.rb +1 -1
  61. data/lib/rack/handler/agoo.rb +3 -1
  62. metadata +12 -12
  63. data/ext/agoo/foo/agoo.c +0 -109
  64. data/ext/agoo/foo/con.c +0 -1220
  65. data/ext/agoo/foo/con.h +0 -65
  66. data/ext/agoo/foo/page.c +0 -699
  67. data/ext/agoo/foo/pub.c +0 -131
  68. data/ext/agoo/foo/pub.h +0 -40
  69. data/ext/agoo/foo/rserver.c +0 -1016
  70. data/ext/agoo/foo/server.c +0 -303
  71. data/ext/agoo/foo/server.h +0 -67
  72. data/ext/agoo/foo/upgraded.c +0 -182
@@ -0,0 +1,198 @@
1
+ // Copyright (c) 2018, Peter Ohler, All rights reserved.
2
+
3
+ #ifndef AGOO_GRAPHQL_H
4
+ #define AGOO_GRAPHQL_H
5
+
6
+ #include <stdbool.h>
7
+ #include <stdint.h>
8
+
9
+ #include "err.h"
10
+ #include "text.h"
11
+
12
+ typedef enum {
13
+ GQL_OBJECT = (int8_t)1,
14
+ GQL_FRAG = (int8_t)2,
15
+ GQL_INPUT = (int8_t)3,
16
+ GQL_UNION = (int8_t)4,
17
+ GQL_INTERFACE = (int8_t)5,
18
+ GQL_ENUM = (int8_t)6,
19
+ GQL_SCALAR = (int8_t)7,
20
+ // LIST
21
+ // NON_NULL
22
+ } gqlKind;
23
+
24
+ struct _gqlType;
25
+ struct _gqlValue;
26
+ struct _gqlLink;
27
+ struct _gqlField;
28
+ struct _Req;
29
+ struct _gqlDirUse;
30
+ struct _gqlLink;
31
+
32
+ // Used for references to implemenation entities.
33
+ typedef void* gqlRef;
34
+ typedef struct _gqlQuery {
35
+ struct _gqlQuery *next;
36
+ struct _gqlValue *result;
37
+ struct _gqlDirUse *dir;
38
+ // TBD data about a query, mutation, or subscription
39
+ } *gqlQuery;
40
+
41
+ typedef struct _gqlKeyVal {
42
+ const char *key;
43
+ struct _gqlValue *value;
44
+ } *gqlKeyVal;
45
+
46
+ typedef struct _gqlStrLink {
47
+ struct _gqlStrLink *next;
48
+ char *str;
49
+ } *gqlStrLink;
50
+
51
+ typedef struct _gqlTypeLink {
52
+ struct _gqlTypeLink *next;
53
+ char *name;
54
+ struct _gqlType *type;
55
+ } *gqlTypeLink;
56
+
57
+ // Resolve field on a target to a child reference.
58
+ typedef gqlRef (*gqlResolveFunc)(gqlRef target, const char *fieldName, gqlKeyVal *args);
59
+
60
+ // Coerce an implemenation reference into a gqlValue.
61
+ typedef struct _gqlValue* (*gqlCoerceFunc)(gqlRef ref, struct _gqlType *type);
62
+
63
+ typedef void (*gqlIterCb)(gqlRef ref, gqlQuery query);
64
+ typedef void (*gqlIterateFunc)(gqlRef ref, gqlIterCb cb, gqlQuery query);
65
+
66
+ typedef struct _gqlArg {
67
+ struct _gqlArg *next;
68
+ const char *name;
69
+ const char *desc;
70
+ const char *type_name;
71
+ struct _gqlType *type;
72
+ struct _gqlValue *default_value;
73
+ struct _gqlDirUse *dir;
74
+ bool required;
75
+ } *gqlArg;
76
+
77
+ typedef struct _gqlField {
78
+ struct _gqlField *next;
79
+ const char *name;
80
+ struct _gqlType *type; // return type
81
+ const char *desc;
82
+ const char *reason; // deprecationReason
83
+ gqlArg args;
84
+ struct _gqlDirUse *dir;
85
+ gqlResolveFunc resolve;
86
+ bool required;
87
+ bool list;
88
+ bool not_empty; // list can not be empty, member is required
89
+ bool deprecated;
90
+ } *gqlField;
91
+
92
+ typedef struct _gqlDir {
93
+ struct _gqlDir *next;
94
+ const char *name;
95
+ const char *desc;
96
+ gqlArg args;
97
+ gqlStrLink locs; // location names
98
+ bool locked;
99
+ } *gqlDir;
100
+
101
+ typedef struct _gqlDirUse {
102
+ gqlDir dir;
103
+ struct _gqlLink *args;
104
+ } *gqlDirUse;
105
+
106
+ typedef struct _gqlType {
107
+ const char *name;
108
+ const char *desc;
109
+ Text (*to_json)(Text text, struct _gqlValue *value, int indent, int depth);
110
+ gqlDirUse dir;
111
+ gqlKind kind;
112
+ bool locked; // set by app
113
+ bool core;
114
+ union {
115
+ struct { // Objects, Fragments, interfaces, and input_objects
116
+ gqlField fields;
117
+ union {
118
+ struct _gqlType **interfaces; // Objects, null terminated array if not NULL.
119
+ struct _gqlType *on; // Fragment
120
+ };
121
+ };
122
+ gqlTypeLink types; // Union
123
+ gqlStrLink choices; // Enums
124
+ // Returns error code. Only for scalars.
125
+ struct {
126
+ int (*coerce)(Err err, struct _gqlValue *src, struct _gqlType *type);
127
+ void (*destroy)(struct _gqlValue *value);
128
+ };
129
+ };
130
+ } *gqlType;
131
+
132
+ extern int gql_init(Err err);
133
+ extern void gql_destroy(); // clear out all
134
+
135
+ extern gqlType gql_type_create(Err err, const char *name, const char *desc, int dlen, bool locked, gqlType *interfaces);
136
+ extern gqlType gql_fragment_create(Err err, const char *name, const char *desc, int dlen, bool locked, gqlType on);
137
+ extern gqlType gql_input_create(Err err, const char *name, const char *desc, int dlen, bool locked);
138
+ extern gqlType gql_interface_create(Err err, const char *name, const char *desc, int dlen, bool locked);
139
+
140
+ extern gqlField gql_type_field(Err err,
141
+ gqlType type,
142
+ const char *name,
143
+ gqlType return_type,
144
+ const char *desc,
145
+ bool required,
146
+ bool list,
147
+ bool not_empty,
148
+ gqlResolveFunc resolve);
149
+
150
+ extern gqlArg gql_field_arg(Err err,
151
+ gqlField field,
152
+ const char *name,
153
+ gqlType type,
154
+ const char *desc,
155
+ struct _gqlValue *def_value,
156
+ bool required);
157
+
158
+ // TBD maybe create then add fields
159
+ // TBD same with op? create then add args
160
+
161
+ extern gqlType gql_scalar_create(Err err, const char *name, const char *desc, int dlen, bool locked);
162
+
163
+ extern gqlDir gql_directive_create(Err err, const char *name, const char *desc, int dlen, bool locked);
164
+ extern int gql_directive_on(Err err, gqlDir d, const char *on, int len);
165
+ extern gqlArg gql_dir_arg(Err err,
166
+ gqlDir dir,
167
+ const char *name,
168
+ const char *type_name,
169
+ const char *desc,
170
+ int dlen,
171
+ struct _gqlValue *def_value,
172
+ bool required);
173
+ extern gqlDir gql_directive_get(const char *name);
174
+
175
+ extern gqlType gql_union_create(Err err, const char *name, const char *desc, int dlen, bool locked);
176
+ extern int gql_union_add(Err err, gqlType type, const char *name, int len);
177
+
178
+ extern gqlType gql_enum_create(Err err, const char *name, const char *desc, int dlen, bool locked);
179
+ extern int gql_enum_add(Err err, gqlType type, const char *value, int len);
180
+ extern int gql_enum_append(Err err, gqlType type, const char *value, int len);
181
+
182
+ extern int gql_type_set(Err err, gqlType type);
183
+ extern gqlType gql_type_get(const char *name);
184
+ extern void gql_type_destroy(gqlType type);
185
+
186
+ extern Text gql_type_sdl(Text text, gqlType type, bool comments);
187
+ extern Text gql_directive_sdl(Text text, gqlDir dir, bool comments);
188
+ extern Text gql_schema_sdl(Text text, bool with_desc, bool all);
189
+
190
+ extern Text gql_object_to_json(Text text, struct _gqlValue *value, int indent, int depth);
191
+ extern Text gql_object_to_graphql(Text text, struct _gqlValue *value, int indent, int depth);
192
+ extern Text gql_union_to_text(Text text, struct _gqlValue *value, int indent, int depth);
193
+ extern Text gql_enum_to_text(Text text, struct _gqlValue *value, int indent, int depth);
194
+
195
+ extern void gql_dump_hook(struct _Req *req);
196
+ extern void gql_eval_hook(struct _Req *req);
197
+
198
+ #endif // AGOO_GRAPHQL_H
@@ -30,6 +30,7 @@ hook_create(Method method, const char *pattern, void *handler, HookType type, Qu
30
30
  hook->handler = handler;
31
31
  hook->type = type;
32
32
  hook->queue = q;
33
+ hook->no_queue = false;
33
34
  }
34
35
  return hook;
35
36
  }
@@ -57,6 +58,7 @@ hook_func_create(Method method, const char *pattern, void (*func)(Req req), Queu
57
58
  hook->func = func;
58
59
  hook->type = FUNC_HOOK;
59
60
  hook->queue = q;
61
+ hook->no_queue = false;
60
62
  }
61
63
  return hook;
62
64
  }
@@ -1,7 +1,7 @@
1
1
  // Copyright (c) 2018, Peter Ohler, All rights reserved.
2
2
 
3
- #ifndef __AGOO_HOOK_H__
4
- #define __AGOO_HOOK_H__
3
+ #ifndef AGOO_HOOK_H
4
+ #define AGOO_HOOK_H
5
5
 
6
6
  #include <stdbool.h>
7
7
 
@@ -31,6 +31,7 @@ typedef struct _Hook {
31
31
  void (*func)(struct _Req *req);
32
32
  };
33
33
  Queue queue;
34
+ bool no_queue;
34
35
  } *Hook;
35
36
 
36
37
  extern Hook hook_create(Method method, const char *pattern, void *handler, HookType type, Queue q);
@@ -40,4 +41,4 @@ extern void hook_destroy(Hook hook);
40
41
  extern bool hook_match(Hook hook, Method method, const Seg seg);
41
42
  extern Hook hook_find(Hook hook, Method method, const Seg seg);
42
43
 
43
- #endif // __AGOO_HOOK_H__
44
+ #endif // AGOO_HOOK_H
@@ -494,8 +494,9 @@ http_cleanup() {
494
494
  Slot *sp = key_cache.buckets;
495
495
  Slot s;
496
496
  Slot n;
497
+ int i;
497
498
 
498
- for (int i = BUCKET_SIZE; 0 < i; i--, sp++) {
499
+ for (i = BUCKET_SIZE; 0 < i; i--, sp++) {
499
500
  for (s = *sp; NULL != s; s = n) {
500
501
  n = s->next;
501
502
  DEBUG_FREE(mem_http_slot, s)
@@ -1,7 +1,7 @@
1
1
  // Copyright (c) 2018, Peter Ohler, All rights reserved.
2
2
 
3
- #ifndef __AGOO_HTTP_H__
4
- #define __AGOO_HTTP_H__
3
+ #ifndef AGOO_HTTP_H
4
+ #define AGOO_HTTP_H
5
5
 
6
6
  #include <stdbool.h>
7
7
 
@@ -14,4 +14,4 @@ extern int http_header_ok(Err err, const char *key, int klen, const char *value
14
14
 
15
15
  extern const char* http_code_message(int code);
16
16
 
17
- #endif // __AGOO_HTTP_H__
17
+ #endif // AGOO_HTTP_H
@@ -1,7 +1,7 @@
1
1
  // Copyright (c) 2018, Peter Ohler, All rights reserved.
2
2
 
3
- #ifndef __AGOO_KINDS_H__
4
- #define __AGOO_KINDS_H__
3
+ #ifndef AGOO_KINDS_H
4
+ #define AGOO_KINDS_H
5
5
 
6
6
  typedef enum {
7
7
  CON_ANY = '\0',
@@ -10,4 +10,4 @@ typedef enum {
10
10
  CON_SSE = 'S',
11
11
  } ConKind;
12
12
 
13
- #endif // __AGOO_KINDS_H__
13
+ #endif // AGOO_KINDS_H
@@ -1,7 +1,7 @@
1
1
  // Copyright 2018 by Peter Ohler, All Rights Reserved
2
2
 
3
- #ifndef __AGOO_LOG_H__
4
- #define __AGOO_LOG_H__
3
+ #ifndef AGOO_LOG_H
4
+ #define AGOO_LOG_H
5
5
 
6
6
  #include <pthread.h>
7
7
  #include <stdarg.h>
@@ -125,4 +125,4 @@ extern void log_start(bool with_pid);
125
125
 
126
126
  extern Color find_color(const char *name);
127
127
 
128
- #endif /* __AGOO_LOG_H__ */
128
+ #endif /* AGOO_LOG_H */
@@ -1,7 +1,7 @@
1
1
  // Copyright 2018 by Peter Ohler, All Rights Reserved
2
2
 
3
- #ifndef __AGOO_LOG_QUEUE_H__
4
- #define __AGOO_LOG_QUEUE_H__
3
+ #ifndef AGOO_LOG_QUEUE_H
4
+ #define AGOO_LOG_QUEUE_H
5
5
 
6
6
  #include <stdatomic.h>
7
7
  #include <stdbool.h>
@@ -27,4 +27,4 @@ extern opoMsg queue_pop(Queue q, double timeout);
27
27
  extern bool queue_empty(Queue q);
28
28
  extern int queue_count(Queue q);
29
29
 
30
- #endif /* __AGOO_LOG_QUEUE_H__ */
30
+ #endif /* AGOO_LOG_QUEUE_H */
@@ -1,7 +1,7 @@
1
1
  // Copyright (c) 2018, Peter Ohler, All rights reserved.
2
2
 
3
- #ifndef __AGOO_METHOD_H__
4
- #define __AGOO_METHOD_H__
3
+ #ifndef AGOO_METHOD_H
4
+ #define AGOO_METHOD_H
5
5
 
6
6
  typedef enum {
7
7
  CONNECT = 'C',
@@ -23,4 +23,4 @@ typedef enum {
23
23
  ON_ERROR = 'F', // use for on_error callback
24
24
  } Method;
25
25
 
26
- #endif // __AGOO_METHOD_H__
26
+ #endif // AGOO_METHOD_H
@@ -1,7 +1,7 @@
1
1
  // Copyright 2016, 2018 by Peter Ohler, All Rights Reserved
2
2
 
3
- #ifndef __AGOO_PAGE_H__
4
- #define __AGOO_PAGE_H__
3
+ #ifndef AGOO_PAGE_H
4
+ #define AGOO_PAGE_H
5
5
 
6
6
  #include <stdint.h>
7
7
  #include <time.h>
@@ -43,4 +43,4 @@ extern Page page_immutable(Err err, const char *path, const char *content, int c
43
43
  extern Page page_get(Err err, const char *path, int plen);
44
44
  extern int mime_set(Err err, const char *key, const char *value);
45
45
 
46
- #endif /* __AGOO_PAGE_H__ */
46
+ #endif /* AGOO_PAGE_H */
@@ -1,7 +1,7 @@
1
1
  // Copyright (c) 2018, Peter Ohler, All rights reserved.
2
2
 
3
- #ifndef __AGOO_PUB_H__
4
- #define __AGOO_PUB_H__
3
+ #ifndef AGOO_PUB_H
4
+ #define AGOO_PUB_H
5
5
 
6
6
  #include <stdbool.h>
7
7
  #include <stdint.h>
@@ -37,4 +37,4 @@ extern Pub pub_write(struct _Upgraded *up, const char *message, size_t mlen, boo
37
37
  extern Pub pub_dup(Pub src);
38
38
  extern void pub_destroy(Pub pub);
39
39
 
40
- #endif // __AGOO_PUB_H__
40
+ #endif // AGOO_PUB_H
@@ -1,7 +1,7 @@
1
1
  // Copyright 2015, 2016, 2018 by Peter Ohler, All Rights Reserved
2
2
 
3
- #ifndef __AGOO_QUEUE_H__
4
- #define __AGOO_QUEUE_H__
3
+ #ifndef AGOO_QUEUE_H
4
+ #define AGOO_QUEUE_H
5
5
 
6
6
  #include <stdatomic.h>
7
7
  #include <stdbool.h>
@@ -37,4 +37,4 @@ extern int queue_count(Queue q);
37
37
 
38
38
  extern void queue_wakeup(Queue q);
39
39
 
40
- #endif /* __AGOO_QUEUE_H__ */
40
+ #endif /* AGOO_QUEUE_H */
@@ -1,7 +1,7 @@
1
1
  // Copyright (c) 2018, Peter Ohler, All rights reserved.
2
2
 
3
- #ifndef __AGOO_RACK_LOGGER_H__
4
- #define __AGOO_RACK_LOGGER_H__
3
+ #ifndef AGOO_RACK_LOGGER_H
4
+ #define AGOO_RACK_LOGGER_H
5
5
 
6
6
  #include <ruby.h>
7
7
 
@@ -10,4 +10,4 @@
10
10
  extern void rack_logger_init(VALUE mod);
11
11
  extern VALUE rack_logger_new();
12
12
 
13
- #endif // __AGOO_RACK_LOGGER_H__
13
+ #endif // AGOO_RACK_LOGGER_H
@@ -81,11 +81,11 @@ req_query_value(Req r, const char *key, int klen, int *vlenp) {
81
81
  char *end;
82
82
 
83
83
  if (0 >= klen) {
84
- klen = strlen(key);
84
+ klen = (int)strlen(key);
85
85
  }
86
86
  value += klen + 1;
87
87
  if (NULL == (end = index(value, '&'))) {
88
- *vlenp = strlen(value);
88
+ *vlenp = (int)strlen(value);
89
89
  } else {
90
90
  *vlenp = (int)(end - value);
91
91
  }
@@ -1,7 +1,7 @@
1
1
  // Copyright (c) 2018, Peter Ohler, All rights reserved.
2
2
 
3
- #ifndef __AGOO_REQ_H__
4
- #define __AGOO_REQ_H__
3
+ #ifndef AGOO_REQ_H
4
+ #define AGOO_REQ_H
5
5
 
6
6
  #include <stdint.h>
7
7
 
@@ -45,4 +45,4 @@ extern const char* req_host(Req r, int *lenp);
45
45
  extern int req_port(Req r);
46
46
  extern const char* req_query_value(Req r, const char *key, int klen, int *vlenp);
47
47
 
48
- #endif // __AGOO_REQ_H__
48
+ #endif // AGOO_REQ_H
@@ -1,7 +1,7 @@
1
1
  // Copyright (c) 2018, Peter Ohler, All rights reserved.
2
2
 
3
- #ifndef __AGOO_REQUEST_H__
4
- #define __AGOO_REQUEST_H__
3
+ #ifndef AGOO_REQUEST_H
4
+ #define AGOO_REQUEST_H
5
5
 
6
6
  #include <stdint.h>
7
7
 
@@ -13,4 +13,4 @@ extern void request_init(VALUE mod);
13
13
  extern VALUE request_wrap(Req req);
14
14
  extern VALUE request_env(Req req, VALUE self);
15
15
 
16
- #endif // __AGOO_REQUEST_H__
16
+ #endif // AGOO_REQUEST_H
@@ -1,7 +1,7 @@
1
1
  // Copyright (c) 2018, Peter Ohler, All rights reserved.
2
2
 
3
- #ifndef __AGOO_RES_H__
4
- #define __AGOO_RES_H__
3
+ #ifndef AGOO_RES_H
4
+ #define AGOO_RES_H
5
5
 
6
6
  #include <stdatomic.h>
7
7
  #include <stdbool.h>
@@ -30,4 +30,4 @@ res_message(Res res) {
30
30
  return atomic_load(&res->message);
31
31
  }
32
32
 
33
- #endif // __AGOO_RES_H__
33
+ #endif // AGOO_RES_H