StringArray HTTPClient::_get_response_headers() { List<String> rh; get_response_headers(&rh); StringArray ret; ret.resize(rh.size()); int idx=0; for(const List<String>::Element *E=rh.front();E;E=E->next()) { ret.set(idx++,E->get()); } return ret; }
Dictionary HTTPClient::_get_response_headers_as_dictionary() { List<String> rh; get_response_headers(&rh); Dictionary ret; for (const List<String>::Element *E = rh.front(); E; E = E->next()) { String s = E->get(); int sp = s.find(":"); if (sp == -1) continue; String key = s.substr(0, sp).strip_edges(); String value = s.substr(sp + 1, s.length()).strip_edges(); ret[key] = value; } return ret; }
static int prov_sc_query_records(PROVISIONING_SERVICE_CLIENT_HANDLE prov_client, PROVISIONING_QUERY_SPECIFICATION* query_spec, char** cont_token_ptr, PROVISIONING_QUERY_RESPONSE** query_res_ptr, const char* path_format) { int result = 0; if (prov_client == NULL) { LogError("Invalid Provisioning Client Handle"); result = __FAILURE__; } else if (query_spec == NULL || query_spec->version != PROVISIONING_QUERY_SPECIFICATION_VERSION_1) { LogError("Invalid Query details"); result = __FAILURE__; } else if (cont_token_ptr == NULL) { LogError("Invalid Continuation Token pointer"); result = __FAILURE__; } else if (query_res_ptr == NULL) { LogError("Invalid Query Response pointer"); result = __FAILURE__; } else { char* content = NULL; //do not serialize the query specification if there is no query_string (i.e. DRS query) if ((query_spec->query_string != NULL) && ((content = querySpecification_serializeToJson(query_spec)) == NULL)) { LogError("Failure serializing query specification"); result = __FAILURE__; } else { STRING_HANDLE registration_path = create_registration_path(path_format, query_spec->registration_id); if (registration_path == NULL) { LogError("Failed to construct a registration path"); result = __FAILURE__; } else { HTTP_HEADERS_HANDLE request_headers; if ((request_headers = construct_http_headers(prov_client, NULL, HTTP_CLIENT_REQUEST_POST)) == NULL) { LogError("Failure constructing http headers"); result = __FAILURE__; } else if ((add_query_headers(request_headers, query_spec->page_size, *cont_token_ptr)) != 0) { LogError("Failure adding query headers"); result = __FAILURE__; } else { result = rest_call(prov_client, HTTP_CLIENT_REQUEST_POST, STRING_c_str(registration_path), request_headers, content); if (result == 0) { const char* resp_type = NULL; char* new_cont_token = NULL; PROVISIONING_QUERY_TYPE type; if (get_response_headers(prov_client, &new_cont_token, &resp_type) != 0) { LogError("Failure reading response headers"); result = __FAILURE__; } else if ((type = queryType_stringToEnum(resp_type)) == QUERY_TYPE_INVALID) { LogError("Failure to parse response type"); result = __FAILURE__; } else if ((*query_res_ptr = queryResponse_deserializeFromJson(prov_client->response, type)) == NULL) { LogError("Failure deserializing query response"); result = __FAILURE__; } free(*cont_token_ptr); *cont_token_ptr = new_cont_token; } else { LogError("Rest call failed"); } clear_response(prov_client); } HTTPHeaders_Free(request_headers); } STRING_delete(registration_path); } free(content); } return result; }