Always pass request strings to other functions as const char *.
This commit is contained in:
parent
291a59b5b7
commit
58007d7efa
8 changed files with 54 additions and 52 deletions
|
@ -44,7 +44,7 @@ static bool control_ok(connection_t *c, int type) {
|
|||
return control_return(c, type, 0);
|
||||
}
|
||||
|
||||
bool control_h(connection_t *c, char *request) {
|
||||
bool control_h(connection_t *c, const char *request) {
|
||||
int type;
|
||||
|
||||
if(!c->status.control || c->allow_request != CONTROL) {
|
||||
|
|
|
@ -34,7 +34,7 @@ bool experimental = false;
|
|||
|
||||
/* Jumptable for the request handlers */
|
||||
|
||||
static bool (*request_handlers[])(connection_t *, char *) = {
|
||||
static bool (*request_handlers[])(connection_t *, const char *) = {
|
||||
id_h, metakey_h, challenge_h, chal_reply_h, ack_h,
|
||||
status_h, error_h, termreq_h,
|
||||
ping_h, pong_h,
|
||||
|
@ -96,16 +96,18 @@ bool send_request(connection_t *c, const char *format, ...) {
|
|||
return send_meta(c, request, len);
|
||||
}
|
||||
|
||||
void forward_request(connection_t *from, char *request) {
|
||||
/* Note: request is not zero terminated anymore after a call to this function! */
|
||||
void forward_request(connection_t *from, const char *request) {
|
||||
logger(DEBUG_META, LOG_DEBUG, "Forwarding %s from %s (%s): %s", request_name[atoi(request)], from->name, from->hostname, request);
|
||||
|
||||
// Create a temporary newline-terminated copy of the request
|
||||
int len = strlen(request);
|
||||
request[len++] = '\n';
|
||||
broadcast_meta(from, request, len);
|
||||
char tmp[len + 1];
|
||||
memcpy(tmp, request, len);
|
||||
tmp[len] = '\n';
|
||||
broadcast_meta(from, tmp, len);
|
||||
}
|
||||
|
||||
bool receive_request(connection_t *c, char *request) {
|
||||
bool receive_request(connection_t *c, const char *request) {
|
||||
int reqno = atoi(request);
|
||||
|
||||
if(reqno || *request == '0') {
|
||||
|
@ -141,14 +143,14 @@ static int past_request_compare(const past_request_t *a, const past_request_t *b
|
|||
|
||||
static void free_past_request(past_request_t *r) {
|
||||
if(r->request)
|
||||
free(r->request);
|
||||
free((char *)r->request);
|
||||
|
||||
free(r);
|
||||
}
|
||||
|
||||
static struct event past_request_event;
|
||||
|
||||
bool seen_request(char *request) {
|
||||
bool seen_request(const char *request) {
|
||||
past_request_t *new, p = {NULL};
|
||||
|
||||
p.request = request;
|
||||
|
|
|
@ -48,7 +48,7 @@ typedef enum request_t {
|
|||
} request_t;
|
||||
|
||||
typedef struct past_request_t {
|
||||
char *request;
|
||||
const char *request;
|
||||
time_t firstseen;
|
||||
} past_request_t;
|
||||
|
||||
|
@ -72,13 +72,13 @@ extern bool experimental;
|
|||
/* Basic functions */
|
||||
|
||||
extern bool send_request(struct connection_t *, const char *, ...) __attribute__ ((__format__(printf, 2, 3)));
|
||||
extern void forward_request(struct connection_t *, char *);
|
||||
extern bool receive_request(struct connection_t *, char *);
|
||||
extern void forward_request(struct connection_t *, const char *);
|
||||
extern bool receive_request(struct connection_t *, const char *);
|
||||
extern bool check_id(const char *);
|
||||
|
||||
extern void init_requests(void);
|
||||
extern void exit_requests(void);
|
||||
extern bool seen_request(char *);
|
||||
extern bool seen_request(const char *);
|
||||
|
||||
/* Requests */
|
||||
|
||||
|
@ -89,7 +89,7 @@ extern bool send_challenge(struct connection_t *);
|
|||
extern bool send_chal_reply(struct connection_t *);
|
||||
extern bool send_ack(struct connection_t *);
|
||||
extern bool send_status(struct connection_t *, int, const char *);
|
||||
extern bool send_error(struct connection_t *, int,const char *);
|
||||
extern bool send_error(struct connection_t *, int, const char *);
|
||||
extern bool send_termreq(struct connection_t *);
|
||||
extern bool send_ping(struct connection_t *);
|
||||
extern bool send_pong(struct connection_t *);
|
||||
|
@ -104,24 +104,24 @@ extern bool send_tcppacket(struct connection_t *, const struct vpn_packet_t *);
|
|||
|
||||
/* Request handlers */
|
||||
|
||||
extern bool id_h(struct connection_t *, char *);
|
||||
extern bool metakey_h(struct connection_t *, char *);
|
||||
extern bool challenge_h(struct connection_t *, char *);
|
||||
extern bool chal_reply_h(struct connection_t *, char *);
|
||||
extern bool ack_h(struct connection_t *, char *);
|
||||
extern bool status_h(struct connection_t *, char *);
|
||||
extern bool error_h(struct connection_t *, char *);
|
||||
extern bool termreq_h(struct connection_t *, char *);
|
||||
extern bool ping_h(struct connection_t *, char *);
|
||||
extern bool pong_h(struct connection_t *, char *);
|
||||
extern bool add_subnet_h(struct connection_t *, char *);
|
||||
extern bool del_subnet_h(struct connection_t *, char *);
|
||||
extern bool add_edge_h(struct connection_t *, char *);
|
||||
extern bool del_edge_h(struct connection_t *, char *);
|
||||
extern bool key_changed_h(struct connection_t *, char *);
|
||||
extern bool req_key_h(struct connection_t *, char *);
|
||||
extern bool ans_key_h(struct connection_t *, char *);
|
||||
extern bool tcppacket_h(struct connection_t *, char *);
|
||||
extern bool control_h(struct connection_t *, char *);
|
||||
extern bool id_h(struct connection_t *, const char *);
|
||||
extern bool metakey_h(struct connection_t *, const char *);
|
||||
extern bool challenge_h(struct connection_t *, const char *);
|
||||
extern bool chal_reply_h(struct connection_t *, const char *);
|
||||
extern bool ack_h(struct connection_t *, const char *);
|
||||
extern bool status_h(struct connection_t *, const char *);
|
||||
extern bool error_h(struct connection_t *, const char *);
|
||||
extern bool termreq_h(struct connection_t *, const char *);
|
||||
extern bool ping_h(struct connection_t *, const char *);
|
||||
extern bool pong_h(struct connection_t *, const char *);
|
||||
extern bool add_subnet_h(struct connection_t *, const char *);
|
||||
extern bool del_subnet_h(struct connection_t *, const char *);
|
||||
extern bool add_edge_h(struct connection_t *, const char *);
|
||||
extern bool del_edge_h(struct connection_t *, const char *);
|
||||
extern bool key_changed_h(struct connection_t *, const char *);
|
||||
extern bool req_key_h(struct connection_t *, const char *);
|
||||
extern bool ans_key_h(struct connection_t *, const char *);
|
||||
extern bool tcppacket_h(struct connection_t *, const char *);
|
||||
extern bool control_h(struct connection_t *, const char *);
|
||||
|
||||
#endif /* __TINC_PROTOCOL_H__ */
|
||||
|
|
|
@ -57,7 +57,7 @@ bool send_id(connection_t *c) {
|
|||
return send_request(c, "%d %s %d.%d", ID, myself->connection->name, myself->connection->protocol_major, minor);
|
||||
}
|
||||
|
||||
bool id_h(connection_t *c, char *request) {
|
||||
bool id_h(connection_t *c, const char *request) {
|
||||
char name[MAX_STRING_SIZE];
|
||||
|
||||
if(sscanf(request, "%*d " MAX_STRING " %d.%d", name, &c->protocol_major, &c->protocol_minor) < 2) {
|
||||
|
@ -219,7 +219,7 @@ bool send_metakey(connection_t *c) {
|
|||
return result;
|
||||
}
|
||||
|
||||
bool metakey_h(connection_t *c, char *request) {
|
||||
bool metakey_h(connection_t *c, const char *request) {
|
||||
char hexkey[MAX_STRING_SIZE];
|
||||
int cipher, digest, maclength, compression;
|
||||
size_t len = rsa_size(&myself->connection->rsa);
|
||||
|
@ -293,7 +293,7 @@ bool send_challenge(connection_t *c) {
|
|||
return send_request(c, "%d %s", CHALLENGE, buffer);
|
||||
}
|
||||
|
||||
bool challenge_h(connection_t *c, char *request) {
|
||||
bool challenge_h(connection_t *c, const char *request) {
|
||||
char buffer[MAX_STRING_SIZE];
|
||||
size_t len = rsa_size(&myself->connection->rsa);
|
||||
size_t digestlen = digest_length(&c->indigest);
|
||||
|
@ -330,7 +330,7 @@ bool challenge_h(connection_t *c, char *request) {
|
|||
return send_request(c, "%d %s", CHAL_REPLY, buffer);
|
||||
}
|
||||
|
||||
bool chal_reply_h(connection_t *c, char *request) {
|
||||
bool chal_reply_h(connection_t *c, const char *request) {
|
||||
char hishash[MAX_STRING_SIZE];
|
||||
|
||||
if(sscanf(request, "%*d " MAX_STRING, hishash) != 1) {
|
||||
|
@ -451,7 +451,7 @@ static void send_everything(connection_t *c) {
|
|||
}
|
||||
}
|
||||
|
||||
static bool upgrade_h(connection_t *c, char *request) {
|
||||
static bool upgrade_h(connection_t *c, const char *request) {
|
||||
char pubkey[MAX_STRING_SIZE];
|
||||
|
||||
if(sscanf(request, "%*d " MAX_STRING, pubkey) != 1) {
|
||||
|
@ -470,7 +470,7 @@ static bool upgrade_h(connection_t *c, char *request) {
|
|||
return send_termreq(c);
|
||||
}
|
||||
|
||||
bool ack_h(connection_t *c, char *request) {
|
||||
bool ack_h(connection_t *c, const char *request) {
|
||||
if(c->protocol_minor == 1)
|
||||
return upgrade_h(c, request);
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ bool send_add_edge(connection_t *c, const edge_t *e) {
|
|||
return x;
|
||||
}
|
||||
|
||||
bool add_edge_h(connection_t *c, char *request) {
|
||||
bool add_edge_h(connection_t *c, const char *request) {
|
||||
edge_t *e;
|
||||
node_t *from, *to;
|
||||
char from_name[MAX_STRING_SIZE];
|
||||
|
@ -167,7 +167,7 @@ bool send_del_edge(connection_t *c, const edge_t *e) {
|
|||
e->from->name, e->to->name);
|
||||
}
|
||||
|
||||
bool del_edge_h(connection_t *c, char *request) {
|
||||
bool del_edge_h(connection_t *c, const char *request) {
|
||||
edge_t *e;
|
||||
char from_name[MAX_STRING_SIZE];
|
||||
char to_name[MAX_STRING_SIZE];
|
||||
|
|
|
@ -51,7 +51,7 @@ void send_key_changed(void) {
|
|||
}
|
||||
}
|
||||
|
||||
bool key_changed_h(connection_t *c, char *request) {
|
||||
bool key_changed_h(connection_t *c, const char *request) {
|
||||
char name[MAX_STRING_SIZE];
|
||||
node_t *n;
|
||||
|
||||
|
@ -87,7 +87,7 @@ bool send_req_key(node_t *to) {
|
|||
return send_request(to->nexthop->connection, "%d %s %s %d", REQ_KEY, myself->name, to->name, experimental ? 1 : 0);
|
||||
}
|
||||
|
||||
bool req_key_h(connection_t *c, char *request) {
|
||||
bool req_key_h(connection_t *c, const char *request) {
|
||||
char from_name[MAX_STRING_SIZE];
|
||||
char to_name[MAX_STRING_SIZE];
|
||||
node_t *from, *to;
|
||||
|
@ -202,7 +202,7 @@ bool send_ans_key(node_t *to) {
|
|||
to->incompression);
|
||||
}
|
||||
|
||||
bool ans_key_h(connection_t *c, char *request) {
|
||||
bool ans_key_h(connection_t *c, const char *request) {
|
||||
char from_name[MAX_STRING_SIZE];
|
||||
char to_name[MAX_STRING_SIZE];
|
||||
char key[MAX_STRING_SIZE];
|
||||
|
|
|
@ -40,7 +40,7 @@ bool send_status(connection_t *c, int statusno, const char *statusstring) {
|
|||
return send_request(c, "%d %d %s", STATUS, statusno, statusstring);
|
||||
}
|
||||
|
||||
bool status_h(connection_t *c, char *request) {
|
||||
bool status_h(connection_t *c, const char *request) {
|
||||
int statusno;
|
||||
char statusstring[MAX_STRING_SIZE];
|
||||
|
||||
|
@ -63,7 +63,7 @@ bool send_error(connection_t *c, int err, const char *errstring) {
|
|||
return send_request(c, "%d %d %s", ERROR, err, errstring);
|
||||
}
|
||||
|
||||
bool error_h(connection_t *c, char *request) {
|
||||
bool error_h(connection_t *c, const char *request) {
|
||||
int err;
|
||||
char errorstring[MAX_STRING_SIZE];
|
||||
|
||||
|
@ -83,7 +83,7 @@ bool send_termreq(connection_t *c) {
|
|||
return send_request(c, "%d", TERMREQ);
|
||||
}
|
||||
|
||||
bool termreq_h(connection_t *c, char *request) {
|
||||
bool termreq_h(connection_t *c, const char *request) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ bool send_ping(connection_t *c) {
|
|||
return send_request(c, "%d", PING);
|
||||
}
|
||||
|
||||
bool ping_h(connection_t *c, char *request) {
|
||||
bool ping_h(connection_t *c, const char *request) {
|
||||
return send_pong(c);
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ bool send_pong(connection_t *c) {
|
|||
return send_request(c, "%d", PONG);
|
||||
}
|
||||
|
||||
bool pong_h(connection_t *c, char *request) {
|
||||
bool pong_h(connection_t *c, const char *request) {
|
||||
c->status.pinged = false;
|
||||
|
||||
/* Succesful connection, reset timeout if this is an outgoing connection. */
|
||||
|
@ -134,7 +134,7 @@ bool send_tcppacket(connection_t *c, const vpn_packet_t *packet) {
|
|||
return send_meta(c, (char *)packet->data, packet->len);
|
||||
}
|
||||
|
||||
bool tcppacket_h(connection_t *c, char *request) {
|
||||
bool tcppacket_h(connection_t *c, const char *request) {
|
||||
short int len;
|
||||
|
||||
if(sscanf(request, "%*d %hd", &len) != 1) {
|
||||
|
|
|
@ -41,7 +41,7 @@ bool send_add_subnet(connection_t *c, const subnet_t *subnet) {
|
|||
return send_request(c, "%d %x %s %s", ADD_SUBNET, rand(), subnet->owner->name, netstr);
|
||||
}
|
||||
|
||||
bool add_subnet_h(connection_t *c, char *request) {
|
||||
bool add_subnet_h(connection_t *c, const char *request) {
|
||||
char subnetstr[MAX_STRING_SIZE];
|
||||
char name[MAX_STRING_SIZE];
|
||||
node_t *owner;
|
||||
|
@ -151,7 +151,7 @@ bool send_del_subnet(connection_t *c, const subnet_t *s) {
|
|||
return send_request(c, "%d %x %s %s", DEL_SUBNET, rand(), s->owner->name, netstr);
|
||||
}
|
||||
|
||||
bool del_subnet_h(connection_t *c, char *request) {
|
||||
bool del_subnet_h(connection_t *c, const char *request) {
|
||||
char subnetstr[MAX_STRING_SIZE];
|
||||
char name[MAX_STRING_SIZE];
|
||||
node_t *owner;
|
||||
|
|
Loading…
Reference in a new issue