1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 15:48:49 -05:00

setopt: split out curl_easy_setopt() to its own file

... to make url.c smaller.

Closes #1944
This commit is contained in:
Daniel Stenberg 2017-11-10 17:45:54 +01:00
parent 2e850dafa5
commit aa7668b948
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
6 changed files with 2640 additions and 2566 deletions

View File

@ -5,7 +5,7 @@
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
# Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
@ -54,7 +54,7 @@ LIB_CFILES = file.c timeval.c base64.c hostip.c progress.c formdata.c \
http_ntlm.c curl_ntlm_wb.c curl_ntlm_core.c curl_sasl.c rand.c \
curl_multibyte.c hostcheck.c conncache.c pipeline.c dotdot.c \
x509asn1.c http2.c smb.c curl_endian.c curl_des.c system_win32.c \
mime.c sha256.c
mime.c sha256.c setopt.c
LIB_HFILES = arpa_telnet.h netrc.h file.h timeval.h hostip.h progress.h \
formdata.h cookie.h http.h sendf.h ftp.h url.h dict.h if2ip.h \
@ -73,7 +73,7 @@ LIB_HFILES = arpa_telnet.h netrc.h file.h timeval.h hostip.h progress.h \
curl_sasl.h curl_multibyte.h hostcheck.h conncache.h \
curl_setup_once.h multihandle.h setup-vms.h pipeline.h dotdot.h \
x509asn1.h http2.h sigpipe.h smb.h curl_endian.h curl_des.h \
curl_printf.h system_win32.h rand.h mime.h curl_sha256.h
curl_printf.h system_win32.h rand.h mime.h curl_sha256.h setopt.h
LIB_RCFILES = libcurl.rc

View File

@ -71,6 +71,8 @@
#include "multiif.h"
#include "sigpipe.h"
#include "ssh.h"
#include "setopt.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
#include "curl_memory.h"
@ -364,28 +366,6 @@ struct Curl_easy *curl_easy_init(void)
return data;
}
/*
* curl_easy_setopt() is the external interface for setting options on an
* easy handle.
*/
#undef curl_easy_setopt
CURLcode curl_easy_setopt(struct Curl_easy *data, CURLoption tag, ...)
{
va_list arg;
CURLcode result;
if(!data)
return CURLE_BAD_FUNCTION_ARGUMENT;
va_start(arg, tag);
result = Curl_setopt(data, tag, arg);
va_end(arg);
return result;
}
#ifdef CURLDEBUG
struct socketmonitor {
@ -860,6 +840,40 @@ CURLcode curl_easy_getinfo(struct Curl_easy *data, CURLINFO info, ...)
return result;
}
static CURLcode dupset(struct Curl_easy *dst, struct Curl_easy *src)
{
CURLcode result = CURLE_OK;
enum dupstring i;
/* Copy src->set into dst->set first, then deal with the strings
afterwards */
dst->set = src->set;
/* clear all string pointers first */
memset(dst->set.str, 0, STRING_LAST * sizeof(char *));
/* duplicate all strings */
for(i = (enum dupstring)0; i< STRING_LASTZEROTERMINATED; i++) {
result = Curl_setstropt(&dst->set.str[i], src->set.str[i]);
if(result)
return result;
}
/* duplicate memory areas pointed to */
i = STRING_COPYPOSTFIELDS;
if(src->set.postfieldsize && src->set.str[i]) {
/* postfieldsize is curl_off_t, Curl_memdup() takes a size_t ... */
dst->set.str[i] = Curl_memdup(src->set.str[i],
curlx_sotouz(src->set.postfieldsize));
if(!dst->set.str[i])
return CURLE_OUT_OF_MEMORY;
/* point to the new copy */
dst->set.postfields = dst->set.str[i];
}
return CURLE_OK;
}
/*
* curl_easy_duphandle() is an external interface to allow duplication of a
* given input easy handle. The returned handle will be a new working handle
@ -887,7 +901,7 @@ struct Curl_easy *curl_easy_duphandle(struct Curl_easy *data)
outcurl->state.headersize = HEADERSIZE;
/* copy all userdefined values */
if(Curl_dupset(outcurl, data))
if(dupset(outcurl, data))
goto fail;
/* the connection cache is setup on demand */

2549
lib/setopt.c Normal file

File diff suppressed because it is too large Load Diff

27
lib/setopt.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef HEADER_CURL_SETOPT_H
#define HEADER_CURL_SETOPT_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* 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 https://curl.haxx.se/docs/copyright.html.
*
* 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.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
CURLcode Curl_setstropt(char **charp, const char *s);
#endif /* HEADER_CURL_SETOPT_H */

2556
lib/url.c

File diff suppressed because it is too large Load Diff

View File

@ -23,6 +23,10 @@
***************************************************************************/
#include "curl_setup.h"
#define READBUFFER_SIZE CURL_MAX_WRITE_SIZE
#define READBUFFER_MAX CURL_MAX_READ_SIZE
#define READBUFFER_MIN 1024
/*
* Prototypes for library-wide functions provided by url.c
*/
@ -51,7 +55,9 @@ int Curl_protocol_getsock(struct connectdata *conn,
int Curl_doing_getsock(struct connectdata *conn,
curl_socket_t *socks,
int numsocks);
CURLcode Curl_parse_login_details(const char *login, const size_t len,
char **userptr, char **passwdptr,
char **optionsptr);
bool Curl_isPipeliningEnabled(const struct Curl_easy *handle);
CURLcode Curl_addHandleToPipeline(struct Curl_easy *handle,
struct curl_llist *pipeline);