Esempio n. 1
0
int main()	{
	curl_response_t*	res;
	char				url[140*2];
	int					ret;
	int					is_post;

	res = create_curl_response();
	is_post = 1;
	sprintf(url, "http://www.daum.net/");
	fprintf(stdout, "url = %s\tis_post = %d\n", url, is_post);
	ret = curl_fetch(res, url, is_post, "");
	destroy_curl_response(res);
	return 0;
}
/* start a transfer now */
static void fetch_now(const userinput *const u, const char *uploaddir, char *name, char *url)
{
  off_t resumesize;
  fetch_curl_t *ft;
  char *fullfile;
  FILE *writefd;
  struct stat s;
  int retval;

  resumesize = 0;
  fullfile = mystrjoin(uploaddir, name, '/');
  writefd = fopen(fullfile, "w+x"); /* NOTRANSLATE */
  if ((writefd == NULL) && (errno == EEXIST)) {
    retval = stat(fullfile, &s);
    if (retval < 0) {
      outerror(OUTERROR_TYPE_WARN_LOUD, "Cant Stat Upload File '%s': %s",
               fullfile, strerror(errno));
      a_respond(u, "File Error, File couldn't be opened for writing");
      mydelete(fullfile);
      return;
    }
    resumesize = s.st_size;
    writefd = fopen(fullfile, "a+"); /* NOTRANSLATE */
  }
  if (writefd == NULL) {
    outerror(OUTERROR_TYPE_WARN_LOUD, "Cant Access Upload File '%s': %s",
             fullfile, strerror(errno));
    a_respond(u, "File Error, File couldn't be opened for writing");
    mydelete(fullfile);
    return;
  }

  updatecontext();
  ft = irlist_add(&fetch_trans, sizeof(fetch_curl_t));
  ft->u.method = u->method;
  if (u->snick != NULL) {
    ft->u.snick = mystrdup(u->snick);
  }
  ft->u.fd = u->fd;
  ft->u.chat = u->chat;
  ft->id = ++fetch_id;
  ft->net = gnetwork->net;
  ft->name = mystrdup(name);
  ft->url = mystrdup(url);
  ft->uploaddir = mystrdup(uploaddir);
  ft->fullname = fullfile;
  fullfile = NULL;
  ft->writefd = writefd;
  ft->resumesize = resumesize;
  ft->errorbuf = mymalloc(CURL_ERROR_SIZE);
  ft->errorbuf[0] = 0;
  ft->starttime = gdata.curtime;

  if (curl_fetch(u, ft)) {
    clean_fetch(ft);
    return;
  }

  a_respond(u, "fetch '%s' started", ft->name);
  ++fetch_started;
}
Esempio n. 3
0
QUVIcode fetch_wrapper(_quvi_t q, lua_State *l, _quvi_net_t *n)
{
  const char *url;
  QUVIcode rc;

  url = luaL_checkstring(l,1);
  rc  = QUVI_OK;

  if (q->status_func)
    {
      QUVIstatusType stat_type = QUVISTATUSTYPE_PAGE; /* Default */

      if (lua_istable(l,2))
        {
          const char *s = NULL;

          lua_pushstring(l, "fetch_type");
          lua_gettable(l,2);

          if (lua_isstring(l,-1))
            s = lua_tostring(l,-1);

          if (s)
            {
              if (strcmp(s, "config") == 0)
                stat_type = QUVISTATUSTYPE_CONFIG;

              else if (strcmp(s, "playlist") == 0)
                stat_type = QUVISTATUSTYPE_PLAYLIST;
            }
        }

      if (q->status_func(_makelong(QUVISTATUS_FETCH, stat_type),
                         (void *)url) != QUVI_OK)
        {
          return (QUVI_ABORTEDBYCALLBACK);
        }
    }

  *n = new_net_handle();
  if (! (*n))
    return (QUVI_MEM);

  freprintf(&(*n)->url, "%s", url);

  /* Features from LUA script (quvi.fetch). */

  if (lua_istable(l,2))
    {
      int i;
      for (i=1; net_prop_feats[i]; ++i)
        {
          lua_pushstring(l, net_prop_feats[i]);
          lua_gettable(l,2);
          if (lua_isstring(l,-1))
            {
              rc = new_feat(*n, net_prop_feats[i], lua_tostring(l,-1));
              if (rc != QUVI_OK)
                return (rc);
            }
        }
    }

  if (q->fetch_func)
    rc = q->fetch_func(*n);
  else
    rc = curl_fetch(q, *n);

  if (rc == QUVI_OK && (*n)->resp_code == 200)
    {
      assert((*n)->fetch.content != NULL);

      if (q->status_func)
        {
          if (q->status_func(_makelong(QUVISTATUS_FETCH,
                                       QUVISTATUSTYPE_DONE), 0) != QUVI_OK)
            {
              rc = QUVI_ABORTEDBYCALLBACK;
            }
        }
    }
  else
    {
      if ((*n)->errmsg)
        freprintf(&q->errmsg, "%s", (*n)->errmsg);
    }

  q->resp_code = (*n)->resp_code;

  return (rc);
}