Annotation of mqtt/src/mqtt.c, revision 1.1.1.1.2.19

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.19! misho      61:        if ((ret = call.InitSessPUB(&cfg, pub, "misho", "doophenschmerz", "127.0.0.1", 12345, 1, 
        !            62:                                        "Topic43", "mmm", 2, 0)) == -1) {
1.1.1.1.2.13  misho      63:                printf("Error:: Session init problem\n");
1.1.1.1.2.12  misho      64:                goto end;
                     65:        } else
                     66:                call.LOG(logg, "InitSess: %d\n", ret);
                     67: 
1.1.1.1.2.19! misho      68:        if ((ret = call.ChkSessPUB(&cfg, pub, "misho", "doophenschmerz", "127.0._.%")) == -1) {
1.1.1.1.2.14  misho      69:                printf("Error:: Session check problem\n");
                     70:                goto end;
                     71:        } else
                     72:                call.LOG(logg, "ChkSess: %d\n", ret);
                     73: 
1.1.1.1.2.19! misho      74:        if ((ret = call.DeletePUB(&cfg, pub, 10, "%", "%", "%", -1)) == -1) {
1.1.1.1.2.16  misho      75:                printf("Error:: Clear problem\n");
                     76:                goto end;
                     77:        } else
                     78:                call.LOG(logg, "Clear: %d\n", ret);
                     79: 
1.1.1.1.2.19! misho      80:        if ((ret = call.WritePUB(&cfg, pub, 10, "oho/boho", "MRYN    \n tryn brymbryn", "misho", "1.1.1.1", 1)) == -1) {
1.1.1.1.2.16  misho      81:                printf("Error:: Publish problem\n");
                     82:                goto end;
                     83:        } else
                     84:                call.LOG(logg, "Publish: %d\n", ret);
1.1.1.1.2.19! misho      85:        if ((ret = call.WritePUB(&cfg, pub, 11, "boh", "testing", "misho", "1.1.1.2", 0)) == -1) {
1.1.1.1.2.16  misho      86:                printf("Error:: Publish problem\n");
                     87:                goto end;
                     88:        } else
                     89:                call.LOG(logg, "Publish: %d\n", ret);
1.1.1.1.2.19! misho      90:        if (!(s = call.ReadPUB(&cfg, pub, 10, "%", -1))) {
1.1.1.1.2.17  misho      91:                printf("Error:: Subscribe problem\n");
                     92:                goto end;
1.1.1.1.2.18  misho      93:        } else {
1.1.1.1.2.17  misho      94:                call.LOG(logg, "Subscribe: %p\n", s);
1.1.1.1.2.18  misho      95:                for (p = s; p->sub_topic._base; p++) {
                     96:                        printf("Retain=%d Topic(%d)=%s Value(%d)=%s\n", p->sub_ret, 
                     97:                                        p->sub_topic._size, p->sub_topic._base, 
                     98:                                        p->sub_value._size, p->sub_value._base);
                     99:                }
                    100:                mqtt_subFree(&s);
                    101:        }
1.1.1.1.2.19! misho     102:        if ((ret = call.DeletePUB(&cfg, pub, 11, "boh", "misho", "1.1.1._", 0)) == -1) {
1.1.1.1.2.16  misho     103:                printf("Error:: Delete problem\n");
                    104:                goto end;
                    105:        } else
                    106:                call.LOG(logg, "Delete: %d\n", ret);
                    107: 
1.1.1.1.2.19! misho     108:        if ((ret = call.FiniSessPUB(&cfg, pub, "misho", "doophenschmerz", "127.0._.1%")) == -1) {
1.1.1.1.2.13  misho     109:                printf("Error:: Session fini problem\n");
                    110:                goto end;
                    111:        } else
                    112:                call.LOG(logg, "FiniSess: %d\n", ret);
                    113: 
1.1.1.1.2.5  misho     114: end:
1.1.1.1.2.10  misho     115:        call.CloseLOG(logg);
                    116:        call.ClosePUB(pub);
                    117:        call.CloseACC(acc);
1.1.1.1.2.9  misho     118:        mqttUnloadRTLM(2);
1.1.1.1.2.8  misho     119:        mqttUnloadRTLM(1);
1.1.1.1.2.5  misho     120:        mqttUnloadRTLM(0);
                    121:        UnloadConfig(&cfg);
1.1       misho     122:        return 0;
                    123: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>