Annotation of mqtt/src/mqtt.c, revision 1.1.1.1.2.18
1.1 misho 1: #include "global.h"
1.1.1.1.2.5 misho 2: #include "rtlm.h"
3:
4:
5: sl_config cfg;
1.1 misho 6:
7:
8: int
9: main(int argc, char **argv)
10: {
1.1.1.1.2.6 misho 11: sqlite3 *acc = NULL, *pub = NULL;
1.1.1.1.2.9 misho 12: FILE *logg = NULL;
1.1.1.1.2.11 misho 13: int ret = 0;
1.1.1.1.2.18! misho 14: mqtt_subscr_t *s, *p;
1.1.1.1.2.5 misho 15:
16: if (LoadConfig("/etc/mqtt.conf", &cfg)) {
17: printf("Error:: Load config #%d - %s\n", cfg_GetErrno(), cfg_GetError());
18: return 1;
19: }
20: if (!mqttLoadRTLM(&cfg, 0)) {
1.1.1.1.2.8 misho 21: printf("Error:: Can't load RTL ACC module\n");
22: UnloadConfig(&cfg);
23: return 2;
24: }
25: if (!mqttLoadRTLM(&cfg, 1)) {
26: printf("Error:: Can't load RTL PUB module\n");
27: mqttUnloadRTLM(0);
28: UnloadConfig(&cfg);
1.1.1.1.2.5 misho 29: return 2;
30: }
1.1.1.1.2.9 misho 31: if (!mqttLoadRTLM(&cfg, 2)) {
32: printf("Error:: Can't load RTL LOG module\n");
33: mqttUnloadRTLM(1);
34: mqttUnloadRTLM(0);
35: UnloadConfig(&cfg);
36: return 2;
37: }
1.1.1.1.2.5 misho 38:
1.1.1.1.2.10 misho 39: acc = call.OpenACC(&cfg);
1.1.1.1.2.5 misho 40: if (!acc)
41: goto end;
1.1.1.1.2.10 misho 42: pub = call.OpenPUB(&cfg);
1.1.1.1.2.6 misho 43: if (!pub)
44: goto end;
1.1.1.1.2.10 misho 45: logg = call.OpenLOG(&cfg);
1.1.1.1.2.9 misho 46: if (!logg)
47: goto end;
1.1.1.1.2.5 misho 48:
1.1.1.1.2.7 misho 49: if (mqttMkDir(&cfg)) {
50: printf("Error:: in statedir #%d - %s\n", errno, strerror(errno));
51: goto end;
52: }
53:
1.1.1.1.2.10 misho 54: call.LOG(logg, "success!\n");
1.1.1.1.2.11 misho 55: if ((ret = call.LoginACC(&cfg, acc, "misho", "test123")) == -1) {
56: printf("Error:: Authentication problem\n");
57: goto end;
58: } else
59: call.LOG(logg, "Login: %s\n", ret ? "ALLOW" : "DENIED");
1.1.1.1.2.5 misho 60:
1.1.1.1.2.12 misho 61: if ((ret = call.InitSessPUB(&cfg, pub, "misho", "127.0.0.1", 12345)) == -1) {
1.1.1.1.2.13 misho 62: printf("Error:: Session init problem\n");
1.1.1.1.2.12 misho 63: goto end;
64: } else
65: call.LOG(logg, "InitSess: %d\n", ret);
66:
1.1.1.1.2.15 misho 67: if ((ret = call.ChkSessPUB(&cfg, pub, "misho", "127.0._.%")) == -1) {
1.1.1.1.2.14 misho 68: printf("Error:: Session check problem\n");
69: goto end;
70: } else
71: call.LOG(logg, "ChkSess: %d\n", ret);
72:
1.1.1.1.2.16 misho 73: if ((ret = call.DeletePUB(&cfg, pub, "%", "%", "%", -1)) == -1) {
74: printf("Error:: Clear problem\n");
75: goto end;
76: } else
77: call.LOG(logg, "Clear: %d\n", ret);
78:
79: if ((ret = call.WritePUB(&cfg, pub, "oho/boho", "MRYN \n tryn brymbryn", "misho", "1.1.1.1", 1)) == -1) {
80: printf("Error:: Publish problem\n");
81: goto end;
82: } else
83: call.LOG(logg, "Publish: %d\n", ret);
84: if ((ret = call.WritePUB(&cfg, pub, "boh", "testing", "misho", "1.1.1.2", 0)) == -1) {
85: printf("Error:: Publish problem\n");
86: goto end;
87: } else
88: call.LOG(logg, "Publish: %d\n", ret);
1.1.1.1.2.18! misho 89: if (!(s = call.ReadPUB(&cfg, pub, "%", -1))) {
1.1.1.1.2.17 misho 90: printf("Error:: Subscribe problem\n");
91: goto end;
1.1.1.1.2.18! misho 92: } else {
1.1.1.1.2.17 misho 93: call.LOG(logg, "Subscribe: %p\n", s);
1.1.1.1.2.18! misho 94: for (p = s; p->sub_topic._base; p++) {
! 95: printf("Retain=%d Topic(%d)=%s Value(%d)=%s\n", p->sub_ret,
! 96: p->sub_topic._size, p->sub_topic._base,
! 97: p->sub_value._size, p->sub_value._base);
! 98: }
! 99: mqtt_subFree(&s);
! 100: }
1.1.1.1.2.16 misho 101: if ((ret = call.DeletePUB(&cfg, pub, "boh", "misho", "1.1.1._", 0)) == -1) {
102: printf("Error:: Delete problem\n");
103: goto end;
104: } else
105: call.LOG(logg, "Delete: %d\n", ret);
106:
1.1.1.1.2.13 misho 107: if ((ret = call.FiniSessPUB(&cfg, pub, "misho", "127.0._.1%")) == -1) {
108: printf("Error:: Session fini problem\n");
109: goto end;
110: } else
111: call.LOG(logg, "FiniSess: %d\n", ret);
112:
1.1.1.1.2.5 misho 113: end:
1.1.1.1.2.10 misho 114: call.CloseLOG(logg);
115: call.ClosePUB(pub);
116: call.CloseACC(acc);
1.1.1.1.2.9 misho 117: mqttUnloadRTLM(2);
1.1.1.1.2.8 misho 118: mqttUnloadRTLM(1);
1.1.1.1.2.5 misho 119: mqttUnloadRTLM(0);
120: UnloadConfig(&cfg);
1.1 misho 121: return 0;
122: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>