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 |
Referenced by parse_subscribe_response().
void handle_dns_found | ( | char const * | name, |
uint32_t | hostip | ||
) |
References handle_start_connect(), m_aCtx, PS_WAIT_DNS, PUBNUB_CTX_MAX, PUBNUB_ORIGIN, pubnub_origin_addr, in_addr::s_addr, sockaddr_in::sin_addr, and pubnub::state.
Referenced by socket_resolve_cb().
|
static |
Handles start of a TCP(HTTP) connection.
References _htons, AF_INET, CONF_WINC_PRINTF, 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.
Referenced by m2m_tcp_socket_handler().
|
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(), pubnub::http_content_len, pubnub::http_content_remaining_len, pubnub::http_reply, pubnub::last_result, 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 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, 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 pubnub::http_reply, pubnub::msg_end, pubnub::msg_ofs, NULL, and valid_ctx_prt().
Referenced by main().
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 m_aCtx, and PUBNUB_CTX_MAX.
Referenced by main().
void pubnub_init | ( | pubnub_t * | pb, |
const char * | publish_key, | ||
const char * | subscribe_key | ||
) |
Initialize the PubNub Client API.
References 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().
Referenced by main().
References handle_start_connect(), handle_transaction(), pubnub::http_buf, pubnub::http_buf_len, pubnub::last_result, PBTT_PUBLISH, PNR_OK, PS_IDLE, PS_WAIT_SEND, pubnub::publish_key, PUBNUB_PRINTF, pubnub::state, pubnub::subscribe_key, pubnub::trans, pubnub::url, and valid_ctx_prt().
Referenced by main().
References 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().
Referenced by main().
|
static |
Split buf
string containing a JSON array (with arbitrary contents) to multiple NUL-terminated C strings, in-place.
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 |
Referenced by handle_dns_found(), and handle_start_connect().