264 struct string response, header_data;
266 if (item == NULL || port < 0 || handle_id < 0)
269 "Error : http2_* functions have the following syntax :\n");
270 nasl_perror (lexic,
"http_*(handle: <handle>, port:<port>, item:<item> "
271 "[,schema:<schema>][, data:<data>]\n");
275 unsigned int table_slot;
276 for (table_slot = 0; table_slot <
MAX_HANDLES; table_slot++)
282 g_message (
"%s: Unknown handle identifier %d", __func__, handle_id);
289 if (port <= 0 || port > 65535)
291 nasl_perror (lexic,
"http2_req: invalid value %d for port parameter\n",
301 curl_easy_reset (handle);
304 curl_easy_setopt (handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
307 url = schema ? g_string_new (schema) : g_string_new (
"https");
308 g_string_append (url,
"://");
318 if (port != 80 && port != 443)
321 snprintf (buf,
sizeof (buf),
":%d", port);
322 g_string_append (url, buf);
324 g_string_append (url, item);
326 g_message (
"%s: URL: %s", __func__, url->str);
328 if (curl_easy_setopt (handle, CURLOPT_URL, url->str) != CURLE_OK)
330 g_warning (
"Not possible to set the URL");
331 curl_easy_cleanup (handle);
334 g_string_free (url, TRUE);
337 curl_easy_setopt (handle, CURLOPT_SSL_VERIFYPEER, 0L);
338 curl_easy_setopt (handle, CURLOPT_SSL_VERIFYHOST, 0L);
345 g_message (
"Not possible to send the User Agent to the host process. "
346 "Invalid IPC context");
350 curl_easy_setopt (handle, CURLOPT_USERAGENT, g_strdup (url->str));
357 curl_easy_setopt (handle, CURLOPT_WRITEDATA, &response);
361 curl_easy_setopt (handle, CURLOPT_HEADERDATA, &header_data);
366 curl_easy_setopt (handle, CURLOPT_CUSTOMREQUEST,
"DELETE");
369 curl_easy_setopt (handle, CURLOPT_NOBODY, 1L);
372 curl_easy_setopt (handle, CURLOPT_CUSTOMREQUEST,
"PUT");
375 curl_easy_setopt (handle, CURLOPT_POSTFIELDS, data);
376 curl_easy_setopt (handle, CURLOPT_POSTFIELDSIZE, strlen (data));
380 curl_easy_setopt (handle, CURLOPT_HTTPGET, 1L);
386 curl_easy_setopt (handle, CURLOPT_POSTFIELDS, data);
387 curl_easy_setopt (handle, CURLOPT_POSTFIELDSIZE, strlen (data));
391 g_message (
"%s: Invalid http method.", __func__);
396 if ((ret = curl_easy_perform (handle)) != CURLE_OK)
398 g_warning (
"%s: Error sending request: %d", __func__, ret);
399 curl_easy_cleanup (handle);
400 g_free (response.
ptr);
404 GString *complete_resp = g_string_new (header_data.
ptr);
405 g_string_append (complete_resp,
"\n");
406 g_string_append (complete_resp, response.
ptr);
407 g_free (response.
ptr);
408 g_free (header_data.
ptr);
411 curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &http_code);
415 retc->
size = complete_resp->len;
416 retc->
x.
str_val = g_strdup (complete_resp->str);
418 g_string_free (complete_resp, TRUE);