Line data Source code
1 : #include "burp.h"
2 : #include "alloc.h"
3 : #include "asfd.h"
4 : #include "cmd.h"
5 : #include "log.h"
6 : #include "prepend.h"
7 : #include "strlist.h"
8 : #include "incexc_send.h"
9 :
10 43 : static int send_incexc_string(struct asfd *asfd,
11 : const char *field, const char *str)
12 : {
13 43 : char *tosend=NULL;
14 43 : int ret=-1;
15 43 : if(!str) return 0;
16 22 : if(!(tosend=prepend_n(field, str, strlen(str), " = ")))
17 : goto end;
18 22 : if(asfd->write_str(asfd, CMD_GEN, tosend))
19 : {
20 0 : logp("Error in async_write_str when sending incexc\n");
21 0 : goto end;
22 : }
23 : ret=0;
24 : end:
25 22 : free_w(&tosend);
26 22 : return ret;
27 : }
28 :
29 22 : static int send_incexc_str(struct asfd *asfd, struct conf *conf)
30 : {
31 22 : return send_incexc_string(asfd, conf->field, get_string(conf));
32 : }
33 :
34 19 : static int send_incexc_uint(struct asfd *asfd, struct conf *conf)
35 : {
36 19 : char tmp[64]="";
37 19 : snprintf(tmp, sizeof(tmp), "%d", get_int(conf));
38 19 : return send_incexc_string(asfd, conf->field, tmp);
39 : }
40 :
41 2 : static int send_incexc_uint64(struct asfd *asfd, struct conf *conf)
42 : {
43 2 : char tmp[32]="";
44 2 : snprintf(tmp, sizeof(tmp), "%" PRIu64, get_uint64_t(conf));
45 2 : return send_incexc_string(asfd, conf->field, tmp);
46 : }
47 :
48 24 : static int send_incexc_strlist(struct asfd *asfd, struct conf *conf)
49 : {
50 : struct strlist *l;
51 24 : for(l=get_strlist(conf); l; l=l->next)
52 0 : if(send_incexc_string(asfd, conf->field, l->path)) return -1;
53 : return 0;
54 : }
55 :
56 5 : static int do_sends(struct asfd *asfd, struct conf **confs, int flag)
57 : {
58 5 : int i=0;
59 5 : int r=-1;
60 870 : for(i=0; i<OPT_MAX; i++)
61 : {
62 865 : if(!(confs[i]->flags & flag)) continue;
63 67 : switch(confs[i]->conf_type)
64 : {
65 : case CT_STRING:
66 22 : if(send_incexc_str(asfd, confs[i]))
67 : goto end;
68 : break;
69 : case CT_STRLIST:
70 24 : if(send_incexc_strlist(asfd, confs[i]))
71 : goto end;
72 : break;
73 : case CT_UINT:
74 19 : if(send_incexc_uint(asfd, confs[i]))
75 : goto end;
76 : break;
77 : case CT_SSIZE_T:
78 2 : if(send_incexc_uint64(asfd, confs[i]))
79 : goto end;
80 : break;
81 : case CT_FLOAT:
82 : case CT_MODE_T:
83 : case CT_E_BURP_MODE:
84 : case CT_E_PROTOCOL:
85 : case CT_E_RECOVERY_METHOD:
86 : case CT_E_RSHASH:
87 : case CT_CNTR:
88 : break;
89 : }
90 : }
91 : r=0;
92 : end:
93 5 : return r;
94 : }
95 :
96 5 : static int do_request_response(struct asfd *asfd,
97 : const char *reqstr, const char *repstr)
98 : {
99 5 : return (asfd->write_str(asfd, CMD_GEN, reqstr)
100 5 : || asfd_read_expect(asfd, CMD_GEN, repstr));
101 : }
102 :
103 0 : int incexc_send_client(struct asfd *asfd, struct conf **confs)
104 : {
105 0 : if(do_request_response(asfd, "incexc", "incexc ok")
106 0 : || do_sends(asfd, confs, CONF_FLAG_INCEXC)
107 0 : || do_request_response(asfd, "incexc end", "incexc end ok"))
108 : return -1;
109 : return 0;
110 : }
111 :
112 1 : int incexc_send_server(struct asfd *asfd, struct conf **confs)
113 : {
114 : /* 'sincexc' and 'sincexc ok' have already been exchanged,
115 : so go straight into doing the sends. */
116 1 : if(do_sends(asfd, confs, CONF_FLAG_INCEXC)
117 1 : || do_request_response(asfd, "sincexc end", "sincexc end ok"))
118 : return -1;
119 : return 0;
120 : }
121 :
122 4 : int incexc_send_server_restore(struct asfd *asfd, struct conf **confs)
123 : {
124 : /* 'srestore' and 'srestore ok' have already been exchanged,
125 : so go straight into doing the sends. */
126 4 : if(do_sends(asfd, confs, CONF_FLAG_INCEXC_RESTORE)
127 4 : || do_request_response(asfd, "srestore end", "srestore end ok"))
128 : return -1;
129 : return 0;
130 : }
|