summaryrefslogtreecommitdiff
path: root/snac.c
diff options
context:
space:
mode:
Diffstat (limited to 'snac.c')
-rw-r--r--snac.c94
1 files changed, 0 insertions, 94 deletions
diff --git a/snac.c b/snac.c
index 3fa4b94..a5b2080 100644
--- a/snac.c
+++ b/snac.c
@@ -148,97 +148,3 @@ int check_password(const char *uid, const char *passwd, const char *hash)
148 148
149 return ret; 149 return ret;
150} 150}
151
152
153void srv_archive(const char *direction, xs_dict *req,
154 const char *payload, int p_size,
155 int status, xs_dict *headers,
156 const char *body, int b_size)
157/* archives a connection */
158{
159 /* obsessive archiving */
160 xs *date = tid(0);
161 xs *dir = xs_fmt("%s/archive/%s_%s", srv_basedir, date, direction);
162 FILE *f;
163
164 if (mkdirx(dir) != -1) {
165 xs *meta_fn = xs_fmt("%s/_META", dir);
166
167 if ((f = fopen(meta_fn, "w")) != NULL) {
168 xs *j1 = xs_json_dumps_pp(req, 4);
169 xs *j2 = xs_json_dumps_pp(headers, 4);
170
171 fprintf(f, "dir: %s\n", direction);
172 fprintf(f, "req: %s\n", j1);
173 fprintf(f, "p_size: %d\n", p_size);
174 fprintf(f, "status: %d\n", status);
175 fprintf(f, "response: %s\n", j2);
176 fprintf(f, "b_size: %d\n", b_size);
177 fclose(f);
178 }
179
180 if (p_size && payload) {
181 xs *payload_fn = NULL;
182 xs *payload_fn_raw = NULL;
183 char *v = xs_dict_get(req, "content-type");
184
185 if (v && xs_str_in(v, "json") != -1) {
186 payload_fn = xs_fmt("%s/payload.json", dir);
187
188 if ((f = fopen(payload_fn, "w")) != NULL) {
189 xs *v1 = xs_json_loads(payload);
190 xs *j1 = NULL;
191
192 if (v1 != NULL)
193 j1 = xs_json_dumps_pp(v1, 4);
194
195 if (j1 != NULL)
196 fwrite(j1, strlen(j1), 1, f);
197 else
198 fwrite(payload, p_size, 1, f);
199
200 fclose(f);
201 }
202 }
203
204 payload_fn_raw = xs_fmt("%s/payload", dir);
205
206 if ((f = fopen(payload_fn_raw, "w")) != NULL) {
207 fwrite(payload, p_size, 1, f);
208 fclose(f);
209 }
210 }
211
212 if (b_size && body) {
213 xs *body_fn = NULL;
214 char *v = xs_dict_get(headers, "content-type");
215
216 if (v && xs_str_in(v, "json") != -1) {
217 body_fn = xs_fmt("%s/body.json", dir);
218
219 if ((f = fopen(body_fn, "w")) != NULL) {
220 xs *v1 = xs_json_loads(body);
221 xs *j1 = NULL;
222
223 if (v1 != NULL)
224 j1 = xs_json_dumps_pp(v1, 4);
225
226 if (j1 != NULL)
227 fwrite(j1, strlen(j1), 1, f);
228 else
229 fwrite(body, b_size, 1, f);
230
231 fclose(f);
232 }
233 }
234 else {
235 body_fn = xs_fmt("%s/body", dir);
236
237 if ((f = fopen(body_fn, "w")) != NULL) {
238 fwrite(body, b_size, 1, f);
239 fclose(f);
240 }
241 }
242 }
243 }
244} \ No newline at end of file