Overview: Network

Summary
Overview: Network
Network InterfaceAllows overriding the default use of libcurl in libquvi.
RequirementsAn application must set the necessary properties in its corresponding callbacks.
Common properties
quvi_callback_fetch
quvi_callback_resolve
quvi_callback_verify
ExampleBasic example.

Network Interface

Allows overriding the default use of libcurl in libquvi.  For example, an application could use libsoup instead of libcurl.

Requirements

An application must set the necessary properties in its corresponding callbacks.  Besides the Common properties, each callback is expected to set any additional properties listed below.

Common properties

quvi_net_setprop(net_handle, QUVI_NET_PROPERTY_RESPONSECODE, resp_code);

Common properties that are expected to be set by all callbacks.

quvi_callback_fetch

quvi_setopt(session_handle, QUVIOPT_FETCHFUNCTION, &fetch_callback_func);

In addition to the Common properties, must set

Return

quvi_callback_resolve

quvi_setopt(session_handle, QUVIOPT_RESOLVEFUNCTION, &resolve_callback_func);

In addition to the Common properties -- if a redirection to another location was found, then must set

Notes

This callback should return QUVI_CALLBACK only if an unrecoverable error occurred, e.g. a network error.  Return QUVI_OK in all other cases, including those in which a redirection URL was not found.

Return

quvi_callback_verify

quvi_setopt(session_handle, QUVIOPT_VERIFYFUNCTION, &verify_callback_func);

In addition to the Common properties, must set

Return

Example

Basic example.  This example assumes that a fictional `do_fetch’ function fetches the data over the network.  The callback then relays the data and any errors back to libquvi.  Some error checks omitted for brewity.

static QUVIcode fetch_callback(quvi_net_t net_handle)
{
  char *url, *reason, *content;
  long resp_code;
  int fetch_ok;

  quvi_net_getprop(net_handle, QUVI_NET_PROPERTY_URL, &url);

  fetch_ok = do_fetch(url, &content, &resp_code, &reason);

  quvi_net_setprop(net_handle, QUVI_NET_PROPERTY_RESPONSECODE, resp_code);

  if (fetch_ok)
    {
      quvi_net_setprop(net_handle, QUVI_NET_PROPERTY_CONTENT, content);
      return (QUVI_OK);
    }

  quvi_net_seterr(net_handle, "%s (http/%d)", reason, resp_code);

  return (QUVI_CALLBACK); /* Tell the library an error occurred */
}

int main(int argc, char **argv)
{
  quvi_t q;
  quvi_init(&q);
  quvi_setopt(q, QUVIOPT_FETCHFUNCTION, &fetch_callback);
  quvi_parse(...);
  quvi_close(&q);
  return (0);
}
Response code returned by the server
Content
No error
Network callback error occurred
URL to another location
Content-type from returned HTTP header
Content-length from returned HTTP header
Close