Annotation of mqtt/src/mqtt.c, revision 1.1.1.1.2.17
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.17! misho 14: mqtt_subscr_t *s;
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.17! misho 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);
1.1.1.1.2.16 misho 94: if ((ret = call.DeletePUB(&cfg, pub, "boh", "misho", "1.1.1._", 0)) == -1) {
95: printf("Error:: Delete problem\n");
96: goto end;
97: } else
98: call.LOG(logg, "Delete: %d\n", ret);
99:
1.1.1.1.2.13 misho 100: if ((ret = call.FiniSessPUB(&cfg, pub, "misho", "127.0._.1%")) == -1) {
101: printf("Error:: Session fini problem\n");
102: goto end;
103: } else
104: call.LOG(logg, "FiniSess: %d\n", ret);
105:
1.1.1.1.2.5 misho 106: end:
1.1.1.1.2.10 misho 107: call.CloseLOG(logg);
108: call.ClosePUB(pub);
109: call.CloseACC(acc);
1.1.1.1.2.9 misho 110: mqttUnloadRTLM(2);
1.1.1.1.2.8 misho 111: mqttUnloadRTLM(1);
1.1.1.1.2.5 misho 112: mqttUnloadRTLM(0);
113: UnloadConfig(&cfg);
1.1 misho 114: return 0;
115: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>