⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 harvest是一个下载html网页得机器人
💻 C
📖 第 1 页 / 共 5 页
字号:
              ptr=sep+1;            }            else if(curl_strnequal("filename=", ptr, 9)) {              filename = &ptr[9];              ptr=strchr(filename, FORM_TYPE_SEPARATOR);              if(!ptr) {                ptr=strchr(filename, FORM_FILE_SEPARATOR);              }              if(ptr) {                *ptr=0; /* zero terminate */                ptr++;              }            }            else              /* confusion, bail out of loop */              break;	  }          /* find the following comma */          if(ptr)            sep=strchr(ptr, FORM_FILE_SEPARATOR);          else            sep=NULL;	}	else {	  sep=strchr(contp, FORM_FILE_SEPARATOR);	}	if(sep) {	  /* the next file name starts here */	  *sep =0;	  sep++;	}        /* if type == NULL curl_formadd takes care of the problem */        if (!AddMultiFiles (contp, type, filename, &multi_start,                            &multi_current)) {          fprintf(stderr, "Error building form post!\n");          free(contents);          FreeMultiInfo (multi_start);          return 3;        }	contp = sep; /* move the contents pointer to after the separator */      } while(sep && *sep); /* loop if there's another file name */      /* now we add the multiple files section */      if (multi_start) {        struct curl_forms *forms = NULL;        struct multi_files *ptr = multi_start;        unsigned int i, count = 0;        while (ptr) {          ptr = ptr->next;          ++count;        }        forms =          (struct curl_forms *)malloc((count+1)*sizeof(struct curl_forms));        if (!forms)        {          fprintf(stderr, "Error building form post!\n");          free(contents);          FreeMultiInfo (multi_start);          return 4;        }        for (i = 0, ptr = multi_start; i < count; ++i, ptr = ptr->next)        {          forms[i].option = ptr->form.option;          forms[i].value = ptr->form.value;        }        forms[count].option = CURLFORM_END;        FreeMultiInfo (multi_start);        if (curl_formadd (httppost, last_post,                          CURLFORM_COPYNAME, name,                          CURLFORM_ARRAY, forms, CURLFORM_END) != 0) {          fprintf(stderr, "curl_formadd failed!\n");          free(forms);          free(contents);          return 5;        }        free(forms);      }    }    else {      if( contp[0]=='<' ) {        if (curl_formadd (httppost, last_post,                          CURLFORM_COPYNAME, name,                          CURLFORM_FILECONTENT, contp+1, CURLFORM_END) != 0) {          fprintf(stderr, "curl_formadd failed!\n");          free(contents);          return 6;        }      }      else {        if (curl_formadd (httppost, last_post,                          CURLFORM_COPYNAME, name,                          CURLFORM_COPYCONTENTS, contp, CURLFORM_END) != 0) {          fprintf(stderr, "curl_formadd failed!\n");          free(contents);          return 7;        }      }    }  }  else {    fprintf(stderr, "Illegally formatted input field!\n");    free(contents);    return 1;  }  free(contents);  return 0;}typedef enum {  PARAM_OK,  PARAM_OPTION_AMBIGUOUS,  PARAM_OPTION_UNKNOWN,  PARAM_REQUIRES_PARAMETER,    PARAM_BAD_USE,  PARAM_HELP_REQUESTED,  PARAM_GOT_EXTRA_PARAMETER,  PARAM_BAD_NUMERIC,  PARAM_LAST} ParameterError;static void cleanarg(char *str){#ifdef HAVE_WRITABLE_ARGV  /* now that GetStr has copied the contents of nextarg, wipe the next   * argument out so that the username:password isn't displayed in the   * system process list */  if (str) {    size_t len = strlen(str);    memset(str, ' ', len);  }#else  (void)str;#endif}/* * Parse the string and write the integer in the given address. Return * non-zero on failure, zero on success. * * The string must start with a digit to be valid. */static int str2num(long *val, char *str){  int retcode = 0;  if(isdigit((int)*str))    *val = atoi(str);  else    retcode = 1; /* badness */  return retcode;  }static void checkpasswd(const char *kind, /* for what purpose */                        char **userpwd) /* pointer to allocated string */{  char *ptr = strchr(*userpwd, ':');  if(!ptr) {    /* no password present, prompt for one */    char passwd[256]="";    char prompt[256];    int passwdlen;    int userlen = strlen(*userpwd);    char *ptr;    /* build a nice-looking prompt */    curl_msnprintf(prompt, sizeof(prompt),                   "Enter %s password for user '%s':",                   kind, *userpwd);    /* get password */    getpass_r(prompt, passwd, sizeof(passwd));    passwdlen = strlen(passwd);    /* extend the allocated memory are to fit the password too */    ptr = realloc(*userpwd,                  passwdlen + 1 + /* an extra for the colon */                  userlen + 1);   /* an extra for the zero */    if(ptr) {      /* append the password separated with a colon */      ptr[userlen]=':';      memcpy(&ptr[userlen+1], passwd, passwdlen+1);      *userpwd = ptr;    }  }}static ParameterError getparameter(char *flag, /* f or -long-flag */                                   char *nextarg, /* NULL if unset */                                   bool *usedarg, /* set to TRUE if the arg                                                     has been used */                                   struct Configurable *config){  char letter;  char subletter=0; /* subletters can only occur on long options */  const char *parse=NULL;  int res;  unsigned int j;  time_t now;  int hit=-1;  bool longopt=FALSE;  bool singleopt=FALSE; /* when true means '-o foo' used '-ofoo' */  /* single-letter,     long-name,     boolean whether it takes an additional argument     */  struct LongShort aliases[]= {    /* all these ones, starting with "*" as a short-option have *no* short       option to mention. */    {"*", "url",         TRUE},    {"*a", "random-file", TRUE},    {"*b", "egd-file",   TRUE},    {"*c", "connect-timeout", TRUE},    {"*d", "ciphers",    TRUE},    {"*e", "disable-epsv", FALSE},#ifdef USE_ENVIRONMENT    {"*f", "environment", FALSE},#endif    {"*g", "trace",      TRUE},    {"*h", "trace-ascii", TRUE},    {"*i", "limit-rate", TRUE},    {"*j", "compressed",  FALSE}, /* might take an arg someday */    {"*k", "digest",     FALSE},    {"*l", "negotiate",  FALSE},    {"*m", "ntlm",       FALSE},    {"*n", "basic",      FALSE},    {"*o", "anyauth",    FALSE},#ifdef __DJGPP__    {"*p", "wdebug",     FALSE},#endif    {"*q", "ftp-create-dirs", FALSE},        {"*r", "create-dirs", FALSE},    {"*s", "max-redirs",   TRUE},    {"*t", "proxy-ntlm",   FALSE},    {"*u", "crlf",        FALSE},    {"*v", "stderr",      TRUE},    {"*w", "interface",   TRUE},    {"*x", "krb4",        TRUE},    {"*y", "max-filesize", TRUE},    {"*z", "disable-eprt", FALSE},    {"0", "http1.0",     FALSE},    {"1", "tlsv1",       FALSE},    {"2", "sslv2",       FALSE},    {"3", "sslv3",       FALSE},    {"4", "ipv4",       FALSE},    {"6", "ipv6",       FALSE},    {"a", "append",      FALSE},    {"A", "user-agent",  TRUE},    {"b", "cookie",      TRUE},    {"B", "use-ascii",   FALSE},    {"c", "cookie-jar",  TRUE},    {"C", "continue-at", TRUE},    {"d", "data",        TRUE},    {"da", "data-ascii", TRUE},    {"db", "data-binary", TRUE},    {"D", "dump-header", TRUE},    {"e", "referer",     TRUE},    {"E", "cert",        TRUE},    {"Ea", "cacert",     TRUE},    {"Eb","cert-type",   TRUE},    {"Ec","key",         TRUE},    {"Ed","key-type",    TRUE},    {"Ee","pass",        TRUE},    {"Ef","engine",      TRUE},    {"Eg","capath ",     TRUE},    {"f", "fail",        FALSE},    {"F", "form",        TRUE},    {"g", "globoff",     FALSE},    {"G", "get",         FALSE},    {"h", "help",        FALSE},    {"H", "header",      TRUE},    {"i", "include",     FALSE},    {"I", "head",        FALSE},    {"j", "junk-session-cookies", FALSE},    {"k", "insecure",    FALSE},    {"K", "config",      TRUE},    {"l", "list-only",   FALSE},    {"L", "location",    FALSE},    {"Lt", "location-trusted", FALSE},    {"m", "max-time",    TRUE},    {"M", "manual",      FALSE},    {"n", "netrc",       FALSE},    {"no", "netrc-optional", FALSE},    {"N", "no-buffer",   FALSE},    {"o", "output",      TRUE},    {"O", "remote-name", FALSE},    {"p", "proxytunnel", FALSE},    {"P", "ftpport",     TRUE},    {"q", "disable",     FALSE},    {"Q", "quote",       TRUE},    {"r", "range",       TRUE},    {"R", "remote-time", FALSE},    {"s", "silent",      FALSE},    {"S", "show-error",  FALSE},    {"t", "telnet-options", TRUE},    {"T", "upload-file", TRUE},    {"u", "user",        TRUE},    {"U", "proxy-user",  TRUE},    {"v", "verbose",     FALSE},    {"V", "version",     FALSE},    {"w", "write-out",   TRUE},    {"x", "proxy",       TRUE},    {"X", "request",     TRUE},    {"X", "http-request", TRUE}, /* OBSOLETE VERSION */    {"Y", "speed-limit",  TRUE},    {"y", "speed-time", TRUE},    {"z", "time-cond",   TRUE},    {"#", "progress-bar",FALSE},  };  if(('-' != flag[0]) ||     (('-' == flag[0]) && ('-' == flag[1]))) {    /* this should be a long name */    char *word=('-' == flag[0])?flag+2:flag;    int fnam=strlen(word);    int numhits=0;    for(j=0; j< sizeof(aliases)/sizeof(aliases[0]); j++) {      if(curl_strnequal(aliases[j].lname, word, fnam)) {        longopt = TRUE;        numhits++;        if(curl_strequal(aliases[j].lname, word)) {          parse = aliases[j].letter;          hit = j;          numhits = 1; /* a single unique hit */          break;        }	parse = aliases[j].letter;	hit = j;      }    }    if(numhits>1) {      /* this is at least the second match! */      return PARAM_OPTION_AMBIGUOUS;    }    if(hit < 0) {      return PARAM_OPTION_UNKNOWN;    }      }  else {    flag++; /* prefixed with one dash, pass it */    hit=-1;    parse = flag;  }  do {    /* we can loop here if we have multiple single-letters */    if(!longopt)      letter = parse?*parse:'\0';    else {      letter = parse[0];      subletter = parse[1];    }    *usedarg = FALSE; /* default is that we don't use the arg */#if 0    fprintf(stderr, "OPTION: %c %s\n", letter, nextarg?nextarg:"<null>");#endif    if(hit < 0) {      for(j=0; j< sizeof(aliases)/sizeof(aliases[0]); j++) {	if(letter == aliases[j].letter[0]) {	  hit = j;	  break;	}      }      if(hit < 0) {	return PARAM_OPTION_UNKNOWN;      }    }    if(hit < 0) {      return PARAM_OPTION_UNKNOWN;    }        if(!longopt && aliases[hit].extraparam && parse[1]) {      nextarg=(char *)&parse[1]; /* this is the actual extra parameter */      singleopt=TRUE;   /* don't loop anymore after this */    }    else if(!nextarg && aliases[hit].extraparam) {      return PARAM_REQUIRES_PARAMETER;    }    else if(nextarg && aliases[hit].extraparam)      *usedarg = TRUE; /* mark it as used */    switch(letter) {    case '*': /* options without a short option */      switch(subletter) {      case 'a': /* random-file */        GetStr(&config->random_file, nextarg);        break;      case 'b': /* egd-file */        GetStr(&config->egd_file, nextarg);        break;      case 'c': /* connect-timeout */        if(str2num(&config->connecttimeout, nextarg))          return PARAM_BAD_NUMERIC;        break;      case 'd': /* ciphers */        GetStr(&config->cipher_list, nextarg);        break;      case 'e': /* --disable-epsv */        config->disable_epsv ^= TRUE;        break;#ifdef USE_ENVIRONMENT      case 'f':        config->writeenv ^= TRUE;        break;#endif      case 'g': /* --trace */        GetStr(&config->trace_dump, nextarg);        break;      case 'h': /* --trace-ascii */        GetStr(&config->trace_dump, nextarg);        config->trace_ascii = TRUE;        break;      case 'i': /* --limit-rate */        {          /* We support G, M, K too */          char *unit;          unsigned long value = strtol(nextarg, &unit, 0);          switch(nextarg[strlen(nextarg)-1]) {          case 'G':          case 'g':            value *= 1024*1024*1024;            break;          case 'M':          case 'm':            value *= 1024*1024;            break;          case 'K':          case 'k':            value *= 1024;            break;          }          config->recvpersecond = value;          config->sendpersecond = value;        }        break;      case 'j': /* --compressed */ 	config->encoding ^= TRUE; 	break;      case 'k': /* --digest */ 	config->authtype = CURLAUTH_DIGEST; 	break;      case 'l': /* --negotiate */	config->authtype = CURLAUTH_GSSNEGOTIATE;	break;      case 'm': /* --ntlm */	config->authtype = CURLAUTH_NTLM;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -