1: #include "global.h"
2: #include "rtlm.h"
3:
4:
5: sl_config cfg;
6:
7:
8: int
9: main(int argc, char **argv)
10: {
11: sqlite3 *acc = NULL, *pub = NULL;
12: FILE *logg = NULL;
13: int ret = 0;
14: mqtt_subscr_t *s, *p;
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)) {
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);
29: return 2;
30: }
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: }
38:
39: acc = call.OpenACC(&cfg);
40: if (!acc)
41: goto end;
42: pub = call.OpenPUB(&cfg);
43: if (!pub)
44: goto end;
45: logg = call.OpenLOG(&cfg);
46: if (!logg)
47: goto end;
48:
49: if (mqttMkDir(&cfg)) {
50: printf("Error:: in statedir #%d - %s\n", errno, strerror(errno));
51: goto end;
52: }
53:
54: call.LOG(logg, "success!\n");
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");
60:
61: if ((ret = call.InitSessPUB(&cfg, pub, "misho", "127.0.0.1", 12345)) == -1) {
62: printf("Error:: Session init problem\n");
63: goto end;
64: } else
65: call.LOG(logg, "InitSess: %d\n", ret);
66:
67: if ((ret = call.ChkSessPUB(&cfg, pub, "misho", "127.0._.%")) == -1) {
68: printf("Error:: Session check problem\n");
69: goto end;
70: } else
71: call.LOG(logg, "ChkSess: %d\n", ret);
72:
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);
89: if (!(s = call.ReadPUB(&cfg, pub, "%", -1))) {
90: printf("Error:: Subscribe problem\n");
91: goto end;
92: } else {
93: call.LOG(logg, "Subscribe: %p\n", s);
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: }
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:
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:
113: end:
114: call.CloseLOG(logg);
115: call.ClosePUB(pub);
116: call.CloseACC(acc);
117: mqttUnloadRTLM(2);
118: mqttUnloadRTLM(1);
119: mqttUnloadRTLM(0);
120: UnloadConfig(&cfg);
121: return 0;
122: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>