Annotation of mqtt/src/aitmqtt.c, revision 1.1.1.1.2.1
1.1 misho 1: #include "global.h"
2:
3:
4: static int mqtt_Errno;
5: static char mqtt_Error[STRSIZ];
6:
7:
8: //
9: // Error maintenance functions ...
10: //
11:
12: // mqtt_GetErrno() Get error code of last operation
13: inline int
14: mqtt_GetErrno()
15: {
16: return mqtt_Errno;
17: }
18:
19: // mqtt_GetError() Get error text of last operation
20: inline const char *
21: mqtt_GetError()
22: {
23: return mqtt_Error;
24: }
25:
26: // mqtt_SetErr() Set error to variables for internal use!!!
27: inline void
28: mqtt_SetErr(int eno, char *estr, ...)
29: {
30: va_list lst;
31:
32: mqtt_Errno = eno;
33: memset(mqtt_Error, 0, sizeof mqtt_Error);
34: va_start(lst, estr);
35: vsnprintf(mqtt_Error, sizeof mqtt_Error, estr, lst);
36: va_end(lst);
37: }
38:
39: // ----------------------------------------------------------
40:
1.1.1.1.2.1! misho 41: /*
! 42: * mqtt_encodeLen() Encode number to MQTT length field
! 43: * @num = number for encode
! 44: * return: -1 error or >-1 length
! 45: */
! 46: inline u_int
! 47: mqtt_encodeLen(u_int num)
! 48: {
! 49: register u_int dig, i;
! 50: u_int ret = 0;
! 51:
! 52: if (num > 268435455)
! 53: return (u_int) -1;
! 54:
! 55: for (i = 0; i < sizeof ret && num > 0; i++) {
! 56: dig = num % 0x80;
! 57: num /= 0x80;
! 58: if (num > 0)
! 59: dig |= 0x80;
! 60:
! 61: *((u_char*) &ret + i) = (u_char) dig;
! 62: }
! 63:
! 64: return ret;
! 65: }
! 66:
! 67: /*
! 68: * mqtt_decodeLen() Decode length from MQTT packet
! 69: * @len = length
! 70: * return: -1 error, >-1 length of message
! 71: */
! 72: inline u_int
! 73: mqtt_decodeLen(u_int len)
! 74: {
! 75: register u_int i, dig, mul;
! 76: u_int ret = 0;
! 77: u_char *p = (u_char*) &len;
! 78:
! 79: if (len > 0xffffff7f)
! 80: return (u_int) -1;
! 81:
! 82: for (mul = 1, i = 0; i < sizeof ret; i++, mul *= 0x80) {
! 83: dig = p[i];
! 84: ret += (dig & 0x7f) * mul;
! 85:
! 86: if (!(dig & 0x80))
! 87: break;
! 88: }
! 89:
! 90: return ret;
! 91: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>