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

1.2       misho       1: #include "global.h"
                      2: #include "rtlm.h"
                      3: 
                      4: 
                      5: struct tagCallbacks call;
                      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 *
1.3     ! misho      26: mqttLoadRTLM(cfg_root_t *cfg, int modtype)
1.2       misho      27: {
                     28:        const char *str, *attr;
                     29:        void *rtlm = NULL;
1.3     ! misho      30:        void *(*mqttOpenRTLM)(cfg_root_t *);
1.2       misho      31:        void (*mqttCloseRTLM)(void *);
                     32: 
                     33:        if (!cfg)
                     34:                return NULL;
                     35: 
                     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: 
1.3     ! misho      48:        str = cfg_getAttribute(cfg, "mqttd", attr);
1.2       misho      49:        if (!str) {
                     50:                mqttLog("Error:: RTL module not found\n");
                     51:                return NULL;
                     52:        }
                     53: 
1.3     ! misho      54:        rtlm = dlopen(str, RTLD_NOW);
1.2       misho      55:        if (!rtlm) {
                     56:                mqttLog("Error:: RTL module %s not found %s\n", str, dlerror());
                     57:                return NULL;
                     58:        }
                     59: 
                     60:        mqttOpenRTLM = dlsym(rtlm, "mqtt_rtlm_open");
                     61:        if (!mqttOpenRTLM) {
1.3     ! misho      62:                mqttLog("Error:: Can't found mqtt_rtlm_open call\n");
1.2       misho      63:                dlclose(rtlm);
                     64:                return NULL;
                     65:        }
                     66:        mqttCloseRTLM = dlsym(rtlm, "mqtt_rtlm_close");
                     67:        if (!mqttCloseRTLM) {
1.3     ! misho      68:                mqttLog("Error:: Can't found mqtt_rtlm_close call\n");
1.2       misho      69:                dlclose(rtlm);
                     70:                return NULL;
                     71:        }
                     72: 
                     73:        switch (modtype) {
                     74:                case 0:
                     75:                        call.OpenACC = mqttOpenRTLM;
                     76:                        call.CloseACC = mqttCloseRTLM;
                     77:                        call.LoginACC = dlsym(rtlm, "mqtt_rtlm_login");
                     78:                        if (!call.LoginACC) {
                     79:                                mqttLog("Error:: incorrect module ...\n");
                     80:                                dlclose(rtlm);
                     81:                                return NULL;
                     82:                        }
                     83:                        break;
                     84:                case 1:
                     85:                        call.OpenPUB = mqttOpenRTLM;
                     86:                        call.ClosePUB = mqttCloseRTLM;
                     87:                        call.InitSessPUB = dlsym(rtlm, "mqtt_rtlm_init_session");
                     88:                        call.FiniSessPUB = dlsym(rtlm, "mqtt_rtlm_fini_session");
                     89:                        call.ChkSessPUB = dlsym(rtlm, "mqtt_rtlm_chk_session");
1.3     ! misho      90:                        call.WritePUB_topic = dlsym(rtlm, "mqtt_rtlm_write_topic");
        !            91:                        call.ReadPUB_topic = dlsym(rtlm, "mqtt_rtlm_read_topic");
        !            92:                        call.DeletePUB_topic = dlsym(rtlm, "mqtt_rtlm_delete_topic");
        !            93:                        call.WipePUB_topic = dlsym(rtlm, "mqtt_rtlm_wipe_topic");
        !            94:                        call.WritePUB_subscribe = dlsym(rtlm, "mqtt_rtlm_write_subscribe");
        !            95:                        call.ReadPUB_subscribe = dlsym(rtlm, "mqtt_rtlm_read_subscribe");
        !            96:                        call.DeletePUB_subscribe = dlsym(rtlm, "mqtt_rtlm_delete_subscribe");
1.2       misho      97:                        if (!call.InitSessPUB || !call.FiniSessPUB || !call.ChkSessPUB || 
1.3     ! misho      98:                                        !call.WritePUB_topic || !call.ReadPUB_topic || 
        !            99:                                        !call.DeletePUB_topic || !call.WritePUB_subscribe || 
        !           100:                                        !call.ReadPUB_subscribe || !call.DeletePUB_subscribe) {
1.2       misho     101:                                mqttLog("Error:: incorrect module ...\n");
                    102:                                dlclose(rtlm);
                    103:                                return NULL;
                    104:                        }
                    105:                        break;
                    106:                default:
                    107:                        call.OpenLOG = mqttOpenRTLM;
                    108:                        call.CloseLOG = mqttCloseRTLM;
                    109:                        call.LOG = dlsym(rtlm, "mqtt_rtlm_logger");
                    110:                        if (!call.LOG) {
                    111:                                mqttLog("Error:: incorrect module ...\n");
                    112:                                dlclose(rtlm);
                    113:                                return NULL;
                    114:                        }
                    115:                        break;
                    116:        }
                    117: 
                    118:        return rtlm;
                    119: }
                    120: 
                    121: void
1.3     ! misho     122: mqttUnloadRTLM(void *rtlm)
1.2       misho     123: {
1.3     ! misho     124:        if (rtlm)
        !           125:                dlclose(rtlm);
1.2       misho     126: }
                    127: 
                    128: inline int
1.3     ! misho     129: mqttMkDir(cfg_root_t *cfg)
1.2       misho     130: {
                    131:        const char *str;
                    132: 
                    133:        if (!cfg)
                    134:                return -1;
                    135: 
1.3     ! misho     136:        str = (const char*) cfg_getAttribute(cfg, "mqttd", "statedir");
1.2       misho     137:        if (!str)
                    138:                return -1;
                    139: 
                    140:        if (mkdir(str, 0600) == -1 && errno != EEXIST)
                    141:                return -1;
                    142: 
                    143:        return 0;
                    144: }

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