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