Skip to content
Snippets Groups Projects
main.c 120 KiB
Newer Older
/***************************************************************************
 *                                  _   _ ____  _
 *  Project                     ___| | | |  _ \| |
 *                             / __| | | | |_) | |
 *                            | (__| |_| |  _ <| |___
Daniel Stenberg's avatar
Daniel Stenberg committed
 *                             \___|\___/|_| \_\_____|
 *
 * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
Daniel Stenberg's avatar
Daniel Stenberg committed
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution. The terms
 * are also available at http://curl.haxx.se/docs/copyright.html.
Daniel Stenberg's avatar
Daniel Stenberg committed
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
 * copies of the Software, and permit persons to whom the Software is
 * furnished to do so, under the terms of the COPYING file.
Daniel Stenberg's avatar
Daniel Stenberg committed
 *
Daniel Stenberg's avatar
Daniel Stenberg committed
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
Daniel Stenberg's avatar
Daniel Stenberg committed
 *
Daniel Stenberg's avatar
Daniel Stenberg committed
 * $Id$
 ***************************************************************************/
Daniel Stenberg's avatar
Daniel Stenberg committed

/* This is now designed to have its own local setup.h */
#include "setup.h"

Daniel Stenberg's avatar
Daniel Stenberg committed
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <sys/types.h>
Daniel Stenberg's avatar
Daniel Stenberg committed
#include <sys/stat.h>
#include <ctype.h>
#include <errno.h>
Daniel Stenberg's avatar
Daniel Stenberg committed

#include <curl/curl.h>
Daniel Stenberg's avatar
Daniel Stenberg committed

Daniel Stenberg's avatar
Daniel Stenberg committed
#include "urlglob.h"
#include "writeout.h"
#ifdef USE_MANUAL
#include "hugehelp.h"
#ifdef USE_ENVIRONMENT
#include "writeenv.h"
#endif
#define CURLseparator   "--_curl_--"
#if defined(WIN32)&&!defined(__CYGWIN32__)
Daniel Stenberg's avatar
Daniel Stenberg committed
#endif

#ifdef __NOVELL_LIBC__
#include <screen.h>
#endif

#ifdef TIME_WITH_SYS_TIME
/* We can include both fine */
#include <time.h>
#else
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#else
# include <time.h>
#endif
Daniel Stenberg's avatar
Daniel Stenberg committed
#include "version.h"

#ifdef HAVE_IO_H /* typical win32 habit */
#include <io.h>
#endif

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif

#ifdef HAVE_SYS_UTIME_H
#include <sys/utime.h>
#endif
Daniel Stenberg's avatar
Daniel Stenberg committed

Daniel Stenberg's avatar
Daniel Stenberg committed

#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif

Daniel Stenberg's avatar
Daniel Stenberg committed
#ifdef HAVE_SYS_POLL_H
#include <sys/poll.h>
#ifdef HAVE_LOCALE_H
#include <locale.h> /* for setlocale() */
#endif

#define ENABLE_CURLX_PRINTF
/* make the curlx header define all printf() functions to use the curlx_*
   versions instead */
#include <curlx.h> /* header from the libcurl directory */
/* The last #include file should be: */
#ifdef CURLDEBUG
#ifndef CURLTOOLDEBUG
#define MEMDEBUG_NODEFINES
#endif
/* This is low-level hard-hacking memory leak tracking and similar. Using
   the library level code from this client-side is ugly, but we do this
   anyway for convenience. */
#define DEFAULT_MAXREDIRS  50L
#include <dos.h>

char *msdosify(char *);
char *rename_if_dos_device_name(char *);

/* we want to glob our own argv[] */
char **__crt0_glob_function (char *arg)
{
  (void)arg;
  return (char**)0;
}
#define CURL_PROGRESS_STATS 0 /* default progress display */
#define CURL_PROGRESS_BAR   1

#define MIN(X,Y)        (((X) < (Y)) ? (X) : (Y))
typedef enum {
  HTTPREQ_UNSPEC,
  HTTPREQ_GET,
  HTTPREQ_HEAD,
  HTTPREQ_POST,
  HTTPREQ_SIMPLEPOST,
  HTTPREQ_CUSTOM,
  HTTPREQ_LAST
} HttpReq;

/* Just a set of bits */
#define CONF_DEFAULT  0

#define CONF_AUTO_REFERER (1<<4) /* the automatic referer-system please! */
#define CONF_VERBOSE  (1<<5) /* talk a lot */
#define CONF_HEADER   (1<<8) /* throw the header out too */
#define CONF_NOPROGRESS (1<<10) /* shut off the progress meter */
#define CONF_NOBODY   (1<<11) /* use HEAD to get http document */
#define CONF_FAILONERROR (1<<12) /* no output on http error codes >= 300 */
#define CONF_FTPLISTONLY (1<<16) /* Use NLST when listing ftp dir */
#define CONF_FTPAPPEND (1<<20) /* Append instead of overwrite on upload! */
#define CONF_NETRC    (1<<22)  /* read user+password from .netrc */
#define CONF_FOLLOWLOCATION (1<<23) /* use Location: Luke! */
#define CONF_GETTEXT  (1<<24) /* use ASCII/text for transfer */
#define CONF_MUTE     (1<<28) /* force NOPROGRESS */

#define CONF_NETRC_OPT (1<<29)  /* read user+password from either
                                 * .netrc or URL*/
#define CONF_UNRESTRICTED_AUTH (1<<30)
/* Send authentication (user+password) when following
 * locations, even when hostname changed */
#ifndef HAVE_STRDUP
/* Ultrix doesn't have strdup(), so make a quick clone: */
char *strdup(char *str)
{
  int len;
  char *newstr;

  len = strlen(str);
  newstr = (char *) malloc((len+1)*sizeof(char));
  if (!newstr)
    return (char *)NULL;

  strcpy(newstr,str);

  return newstr;

}
#endif
Daniel Stenberg's avatar
Daniel Stenberg committed
#ifdef WIN32
#include <direct.h>
#define F_OK 0
#define mkdir(x,y) (mkdir)(x)
#endif

/* Support uploading and resuming of >2GB files
 */
#if defined(WIN32) && (SIZEOF_CURL_OFF_T > 4)
#define struct_stat struct _stati64
#define stat(file,st) _stati64(file,st)
#else
#define struct_stat struct stat
#endif

Gisle Vanem's avatar
 
Gisle Vanem committed
#ifdef WIN32
Gisle Vanem's avatar
Gisle Vanem committed
/*
Gisle Vanem's avatar
 
Gisle Vanem committed
 * Truncate a file handle at a 64-bit position 'where'.
 * Borland doesn't even support 64-bit types.
Gisle Vanem's avatar
Gisle Vanem committed
 */
Gisle Vanem's avatar
 
Gisle Vanem committed
#ifdef __BORLANDC__
#define _lseeki64(hnd,ofs,whence) lseek(hnd,ofs,whence)
#endif

Gisle Vanem's avatar
 
Gisle Vanem committed
static int ftruncate64 (int fd, curl_off_t where)
Gisle Vanem's avatar
Gisle Vanem committed
{
  curl_off_t curr;
  int rc = 0;

  if ((curr = _lseeki64(fd, 0, SEEK_CUR)) < 0)
     return -1;

  if (_lseeki64(fd, where, SEEK_SET) < 0)
     return -1;

Gisle Vanem's avatar
Gisle Vanem committed
  if (write(fd, 0, 0) < 0)
Gisle Vanem's avatar
Gisle Vanem committed
     rc = -1;
  _lseeki64(fd, curr, SEEK_SET);
  return rc;
}
Gisle Vanem's avatar
 
Gisle Vanem committed
#define ftruncate(fd,where) ftruncate64(fd,where)
Gisle Vanem's avatar
Gisle Vanem committed
#endif

/*
 * This is the main global constructor for the app. Call this before
 * _any_ libcurl usage. If this fails, *NO* libcurl functions may be
 * used, or havoc may be the result.
 */
static CURLcode main_init(void)
  return curl_global_init(CURL_GLOBAL_DEFAULT);
}

/*
 * This is the main global destructor for the app. Call this after
 * _all_ libcurl usage is done.
 */
static void main_free(void)
static int SetHTTPrequest(HttpReq req, HttpReq *store)
{
  if((*store == HTTPREQ_UNSPEC) ||
     (*store == req)) {
    *store = req;
  }
  fprintf(stderr, "You can only select one HTTP request!\n");
static void helpf(const char *fmt, ...)
Daniel Stenberg's avatar
Daniel Stenberg committed
{
  va_list ap;
  if(fmt) {
    va_start(ap, fmt);
    fputs("curl: ", stderr); /* prefix it */
    vfprintf(stderr, fmt, ap);
    va_end(ap);
  }
  fprintf(stderr, "curl: try 'curl --help' "
#ifdef USE_MANUAL
          "or 'curl --manual' "
#endif
          "for more information\n");
/*
 * A chain of these nodes contain URL to get and where to put the URL's
 * contents.
 */
struct getout {
Loading
Loading full blame...