Annotation of libaitmqtt/src/srvside.c, revision 1.1.2.3
1.1.2.1 misho 1: #include "global.h"
2:
3:
1.1.2.2 misho 4:
5: /*
6: * mqtt_srv_Init() Init MQTT server side support
7: *
8: * @sock = Client socket from accept()
9: * @buf = Message buffer
10: * return: NULL error or !=NULL allocated server handle
11: */
12: mqtt_srv_t *
13: mqtt_srv_Init(int sock, mqtt_msg_t * __restrict buf)
14: {
15: mqtt_srv_t *srv = NULL;
16:
17: if (!buf || !buf->msg_base || !buf->msg_len)
18: return srv;
19:
20: srv = malloc(sizeof(mqtt_srv_t));
21: if (!srv) {
22: LOGERR;
23: return srv;
24: } else
25: memset(srv, 0, sizeof(mqtt_srv_t));
26:
27: srv->sock = sock;
1.1.2.3 ! misho 28: srv->buf = buf;
1.1.2.2 misho 29:
30: return srv;
31: }
32:
33: /*
34: * mqtt_srv_Fini() Finish MQTT server side support
35: *
36: * @psrv = Server handle
37: * return: none
38: */
39: void
40: mqtt_srv_Fini(mqtt_srv_t ** __restrict psrv)
41: {
42: if (psrv && *psrv) {
43: free(*psrv);
44: *psrv = NULL;
45: }
46: }
47:
48: /*
49: * mqtt_srv_Dispatch() MQTT server dispatcher
50: *
51: * @srv = Server handle
52: * @arg = Argument pass to command callback
53: * return: -1 error or 0 ok
54: */
55: int
56: mqtt_srv_Dispatch(mqtt_srv_t * __restrict srv, void *arg)
57: {
58: struct mqtthdr *hdr;
59:
60: if (!srv || !srv->buf->msg_base || !srv->buf->msg_len)
61: return -1;
62: if (srv->buf->msg_len < sizeof(struct mqtthdr)) {
63: mqtt_SetErr(EINVAL, "Error:: message is too small ...");
64: return -1;
65: }
66: hdr = (struct mqtthdr*) srv->buf->msg_base;
67: if (hdr->mqtt_msg.type > MQTT_TYPE_MAX) {
68: mqtt_SetErr(ENOSYS, "Error:: message type %d not implemented", hdr->mqtt_msg.type);
69: return -1;
70: }
71: if (srv->cmds[hdr->mqtt_msg.type])
72: return srv->cmds[hdr->mqtt_msg.type]((void*) srv, arg);
73:
74: mqtt_SetErr(ENOTSUP, "Error:: Unsupported message type %d", hdr->mqtt_msg.type);
75: return -1;
76: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>