|
version 1.2, 2012/01/27 15:05:38
|
version 1.2.2.2, 2012/01/30 13:39:22
|
|
Line 1
|
Line 1
|
| #include "global.h" |
#include "global.h" |
| #include "mqttd.h" |
#include "mqttd.h" |
| |
#include "rtlm.h" |
| #include "mqttd_calls.h" |
#include "mqttd_calls.h" |
| |
|
| |
|
| int |
int |
| Publish(struct tagSession *sess) | cmdPUBLISH(void *srv, void *arg) |
| { |
{ |
| struct mqtthdr *hdr; |
struct mqtthdr *hdr; |
| |
struct tagSession *sess = (struct tagSession*) arg; |
| |
|
| ioTRACE(2); |
ioTRACE(2); |
| |
|
|
Line 27 Publish(struct tagSession *sess)
|
Line 29 Publish(struct tagSession *sess)
|
| return 0; |
return 0; |
| } |
} |
| |
|
| |
return 0; |
| |
} |
| |
|
| |
int |
| |
cmdPUBREL(void *srv, void *arg) |
| |
{ |
| |
struct mqtthdr *hdr; |
| |
struct tagSession *sess = (struct tagSession*) arg; |
| |
|
| |
ioTRACE(2); |
| |
|
| |
if (!sess) |
| |
return -1; |
| |
|
| |
hdr = (struct mqtthdr*) sess->sess_buf->msg_base; |
| |
|
| |
return 0; |
| |
} |
| |
|
| |
int |
| |
cmdSUBSCRIBE(void *srv, void *arg) |
| |
{ |
| |
struct mqtthdr *hdr; |
| |
struct tagSession *sess = (struct tagSession*) arg; |
| |
|
| |
ioTRACE(2); |
| |
|
| |
if (!sess) |
| |
return -1; |
| |
|
| |
hdr = (struct mqtthdr*) sess->sess_buf->msg_base; |
| |
|
| |
return 0; |
| |
} |
| |
|
| |
int |
| |
cmdUNSUBSCRIBE(void *srv, void *arg) |
| |
{ |
| |
struct mqtthdr *hdr; |
| |
struct tagSession *sess = (struct tagSession*) arg; |
| |
|
| |
ioTRACE(2); |
| |
|
| |
if (!sess) |
| |
return -1; |
| |
|
| |
hdr = (struct mqtthdr*) sess->sess_buf->msg_base; |
| |
|
| |
return 0; |
| |
} |
| |
|
| |
int |
| |
cmdPINGREQ(void *srv, void *arg) |
| |
{ |
| |
struct mqtthdr *hdr; |
| |
struct tagSession *sess = (struct tagSession*) arg; |
| |
int siz = 0; |
| |
|
| |
ioTRACE(2); |
| |
|
| |
if (!sess) |
| |
return -1; |
| |
|
| |
hdr = (struct mqtthdr*) sess->sess_buf->msg_base; |
| |
siz = mqtt_msgPINGRESP(sess->sess_buf); |
| |
if (siz == -1) { |
| |
ioDEBUG(5, "Error:: in msgPINGRESP #%d - %s", mqtt_GetErrno(), mqtt_GetError()); |
| |
return 0; |
| |
} |
| |
if ((siz = send(sess->sess_sock, sess->sess_buf->msg_base, siz, 0)) == -1) { |
| |
ioSYSERR(0); |
| |
return 0; |
| |
} else |
| |
ioDEBUG(5, "Sended %d bytes.", siz); |
| |
|
| |
return 0; |
| |
} |
| |
|
| |
int |
| |
cmdCONNECT(void *srv, void *arg) |
| |
{ |
| |
struct tagStore *store; |
| |
struct tagSession *sess = (struct tagSession*) arg; |
| |
|
| |
ioTRACE(2); |
| |
|
| |
if (!sess) |
| |
return -1; |
| |
|
| |
pthread_mutex_lock(&mtx_sess); |
| |
TAILQ_REMOVE(&Sessions, sess, sess_node); |
| |
pthread_mutex_unlock(&mtx_sess); |
| |
|
| |
if (call.FiniSessPUB) |
| |
call.FiniSessPUB(&cfg, pub, sess->sess_cid, sess->sess_user, "%"); |
| |
|
| |
pthread_mutex_lock(&sess->sess_mtx); |
| |
while ((store = TAILQ_FIRST(&sess->sess_sndqueue))) { |
| |
TAILQ_REMOVE(&sess->sess_sndqueue, store, st_node); |
| |
|
| |
if (store->st_subscr.sub_topic.msg_base) |
| |
free(store->st_subscr.sub_topic.msg_base); |
| |
if (store->st_subscr.sub_value.msg_base) |
| |
free(store->st_subscr.sub_value.msg_base); |
| |
|
| |
free(store); |
| |
} |
| |
pthread_mutex_unlock(&sess->sess_mtx); |
| |
|
| |
if (sess->sess_will.msg) |
| |
free(sess->sess_will.msg); |
| |
if (sess->sess_will.topic) |
| |
free(sess->sess_will.topic); |
| |
|
| |
call.LOG(logg, "Session %s stopped from %s for user %s.\n", sess->sess_cid, |
| |
sess->sess_addr, sess->sess_user); |
| |
return 0; |
| |
} |
| |
|
| |
int |
| |
cmdDISCONNECT(void *srv, void *arg) |
| |
{ |
| |
struct tagSession *sess = (struct tagSession*) arg; |
| |
|
| |
ioTRACE(2); |
| |
|
| |
if (!sess) |
| |
return -1; |
| |
|
| |
pthread_mutex_lock(&mtx_sess); |
| |
TAILQ_REMOVE(&Sessions, sess, sess_node); |
| |
pthread_mutex_unlock(&mtx_sess); |
| |
|
| |
call.LOG(logg, "Session %s stopped from %s for user %s.\n", sess->sess_cid, |
| |
sess->sess_addr, sess->sess_user); |
| return 0; |
return 0; |
| } |
} |