Line data Source code
1 : #include "burp.h"
2 : #include "alloc.h"
3 : #include "asfd.h"
4 : #include "async.h"
5 : #include "cmd.h"
6 : #include "iobuf.h"
7 : #include "prepend.h"
8 :
9 : static const char *endreqstrf;
10 : static const char *endrepstrf;
11 :
12 9 : static int add_to_incexc(char **incexc, const char *src, size_t len, const char *sep)
13 : {
14 : char *tmp;
15 9 : if(!(tmp=prepend_n(*incexc?:"", src, len, *incexc?"\n":""))) return -1;
16 9 : free_w(incexc);
17 9 : *incexc=tmp;
18 : return 0;
19 : }
20 :
21 9 : static enum asl_ret incexc_recv_func(struct asfd *asfd,
22 : struct conf **confs, void *param)
23 : {
24 9 : char **incexc=(char **)param;
25 9 : if(!strcmp(asfd->rbuf->buf, endreqstrf))
26 : {
27 3 : if(asfd->write_str(asfd, CMD_GEN, endrepstrf))
28 : return ASL_END_ERROR;
29 3 : return ASL_END_OK;
30 : }
31 6 : if(add_to_incexc(incexc,
32 6 : asfd->rbuf->buf, asfd->rbuf->len, *incexc?"\n":""))
33 : return ASL_END_ERROR;
34 6 : return ASL_CONTINUE;
35 : }
36 :
37 :
38 3 : static int incexc_recv(struct asfd *asfd, char **incexc,
39 : const char *reqstr, const char *repstr,
40 : const char *endreqstr, const char *endrepstr, struct conf **confs)
41 : {
42 3 : free_w(incexc);
43 3 : if(asfd->write_str(asfd, CMD_GEN, repstr)) return -1;
44 :
45 3 : endreqstrf=endreqstr;
46 3 : endrepstrf=endrepstr;
47 3 : if(asfd->simple_loop(asfd, confs, incexc, __func__, incexc_recv_func))
48 : return -1;
49 :
50 : // Need to put another new line at the end.
51 3 : return add_to_incexc(incexc, "\n", 1, "");
52 : }
53 :
54 1 : int incexc_recv_client(struct asfd *asfd,
55 : char **incexc, struct conf **confs)
56 : {
57 : return incexc_recv(asfd, incexc,
58 : "sincexc", "sincexc ok",
59 : "sincexc end", "sincexc end ok",
60 1 : confs);
61 : }
62 :
63 1 : int incexc_recv_client_restore(struct asfd *asfd,
64 : char **incexc, struct conf **confs)
65 : {
66 : return incexc_recv(asfd, incexc,
67 : "srestore", "srestore ok",
68 : "srestore end", "srestore end ok",
69 1 : confs);
70 : }
71 :
72 1 : int incexc_recv_server(struct asfd *asfd,
73 : char **incexc, struct conf **confs)
74 : {
75 : return incexc_recv(asfd, incexc,
76 : "incexc", "incexc ok",
77 : "incexc end", "incexc end ok",
78 1 : confs);
79 : }
|