Annotation of mqtt/src/dl.c, revision 1.1.2.4

1.1.2.1   misho       1: #include "global.h"
                      2: #include "rtlm.h"
                      3: 
                      4: 
1.1.2.4 ! misho       5: static void *acc_rtlm, *pub_rtlm, *log_rtlm;
1.1.2.1   misho       6: 
                      7: 
                      8: /*
                      9:  * mqttLog() Log message to syslog
                     10:  *
                     11:  * @fmt = format string
                     12:  * @... = argument list
                     13:  * return: none
                     14:  */
                     15: void
                     16: mqttLog(const char *fmt, ...)
                     17: {
                     18:        va_list lst;
                     19: 
                     20:        va_start(lst, fmt);
                     21:        vsyslog(LOG_ERR, fmt, lst);
                     22:        va_end(lst);
                     23: }
                     24: 
                     25: void *
                     26: mqttLoadRTLM(sl_config *cfg, int modtype)
                     27: {
1.1.2.4 ! misho      28:        const char *str, *attr;
1.1.2.1   misho      29:        void *rtlm = NULL;
1.1.2.4 ! misho      30:        void *(*mqttOpenRTLM)(sl_config *);
        !            31:        void (*mqttCloseRTLM)(void *);
1.1.2.1   misho      32: 
                     33:        if (!cfg)
                     34:                return NULL;
                     35: 
1.1.2.4 ! misho      36:        switch (modtype) {
        !            37:                case 0:
        !            38:                        attr = "acc_file";
        !            39:                        break;
        !            40:                case 1:
        !            41:                        attr = "pub_file";
        !            42:                        break;
        !            43:                default:
        !            44:                        attr = "log_file";
        !            45:                        break;
        !            46:        }
        !            47: 
        !            48:        str = (const char*) CFG(cfg_GetAttribute(cfg, CFG("mqttd"), CFG(attr)));
1.1.2.1   misho      49:        if (!str) {
                     50:                mqttLog("Error:: RTL module not found\n");
                     51:                return NULL;
                     52:        }
                     53: 
                     54:        rtlm = dlopen(str, RTLD_LAZY);
                     55:        if (!rtlm) {
                     56:                mqttLog("Error:: RTL module not found %s\n", dlerror());
                     57:                return NULL;
                     58:        }
                     59: 
1.1.2.4 ! misho      60:        mqttOpenRTLM = dlsym(rtlm, "mqtt_rtlm_open");
        !            61:        if (!mqttOpenRTLM) {
1.1.2.1   misho      62:                mqttLog("Error:: Can't found mqtt_db_open call\n");
                     63:                dlclose(rtlm);
                     64:                return NULL;
                     65:        }
1.1.2.4 ! misho      66:        mqttCloseRTLM = dlsym(rtlm, "mqtt_rtlm_close");
        !            67:        if (!mqttCloseRTLM) {
1.1.2.1   misho      68:                mqttLog("Error:: Can't found mqtt_db_close call\n");
                     69:                dlclose(rtlm);
                     70:                return NULL;
                     71:        }
                     72: 
1.1.2.4 ! misho      73:        switch (modtype) {
        !            74:                case 0:
        !            75:                        acc_rtlm = rtlm;
        !            76:                        mqttOpenACC = mqttOpenRTLM;
        !            77:                        mqttCloseACC = mqttCloseRTLM;
        !            78:                        break;
        !            79:                case 1:
        !            80:                        pub_rtlm = rtlm;
        !            81:                        mqttOpenPUB = mqttOpenRTLM;
        !            82:                        mqttClosePUB = mqttCloseRTLM;
        !            83:                        break;
        !            84:                default:
        !            85:                        log_rtlm = rtlm;
        !            86:                        mqttOpenLOG = mqttOpenRTLM;
        !            87:                        mqttCloseLOG = mqttCloseRTLM;
        !            88:                        break;
1.1.2.1   misho      89:        }
                     90: 
                     91:        return rtlm;
                     92: }
                     93: 
                     94: void
                     95: mqttUnloadRTLM(int modtype)
                     96: {
1.1.2.4 ! misho      97:        switch (modtype) {
        !            98:                case 0:
        !            99:                        dlclose(acc_rtlm);
        !           100:                        break;
        !           101:                case 1:
        !           102:                        dlclose(pub_rtlm);
        !           103:                        break;
        !           104:                default:
        !           105:                        dlclose(log_rtlm);
        !           106:                        break;
        !           107:        }
1.1.2.1   misho     108: }
1.1.2.2   misho     109: 
                    110: inline int
                    111: mqttMkDir(sl_config *cfg)
                    112: {
1.1.2.3   misho     113:        const char *str;
1.1.2.2   misho     114: 
                    115:        if (!cfg)
                    116:                return -1;
                    117: 
1.1.2.3   misho     118:        str = (const char*) cfg_GetAttribute(cfg, CFG("mqttd"), CFG("statedir"));
1.1.2.2   misho     119:        if (!str)
                    120:                return -1;
                    121: 
                    122:        if (mkdir(str, 0600) == -1 && errno != EEXIST)
                    123:                return -1;
                    124: 
                    125:        return 0;
                    126: }

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