Blame src/api/set.c

Packit 3ff1e7
/* libquvi
Packit 3ff1e7
 * Copyright (C) 2012,2013  Toni Gundogdu <legatvs@gmail.com>
Packit 3ff1e7
 *
Packit 3ff1e7
 * This file is part of libquvi <http://quvi.sourceforge.net/>.
Packit 3ff1e7
 *
Packit 3ff1e7
 * This library is free software: you can redistribute it and/or
Packit 3ff1e7
 * modify it under the terms of the GNU Affero General Public
Packit 3ff1e7
 * License as published by the Free Software Foundation, either
Packit 3ff1e7
 * version 3 of the License, or (at your option) any later version.
Packit 3ff1e7
 *
Packit 3ff1e7
 * This library is distributed in the hope that it will be useful,
Packit 3ff1e7
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 3ff1e7
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 3ff1e7
 * GNU Affero General Public License for more details.
Packit 3ff1e7
 *
Packit 3ff1e7
 * You should have received a copy of the GNU Affero General
Packit 3ff1e7
 * Public License along with this library.  If not, see
Packit 3ff1e7
 * <http://www.gnu.org/licenses/>.
Packit 3ff1e7
 */
Packit 3ff1e7
Packit 3ff1e7
/** @file set.c */
Packit 3ff1e7
Packit 3ff1e7
#include "config.h"
Packit 3ff1e7
Packit 3ff1e7
#include <glib.h>
Packit 3ff1e7
#include <curl/curl.h>
Packit 3ff1e7
Packit 3ff1e7
#include "quvi.h"
Packit 3ff1e7
/* -- */
Packit 3ff1e7
#include "_quvi_s.h"
Packit 3ff1e7
Packit 3ff1e7
static QuviError _set(_quvi_t q, const QuviOption o, va_list arg)
Packit 3ff1e7
{
Packit 3ff1e7
  switch (o)
Packit 3ff1e7
    {
Packit 3ff1e7
    case QUVI_OPTION_ALLOW_COOKIES:
Packit 3ff1e7
      q->opt.allow_cookies = (gboolean) va_arg(arg, glong) >0;
Packit 3ff1e7
      break;
Packit 3ff1e7
Packit 3ff1e7
    case QUVI_OPTION_AUTOPROXY:
Packit 3ff1e7
      q->opt.autoproxy = (gboolean) va_arg(arg, glong) >0;
Packit 3ff1e7
      break;
Packit 3ff1e7
Packit 3ff1e7
    case QUVI_OPTION_USER_AGENT:
Packit 3ff1e7
      /* Save for later use: c_reset will reuse this value. */
Packit 3ff1e7
      g_string_assign(q->opt.user_agent, va_arg(arg, gchar*));
Packit 3ff1e7
      /* Apply for immediate effect. */
Packit 3ff1e7
      curl_easy_setopt(q->handle.curl, CURLOPT_USERAGENT,
Packit 3ff1e7
                       q->opt.user_agent->str);
Packit 3ff1e7
      break;
Packit 3ff1e7
Packit 3ff1e7
    case QUVI_OPTION_CALLBACK_STATUS:
Packit 3ff1e7
      q->cb.status = va_arg(arg, quvi_callback_status);
Packit 3ff1e7
      break;
Packit 3ff1e7
Packit 3ff1e7
    case QUVI_OPTION_CALLBACK_STATUS_USERDATA:
Packit 3ff1e7
      q->cb.userdata.status = va_arg(arg, void*);
Packit 3ff1e7
      break;
Packit 3ff1e7
Packit 3ff1e7
    default:
Packit 3ff1e7
      return (QUVI_ERROR_INVALID_ARG);
Packit 3ff1e7
    }
Packit 3ff1e7
Packit 3ff1e7
  return (QUVI_OK);
Packit 3ff1e7
}
Packit 3ff1e7
Packit 3ff1e7
/** @brief Set library handle option
Packit 3ff1e7
@sa @ref getting_started
Packit 3ff1e7
@ingroup lib
Packit 3ff1e7
*/
Packit 3ff1e7
void quvi_set(quvi_t handle, QuviOption option, ...)
Packit 3ff1e7
{
Packit 3ff1e7
  va_list arg;
Packit 3ff1e7
  _quvi_t q;
Packit 3ff1e7
Packit 3ff1e7
  /* If G_DISABLE_CHECKS is defined then the check is not performed. */
Packit 3ff1e7
  g_return_if_fail(handle != NULL);
Packit 3ff1e7
Packit 3ff1e7
  q = (_quvi_t) handle;
Packit 3ff1e7
Packit 3ff1e7
  va_start(arg, option);
Packit 3ff1e7
  q->status.rc = _set(handle, option, arg);
Packit 3ff1e7
  va_end(arg);
Packit 3ff1e7
}
Packit 3ff1e7
Packit 3ff1e7
/* vim: set ts=2 sw=2 tw=72 expandtab: */