void nth_engine_destroy(nth_engine_t * he) { if (he) { size_t i; hc_htable_t *hct = he->he_clients; for (i = 0; i < hct->hct_size; i++) hc_free(hct->hct_table[i]); tport_destroy(he->he_tports); su_timer_destroy(he->he_timer), he->he_timer = NULL; su_home_unref(he->he_home); } }
struct hc * hc_start_request(char * url) { struct hc * hc; char * e; hc = malloc(sizeof *hc); memset(hc, 0, sizeof *hc); if (strncmp(url, "http://", 7) != 0) { goto error; } url += 7; e = strchr(url, '/'); if (!e) { hc->hostname = strdup(url); hc->localpart = strdup("/"); } else { hc->hostname = malloc(e - url + 1); if (!hc->hostname) goto error; memcpy(hc->hostname, url, e - url); hc->hostname[e-url] = '\0'; hc->localpart = strdup(e); if (!hc->localpart) goto error; } if (hc_add_req_header(hc, "Host", hc->hostname) < 0) goto error; e = strchr(hc->hostname, ':'); if (e) { *e = '\0'; hc->port = (short)strtoul(e+1, NULL, 10); } else { hc->port = 80; } hc->nc = nc_open(hc->hostname, hc->port); if (!hc->nc) goto error; return hc; error: if (hc) hc_free(hc); return NULL; }
unsigned long guide_client_get_snapshot(unsigned char ** presult, unsigned char ** ptimestamp, unsigned long * psize, const char * address, const char * cur_timestamp) { struct snapshot_data data; char url[512]; struct hc * hc; memset(&data, 0, sizeof data); data.firsttime = 1; data.status = -1; sprintf(url, "http://%s/http_replay_guide-get_snapshot?" "guide_file_name=%s&serial_no=RTV4080K0000000000", address, cur_timestamp); hc = hc_start_request(url); if (!hc) { perror("Error: guide_client_get_snapshot(): hc_start_request()"); goto exit; } hc_send_request(hc); hc_read_pieces(hc, get_snapshot_callback, &data); hc_free(hc); *ptimestamp = (unsigned char*)data.timestamp; *presult = (unsigned char*)data.buf; *psize = data.filesize; exit: return data.status; }
// // rtv_get_device_info // returns pointer to replaytv device. // int rtv_get_device_info(const char *address, char *queryStr, rtv_device_t **device_p) { char url[512]; struct hc *hc; int rc, new_entry; rtv_device_t *rtv; rtv_device_info_t *devinfo; RTV_DBGLOG(RTVLOG_DSCVR, "%s: Enter: address=%s: current_rtv_cnt=%d\n", __FUNCTION__, address, rtv_devices.num_rtvs); *device_p = NULL; rtv = rtv_get_device_struct(address, &new_entry); devinfo = &(rtv->device); if ( !(new_entry) ) { RTV_DBGLOG(RTVLOG_DSCVR, "%s: address=%s already exists in device struct. Decrement count.\n", __FUNCTION__, address); rtv_devices.num_rtvs--; } rtv_free_device_info(devinfo); devinfo->ipaddr = malloc(strlen(address) + 1); strcpy(devinfo->ipaddr, address); parser = XML_ParserCreate("US-ASCII"); XML_SetElementHandler(parser, devinfo_xml_start, devinfo_xml_end); XML_SetCharacterDataHandler(parser, devinfo_xml_charhndlr); XML_SetDefaultHandler(parser, devinfo_default_handler); XML_SetUserData(parser, devinfo); if ( queryStr == NULL ) { sprintf(url, "http://%s/Device_Descr.xml", address); RTV_DBGLOG(RTVLOG_DSCVR, "%s: Build default query str: %s\n", __FUNCTION__, url); } else { strncpy(url, queryStr, 511); RTV_DBGLOG(RTVLOG_DSCVR, "%s: Use supplied query str: %s\n", __FUNCTION__, url); } hc = hc_start_request(url); if (!hc) { RTV_ERRLOG("%s: hc_start_request(): %d=>%s\n", __FUNCTION__, errno, strerror(errno)); rtv_free_device_info(devinfo); return(-EPROTO); } hc_send_request(hc, NULL); rc = hc_read_pieces(hc, get_deviceinfo_callback, NULL, 0); hc_free(hc); if ( rc != 0 ) { RTV_ERRLOG("%s: hc_read_pieces call failed: rc=%d\n", __FUNCTION__, rc); rtv_free_device_info(devinfo); return(rc); } if ( (devinfo->status & RTV_EXPECTED_FIELDS) != RTV_EXPECTED_FIELDS ) { RTV_ERRLOG("%s: Missing XML Fields exp=%08X got=%08lX\n", __FUNCTION__, RTV_EXPECTED_FIELDS, devinfo->status); rtv_free_device_info(devinfo); return(-EBADE); } if ( (rc = parse_version_info(devinfo)) != 0 ) { } *device_p = rtv; rtv_devices.num_rtvs++; if ( RTVLOG_DSCVR ) { rtv_print_device_info(devinfo); } return (rc); }