-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbg_analytics.c
More file actions
3826 lines (3314 loc) · 99.4 KB
/
bg_analytics.c
File metadata and controls
3826 lines (3314 loc) · 99.4 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "bg_analytics.h"
#ifndef AMALGAMATION
#include "palloc.h"
#endif
#include <stdio.h>
#include <string.h>
static int registered;
struct PoolEntry
{
void *ptr;
size_t size;
char *type;
int used;
struct PoolEntry *next;
};
struct PoolEntry *poolHead;
void pool_cleanup()
{
struct PoolEntry *curr = poolHead;
printf("[palloc]Evaluating memory...\n");
while(curr)
{
struct PoolEntry *tmp = curr;
if(curr->used)
{
printf("[palloc]Leak\n");
printf(" Type: %s\n", curr->type);
printf(" Size: %i\n", (int)curr->size);
printf(" Used: %i\n", curr->used);
}
else
{
size_t i = 0;
char *ptr = (char*)curr->ptr;
int dirty = 0;
for(i = 0; i < curr->size; i++)
{
if(*ptr != PALLOC_SENTINEL)
{
dirty = 1;
}
ptr++;
}
if(dirty == 1)
{
printf("[palloc]Use after free\n");
printf(" Type: %s\n", curr->type);
printf(" Size: %i\n", (int)curr->size);
}
}
curr = curr->next;
free(tmp->ptr);
free(tmp->type);
free(tmp);
}
poolHead = NULL;
}
#ifdef PALLOC_ACTIVE
void pfree(void *ptr)
{
struct PoolEntry *entry = poolHead;
while(entry)
{
if(entry->ptr == ptr)
{
if(!entry->used)
{
printf("Error: Memory already freed\n");
}
#ifdef PALLOC_DEBUG
printf("Freeing: %s\n", entry->type);
#endif
memset(entry->ptr, PALLOC_SENTINEL, entry->size);
entry->used = 0;
return;
}
entry = entry->next;
}
printf("Error: Memory not managed by pool\n");
}
#else
void pfree(void *ptr)
{
free(ptr);
}
#endif
#ifdef PALLOC_ACTIVE
void *_palloc(size_t size, const char *type)
{
struct PoolEntry *entry = poolHead;
if(!registered)
{
printf("[palloc]Registering hook...\n");
registered = 1;
atexit(pool_cleanup);
}
while(entry)
{
if(!entry->used && strcmp(type, entry->type) == 0)
{
char *ptr = (char *)entry->ptr;
size_t i = 0;
int dirty = 0;
#ifdef PALLOC_DEBUG
printf("Reusing: %s\n", type);
#endif
for(i = 0; i < entry->size; i++)
{
if(*ptr != PALLOC_SENTINEL)
{
dirty = 1;
break;
}
ptr++;
}
if(dirty)
{
printf("[palloc]Use after free\n");
printf(" Type: %s\n", entry->type);
printf(" Size: %i\n", (int)entry->size);
}
entry->used = 1;
if(PALLOC_SENTINEL != 0)
{
memset(entry->ptr, 0, entry->size);
}
return entry->ptr;
}
entry = entry->next;
}
#ifdef PALLOC_DEBUG
printf("Allocating: %s\n", type);
#endif
entry = (struct PoolEntry *)calloc(1, sizeof(*entry));
if(!entry) return NULL;
entry->ptr = calloc(1, size);
if(!entry->ptr)
{
free(entry);
return NULL;
}
entry->size = size;
entry->type = (char *)calloc(strlen(type) + 1, sizeof(char));
strcpy(entry->type, type);
entry->used = 1;
entry->next = poolHead;
poolHead = entry;
return entry->ptr;
}
#else
void *_palloc(size_t size, const char *type)
{
void *rtn = NULL;
rtn = calloc(1, size);
return rtn;
}
#endif
#ifndef AMALGAMATION
#include "vector.h"
#include "palloc.h"
#endif
#include <string.h>
void *_VectorNew(size_t size, const char *type)
{
struct _Vector *rtn = NULL;
char typeStr[256] = {0};
strcpy(typeStr, "vector(");
strcat(typeStr, type);
strcat(typeStr, ")");
rtn = (struct _Vector *)_palloc(sizeof(*rtn), typeStr);
strcpy(typeStr, "vector_header(");
strcat(typeStr, type);
strcat(typeStr, ")");
rtn->vh = (struct _VectorHeader *)_palloc(sizeof(*rtn->vh), typeStr);
rtn->vh->entrySize = size;
return rtn;
}
int _VectorOobAssert(void *_vh, size_t idx)
{
struct _VectorHeader *vh = (struct _VectorHeader *)_vh;
if(vh->size <= idx)
{
printf("Error: Index out of bounds\n");
return 1;
}
return 0;
}
void _VectorErase(void *_vh, void *_v, size_t idx)
{
struct _VectorHeader *vh = (struct _VectorHeader *)_vh;
struct _Vector *v = (struct _Vector *)_v;
size_t restSize = (vh->size - (idx + 1)) * vh->entrySize;
_VectorOobAssert(_vh, idx);
if(restSize > 0)
{
char *element = (char *)v->data + idx * vh->entrySize;
char *rest = element + vh->entrySize;
memmove(element, rest, restSize);
}
vh->size --;
}
void _VectorResize(void *_vh, void *_v, size_t size)
{
struct _Vector *v = (struct _Vector *)_v;
struct _VectorHeader *vh = (struct _VectorHeader *)_vh;
if(vh->size == size)
{
return;
}
else if(size == 0)
{
if(v->data)
{
free(v->data);
v->data = NULL;
}
}
else if(vh->size > size)
{
v->data = realloc(v->data, size * vh->entrySize);
if(!v->data)
{
/* TODO: Should cache and revert */
printf("Error: Failed to reallocate\n");
}
}
else if(vh->size < size)
{
char *cur = NULL;
char *last = NULL;
v->data = realloc(v->data, size * vh->entrySize);
if(!v->data)
{
/* TODO: Should cache and revert */
printf("Error: Failed to reallocate\n");
}
cur = (char *)v->data;
cur += vh->size * vh->entrySize;
last = (char *)v->data;
last += size * vh->entrySize;
while(cur != last)
{
*cur = 0;
cur++;
}
}
vh->size = size;
}
size_t _VectorSize(void *_vh)
{
struct _VectorHeader *vh = (struct _VectorHeader *)_vh;
return vh->size;
}
void _VectorDelete(void *_vh, void *_v)
{
struct _Vector *v = (struct _Vector *)_v;
struct _VectorHeader *vh = (struct _VectorHeader *)_vh;
if(v->vh != vh)
{
printf("Error: Invalid vector\n");
}
if(v->data)
{
free(v->data);
}
pfree(vh);
pfree(v);
}
#ifndef AMALGAMATION
#include "sstream.h"
#include "palloc.h"
#endif
#include <string.h>
#include <stdio.h>
struct sstream *sstream_new()
{
struct sstream *rtn = NULL;
rtn = palloc(struct sstream);
return rtn;
}
void sstream_clear(struct sstream *ctx)
{
struct Chunk *curr = ctx->first;
while(curr)
{
struct Chunk *tmp = curr;
curr = curr->next;
if(tmp->s) free(tmp->s);
pfree(tmp);
}
ctx->first = NULL;
}
void sstream_delete(struct sstream *ctx)
{
sstream_clear(ctx);
pfree(ctx);
}
void sstream_push_int(struct sstream *ctx, int val)
{
char buffer[128] = {0};
sprintf(buffer, "%i", val);
sstream_push_cstr(ctx, buffer);
}
void sstream_push_float(struct sstream *ctx, float val)
{
char buffer[128] = {0};
sprintf(buffer, "%f", val);
sstream_push_cstr(ctx, buffer);
}
void sstream_push_double(struct sstream *ctx, double val)
{
char buffer[128] = {0};
sprintf(buffer, "%f", val);
sstream_push_cstr(ctx, buffer);
}
void sstream_push_char(struct sstream *ctx, char val)
{
/*
char buffer[2] = {0};
buffer[0] = val;
sstream_push_cstr(ctx, buffer);
*/
struct Chunk *nc = NULL;
struct Chunk *curr = NULL;
nc = palloc(struct Chunk);
nc->c = val;
nc->len = 1;
if(!ctx->first)
{
ctx->first = nc;
return;
}
curr = ctx->first;
while(curr->next)
{
curr = curr->next;
}
curr->next = nc;
}
void sstream_push_cstr(struct sstream *ctx, const char *s)
{
struct Chunk *nc = NULL;
struct Chunk *curr = NULL;
size_t len = strlen(s);
if(len < 1) return;
nc = palloc(struct Chunk);
nc->s = (char *)malloc(sizeof(char) * (len + 1));
strcpy(nc->s, s);
nc->len = len;
if(!ctx->first)
{
ctx->first = nc;
return;
}
curr = ctx->first;
while(curr->next)
{
curr = curr->next;
}
curr->next = nc;
}
void sstream_collate(struct sstream *ctx)
{
size_t allocSize = 0;
struct Chunk *curr = ctx->first;
char *ns = NULL;
if(!curr) return;
if(curr->s)
{
if(!curr->next) return;
}
while(curr)
{
allocSize += curr->len;
curr = curr->next;
}
allocSize++;
ns = (char *)malloc(allocSize * sizeof(char));
ns[0] = '\0';
curr = ctx->first;
while(curr)
{
struct Chunk *tmp = curr;
if(!curr->s)
{
char cs[2] = {0};
cs[0] = curr->c;
strcat(ns, cs);
}
else
{
strcat(ns, curr->s);
}
curr = curr->next;
if(tmp->s) free(tmp->s);
pfree(tmp);
}
ctx->first = palloc(struct Chunk);
ctx->first->s = ns;
ctx->first->len = allocSize - 1;
}
char *sstream_cstr(struct sstream *ctx)
{
sstream_collate(ctx);
/* TODO */
if(!ctx->first) return (char *)"";
return ctx->first->s;
}
size_t sstream_length(struct sstream *ctx)
{
sstream_collate(ctx);
if(!ctx->first) return 0;
return ctx->first->len;
}
int sstream_int(struct sstream *ctx)
{
sstream_collate(ctx);
if(!ctx->first) return 0;
return atoi(ctx->first->s);
}
char sstream_at(struct sstream *ctx, size_t i)
{
sstream_collate(ctx);
if(!ctx->first)
{
printf("Error: Stream is empty\n");
abort();
}
if(i >= ctx->first->len)
{
printf("Error: Index out of bounds\n");
abort();
}
return ctx->first->s[i];
}
void sstream_push_chars(struct sstream *ctx, char *values, size_t count)
{
char *tmp = NULL;
tmp = (char *)malloc(sizeof(char) * (count + 1));
tmp[count] = 0;
memcpy(tmp, values, sizeof(char) * count);
sstream_push_cstr(ctx, tmp);
free(tmp);
}
void sstream_split(struct sstream *ctx, char token,
vector(struct sstream*) *out)
{
size_t i = 0;
struct sstream *curr = NULL;
curr = sstream_new();
for(i = 0; i < sstream_length(ctx); i++)
{
if(sstream_at(ctx, i) == token)
{
vector_push_back(out, curr);
curr = sstream_new();
}
else
{
sstream_push_char(curr, sstream_at(ctx, i));
}
}
if(sstream_length(curr) > 0)
{
vector_push_back(out, curr);
}
else
{
sstream_delete(curr);
}
}
#ifndef AMALGAMATION
#include "http.h"
#include <palloc/palloc.h>
#include <palloc/vector.h>
#include <palloc/sstream.h>
#endif
#ifdef _WIN32
#define USE_WINSOCK
#define USE_WINAPI
#else
#define USE_POSIX
#endif
#ifdef USE_WINSOCK
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#endif
#ifdef USE_POSIX
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#endif
#include <stdio.h>
#include <string.h>
#define HTTP_CONNECTING 1
#define HTTP_RECEIVING 2
#define HTTP_COMPLETE 3
#define BUFFER_SIZE 1024
#ifdef USE_POSIX
#define NULL_SOCKET -1
#endif
#ifdef USE_WINSOCK
#define NULL_SOCKET INVALID_SOCKET
#endif
static int winsockInitialized;
struct CustomHeader
{
sstream *variable;
sstream *value;
};
struct Http
{
sstream *host;
sstream *path;
sstream *query;
sstream *post;
vector(char) *raw;
vector(int) *socks;
sstream *rawHeaders;
sstream *rawContent;
vector(struct CustomHeader) *customHeaders;
int sock;
int status;
};
void HttpAddCustomHeader(struct Http *ctx, const char *variable, const char *value)
{
struct CustomHeader ch = {0};
ch.variable = sstream_new();
sstream_push_cstr(ch.variable, variable);
ch.value = sstream_new();
sstream_push_cstr(ch.value, value);
vector_push_back(ctx->customHeaders, ch);
}
void _HttpClearSocks(struct Http *ctx)
{
size_t i = 0;
for(i = 0; i < vector_size(ctx->socks); i++)
{
#ifdef USE_POSIX
close(vector_at(ctx->socks, i));
#endif
#ifdef USE_WINSOCK
shutdown(vector_at(ctx->socks, i), SD_BOTH);
closesocket(vector_at(ctx->socks, i));
#endif
}
vector_clear(ctx->socks);
}
int HttpState(struct Http *ctx)
{
if(vector_size(ctx->socks) > 0)
{
return HTTP_CONNECTING;
}
else if(ctx->sock != NULL_SOCKET)
{
return HTTP_RECEIVING;
}
return HTTP_COMPLETE;
}
#ifdef USE_WINSOCK
void _HttpShutdownWinsock()
{
WSACleanup();
}
#endif
struct Http *HttpCreate()
{
struct Http *rtn = NULL;
#ifdef USE_WINSOCK
if(!winsockInitialized)
{
WSADATA wsaData = {0};
int result = 0;
result = WSAStartup(MAKEWORD(2, 2), &wsaData);
if(result != 0)
{
printf("WSAStartup failed with error: %d\n", result);
return NULL;
}
winsockInitialized = 1;
atexit(_HttpShutdownWinsock);
}
#endif
rtn = palloc(struct Http);
rtn->raw = vector_new(char);
rtn->rawContent = sstream_new();
rtn->rawHeaders = sstream_new();
rtn->socks = vector_new(int);
rtn->customHeaders = vector_new(struct CustomHeader);
rtn->sock = NULL_SOCKET;
rtn->host = sstream_new();
rtn->path = sstream_new();
rtn->query = sstream_new();
rtn->post = sstream_new();
return rtn;
}
void HttpDestroy(struct Http *ctx)
{
size_t i = 0;
_HttpClearSocks(ctx);
vector_delete(ctx->socks);
sstream_delete(ctx->rawHeaders);
sstream_delete(ctx->rawContent);
vector_delete(ctx->raw);
sstream_delete(ctx->host);
sstream_delete(ctx->path);
sstream_delete(ctx->query);
sstream_delete(ctx->post);
for(i = 0; i < vector_size(ctx->customHeaders); i++)
{
sstream_delete(vector_at(ctx->customHeaders, i).variable);
sstream_delete(vector_at(ctx->customHeaders, i).value);
}
vector_delete(ctx->customHeaders);
pfree(ctx);
}
void _HttpPollConnect(struct Http *ctx)
{
size_t i = 0;
sstream *content = NULL;
//printf("polling connect\n");
for(i = 0; i < vector_size(ctx->socks); i++)
{
fd_set write_fds = {0};
struct timeval tv = {0};
int err = 0;
int sock = vector_at(ctx->socks, i);
FD_SET(sock, &write_fds);
err = select(sock + 1, NULL, &write_fds, NULL, &tv);
if(err == 0)
{
continue;
}
else if(err == -1)
{
#ifdef USE_POSIX
close(sock);
#endif
#ifdef USE_WINSOCK
shutdown(sock, SD_BOTH);
closesocket(sock);
#endif
vector_erase(ctx->socks, i);
i--;
continue;
}
else
{
int optval = 0;
int optlen = sizeof(optval);
#ifdef USE_POSIX
if(getsockopt(sock, SOL_SOCKET, SO_ERROR, &optval, (socklen_t *)&optlen) == -1)
#endif
#ifdef USE_WINSOCK
if(getsockopt(sock, SOL_SOCKET, SO_ERROR, (char*)&optval, &optlen) == -1)
#endif
{
#ifdef USE_POSIX
close(sock);
#endif
#ifdef USE_WINSOCK
shutdown(sock, SD_BOTH);
closesocket(sock);
#endif
vector_erase(ctx->socks, i);
i--;
continue;
}
if(optval != 0)
{
#ifdef USE_POSIX
close(sock);
#endif
#ifdef USE_WINSOCK
shutdown(sock, SD_BOTH);
closesocket(sock);
#endif
vector_erase(ctx->socks, i);
i--;
continue;
}
}
ctx->sock = sock;
vector_erase(ctx->socks, i);
_HttpClearSocks(ctx);
break;
}
if(ctx->sock == NULL_SOCKET && vector_size(ctx->socks) < 1)
{
ctx->status = -1;
return;
}
if(ctx->sock == NULL_SOCKET)
{
return;
}
content = sstream_new();
if(sstream_length(ctx->post) > 0)
{
sstream_push_cstr(content, "POST ");
}
else
{
sstream_push_cstr(content, "GET ");
}
sstream_push_cstr(content, sstream_cstr(ctx->path));
if(sstream_length(ctx->query) > 0)
{
sstream_push_char(content, '?');
sstream_push_cstr(content, sstream_cstr(ctx->query));
}
sstream_push_cstr(content, " HTTP/1.0\r\n");
sstream_push_cstr(content, "Host: ");
sstream_push_cstr(content, sstream_cstr(ctx->host));
sstream_push_cstr(content, "\r\n");
for(i = 0; i < vector_size(ctx->customHeaders); i++)
{
sstream_push_cstr(content,
sstream_cstr(vector_at(ctx->customHeaders, i).variable));
sstream_push_cstr(content, ": ");
sstream_push_cstr(content,
sstream_cstr(vector_at(ctx->customHeaders, i).value));
sstream_push_cstr(content, "\r\n");
}
if(sstream_length(ctx->post) > 0)
{
sstream_push_cstr(content, "Content-Length: ");
sstream_push_int(content, sstream_length(ctx->post));
sstream_push_cstr(content, "\r\n");
}
sstream_push_cstr(content, "\r\n");
if(sstream_length(ctx->post) > 0)
{
sstream_push_cstr(content, sstream_cstr(ctx->post));
}
#ifdef USE_POSIX
send(ctx->sock, sstream_cstr(content), sstream_length(content), MSG_NOSIGNAL);
#endif
#ifdef USE_WINSOCK
send(ctx->sock, sstream_cstr(content), sstream_length(content), 0);
#endif
sstream_delete(content);
}
void _HttpProcessHeaders(struct Http *ctx)
{
vector(sstream *) *lines = NULL;
vector(sstream *) *line = NULL;
size_t i = 0;
size_t j = 0;
lines = vector_new(sstream *);
line = vector_new(sstream *);
sstream_split(ctx->rawHeaders, '\n', lines);
for(i = 0; i < vector_size(lines); i++)
{
sstream_split(vector_at(lines, i), ' ', line);
if(vector_size(line) >= 2)
{
if(strcmp(sstream_cstr(vector_at(line, 0)), "HTTP/1.1") == 0 ||
strcmp(sstream_cstr(vector_at(line, 0)), "HTTP/1.0") == 0)
{
//printf("Status: %s\n", sstream_cstr(vector_at(line, 1)));
ctx->status = atoi(sstream_cstr(vector_at(line, 1)));
}
}
for(j = 0; j < vector_size(line); j++)
{
sstream_delete(vector_at(line, j));
}
vector_clear(line);
}
//printf("%i %s\n", (int)vector_size(lines), sstream_cstr(ctx->rawHeaders));
for(i = 0; i < vector_size(lines); i++)
{
sstream_delete(vector_at(lines, i));
}
vector_delete(lines);
vector_delete(line);
}
void _HttpProcessRaw(struct Http *ctx)
{
if(sstream_length(ctx->rawHeaders) == 0)
{
size_t i = 0;
char last[5] = {0};
for(i = 0; i < vector_size(ctx->raw); i++)
{
last[0] = last[1];
last[1] = last[2];
last[2] = last[3];
last[3] = vector_at(ctx->raw, i);
if(strcmp(last, "\r\n\r\n") == 0)
{
size_t c = 0;
for(c = 0; c < i-3; c++)
{
sstream_push_char(ctx->rawHeaders, vector_at(ctx->raw, c));
}