Process message is now a method of a conn object to hook in.
FossilOrigin-Name: 85006fd643f6b17869c3fcba929d1af488a25d288af1772a184c5fbc1ea10ebf
This commit is contained in:
parent
3b347b3bfb
commit
4faa14e265
@ -179,6 +179,8 @@ struct conn {
|
||||
|
||||
|
||||
int (*process_packet)(struct conn *conn, uint8_t * packet, int len,struct sockaddr *from);
|
||||
int (*process_message)(struct conn *conn, uint8_t * rawmsg, int rawlen,
|
||||
struct sockaddr *from);
|
||||
|
||||
|
||||
|
||||
@ -199,6 +201,8 @@ extern int conn_send_cwmsg(struct conn *conn, struct cwmsg *cwmsg);
|
||||
// int (*cb) (void *, uint8_t *,int len), void *cbarg);
|
||||
|
||||
extern int conn_process_packet(struct conn *conn, uint8_t * packet, int len,struct sockaddr *from);
|
||||
extern int process_message(struct conn *conn, uint8_t * rawmsg, int rawlen,
|
||||
struct sockaddr *from);
|
||||
|
||||
extern uint8_t *conn_get_message(struct conn *conn);
|
||||
|
||||
|
@ -45,6 +45,7 @@ void conn_init(struct conn * conn)
|
||||
conn->remote = mbag_create();
|
||||
|
||||
conn->process_packet=conn_process_packet;
|
||||
conn->process_message=process_message;
|
||||
}
|
||||
|
||||
|
||||
|
@ -86,8 +86,6 @@ void cw_init_request(struct conn *conn, int msg_id)
|
||||
cw_set_msg_type(msgptr, msg_id);
|
||||
cw_set_msg_flags(msgptr, 0);
|
||||
cw_set_msg_elems_len(msgptr, 0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -130,7 +128,8 @@ int cw_send_error_response(struct conn *conn, uint8_t * rawmsg, uint32_t result_
|
||||
}
|
||||
|
||||
|
||||
static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,struct sockaddr *from)
|
||||
static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
struct sockaddr *from)
|
||||
{
|
||||
struct cw_action_in as, *af, *afm;
|
||||
|
||||
@ -241,14 +240,15 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,struct
|
||||
if (!af) {
|
||||
cw_dbg(DBG_ELEM_ERR,
|
||||
"Element %d (%s) not allowed in msg of type %d (%s), ignoring.",
|
||||
as.elem_id, cw_strelemp(conn->actions,as.elem_id), as.msg_id,
|
||||
cw_strmsg(as.msg_id));
|
||||
as.elem_id, cw_strelemp(conn->actions, as.elem_id),
|
||||
as.msg_id, cw_strmsg(as.msg_id));
|
||||
continue;
|
||||
}
|
||||
|
||||
int afrc = 1;
|
||||
if (af->start) {
|
||||
afrc = af->start(conn, af, cw_get_elem_data(elem), elem_len,from);
|
||||
afrc =
|
||||
af->start(conn, af, cw_get_elem_data(elem), elem_len, from);
|
||||
|
||||
}
|
||||
|
||||
@ -302,7 +302,8 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,struct
|
||||
|
||||
|
||||
|
||||
static int process_message(struct conn *conn, uint8_t * rawmsg, int rawlen,struct sockaddr *from)
|
||||
int process_message(struct conn *conn, uint8_t * rawmsg, int rawlen,
|
||||
struct sockaddr *from)
|
||||
{
|
||||
uint8_t *msgptr = rawmsg + cw_get_hdr_msg_offset(rawmsg);
|
||||
|
||||
@ -369,7 +370,8 @@ static int process_message(struct conn *conn, uint8_t * rawmsg, int rawlen,struc
|
||||
* @param packet pointer to packet data
|
||||
* @param len lenght of packet data
|
||||
*/
|
||||
int conn_process_packet(struct conn *conn, uint8_t * packet, int len,struct sockaddr *from)
|
||||
int conn_process_packet(struct conn *conn, uint8_t * packet, int len,
|
||||
struct sockaddr *from)
|
||||
{
|
||||
/* show this packet in debug output */
|
||||
cw_dbg_pkt(DBG_PKT_IN, conn, packet, len, from);
|
||||
@ -419,7 +421,7 @@ int conn_process_packet(struct conn *conn, uint8_t * packet, int len,struct sock
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Check if Radio MAC is preset */
|
||||
/* Check if Radio MAC is present */
|
||||
if (cw_get_hdr_flag_m(packet)) {
|
||||
|
||||
if (cw_get_hdr_rmac_len(packet) + 8 > offs) {
|
||||
@ -449,7 +451,7 @@ int conn_process_packet(struct conn *conn, uint8_t * packet, int len,struct sock
|
||||
|
||||
// XXX: Modify fragman to not throw away CAPWAP headers
|
||||
|
||||
int rc = process_message(conn, f + 4, *(uint32_t *) f, from);
|
||||
int rc = conn->process_message(conn, f + 4, *(uint32_t *) f, from);
|
||||
|
||||
free(f);
|
||||
return rc;
|
||||
@ -457,7 +459,7 @@ int conn_process_packet(struct conn *conn, uint8_t * packet, int len,struct sock
|
||||
|
||||
/* not fragmented, we have a complete message */
|
||||
cw_dbg_msg(DBG_MSG_IN, conn, packet, len, from);
|
||||
return process_message(conn, packet, len, from);
|
||||
return conn->process_message(conn, packet, len, from);
|
||||
}
|
||||
|
||||
|
||||
@ -474,7 +476,8 @@ int cw_read_messages(struct conn *conn)
|
||||
return n;
|
||||
|
||||
if (n > 0) {
|
||||
return conn->process_packet(conn, buf, n,(struct sockaddr*)&conn->addr);
|
||||
return conn->process_packet(conn, buf, n,
|
||||
(struct sockaddr *) &conn->addr);
|
||||
}
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
@ -496,10 +499,8 @@ int cw_read_from(struct conn * conn)
|
||||
return n;
|
||||
|
||||
if (n > 0) {
|
||||
return conn_process_packet(conn, buf, n,(struct sockaddr*)&from);
|
||||
return conn->process_packet(conn, buf, n, (struct sockaddr *) &from);
|
||||
}
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user