int cb_bz_RecordsCount_get(cb_t cb, const char *namedcmd, unsigned long int *count) { /* TODO: the number of results is almost at the top of the page. * So we can terminate the connection as soon as we read that number * (with custom writefunction callback) * and _maybe_ save some resources but probably not. */ if(count == NULL) return -EINVAL; char *url = strdup(cb->url.mem); CB_ENULL(url); char *namedcmd_e = curl_easy_escape(cb->curl, namedcmd, strlen(namedcmd)); CB_ENULL(namedcmd_e); int len = strlen(url_namedcmd) -2 + strlen(namedcmd_e) +1; char query[len]; if(0 > snprintf(query, len, url_namedcmd, namedcmd_e)) return CB_E; url = realloc(url, sizeof(char)*(cb->url.len + strlen(query))); CB_ENULL(url); url = strcat(url, query); CB_ENULL(url); CB_CURLE(curl_easy_setopt(cb->curl, CURLOPT_URL, url)); CB_CURLE(curl_easy_setopt(cb->curl, CURLOPT_HTTPGET, 1L)); CB_CURLE(curl_easy_setopt(cb->curl, CURLOPT_FOLLOWLOCATION, 1)); // BZ will respond with 302 to <oururl>&list_id=X // so follow it CB_BO(cb->curl_perform(cb)); char *headline; headline = calloc(100, sizeof(char)); if(0 > sprintf(headline, "rec: %93s\n", namedcmd)) return CB_E; cb->log_response(cb, headline); TidyDoc tdoc; CB_BO(cb_tidy_loadBuf(&tdoc, cb->response.mem, cb->response.size)); CB_BO(cb_parse_recordsCount(tdoc, tidyGetBody(tdoc), count)); return CB_SUCCESS; }
static void php_tidy_create_node(INTERNAL_FUNCTION_PARAMETERS, tidy_base_nodetypes node_type) { PHPTidyObj *newobj; TidyNode node; TIDY_FETCH_OBJECT; switch (node_type) { case is_root_node: node = tidyGetRoot(obj->ptdoc->doc); break; case is_html_node: node = tidyGetHtml(obj->ptdoc->doc); break; case is_head_node: node = tidyGetHead(obj->ptdoc->doc); break; case is_body_node: node = tidyGetBody(obj->ptdoc->doc); break; default: RETURN_NULL(); break; } if (!node) { RETURN_NULL(); } tidy_instanciate(tidy_ce_node, return_value); newobj = Z_TIDY_P(return_value); newobj->type = is_node; newobj->ptdoc = obj->ptdoc; newobj->node = node; newobj->ptdoc->ref_count++; tidy_add_default_properties(newobj, is_node); }