uint8_t httplog(char status[140] ) { /* Transmission taking action */ if (httplog_tmp_buf) return 0; uint8_t len = strlen(status); if (len > 140) { HTTPLOG_DEBUG("message too long: cropping"); len = 140; } httplog_tmp_buf = malloc(140); if (!httplog_tmp_buf) return 0; memcpy(httplog_tmp_buf, status, len); httplog_tmp_buf[len] = 0; uip_ipaddr_t *ipaddr; if (!(ipaddr = resolv_lookup(CONF_HTTPLOG_SERVICE))) { resolv_query(CONF_HTTPLOG_SERVICE, httplog_dns_query_cb); } else { httplog_dns_query_cb(NULL, ipaddr); } return 1; }
static void httplog_net_main(void) { if (uip_aborted() || uip_timedout()) { HTTPLOG_DEBUG("connection aborted\n"); goto end; } if (uip_closed()) { HTTPLOG_DEBUG("connection closed\n"); goto end; } if (uip_connected() || uip_rexmit()) { HTTPLOG_DEBUG("new connection or rexmit, sending message\n"); char *p = uip_appdata; p += sprintf_P(p, get_string_head); #ifdef CONF_HTTPLOG_INCLUDE_UUID p += sprintf_P(p, uuid_string); #endif #ifdef CONF_HTTPLOG_INCLUDE_TIMESTAMP p += sprintf_P(p, time_string); p += sprintf(p, "%lu&", clock_get_time()); #endif p += sprintf(p, httplog_tmp_buf); p += sprintf_P(p, get_string_foot); uip_udp_send(p - (char *) uip_appdata); HTTPLOG_DEBUG("send %d bytes\n", p - (char *) uip_appdata); } if (uip_acked()) { uip_close(); end: if (httplog_tmp_buf) { free(httplog_tmp_buf); httplog_tmp_buf = NULL; } } }
static void httplog_dns_query_cb(char *name, uip_ipaddr_t *ipaddr) { HTTPLOG_DEBUG("got dns response, connecting\n"); if(!uip_connect(ipaddr, HTONS(80), httplog_net_main)) { if (httplog_tmp_buf) { free(httplog_tmp_buf); httplog_tmp_buf = NULL; } } }