Annotation of libaitmqtt/src/srvside.c, revision 1.1.2.2
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;
! 28: srv->buf->msg_base = buf->msg_base;
! 29: srv->buf->msg_len = buf->msg_len;
! 30:
! 31: return srv;
! 32: }
! 33:
! 34: /*
! 35: * mqtt_srv_Fini() Finish MQTT server side support
! 36: *
! 37: * @psrv = Server handle
! 38: * return: none
! 39: */
! 40: void
! 41: mqtt_srv_Fini(mqtt_srv_t ** __restrict psrv)
! 42: {
! 43: if (psrv && *psrv) {
! 44: free(*psrv);
! 45: *psrv = NULL;
! 46: }
! 47: }
! 48:
! 49: /*
! 50: * mqtt_srv_Dispatch() MQTT server dispatcher
! 51: *
! 52: * @srv = Server handle
! 53: * @arg = Argument pass to command callback
! 54: * return: -1 error or 0 ok
! 55: */
! 56: int
! 57: mqtt_srv_Dispatch(mqtt_srv_t * __restrict srv, void *arg)
! 58: {
! 59: struct mqtthdr *hdr;
! 60:
! 61: if (!srv || !srv->buf->msg_base || !srv->buf->msg_len)
! 62: return -1;
! 63: if (srv->buf->msg_len < sizeof(struct mqtthdr)) {
! 64: mqtt_SetErr(EINVAL, "Error:: message is too small ...");
! 65: return -1;
! 66: }
! 67: hdr = (struct mqtthdr*) srv->buf->msg_base;
! 68: if (hdr->mqtt_msg.type > MQTT_TYPE_MAX) {
! 69: mqtt_SetErr(ENOSYS, "Error:: message type %d not implemented", hdr->mqtt_msg.type);
! 70: return -1;
! 71: }
! 72: if (srv->cmds[hdr->mqtt_msg.type])
! 73: return srv->cmds[hdr->mqtt_msg.type]((void*) srv, arg);
! 74:
! 75: mqtt_SetErr(ENOTSUP, "Error:: Unsupported message type %d", hdr->mqtt_msg.type);
! 76: return -1;
! 77: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>