PubNub Example.
Copyright (c) 2016-2018 Microchip Technology Inc. and its subsidiaries.
Functions | |
static int | find_string_start (char const *buf, int len) |
void | handle_dns_found (char const *name, uint32_t hostip) |
static void | handle_start_connect (pubnub_t *pb) |
Handles start of a TCP(HTTP) connection. More... | |
void | handle_tcpip (SOCKET sock, uint8_t u8Msg, void *pvMsg) |
static void | handle_tcpip_connect (SOCKET sock, uint8_t u8Msg, void *pvMsg) |
static void | handle_tcpip_recv (SOCKET sock, uint8_t u8Msg, void *pvMsg) |
static void | handle_transaction (pubnub_t *pb) |
static int | parse_subscribe_response (pubnub_t *p) |
static pubnub_t * | pubnub_find_ctx (SOCKET sock, enum pubnub_state state) |
char const * | pubnub_get (pubnub_t *pb) |
pubnub_t * | pubnub_get_ctx (uint8_t index) |
Return a context for the given index. More... | |
void | pubnub_init (pubnub_t *pb, const char *publish_key, const char *subscribe_key) |
Initialize the PubNub Client API. More... | |
bool | pubnub_publish (pubnub_t *pb, const char *channel, const char *message) |
bool | pubnub_subscribe (pubnub_t *pb, const char *channel) |
static bool | split_array (char *buf) |
Split buf string containing a JSON array (with arbitrary contents) to multiple NUL-terminated C strings, in-place. More... | |
static bool | valid_ctx_prt (pubnub_t const *pb) |
Variables | |
static struct pubnub | m_aCtx [PUBNUB_CTX_MAX] |
struct sockaddr_in | pubnub_origin_addr |
|
static |
References i.
Referenced by parse_subscribe_response().
void handle_dns_found | ( | char const * | name, |
uint32_t | hostip | ||
) |
|
static |
Handles start of a TCP(HTTP) connection.
References _htons, AF_INET, assert, connect(), gethostbyname(), PS_IDLE, PS_WAIT_CONNECT, PS_WAIT_DNS, PUBNUB_ORIGIN, pubnub_origin_addr, PUBNUB_ORIGIN_PORT, in_addr::s_addr, sockaddr_in::sin_addr, sockaddr_in::sin_family, sockaddr_in::sin_port, SOCK_STREAM, socket(), pubnub::state, pubnub::tcp_socket, and valid_ctx_prt().
Referenced by handle_dns_found(), pubnub_publish(), and pubnub_subscribe().
void handle_tcpip | ( | SOCKET | sock, |
uint8_t | u8Msg, | ||
void * | pvMsg | ||
) |
References handle_tcpip_connect(), handle_tcpip_recv(), handle_transaction(), NULL, PS_WAIT_RECV, PS_WAIT_SEND, tstrSocketRecvMsg::pu8Buffer, pubnub_find_ctx(), PUBNUB_PRINTF, tstrSocketRecvMsg::s16BufferSize, SOCKET_MSG_CONNECT, SOCKET_MSG_RECV, SOCKET_MSG_SEND, pubnub::state, and tstrSocketRecvMsg::u16RemainingSize.
|
static |
References close(), handle_transaction(), pubnub::last_result, NULL, PNR_IO_ERROR, PS_IDLE, PS_WAIT_CONNECT, PS_WAIT_SEND, pubnub_find_ctx(), PUBNUB_PRINTF, tstrSocketConnectMsg::s8Error, pubnub::state, and pubnub::tcp_socket.
Referenced by handle_tcpip().
|
static |
References close(), content, pubnub::http_content_len, pubnub::http_content_remaining_len, pubnub::http_reply, pubnub::last_result, length, m2m_strstr(), m_aCtx, NULL, parse_subscribe_response(), PBTT_PUBLISH, PNR_IO_ERROR, PNR_OK, PS_IDLE, PS_WAIT_RECV, tstrSocketRecvMsg::pu8Buffer, PUBNUB_CTX_MAX, PUBNUB_PRINTF, tstrSocketRecvMsg::s16BufferSize, pubnub::state, pubnub::tcp_socket, pubnub::timetoken, pubnub::trans, and tstrSocketRecvMsg::u16RemainingSize.
Referenced by handle_tcpip().
|
static |
References buf, pubnub::http_buf, PS_RECV, PS_WAIT_RECV, PS_WAIT_SEND, PUBNUB_BUF_MAXLEN, PUBNUB_ORIGIN, PUBNUB_PRINTF, PUBNUB_REQUEST, recv(), send(), pubnub::state, pubnub::tcp_socket, and pubnub::url.
Referenced by handle_tcpip(), handle_tcpip_connect(), pubnub_publish(), and pubnub_subscribe().
|
static |
References pubnub::chan_end, pubnub::chan_ofs, find_string_start(), pubnub::http_reply, i, pubnub::msg_end, pubnub::msg_ofs, split_array(), and pubnub::timetoken.
Referenced by handle_tcpip_recv().
|
static |
References m_aCtx, NULL, PUBNUB_CTX_MAX, pubnub::state, and pubnub::tcp_socket.
Referenced by handle_tcpip(), and handle_tcpip_connect().
char const* pubnub_get | ( | pubnub_t * | pb | ) |
References assert, pubnub::http_reply, pubnub::msg_end, pubnub::msg_ofs, NULL, and valid_ctx_prt().
pubnub_t* pubnub_get_ctx | ( | uint8_t | index | ) |
Return a context for the given index.
Contexts are statically allocated by the PubNub library and this is the only to get a pointer to one of them.
References assert, m_aCtx, and PUBNUB_CTX_MAX.
void pubnub_init | ( | pubnub_t * | pb, |
const char * | publish_key, | ||
const char * | subscribe_key | ||
) |
Initialize the PubNub Client API.
References assert, pubnub::auth, pubnub::last_result, NULL, PNR_IO_ERROR, PS_IDLE, pubnub::publish_key, pubnub::state, pubnub::subscribe_key, pubnub::tcp_socket, pubnub::timetoken, pubnub::uuid, and valid_ctx_prt().
References assert, pubnub::auth, handle_start_connect(), handle_transaction(), pubnub::http_buf, pubnub::http_buf_len, pubnub::http_reply, pubnub::last_result, PBTT_SUBSCRIBE, PNR_OK, PS_IDLE, PS_WAIT_SEND, PUBNUB_REPLY_MAXLEN, pubnub::state, pubnub::subscribe_key, pubnub::timetoken, pubnub::trans, pubnub::url, pubnub::uuid, and valid_ctx_prt().
|
static |
Split buf
string containing a JSON array (with arbitrary contents) to multiple NUL-terminated C strings, in-place.
References buf.
Referenced by parse_subscribe_response().
References m_aCtx, and PUBNUB_CTX_MAX.
Referenced by handle_start_connect(), pubnub_get(), pubnub_init(), pubnub_publish(), and pubnub_subscribe().
|
static |
Referenced by handle_dns_found(), handle_tcpip_recv(), pubnub_find_ctx(), pubnub_get_ctx(), and valid_ctx_prt().
struct sockaddr_in pubnub_origin_addr |