repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
Curl_meets_timecondition
bool Curl_meets_timecondition(struct SessionHandle *data, time_t timeofdoc) { if((timeofdoc == 0) || (data->set.timevalue == 0)) return TRUE; switch(data->set.timecondition) { case CURL_TIMECOND_IFMODSINCE: default: if(timeofdoc <= data->set.timevalue) { infof(data, "The requested document is not new enough\n"); data->info.timecond = TRUE; return FALSE; } break; case CURL_TIMECOND_IFUNMODSINCE: if(timeofdoc >= data->set.timevalue) { infof(data, "The requested document is not old enough\n"); data->info.timecond = TRUE; return FALSE; } break; } return TRUE; }
/* * Check to see if CURLOPT_TIMECONDITION was met by comparing the time of the * remote document with the time provided by CURLOPT_TIMEVAL */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/transfer.c#L339-L365
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
readwrite_data
static CURLcode readwrite_data(struct SessionHandle *data, struct connectdata *conn, struct SingleRequest *k, int *didwhat, bool *done) { CURLcode result = CURLE_OK; ssize_t nread; /* number of bytes read */ size_t excess = 0; /* excess bytes read */ bool is_empty_data = FALSE; bool readmore = FALSE; /* used by RTP to signal for more data */ *done = FALSE; /* This is where we loop until we have read everything there is to read or we get a CURLE_AGAIN */ do { size_t buffersize = data->set.buffer_size? data->set.buffer_size : BUFSIZE; size_t bytestoread = buffersize; if(k->size != -1 && !k->header) { /* make sure we don't read "too much" if we can help it since we might be pipelining and then someone else might want to read what follows! */ curl_off_t totalleft = k->size - k->bytecount; if(totalleft < (curl_off_t)bytestoread) bytestoread = (size_t)totalleft; } if(bytestoread) { /* receive data from the network! */ result = Curl_read(conn, conn->sockfd, k->buf, bytestoread, &nread); /* read would've blocked */ if(CURLE_AGAIN == result) break; /* get out of loop */ if(result>0) return result; } else { /* read nothing but since we wanted nothing we consider this an OK situation to proceed from */ nread = 0; } if((k->bytecount == 0) && (k->writebytecount == 0)) { Curl_pgrsTime(data, TIMER_STARTTRANSFER); if(k->exp100 > EXP100_SEND_DATA) /* set time stamp to compare with when waiting for the 100 */ k->start100 = Curl_tvnow(); } *didwhat |= KEEP_RECV; /* indicates data of zero size, i.e. empty file */ is_empty_data = ((nread == 0) && (k->bodywrites == 0)) ? TRUE : FALSE; /* NUL terminate, allowing string ops to be used */ if(0 < nread || is_empty_data) { k->buf[nread] = 0; } else if(0 >= nread) { /* if we receive 0 or less here, the server closed the connection and we bail out from this! */ DEBUGF(infof(data, "nread <= 0, server closed connection, bailing\n")); k->keepon &= ~KEEP_RECV; break; } /* Default buffer to use when we write the buffer, it may be changed in the flow below before the actual storing is done. */ k->str = k->buf; if(conn->handler->readwrite) { result = conn->handler->readwrite(data, conn, &nread, &readmore); if(result) return result; if(readmore) break; } #ifndef CURL_DISABLE_HTTP /* Since this is a two-state thing, we check if we are parsing headers at the moment or not. */ if(k->header) { /* we are in parse-the-header-mode */ bool stop_reading = FALSE; result = Curl_http_readwrite_headers(data, conn, &nread, &stop_reading); if(result) return result; if(conn->handler->readwrite && (k->maxdownload <= 0 && nread > 0)) { result = conn->handler->readwrite(data, conn, &nread, &readmore); if(result) return result; if(readmore) break; } if(stop_reading) { /* We've stopped dealing with input, get out of the do-while loop */ if(nread > 0) { if(conn->data->multi && Curl_multi_canPipeline(conn->data->multi)) { infof(data, "Rewinding stream by : %zd" " bytes on url %s (zero-length body)\n", nread, data->state.path); read_rewind(conn, (size_t)nread); } else { infof(data, "Excess found in a non pipelined read:" " excess = %zd" " url = %s (zero-length body)\n", nread, data->state.path); } } break; } } #endif /* CURL_DISABLE_HTTP */ /* This is not an 'else if' since it may be a rest from the header parsing, where the beginning of the buffer is headers and the end is non-headers. */ if(k->str && !k->header && (nread > 0 || is_empty_data)) { #ifndef CURL_DISABLE_HTTP if(0 == k->bodywrites && !is_empty_data) { /* These checks are only made the first time we are about to write a piece of the body */ if(conn->handler->protocol&(CURLPROTO_HTTP|CURLPROTO_RTSP)) { /* HTTP-only checks */ if(data->req.newurl) { if(conn->bits.close) { /* Abort after the headers if "follow Location" is set and we're set to close anyway. */ k->keepon &= ~KEEP_RECV; *done = TRUE; return CURLE_OK; } /* We have a new url to load, but since we want to be able to re-use this connection properly, we read the full response in "ignore more" */ k->ignorebody = TRUE; infof(data, "Ignoring the response-body\n"); } if(data->state.resume_from && !k->content_range && (data->set.httpreq==HTTPREQ_GET) && !k->ignorebody) { /* we wanted to resume a download, although the server doesn't * seem to support this and we did this with a GET (if it * wasn't a GET we did a POST or PUT resume) */ failf(data, "HTTP server doesn't seem to support " "byte ranges. Cannot resume."); return CURLE_RANGE_ERROR; } if(data->set.timecondition && !data->state.range) { /* A time condition has been set AND no ranges have been requested. This seems to be what chapter 13.3.4 of RFC 2616 defines to be the correct action for a HTTP/1.1 client */ if(!Curl_meets_timecondition(data, k->timeofdoc)) { *done = TRUE; /* we abort the transfer before it is completed == we ruin the re-use ability. Close the connection */ conn->bits.close = TRUE; return CURLE_OK; } } /* we have a time condition */ } /* this is HTTP or RTSP */ } /* this is the first time we write a body part */ #endif /* CURL_DISABLE_HTTP */ k->bodywrites++; /* pass data to the debug function before it gets "dechunked" */ if(data->set.verbose) { if(k->badheader) { Curl_debug(data, CURLINFO_DATA_IN, data->state.headerbuff, (size_t)k->hbuflen, conn); if(k->badheader == HEADER_PARTHEADER) Curl_debug(data, CURLINFO_DATA_IN, k->str, (size_t)nread, conn); } else Curl_debug(data, CURLINFO_DATA_IN, k->str, (size_t)nread, conn); } #ifndef CURL_DISABLE_HTTP if(k->chunk) { /* * Here comes a chunked transfer flying and we need to decode this * properly. While the name says read, this function both reads * and writes away the data. The returned 'nread' holds the number * of actual data it wrote to the client. */ CHUNKcode res = Curl_httpchunk_read(conn, k->str, nread, &nread); if(CHUNKE_OK < res) { if(CHUNKE_WRITE_ERROR == res) { failf(data, "Failed writing data"); return CURLE_WRITE_ERROR; } failf(data, "Problem (%d) in the Chunked-Encoded data", (int)res); return CURLE_RECV_ERROR; } else if(CHUNKE_STOP == res) { size_t dataleft; /* we're done reading chunks! */ k->keepon &= ~KEEP_RECV; /* read no more */ /* There are now possibly N number of bytes at the end of the str buffer that weren't written to the client. We DO care about this data if we are pipelining. Push it back to be read on the next pass. */ dataleft = conn->chunk.dataleft; if(dataleft != 0) { infof(conn->data, "Leftovers after chunking: %zu bytes\n", dataleft); if(conn->data->multi && Curl_multi_canPipeline(conn->data->multi)) { /* only attempt the rewind if we truly are pipelining */ infof(conn->data, "Rewinding %zu bytes\n",dataleft); read_rewind(conn, dataleft); } } } /* If it returned OK, we just keep going */ } #endif /* CURL_DISABLE_HTTP */ /* Account for body content stored in the header buffer */ if(k->badheader && !k->ignorebody) { DEBUGF(infof(data, "Increasing bytecount by %zu from hbuflen\n", k->hbuflen)); k->bytecount += k->hbuflen; } if((-1 != k->maxdownload) && (k->bytecount + nread >= k->maxdownload)) { excess = (size_t)(k->bytecount + nread - k->maxdownload); if(excess > 0 && !k->ignorebody) { if(conn->data->multi && Curl_multi_canPipeline(conn->data->multi)) { /* The 'excess' amount below can't be more than BUFSIZE which always will fit in a size_t */ infof(data, "Rewinding stream by : %zu" " bytes on url %s (size = %" FORMAT_OFF_T ", maxdownload = %" FORMAT_OFF_T ", bytecount = %" FORMAT_OFF_T ", nread = %zd)\n", excess, data->state.path, k->size, k->maxdownload, k->bytecount, nread); read_rewind(conn, excess); } else { infof(data, "Excess found in a non pipelined read:" " excess = %zu" ", size = %" FORMAT_OFF_T ", maxdownload = %" FORMAT_OFF_T ", bytecount = %" FORMAT_OFF_T "\n", excess, k->size, k->maxdownload, k->bytecount); } } nread = (ssize_t) (k->maxdownload - k->bytecount); if(nread < 0 ) /* this should be unusual */ nread = 0; k->keepon &= ~KEEP_RECV; /* we're done reading */ } k->bytecount += nread; Curl_pgrsSetDownloadCounter(data, k->bytecount); if(!k->chunk && (nread || k->badheader || is_empty_data)) { /* If this is chunky transfer, it was already written */ if(k->badheader && !k->ignorebody) { /* we parsed a piece of data wrongly assuming it was a header and now we output it as body instead */ /* Don't let excess data pollute body writes */ if(k->maxdownload == -1 || (curl_off_t)k->hbuflen <= k->maxdownload) result = Curl_client_write(conn, CLIENTWRITE_BODY, data->state.headerbuff, k->hbuflen); else result = Curl_client_write(conn, CLIENTWRITE_BODY, data->state.headerbuff, (size_t)k->maxdownload); if(result) return result; } if(k->badheader < HEADER_ALLBAD) { /* This switch handles various content encodings. If there's an error here, be sure to check over the almost identical code in http_chunks.c. Make sure that ALL_CONTENT_ENCODINGS contains all the encodings handled here. */ #ifdef HAVE_LIBZ switch (conn->data->set.http_ce_skip ? IDENTITY : k->auto_decoding) { case IDENTITY: #endif /* This is the default when the server sends no Content-Encoding header. See Curl_readwrite_init; the memset() call initializes k->auto_decoding to zero. */ if(!k->ignorebody) { #ifndef CURL_DISABLE_POP3 if(conn->handler->protocol&CURLPROTO_POP3) result = Curl_pop3_write(conn, k->str, nread); else #endif /* CURL_DISABLE_POP3 */ result = Curl_client_write(conn, CLIENTWRITE_BODY, k->str, nread); } #ifdef HAVE_LIBZ break; case DEFLATE: /* Assume CLIENTWRITE_BODY; headers are not encoded. */ if(!k->ignorebody) result = Curl_unencode_deflate_write(conn, k, nread); break; case GZIP: /* Assume CLIENTWRITE_BODY; headers are not encoded. */ if(!k->ignorebody) result = Curl_unencode_gzip_write(conn, k, nread); break; case COMPRESS: default: failf (data, "Unrecognized content encoding type. " "libcurl understands `identity', `deflate' and `gzip' " "content encodings."); result = CURLE_BAD_CONTENT_ENCODING; break; } #endif } k->badheader = HEADER_NORMAL; /* taken care of now */ if(result) return result; } } /* if(! header and data to read ) */ if(conn->handler->readwrite && (excess > 0 && !conn->bits.stream_was_rewound)) { /* Parse the excess data */ k->str += nread; nread = (ssize_t)excess; result = conn->handler->readwrite(data, conn, &nread, &readmore); if(result) return result; if(readmore) k->keepon |= KEEP_RECV; /* we're not done reading */ break; } if(is_empty_data) { /* if we received nothing, the server closed the connection and we are done */ k->keepon &= ~KEEP_RECV; } } while(data_pending(conn)); if(((k->keepon & (KEEP_RECV|KEEP_SEND)) == KEEP_SEND) && conn->bits.close ) { /* When we've read the entire thing and the close bit is set, the server may now close the connection. If there's now any kind of sending going on from our side, we need to stop that immediately. */ infof(data, "we are done reading and this is set to close, stop send\n"); k->keepon &= ~KEEP_SEND; /* no writing anymore either */ } return CURLE_OK; }
/* * Go ahead and do a read if we have a readable socket or if * the stream was rewound (in which case we have data in a * buffer) */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/transfer.c#L372-L774
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
readwrite_upload
static CURLcode readwrite_upload(struct SessionHandle *data, struct connectdata *conn, struct SingleRequest *k, int *didwhat) { ssize_t i, si; ssize_t bytes_written; CURLcode result; ssize_t nread; /* number of bytes read */ bool sending_http_headers = FALSE; if((k->bytecount == 0) && (k->writebytecount == 0)) Curl_pgrsTime(data, TIMER_STARTTRANSFER); *didwhat |= KEEP_SEND; /* * We loop here to do the READ and SEND loop until we run out of * data to send or until we get EWOULDBLOCK back * * FIXME: above comment is misleading. Currently no looping is * actually done in do-while loop below. */ do { /* only read more data if there's no upload data already present in the upload buffer */ if(0 == data->req.upload_present) { /* init the "upload from here" pointer */ data->req.upload_fromhere = k->uploadbuf; if(!k->upload_done) { /* HTTP pollution, this should be written nicer to become more protocol agnostic. */ int fillcount; if((k->exp100 == EXP100_SENDING_REQUEST) && (data->state.proto.http->sending == HTTPSEND_BODY)) { /* If this call is to send body data, we must take some action: We have sent off the full HTTP 1.1 request, and we shall now go into the Expect: 100 state and await such a header */ k->exp100 = EXP100_AWAITING_CONTINUE; /* wait for the header */ k->keepon &= ~KEEP_SEND; /* disable writing */ k->start100 = Curl_tvnow(); /* timeout count starts now */ *didwhat &= ~KEEP_SEND; /* we didn't write anything actually */ /* set a timeout for the multi interface */ Curl_expire(data, CURL_TIMEOUT_EXPECT_100); break; } if(conn->handler->protocol&(CURLPROTO_HTTP|CURLPROTO_RTSP)) { if(data->state.proto.http->sending == HTTPSEND_REQUEST) /* We're sending the HTTP request headers, not the data. Remember that so we don't change the line endings. */ sending_http_headers = TRUE; else sending_http_headers = FALSE; } result = Curl_fillreadbuffer(conn, BUFSIZE, &fillcount); if(result) return result; nread = (ssize_t)fillcount; } else nread = 0; /* we're done uploading/reading */ if(!nread && (k->keepon & KEEP_SEND_PAUSE)) { /* this is a paused transfer */ break; } else if(nread<=0) { /* done */ k->keepon &= ~KEEP_SEND; /* we're done writing */ if(conn->bits.rewindaftersend) { result = Curl_readrewind(conn); if(result) return result; } break; } /* store number of bytes available for upload */ data->req.upload_present = nread; #ifndef CURL_DISABLE_SMTP if(conn->handler->protocol & CURLPROTO_SMTP) { result = Curl_smtp_escape_eob(conn, nread); if(result) return result; } else #endif /* CURL_DISABLE_SMTP */ /* convert LF to CRLF if so asked */ if((!sending_http_headers) && ( #ifdef CURL_DO_LINEEND_CONV /* always convert if we're FTPing in ASCII mode */ (data->set.prefer_ascii) || #endif (data->set.crlf))) { if(data->state.scratch == NULL) data->state.scratch = malloc(2*BUFSIZE); if(data->state.scratch == NULL) { failf (data, "Failed to alloc scratch buffer!"); return CURLE_OUT_OF_MEMORY; } /* * ASCII/EBCDIC Note: This is presumably a text (not binary) * transfer so the data should already be in ASCII. * That means the hex values for ASCII CR (0x0d) & LF (0x0a) * must be used instead of the escape sequences \r & \n. */ for(i = 0, si = 0; i < nread; i++, si++) { if(data->req.upload_fromhere[i] == 0x0a) { data->state.scratch[si++] = 0x0d; data->state.scratch[si] = 0x0a; if(!data->set.crlf) { /* we're here only because FTP is in ASCII mode... bump infilesize for the LF we just added */ data->set.infilesize++; } } else data->state.scratch[si] = data->req.upload_fromhere[i]; } if(si != nread) { /* only perform the special operation if we really did replace anything */ nread = si; /* upload from the new (replaced) buffer instead */ data->req.upload_fromhere = data->state.scratch; /* set the new amount too */ data->req.upload_present = nread; } } } /* if 0 == data->req.upload_present */ else { /* We have a partial buffer left from a previous "round". Use that instead of reading more data */ } /* write to socket (send away data) */ result = Curl_write(conn, conn->writesockfd, /* socket to send to */ data->req.upload_fromhere, /* buffer pointer */ data->req.upload_present, /* buffer size */ &bytes_written); /* actually sent */ if(result) return result; if(data->set.verbose) /* show the data before we change the pointer upload_fromhere */ Curl_debug(data, CURLINFO_DATA_OUT, data->req.upload_fromhere, (size_t)bytes_written, conn); k->writebytecount += bytes_written; if(k->writebytecount == data->set.infilesize) { /* we have sent all data we were supposed to */ k->upload_done = TRUE; infof(data, "We are completely uploaded and fine\n"); } if(data->req.upload_present != bytes_written) { /* we only wrote a part of the buffer (if anything), deal with it! */ /* store the amount of bytes left in the buffer to write */ data->req.upload_present -= bytes_written; /* advance the pointer where to find the buffer when the next send is to happen */ data->req.upload_fromhere += bytes_written; } else { /* we've uploaded that buffer now */ data->req.upload_fromhere = k->uploadbuf; data->req.upload_present = 0; /* no more bytes left */ if(k->upload_done) { /* switch off writing, we're done! */ k->keepon &= ~KEEP_SEND; /* we're done writing */ } } Curl_pgrsSetUploadCounter(data, k->writebytecount); } WHILE_FALSE; /* just to break out from! */ return CURLE_OK; }
/* * Send data to upload to the server, when the socket is writable. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/transfer.c#L779-L975
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
Curl_readwrite
CURLcode Curl_readwrite(struct connectdata *conn, bool *done) { struct SessionHandle *data = conn->data; struct SingleRequest *k = &data->req; CURLcode result; int didwhat=0; curl_socket_t fd_read; curl_socket_t fd_write; int select_res = conn->cselect_bits; conn->cselect_bits = 0; /* only use the proper socket if the *_HOLD bit is not set simultaneously as then we are in rate limiting state in that transfer direction */ if((k->keepon & KEEP_RECVBITS) == KEEP_RECV) fd_read = conn->sockfd; else fd_read = CURL_SOCKET_BAD; if((k->keepon & KEEP_SENDBITS) == KEEP_SEND) fd_write = conn->writesockfd; else fd_write = CURL_SOCKET_BAD; if(!select_res) /* Call for select()/poll() only, if read/write/error status is not known. */ select_res = Curl_socket_ready(fd_read, fd_write, 0); if(select_res == CURL_CSELECT_ERR) { failf(data, "select/poll returned error"); return CURLE_SEND_ERROR; } /* We go ahead and do a read if we have a readable socket or if the stream was rewound (in which case we have data in a buffer) */ if((k->keepon & KEEP_RECV) && ((select_res & CURL_CSELECT_IN) || conn->bits.stream_was_rewound)) { result = readwrite_data(data, conn, k, &didwhat, done); if(result || *done) return result; } /* If we still have writing to do, we check if we have a writable socket. */ if((k->keepon & KEEP_SEND) && (select_res & CURL_CSELECT_OUT)) { /* write */ result = readwrite_upload(data, conn, k, &didwhat); if(result) return result; } k->now = Curl_tvnow(); if(didwhat) { /* Update read/write counters */ if(k->bytecountp) *k->bytecountp = k->bytecount; /* read count */ if(k->writebytecountp) *k->writebytecountp = k->writebytecount; /* write count */ } else { /* no read no write, this is a timeout? */ if(k->exp100 == EXP100_AWAITING_CONTINUE) { /* This should allow some time for the header to arrive, but only a very short time as otherwise it'll be too much wasted time too often. */ /* Quoting RFC2616, section "8.2.3 Use of the 100 (Continue) Status": Therefore, when a client sends this header field to an origin server (possibly via a proxy) from which it has never seen a 100 (Continue) status, the client SHOULD NOT wait for an indefinite period before sending the request body. */ long ms = Curl_tvdiff(k->now, k->start100); if(ms > CURL_TIMEOUT_EXPECT_100) { /* we've waited long enough, continue anyway */ k->exp100 = EXP100_SEND_DATA; k->keepon |= KEEP_SEND; infof(data, "Done waiting for 100-continue\n"); } } } if(Curl_pgrsUpdate(conn)) result = CURLE_ABORTED_BY_CALLBACK; else result = Curl_speedcheck(data, k->now); if(result) return result; if(k->keepon) { if(0 > Curl_timeleft(data, &k->now, FALSE)) { if(k->size != -1) { failf(data, "Operation timed out after %ld milliseconds with %" FORMAT_OFF_T " out of %" FORMAT_OFF_T " bytes received", Curl_tvdiff(k->now, data->progress.t_startsingle), k->bytecount, k->size); } else { failf(data, "Operation timed out after %ld milliseconds with %" FORMAT_OFF_T " bytes received", Curl_tvdiff(k->now, data->progress.t_startsingle), k->bytecount); } return CURLE_OPERATION_TIMEDOUT; } } else { /* * The transfer has been performed. Just make some general checks before * returning. */ if(!(data->set.opt_no_body) && (k->size != -1) && (k->bytecount != k->size) && #ifdef CURL_DO_LINEEND_CONV /* Most FTP servers don't adjust their file SIZE response for CRLFs, so we'll check to see if the discrepancy can be explained by the number of CRLFs we've changed to LFs. */ (k->bytecount != (k->size + data->state.crlf_conversions)) && #endif /* CURL_DO_LINEEND_CONV */ !data->req.newurl) { failf(data, "transfer closed with %" FORMAT_OFF_T " bytes remaining to read", k->size - k->bytecount); return CURLE_PARTIAL_FILE; } else if(!(data->set.opt_no_body) && k->chunk && (conn->chunk.state != CHUNK_STOP)) { /* * In chunked mode, return an error if the connection is closed prior to * the empty (terminating) chunk is read. * * The condition above used to check for * conn->proto.http->chunk.datasize != 0 which is true after reading * *any* chunk, not just the empty chunk. * */ failf(data, "transfer closed with outstanding read data remaining"); return CURLE_PARTIAL_FILE; } if(Curl_pgrsUpdate(conn)) return CURLE_ABORTED_BY_CALLBACK; } /* Now update the "done" boolean we return */ *done = (0 == (k->keepon&(KEEP_RECV|KEEP_SEND| KEEP_RECV_PAUSE|KEEP_SEND_PAUSE))) ? TRUE : FALSE; return CURLE_OK; }
/* * Curl_readwrite() is the low-level function to be called when data is to * be read and written to/from the connection. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/transfer.c#L981-L1139
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
Curl_single_getsock
int Curl_single_getsock(const struct connectdata *conn, curl_socket_t *sock, /* points to numsocks number of sockets */ int numsocks) { const struct SessionHandle *data = conn->data; int bitmap = GETSOCK_BLANK; unsigned sockindex = 0; if(conn->handler->perform_getsock) return conn->handler->perform_getsock(conn, sock, numsocks); if(numsocks < 2) /* simple check but we might need two slots */ return GETSOCK_BLANK; /* don't include HOLD and PAUSE connections */ if((data->req.keepon & KEEP_RECVBITS) == KEEP_RECV) { DEBUGASSERT(conn->sockfd != CURL_SOCKET_BAD); bitmap |= GETSOCK_READSOCK(sockindex); sock[sockindex] = conn->sockfd; } /* don't include HOLD and PAUSE connections */ if((data->req.keepon & KEEP_SENDBITS) == KEEP_SEND) { if((conn->sockfd != conn->writesockfd) || !(data->req.keepon & KEEP_RECV)) { /* only if they are not the same socket or we didn't have a readable one, we increase index */ if(data->req.keepon & KEEP_RECV) sockindex++; /* increase index if we need two entries */ DEBUGASSERT(conn->writesockfd != CURL_SOCKET_BAD); sock[sockindex] = conn->writesockfd; } bitmap |= GETSOCK_WRITESOCK(sockindex); } return bitmap; }
/* * Curl_single_getsock() gets called by the multi interface code when the app * has requested to get the sockets for the current connection. This function * will then be called once for every connection that the multi interface * keeps track of. This function will only be called for connections that are * in the proper state to have this information available. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/transfer.c#L1148-L1192
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
Curl_sleep_time
long Curl_sleep_time(curl_off_t rate_bps, curl_off_t cur_rate_bps, int pkt_size) { curl_off_t min_sleep = 0; curl_off_t rv = 0; if(rate_bps == 0) return 0; /* If running faster than about .1% of the desired speed, slow * us down a bit. Use shift instead of division as the 0.1% * cutoff is arbitrary anyway. */ if(cur_rate_bps > (rate_bps + (rate_bps >> 10))) { /* running too fast, decrease target rate by 1/64th of rate */ rate_bps -= rate_bps >> 6; min_sleep = 1; } else if(cur_rate_bps < (rate_bps - (rate_bps >> 10))) { /* running too slow, increase target rate by 1/64th of rate */ rate_bps += rate_bps >> 6; } /* Determine number of milliseconds to wait until we do * the next packet at the adjusted rate. We should wait * longer when using larger packets, for instance. */ rv = ((curl_off_t)((pkt_size * 8) * 1000) / rate_bps); /* Catch rounding errors and always slow down at least 1ms if * we are running too fast. */ if(rv < min_sleep) rv = min_sleep; /* Bound value to fit in 'long' on 32-bit platform. That's * plenty long enough anyway! */ if(rv > 0x7fffffff) rv = 0x7fffffff; return (long)rv; }
/* * Determine optimum sleep time based on configured rate, current rate, * and packet size. * Returns value in milliseconds. * * The basic idea is to adjust the desired rate up/down in this method * based on whether we are running too slow or too fast. Then, calculate * how many milliseconds to wait for the next packet to achieve this new * rate. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/transfer.c#L1204-L1246
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
Curl_pretransfer
CURLcode Curl_pretransfer(struct SessionHandle *data) { CURLcode res; if(!data->change.url) { /* we can't do anything without URL */ failf(data, "No URL set!"); return CURLE_URL_MALFORMAT; } /* Init the SSL session ID cache here. We do it here since we want to do it after the *_setopt() calls (that could specify the size of the cache) but before any transfer takes place. */ res = Curl_ssl_initsessions(data, data->set.ssl.max_ssl_sessions); if(res) return res; data->set.followlocation=0; /* reset the location-follow counter */ data->state.this_is_a_follow = FALSE; /* reset this */ data->state.errorbuf = FALSE; /* no error has occurred */ data->state.httpversion = 0; /* don't assume any particular server version */ data->state.ssl_connect_retry = FALSE; data->state.authproblem = FALSE; data->state.authhost.want = data->set.httpauth; data->state.authproxy.want = data->set.proxyauth; Curl_safefree(data->info.wouldredirect); data->info.wouldredirect = NULL; /* If there is a list of cookie files to read, do it now! */ if(data->change.cookielist) Curl_cookie_loadfiles(data); /* If there is a list of host pairs to deal with */ if(data->change.resolve) res = Curl_loadhostpairs(data); if(!res) { /* Allow data->set.use_port to set which port to use. This needs to be * disabled for example when we follow Location: headers to URLs using * different ports! */ data->state.allow_port = TRUE; #if defined(HAVE_SIGNAL) && defined(SIGPIPE) && !defined(HAVE_MSG_NOSIGNAL) /************************************************************* * Tell signal handler to ignore SIGPIPE *************************************************************/ if(!data->set.no_signal) data->state.prev_signal = signal(SIGPIPE, SIG_IGN); #endif Curl_initinfo(data); /* reset session-specific information "variables" */ Curl_pgrsStartNow(data); if(data->set.timeout) Curl_expire(data, data->set.timeout); if(data->set.connecttimeout) Curl_expire(data, data->set.connecttimeout); /* In case the handle is re-used and an authentication method was picked in the session we need to make sure we only use the one(s) we now consider to be fine */ data->state.authhost.picked &= data->state.authhost.want; data->state.authproxy.picked &= data->state.authproxy.want; } return res; }
/* * Curl_pretransfer() is called immediately before a transfer starts. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/transfer.c#L1251-L1319
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
Curl_posttransfer
CURLcode Curl_posttransfer(struct SessionHandle *data) { #if defined(HAVE_SIGNAL) && defined(SIGPIPE) && !defined(HAVE_MSG_NOSIGNAL) /* restore the signal handler for SIGPIPE before we get back */ if(!data->set.no_signal) signal(SIGPIPE, data->state.prev_signal); #else (void)data; /* unused parameter */ #endif return CURLE_OK; }
/* * Curl_posttransfer() is called immediately after a transfer ends */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/transfer.c#L1324-L1335
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
strlen_url
static size_t strlen_url(const char *url) { const char *ptr; size_t newlen=0; bool left=TRUE; /* left side of the ? */ for(ptr=url; *ptr; ptr++) { switch(*ptr) { case '?': left=FALSE; /* fall through */ default: newlen++; break; case ' ': if(left) newlen+=3; else newlen++; break; } } return newlen; }
/* * strlen_url() returns the length of the given URL if the spaces within the * URL were properly URL encoded. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/transfer.c#L1342-L1365
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
strcpy_url
static void strcpy_url(char *output, const char *url) { /* we must add this with whitespace-replacing */ bool left=TRUE; const char *iptr; char *optr = output; for(iptr = url; /* read from here */ *iptr; /* until zero byte */ iptr++) { switch(*iptr) { case '?': left=FALSE; /* fall through */ default: *optr++=*iptr; break; case ' ': if(left) { *optr++='%'; /* add a '%' */ *optr++='2'; /* add a '2' */ *optr++='0'; /* add a '0' */ } else *optr++='+'; /* add a '+' here */ break; } } *optr=0; /* zero terminate output buffer */ }
/* strcpy_url() copies a url to a output buffer and URL-encodes the spaces in * the source URL accordingly. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/transfer.c#L1370-L1399
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
is_absolute_url
static bool is_absolute_url(const char *url) { char prot[16]; /* URL protocol string storage */ char letter; /* used for a silly sscanf */ return (2 == sscanf(url, "%15[^?&/:]://%c", prot, &letter)) ? TRUE : FALSE; }
/* * Returns true if the given URL is absolute (as opposed to relative) */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/transfer.c#L1404-L1410
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
Curl_follow
CURLcode Curl_follow(struct SessionHandle *data, char *newurl, /* this 'newurl' is the Location: string, and it must be malloc()ed before passed here */ followtype type) /* see transfer.h */ { #ifdef CURL_DISABLE_HTTP (void)data; (void)newurl; (void)type; /* Location: following will not happen when HTTP is disabled */ return CURLE_TOO_MANY_REDIRECTS; #else /* Location: redirect */ bool disallowport = FALSE; if(type == FOLLOW_REDIR) { if((data->set.maxredirs != -1) && (data->set.followlocation >= data->set.maxredirs)) { failf(data,"Maximum (%ld) redirects followed", data->set.maxredirs); return CURLE_TOO_MANY_REDIRECTS; } /* mark the next request as a followed location: */ data->state.this_is_a_follow = TRUE; data->set.followlocation++; /* count location-followers */ if(data->set.http_auto_referer) { /* We are asked to automatically set the previous URL as the referer when we get the next URL. We pick the ->url field, which may or may not be 100% correct */ if(data->change.referer_alloc) { Curl_safefree(data->change.referer); data->change.referer_alloc = FALSE; } data->change.referer = strdup(data->change.url); if(!data->change.referer) return CURLE_OUT_OF_MEMORY; data->change.referer_alloc = TRUE; /* yes, free this later */ } } if(!is_absolute_url(newurl)) { /*** *DANG* this is an RFC 2068 violation. The URL is supposed to be absolute and this doesn't seem to be that! */ char *absolute = concat_url(data->change.url, newurl); if(!absolute) return CURLE_OUT_OF_MEMORY; free(newurl); newurl = absolute; } else { /* This is an absolute URL, don't allow the custom port number */ disallowport = TRUE; if(strchr(newurl, ' ')) { /* This new URL contains at least one space, this is a mighty stupid redirect but we still make an effort to do "right". */ char *newest; size_t newlen = strlen_url(newurl); newest = malloc(newlen+1); /* get memory for this */ if(!newest) return CURLE_OUT_OF_MEMORY; strcpy_url(newest, newurl); /* create a space-free URL */ free(newurl); /* that was no good */ newurl = newest; /* use this instead now */ } } if(type == FOLLOW_FAKE) { /* we're only figuring out the new url if we would've followed locations but now we're done so we can get out! */ data->info.wouldredirect = newurl; return CURLE_OK; } if(disallowport) data->state.allow_port = FALSE; if(data->change.url_alloc) { Curl_safefree(data->change.url); data->change.url_alloc = FALSE; } data->change.url = newurl; data->change.url_alloc = TRUE; newurl = NULL; /* don't free! */ infof(data, "Issue another request to this URL: '%s'\n", data->change.url); /* * We get here when the HTTP code is 300-399 (and 401). We need to perform * differently based on exactly what return code there was. * * News from 7.10.6: we can also get here on a 401 or 407, in case we act on * a HTTP (proxy-) authentication scheme other than Basic. */ switch(data->info.httpcode) { /* 401 - Act on a WWW-Authenticate, we keep on moving and do the Authorization: XXXX header in the HTTP request code snippet */ /* 407 - Act on a Proxy-Authenticate, we keep on moving and do the Proxy-Authorization: XXXX header in the HTTP request code snippet */ /* 300 - Multiple Choices */ /* 306 - Not used */ /* 307 - Temporary Redirect */ default: /* for all above (and the unknown ones) */ /* Some codes are explicitly mentioned since I've checked RFC2616 and they * seem to be OK to POST to. */ break; case 301: /* Moved Permanently */ /* (quote from RFC2616, section 10.3.2): * * When automatically redirecting a POST request after receiving a 301 * status code, some existing HTTP/1.0 user agents will erroneously change * it into a GET request. * * ---- * * As most of the important user agents do this obvious RFC2616 violation, * many webservers expect this. So these servers often answers to a POST * request with an error page. To be sure that libcurl gets the page that * most user agents would get, libcurl has to force GET. * * This behavior can be overridden with CURLOPT_POSTREDIR. */ if((data->set.httpreq == HTTPREQ_POST || data->set.httpreq == HTTPREQ_POST_FORM) && !(data->set.keep_post & CURL_REDIR_POST_301)) { infof(data, "Violate RFC 2616/10.3.2 and switch from POST to GET\n"); data->set.httpreq = HTTPREQ_GET; } break; case 302: /* Found */ /* (From 10.3.3) Note: RFC 1945 and RFC 2068 specify that the client is not allowed to change the method on the redirected request. However, most existing user agent implementations treat 302 as if it were a 303 response, performing a GET on the Location field-value regardless of the original request method. The status codes 303 and 307 have been added for servers that wish to make unambiguously clear which kind of reaction is expected of the client. (From 10.3.4) Note: Many pre-HTTP/1.1 user agents do not understand the 303 status. When interoperability with such clients is a concern, the 302 status code may be used instead, since most user agents react to a 302 response as described here for 303. This behavior can be overridden with CURLOPT_POSTREDIR */ if((data->set.httpreq == HTTPREQ_POST || data->set.httpreq == HTTPREQ_POST_FORM) && !(data->set.keep_post & CURL_REDIR_POST_302)) { infof(data, "Violate RFC 2616/10.3.3 and switch from POST to GET\n"); data->set.httpreq = HTTPREQ_GET; } break; case 303: /* See Other */ /* Disable both types of POSTs, unless the user explicitely asks for POST after POST */ if(data->set.httpreq != HTTPREQ_GET && !(data->set.keep_post & CURL_REDIR_POST_303)) { data->set.httpreq = HTTPREQ_GET; /* enforce GET request */ infof(data, "Disables POST, goes with %s\n", data->set.opt_no_body?"HEAD":"GET"); } break; case 304: /* Not Modified */ /* 304 means we did a conditional request and it was "Not modified". * We shouldn't get any Location: header in this response! */ break; case 305: /* Use Proxy */ /* (quote from RFC2616, section 10.3.6): * "The requested resource MUST be accessed through the proxy given * by the Location field. The Location field gives the URI of the * proxy. The recipient is expected to repeat this single request * via the proxy. 305 responses MUST only be generated by origin * servers." */ break; } Curl_pgrsTime(data, TIMER_REDIRECT); Curl_pgrsResetTimesSizes(data); return CURLE_OK; #endif /* CURL_DISABLE_HTTP */ }
/* CURL_DISABLE_HTTP */ /* * Curl_follow() handles the URL redirect magic. Pass in the 'newurl' string * as given by the remote server and set up the new URL to request. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/transfer.c#L1574-L1776
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
Curl_retry_request
CURLcode Curl_retry_request(struct connectdata *conn, char **url) { struct SessionHandle *data = conn->data; *url = NULL; /* if we're talking upload, we can't do the checks below, unless the protocol is HTTP as when uploading over HTTP we will still get a response */ if(data->set.upload && !(conn->handler->protocol&(CURLPROTO_HTTP|CURLPROTO_RTSP))) return CURLE_OK; if(/* workaround for broken TLS servers */ data->state.ssl_connect_retry || ((data->req.bytecount + data->req.headerbytecount == 0) && conn->bits.reuse && !data->set.opt_no_body && data->set.rtspreq != RTSPREQ_RECEIVE)) { /* We got no data, we attempted to re-use a connection and yet we want a "body". This might happen if the connection was left alive when we were done using it before, but that was closed when we wanted to read from it again. Bad luck. Retry the same request on a fresh connect! */ infof(conn->data, "Connection died, retrying a fresh connect\n"); *url = strdup(conn->data->change.url); if(!*url) return CURLE_OUT_OF_MEMORY; conn->bits.close = TRUE; /* close this connection */ conn->bits.retry = TRUE; /* mark this as a connection we're about to retry. Marking it this way should prevent i.e HTTP transfers to return error just because nothing has been transferred! */ if((conn->handler->protocol&CURLPROTO_HTTP) && data->state.proto.http->writebytecount) return Curl_readrewind(conn); } return CURLE_OK; }
/* Returns CURLE_OK *and* sets '*url' if a request retry is wanted. NOTE: that the *url is malloc()ed. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/transfer.c#L1838-L1879
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
Curl_setup_transfer
void Curl_setup_transfer( struct connectdata *conn, /* connection data */ int sockindex, /* socket index to read from or -1 */ curl_off_t size, /* -1 if unknown at this point */ bool getheader, /* TRUE if header parsing is wanted */ curl_off_t *bytecountp, /* return number of bytes read or NULL */ int writesockindex, /* socket index to write to, it may very well be the same we read from. -1 disables */ curl_off_t *writecountp /* return number of bytes written or NULL */ ) { struct SessionHandle *data; struct SingleRequest *k; DEBUGASSERT(conn != NULL); data = conn->data; k = &data->req; DEBUGASSERT((sockindex <= 1) && (sockindex >= -1)); /* now copy all input parameters */ conn->sockfd = sockindex == -1 ? CURL_SOCKET_BAD : conn->sock[sockindex]; conn->writesockfd = writesockindex == -1 ? CURL_SOCKET_BAD:conn->sock[writesockindex]; k->getheader = getheader; k->size = size; k->bytecountp = bytecountp; k->writebytecountp = writecountp; /* The code sequence below is placed in this function just because all necessary input is not always known in do_complete() as this function may be called after that */ if(!k->getheader) { k->header = FALSE; if(size > 0) Curl_pgrsSetDownloadSize(data, size); } /* we want header and/or body, if neither then don't do this! */ if(k->getheader || !data->set.opt_no_body) { if(conn->sockfd != CURL_SOCKET_BAD) k->keepon |= KEEP_RECV; if(conn->writesockfd != CURL_SOCKET_BAD) { /* HTTP 1.1 magic: Even if we require a 100-return code before uploading data, we might need to write data before that since the REQUEST may not have been finished sent off just yet. Thus, we must check if the request has been sent before we set the state info where we wait for the 100-return code */ if((data->state.expect100header) && (data->state.proto.http->sending == HTTPSEND_BODY)) { /* wait with write until we either got 100-continue or a timeout */ k->exp100 = EXP100_AWAITING_CONTINUE; k->start100 = Curl_tvnow(); /* set a timeout for the multi interface */ Curl_expire(data, CURL_TIMEOUT_EXPECT_100); } else { if(data->state.expect100header) /* when we've sent off the rest of the headers, we must await a 100-continue but first finish sending the request */ k->exp100 = EXP100_SENDING_REQUEST; /* enable the write bit when we're not waiting for continue */ k->keepon |= KEEP_SEND; } } /* if(conn->writesockfd != CURL_SOCKET_BAD) */ } /* if(k->getheader || !data->set.opt_no_body) */ }
/* * Curl_setup_transfer() is called to setup some basic properties for the * upcoming transfer. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/transfer.c#L1885-L1964
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
Curl_close
CURLcode Curl_close(struct SessionHandle *data) { struct Curl_multi *m; if(!data) return CURLE_OK; Curl_expire(data, 0); /* shut off timers */ m = data->multi; if(m) /* This handle is still part of a multi handle, take care of this first and detach this handle from there. */ curl_multi_remove_handle(data->multi, data); if(data->multi_easy) /* when curl_easy_perform() is used, it creates its own multi handle to use and this is the one */ curl_multi_cleanup(data->multi_easy); /* Destroy the timeout list that is held in the easy handle. It is /normally/ done by curl_multi_remove_handle() but this is "just in case" */ if(data->state.timeoutlist) { Curl_llist_destroy(data->state.timeoutlist, NULL); data->state.timeoutlist = NULL; } data->magic = 0; /* force a clear AFTER the possibly enforced removal from the multi handle, since that function uses the magic field! */ if(data->state.rangestringalloc) free(data->state.range); /* Free the pathbuffer */ Curl_safefree(data->state.pathbuffer); data->state.path = NULL; Curl_safefree(data->state.proto.generic); /* Close down all open SSL info and sessions */ Curl_ssl_close_all(data); Curl_safefree(data->state.first_host); Curl_safefree(data->state.scratch); Curl_ssl_free_certinfo(data); if(data->change.referer_alloc) { Curl_safefree(data->change.referer); data->change.referer_alloc = FALSE; } data->change.referer = NULL; if(data->change.url_alloc) { Curl_safefree(data->change.url); data->change.url_alloc = FALSE; } data->change.url = NULL; Curl_safefree(data->state.headerbuff); Curl_flush_cookies(data, 1); Curl_digest_cleanup(data); Curl_safefree(data->info.contenttype); Curl_safefree(data->info.wouldredirect); /* this destroys the channel and we cannot use it anymore after this */ Curl_resolver_cleanup(data->state.resolver); Curl_convert_close(data); /* No longer a dirty share, if it exists */ if(data->share) { Curl_share_lock(data, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE); data->share->dirty--; Curl_share_unlock(data, CURL_LOCK_DATA_SHARE); } Curl_freeset(data); free(data); return CURLE_OK; }
/* * This is the internal function curl_easy_cleanup() calls. This should * cleanup and free all resources associated with this sessionhandle. * * NOTE: if we ever add something that attempts to write to a socket or * similar here, we must ignore SIGPIPE first. It is currently only done * when curl_easy_perform() is invoked. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L366-L450
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
Curl_init_userdefined
CURLcode Curl_init_userdefined(struct UserDefined *set) { CURLcode res = CURLE_OK; set->out = stdout; /* default output to stdout */ set->in = stdin; /* default input from stdin */ set->err = stderr; /* default stderr to stderr */ /* use fwrite as default function to store output */ set->fwrite_func = (curl_write_callback)fwrite; /* use fread as default function to read input */ set->fread_func = (curl_read_callback)fread; set->is_fread_set = 0; set->is_fwrite_set = 0; set->seek_func = ZERO_NULL; set->seek_client = ZERO_NULL; /* conversion callbacks for non-ASCII hosts */ set->convfromnetwork = ZERO_NULL; set->convtonetwork = ZERO_NULL; set->convfromutf8 = ZERO_NULL; set->infilesize = -1; /* we don't know any size */ set->postfieldsize = -1; /* unknown size */ set->maxredirs = -1; /* allow any amount by default */ set->httpreq = HTTPREQ_GET; /* Default HTTP request */ set->rtspreq = RTSPREQ_OPTIONS; /* Default RTSP request */ set->ftp_use_epsv = TRUE; /* FTP defaults to EPSV operations */ set->ftp_use_eprt = TRUE; /* FTP defaults to EPRT operations */ set->ftp_use_pret = FALSE; /* mainly useful for drftpd servers */ set->ftp_filemethod = FTPFILE_MULTICWD; set->dns_cache_timeout = 60; /* Timeout every 60 seconds by default */ /* Set the default size of the SSL session ID cache */ set->ssl.max_ssl_sessions = 5; set->proxyport = CURL_DEFAULT_PROXY_PORT; /* from url.h */ set->proxytype = CURLPROXY_HTTP; /* defaults to HTTP proxy */ set->httpauth = CURLAUTH_BASIC; /* defaults to basic */ set->proxyauth = CURLAUTH_BASIC; /* defaults to basic */ /* make libcurl quiet by default: */ set->hide_progress = TRUE; /* CURLOPT_NOPROGRESS changes these */ /* * libcurl 7.10 introduced SSL verification *by default*! This needs to be * switched off unless wanted. */ set->ssl.verifypeer = TRUE; set->ssl.verifyhost = TRUE; #ifdef USE_TLS_SRP set->ssl.authtype = CURL_TLSAUTH_NONE; #endif set->ssh_auth_types = CURLSSH_AUTH_DEFAULT; /* defaults to any auth type */ set->ssl.sessionid = TRUE; /* session ID caching enabled by default */ set->new_file_perms = 0644; /* Default permissions */ set->new_directory_perms = 0755; /* Default permissions */ /* for the *protocols fields we don't use the CURLPROTO_ALL convenience define since we internally only use the lower 16 bits for the passed in bitmask to not conflict with the private bits */ set->allowed_protocols = CURLPROTO_ALL; set->redir_protocols = CURLPROTO_ALL & ~(CURLPROTO_FILE|CURLPROTO_SCP); /* not FILE or SCP */ #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI) /* * disallow unprotected protection negotiation NEC reference implementation * seem not to follow rfc1961 section 4.3/4.4 */ set->socks5_gssapi_nec = FALSE; /* set default gssapi service name */ res = setstropt(&set->str[STRING_SOCKS5_GSSAPI_SERVICE], (char *) CURL_DEFAULT_SOCKS5_GSSAPI_SERVICE); if(res != CURLE_OK) return res; #endif /* This is our preferred CA cert bundle/path since install time */ #if defined(CURL_CA_BUNDLE) res = setstropt(&set->str[STRING_SSL_CAFILE], (char *) CURL_CA_BUNDLE); #elif defined(CURL_CA_PATH) res = setstropt(&set->str[STRING_SSL_CAPATH], (char *) CURL_CA_PATH); #endif set->wildcardmatch = FALSE; set->chunk_bgn = ZERO_NULL; set->chunk_end = ZERO_NULL; /* tcp keepalives are disabled by default, but provide reasonable values for * the interval and idle times. */ set->tcp_keepalive = FALSE; set->tcp_keepintvl = 60; set->tcp_keepidle = 60; return res; }
/* * Initialize the UserDefined fields within a SessionHandle. * This may be safely called on a new or existing SessionHandle. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L456-L559
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
Curl_open
CURLcode Curl_open(struct SessionHandle **curl) { CURLcode res = CURLE_OK; struct SessionHandle *data; CURLcode status; /* Very simple start-up: alloc the struct, init it with zeroes and return */ data = calloc(1, sizeof(struct SessionHandle)); if(!data) { /* this is a very serious error */ DEBUGF(fprintf(stderr, "Error: calloc of SessionHandle failed\n")); return CURLE_OUT_OF_MEMORY; } data->magic = CURLEASY_MAGIC_NUMBER; status = Curl_resolver_init(&data->state.resolver); if(status) { DEBUGF(fprintf(stderr, "Error: resolver_init failed\n")); free(data); return status; } /* We do some initial setup here, all those fields that can't be just 0 */ data->state.headerbuff = malloc(HEADERSIZE); if(!data->state.headerbuff) { DEBUGF(fprintf(stderr, "Error: malloc of headerbuff failed\n")); res = CURLE_OUT_OF_MEMORY; } else { Curl_easy_initHandleData(data); res = Curl_init_userdefined(&data->set); data->state.headersize=HEADERSIZE; Curl_convert_init(data); /* most recent connection is not yet defined */ data->state.lastconnect = NULL; data->progress.flags |= PGRS_HIDE; data->state.current_speed = -1; /* init to negative == impossible */ data->wildcard.state = CURLWC_INIT; data->wildcard.filelist = NULL; data->set.fnmatch = ZERO_NULL; /* This no longer creates a connection cache here. It is instead made on the first call to curl_easy_perform() or when the handle is added to a multi stack. */ } if(res) { Curl_resolver_cleanup(data->state.resolver); if(data->state.headerbuff) free(data->state.headerbuff); Curl_freeset(data); free(data); data = NULL; } else *curl = data; return res; }
/** * Curl_open() * * @param curl is a pointer to a sessionhandle pointer that gets set by this * function. * @return CURLcode */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L569-L634
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
SocketIsDead
static bool SocketIsDead(curl_socket_t sock) { int sval; bool ret_val = TRUE; sval = Curl_socket_ready(sock, CURL_SOCKET_BAD, 0); if(sval == 0) /* timeout */ ret_val = FALSE; return ret_val; }
/* * This function should return TRUE if the socket is to be assumed to * be dead. Most commonly this happens when the server has closed the * connection due to inactivity. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L2587-L2598
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
Curl_printPipeline
static void Curl_printPipeline(struct curl_llist *pipeline) { struct curl_llist_element *curr; curr = pipeline->head; while(curr) { struct SessionHandle *data = (struct SessionHandle *) curr->ptr; infof(data, "Handle in pipeline: %s\n", data->state.path); curr = curr->next; } }
/* this code is saved here as it is useful for debugging purposes */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L2647-L2657
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
Curl_getoff_all_pipelines
void Curl_getoff_all_pipelines(struct SessionHandle *data, struct connectdata *conn) { bool recv_head = (conn->readchannel_inuse && (gethandleathead(conn->recv_pipe) == data)) ? TRUE : FALSE; bool send_head = (conn->writechannel_inuse && (gethandleathead(conn->send_pipe) == data)) ? TRUE : FALSE; if(Curl_removeHandleFromPipeline(data, conn->recv_pipe) && recv_head) conn->readchannel_inuse = FALSE; if(Curl_removeHandleFromPipeline(data, conn->send_pipe) && send_head) conn->writechannel_inuse = FALSE; Curl_removeHandleFromPipeline(data, conn->pend_pipe); Curl_removeHandleFromPipeline(data, conn->done_pipe); }
/* remove the specified connection from all (possible) pipelines and related queues */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L2672-L2687
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
ConnectionExists
static bool ConnectionExists(struct SessionHandle *data, struct connectdata *needle, struct connectdata **usethis) { struct connectdata *check; struct connectdata *chosen = 0; bool canPipeline = IsPipeliningPossible(data, needle); bool wantNTLM = (data->state.authhost.want==CURLAUTH_NTLM) || (data->state.authhost.want==CURLAUTH_NTLM_WB) ? TRUE : FALSE; struct connectbundle *bundle; /* Look up the bundle with all the connections to this particular host */ bundle = Curl_conncache_find_bundle(data->state.conn_cache, needle->host.name); if(bundle) { struct curl_llist_element *curr; infof(data, "Found bundle for host %s: %p\n", needle->host.name, bundle); curr = bundle->conn_list->head; while(curr) { bool match = FALSE; bool credentialsMatch = FALSE; size_t pipeLen; /* * Note that if we use a HTTP proxy, we check connections to that * proxy and not to the actual remote server. */ check = curr->ptr; curr = curr->next; pipeLen = check->send_pipe->size + check->recv_pipe->size; if(!pipeLen && !check->inuse) { /* The check for a dead socket makes sense only if there are no handles in pipeline and the connection isn't already marked in use */ bool dead; if(check->handler->protocol & CURLPROTO_RTSP) /* RTSP is a special case due to RTP interleaving */ dead = Curl_rtsp_connisdead(check); else dead = SocketIsDead(check->sock[FIRSTSOCKET]); if(dead) { check->data = data; infof(data, "Connection %d seems to be dead!\n", check->connection_id); /* disconnect resources */ Curl_disconnect(check, /* dead_connection */ TRUE); continue; } } if(canPipeline) { /* Make sure the pipe has only GET requests */ struct SessionHandle* sh = gethandleathead(check->send_pipe); struct SessionHandle* rh = gethandleathead(check->recv_pipe); if(sh) { if(!IsPipeliningPossible(sh, check)) continue; } else if(rh) { if(!IsPipeliningPossible(rh, check)) continue; } #ifdef DEBUGBUILD if(pipeLen > MAX_PIPELINE_LENGTH) { infof(data, "BAD! Connection #%ld has too big pipeline!\n", check->connection_id); } #endif } else { if(pipeLen > 0) { /* can only happen within multi handles, and means that another easy handle is using this connection */ continue; } if(Curl_resolver_asynch()) { /* ip_addr_str[0] is NUL only if the resolving of the name hasn't completed yet and until then we don't re-use this connection */ if(!check->ip_addr_str[0]) { infof(data, "Connection #%ld is still name resolving, can't reuse\n", check->connection_id); continue; } } if((check->sock[FIRSTSOCKET] == CURL_SOCKET_BAD) || check->bits.close) { /* Don't pick a connection that hasn't connected yet or that is going to get closed. */ infof(data, "Connection #%ld isn't open enough, can't reuse\n", check->connection_id); #ifdef DEBUGBUILD if(check->recv_pipe->size > 0) { infof(data, "BAD! Unconnected #%ld has a non-empty recv pipeline!\n", check->connection_id); } #endif continue; } } if((needle->handler->flags&PROTOPT_SSL) != (check->handler->flags&PROTOPT_SSL)) /* don't do mixed SSL and non-SSL connections */ if(!(needle->handler->protocol & check->handler->protocol)) /* except protocols that have been upgraded via TLS */ continue; if(needle->handler->flags&PROTOPT_SSL) { if((data->set.ssl.verifypeer != check->verifypeer) || (data->set.ssl.verifyhost != check->verifyhost)) continue; } if(needle->bits.proxy != check->bits.proxy) /* don't do mixed proxy and non-proxy connections */ continue; if(!canPipeline && check->inuse) /* this request can't be pipelined but the checked connection is already in use so we skip it */ continue; if(needle->localdev || needle->localport) { /* If we are bound to a specific local end (IP+port), we must not re-use a random other one, although if we didn't ask for a particular one we can reuse one that was bound. This comparison is a bit rough and too strict. Since the input parameters can be specified in numerous ways and still end up the same it would take a lot of processing to make it really accurate. Instead, this matching will assume that re-uses of bound connections will most likely also re-use the exact same binding parameters and missing out a few edge cases shouldn't hurt anyone very much. */ if((check->localport != needle->localport) || (check->localportrange != needle->localportrange) || !check->localdev || !needle->localdev || strcmp(check->localdev, needle->localdev)) continue; } if(!needle->bits.httpproxy || needle->handler->flags&PROTOPT_SSL || (needle->bits.httpproxy && check->bits.httpproxy && needle->bits.tunnel_proxy && check->bits.tunnel_proxy && Curl_raw_equal(needle->proxy.name, check->proxy.name) && (needle->port == check->port))) { /* The requested connection does not use a HTTP proxy or it uses SSL or it is a non-SSL protocol tunneled over the same http proxy name and port number or it is a non-SSL protocol which is allowed to be upgraded via TLS */ if((Curl_raw_equal(needle->handler->scheme, check->handler->scheme) || needle->handler->protocol & check->handler->protocol) && Curl_raw_equal(needle->host.name, check->host.name) && needle->remote_port == check->remote_port) { if(needle->handler->flags & PROTOPT_SSL) { /* This is a SSL connection so verify that we're using the same SSL options as well */ if(!Curl_ssl_config_matches(&needle->ssl_config, &check->ssl_config)) { DEBUGF(infof(data, "Connection #%ld has different SSL parameters, " "can't reuse\n", check->connection_id)); continue; } else if(check->ssl[FIRSTSOCKET].state != ssl_connection_complete) { DEBUGF(infof(data, "Connection #%ld has not started SSL connect, " "can't reuse\n", check->connection_id)); continue; } } if((needle->handler->protocol & CURLPROTO_FTP) || ((needle->handler->protocol & CURLPROTO_HTTP) && wantNTLM)) { /* This is FTP or HTTP+NTLM, verify that we're using the same name and password as well */ if(!strequal(needle->user, check->user) || !strequal(needle->passwd, check->passwd)) { /* one of them was different */ continue; } credentialsMatch = TRUE; } match = TRUE; } } else { /* The requested needle connection is using a proxy, is the checked one using the same host, port and type? */ if(check->bits.proxy && (needle->proxytype == check->proxytype) && (needle->bits.tunnel_proxy == check->bits.tunnel_proxy) && Curl_raw_equal(needle->proxy.name, check->proxy.name) && needle->port == check->port) { /* This is the same proxy connection, use it! */ match = TRUE; } } if(match) { chosen = check; /* If we are not looking for an NTLM connection, we can choose this one immediately. */ if(!wantNTLM) break; /* Otherwise, check if this is already authenticating with the right credentials. If not, keep looking so that we can reuse NTLM connections if possible. (Especially we must reuse the same connection if partway through a handshake!) */ if(credentialsMatch && chosen->ntlm.state != NTLMSTATE_NONE) break; } } } if(chosen) { chosen->inuse = TRUE; /* mark this as being in use so that no other handle in a multi stack may nick it */ *usethis = chosen; return TRUE; /* yes, we found one to use! */ } return FALSE; /* no matching connecting exists */ }
/* * Given one filled in connection struct (named needle), this function should * detect if there already is one that has all the significant details * exactly the same and thus should be used instead. * * If there is a match, this function returns TRUE - and has marked the * connection as 'in-use'. It must later be called with ConnectionDone() to * return back to 'idle' (unused) state. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L2777-L3016
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
ConnectionDone
static bool ConnectionDone(struct SessionHandle *data, struct connectdata *conn) { /* data->multi->maxconnects can be negative, deal with it. */ size_t maxconnects = (data->multi->maxconnects < 0) ? 0 : data->multi->maxconnects; struct connectdata *conn_candidate = NULL; /* Mark the current connection as 'unused' */ conn->inuse = FALSE; if(maxconnects > 0 && data->state.conn_cache->num_connections > maxconnects) { infof(data, "Connection cache is full, closing the oldest one.\n"); conn_candidate = find_oldest_idle_connection(data); if(conn_candidate) { /* Set the connection's owner correctly */ conn_candidate->data = data; /* the winner gets the honour of being disconnected */ (void)Curl_disconnect(conn_candidate, /* dead_connection */ FALSE); } } return (conn_candidate == conn) ? FALSE : TRUE; }
/* Mark the connection as 'idle', or close it if the cache is full. Returns TRUE if the connection is kept, or FALSE if it was closed. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L3020-L3047
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
ConnectionStore
static CURLcode ConnectionStore(struct SessionHandle *data, struct connectdata *conn) { static int connection_id_counter = 0; CURLcode result; /* Assign a number to the connection for easier tracking in the log output */ conn->connection_id = connection_id_counter++; result = Curl_conncache_add_conn(data->state.conn_cache, conn); if(result != CURLE_OK) conn->connection_id = -1; return result; }
/* * The given input connection struct pointer is to be stored in the connection * cache. If the cache is already full, least interesting existing connection * (if any) gets closed. * * The given connection should be unique. That must've been checked prior to * this call. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L3057-L3073
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
Curl_connected_proxy
CURLcode Curl_connected_proxy(struct connectdata *conn) { switch(conn->proxytype) { #ifndef CURL_DISABLE_PROXY case CURLPROXY_SOCKS5: case CURLPROXY_SOCKS5_HOSTNAME: return Curl_SOCKS5(conn->proxyuser, conn->proxypasswd, conn->host.name, conn->remote_port, FIRSTSOCKET, conn); case CURLPROXY_SOCKS4: return Curl_SOCKS4(conn->proxyuser, conn->host.name, conn->remote_port, FIRSTSOCKET, conn, FALSE); case CURLPROXY_SOCKS4A: return Curl_SOCKS4(conn->proxyuser, conn->host.name, conn->remote_port, FIRSTSOCKET, conn, TRUE); #endif /* CURL_DISABLE_PROXY */ case CURLPROXY_HTTP: case CURLPROXY_HTTP_1_0: /* do nothing here. handled later. */ break; default: break; } /* switch proxytype */ return CURLE_OK; }
/* after a TCP connection to the proxy has been verified, this function does the next magic step. Note: this function's sub-functions call failf() */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L3081-L3109
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
Curl_protocol_connecting
CURLcode Curl_protocol_connecting(struct connectdata *conn, bool *done) { CURLcode result=CURLE_OK; if(conn && conn->handler->connecting) { *done = FALSE; result = conn->handler->connecting(conn, done); } else *done = TRUE; return result; }
/* * We are doing protocol-specific connecting and this is being called over and * over from the multi interface until the connection phase is done on * protocol layer. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L3191-L3204
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
Curl_protocol_doing
CURLcode Curl_protocol_doing(struct connectdata *conn, bool *done) { CURLcode result=CURLE_OK; if(conn && conn->handler->doing) { *done = FALSE; result = conn->handler->doing(conn, done); } else *done = TRUE; return result; }
/* * We are DOING this is being called over and over from the multi interface * until the DOING phase is done on protocol layer. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L3211-L3223
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
Curl_protocol_connect
CURLcode Curl_protocol_connect(struct connectdata *conn, bool *protocol_done) { CURLcode result=CURLE_OK; *protocol_done = FALSE; if(conn->bits.tcpconnect[FIRSTSOCKET] && conn->bits.protoconnstart) { /* We already are connected, get back. This may happen when the connect worked fine in the first call, like when we connect to a local server or proxy. Note that we don't know if the protocol is actually done. Unless this protocol doesn't have any protocol-connect callback, as then we know we're done. */ if(!conn->handler->connecting) *protocol_done = TRUE; return CURLE_OK; } if(!conn->bits.protoconnstart) { result = Curl_proxy_connect(conn); if(result) return result; if(conn->bits.tunnel_proxy && conn->bits.httpproxy && (conn->tunnel_state[FIRSTSOCKET] != TUNNEL_COMPLETE)) /* when using an HTTP tunnel proxy, await complete tunnel establishment before proceeding further. Return CURLE_OK so we'll be called again */ return CURLE_OK; if(conn->handler->connect_it) { /* is there a protocol-specific connect() procedure? */ /* Call the protocol-specific connect function */ result = conn->handler->connect_it(conn, protocol_done); } else *protocol_done = TRUE; /* it has started, possibly even completed but that knowledge isn't stored in this bit! */ if(!result) conn->bits.protoconnstart = TRUE; } return result; /* pass back status */ }
/* * We have discovered that the TCP connection has been successful, we can now * proceed with some action. * */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L3230-L3278
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
is_ASCII_name
static bool is_ASCII_name(const char *hostname) { const unsigned char *ch = (const unsigned char*)hostname; while(*ch) { if(*ch++ & 0x80) return FALSE; } return TRUE; }
/* * Helpers for IDNA convertions. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L3283-L3292
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
tld_check_name
static bool tld_check_name(struct SessionHandle *data, const char *ace_hostname) { size_t err_pos; char *uc_name = NULL; int rc; #ifndef CURL_DISABLE_VERBOSE_STRINGS const char *tld_errmsg = "<no msg>"; #else (void)data; #endif /* Convert (and downcase) ACE-name back into locale's character set */ rc = idna_to_unicode_lzlz(ace_hostname, &uc_name, 0); if(rc != IDNA_SUCCESS) return FALSE; rc = tld_check_lz(uc_name, &err_pos, NULL); #ifndef CURL_DISABLE_VERBOSE_STRINGS #ifdef HAVE_TLD_STRERROR if(rc != TLD_SUCCESS) tld_errmsg = tld_strerror((Tld_rc)rc); #endif if(rc == TLD_INVALID) infof(data, "WARNING: %s; pos %u = `%c'/0x%02X\n", tld_errmsg, err_pos, uc_name[err_pos], uc_name[err_pos] & 255); else if(rc != TLD_SUCCESS) infof(data, "WARNING: TLD check for %s failed; %s\n", uc_name, tld_errmsg); #endif /* CURL_DISABLE_VERBOSE_STRINGS */ if(uc_name) idn_free(uc_name); if(rc != TLD_SUCCESS) return FALSE; return TRUE; }
/* * Check if characters in hostname is allowed in Top Level Domain. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L3298-L3335
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
fix_hostname
static void fix_hostname(struct SessionHandle *data, struct connectdata *conn, struct hostname *host) { #ifndef USE_LIBIDN (void)data; (void)conn; #elif defined(CURL_DISABLE_VERBOSE_STRINGS) (void)conn; #endif /* set the name we use to display the host name */ host->dispname = host->name; if(!is_ASCII_name(host->name)) { #ifdef USE_LIBIDN /************************************************************* * Check name for non-ASCII and convert hostname to ACE form. *************************************************************/ if(stringprep_check_version(LIBIDN_REQUIRED_VERSION)) { char *ace_hostname = NULL; int rc = idna_to_ascii_lz(host->name, &ace_hostname, 0); infof (data, "Input domain encoded as `%s'\n", stringprep_locale_charset ()); if(rc != IDNA_SUCCESS) infof(data, "Failed to convert %s to ACE; %s\n", host->name, Curl_idn_strerror(conn,rc)); else { /* tld_check_name() displays a warning if the host name contains "illegal" characters for this TLD */ (void)tld_check_name(data, ace_hostname); host->encalloc = ace_hostname; /* change the name pointer to point to the encoded hostname */ host->name = host->encalloc; } } #elif defined(USE_WIN32_IDN) /************************************************************* * Check name for non-ASCII and convert hostname to ACE form. *************************************************************/ char *ace_hostname = NULL; int rc = curl_win32_idn_to_ascii(host->name, &ace_hostname); if(rc == 0) infof(data, "Failed to convert %s to ACE;\n", host->name); else { host->encalloc = ace_hostname; /* change the name pointer to point to the encoded hostname */ host->name = host->encalloc; } #else infof(data, "IDN support not present, can't parse Unicode domains\n"); #endif } }
/* * Perform any necessary IDN conversion of hostname */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L3341-L3394
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
parseurlandfillconn
static CURLcode parseurlandfillconn(struct SessionHandle *data, struct connectdata *conn, bool *prot_missing, char *user, char *passwd) { char *at; char *fragment; char *path = data->state.path; char *query; int rc; char protobuf[16]; const char *protop; CURLcode result; *prot_missing = FALSE; /************************************************************* * Parse the URL. * * We need to parse the url even when using the proxy, because we will need * the hostname and port in case we are trying to SSL connect through the * proxy -- and we don't know if we will need to use SSL until we parse the * url ... ************************************************************/ if((2 == sscanf(data->change.url, "%15[^:]:%[^\n]", protobuf, path)) && Curl_raw_equal(protobuf, "file")) { if(path[0] == '/' && path[1] == '/') { /* Allow omitted hostname (e.g. file:/<path>). This is not strictly * speaking a valid file: URL by RFC 1738, but treating file:/<path> as * file://localhost/<path> is similar to how other schemes treat missing * hostnames. See RFC 1808. */ /* This cannot be done with strcpy() in a portable manner, since the memory areas overlap! */ memmove(path, path + 2, strlen(path + 2)+1); } /* * we deal with file://<host>/<path> differently since it supports no * hostname other than "localhost" and "127.0.0.1", which is unique among * the URL protocols specified in RFC 1738 */ if(path[0] != '/') { /* the URL included a host name, we ignore host names in file:// URLs as the standards don't define what to do with them */ char *ptr=strchr(path, '/'); if(ptr) { /* there was a slash present RFC1738 (section 3.1, page 5) says: The rest of the locator consists of data specific to the scheme, and is known as the "url-path". It supplies the details of how the specified resource can be accessed. Note that the "/" between the host (or port) and the url-path is NOT part of the url-path. As most agents use file://localhost/foo to get '/foo' although the slash preceding foo is a separator and not a slash for the path, a URL as file://localhost//foo must be valid as well, to refer to the same file with an absolute path. */ if(ptr[1] && ('/' == ptr[1])) /* if there was two slashes, we skip the first one as that is then used truly as a separator */ ptr++; /* This cannot be made with strcpy, as the memory chunks overlap! */ memmove(path, ptr, strlen(ptr)+1); } } protop = "file"; /* protocol string */ } else { /* clear path */ path[0]=0; if(2 > sscanf(data->change.url, "%15[^\n:]://%[^\n/?]%[^\n]", protobuf, conn->host.name, path)) { /* * The URL was badly formatted, let's try the browser-style _without_ * protocol specified like 'http://'. */ rc = sscanf(data->change.url, "%[^\n/?]%[^\n]", conn->host.name, path); if(1 > rc) { /* * We couldn't even get this format. * djgpp 2.04 has a sscanf() bug where 'conn->host.name' is * assigned, but the return value is EOF! */ #if defined(__DJGPP__) && (DJGPP_MINOR == 4) if(!(rc == -1 && *conn->host.name)) #endif { failf(data, "<url> malformed"); return CURLE_URL_MALFORMAT; } } /* * Since there was no protocol part specified, we guess what protocol it * is based on the first letters of the server name. */ /* Note: if you add a new protocol, please update the list in * lib/version.c too! */ if(checkprefix("FTP.", conn->host.name)) protop = "ftp"; else if(checkprefix("DICT.", conn->host.name)) protop = "DICT"; else if(checkprefix("LDAP.", conn->host.name)) protop = "LDAP"; else if(checkprefix("IMAP.", conn->host.name)) protop = "IMAP"; else { protop = "http"; } *prot_missing = TRUE; /* not given in URL */ } else protop = protobuf; } /* We search for '?' in the host name (but only on the right side of a * @-letter to allow ?-letters in username and password) to handle things * like http://example.com?param= (notice the missing '/'). */ at = strchr(conn->host.name, '@'); if(at) query = strchr(at+1, '?'); else query = strchr(conn->host.name, '?'); if(query) { /* We must insert a slash before the '?'-letter in the URL. If the URL had a slash after the '?', that is where the path currently begins and the '?string' is still part of the host name. We must move the trailing part from the host name and put it first in the path. And have it all prefixed with a slash. */ size_t hostlen = strlen(query); size_t pathlen = strlen(path); /* move the existing path plus the zero byte forward, to make room for the host-name part */ memmove(path+hostlen+1, path, pathlen+1); /* now copy the trailing host part in front of the existing path */ memcpy(path+1, query, hostlen); path[0]='/'; /* prepend the missing slash */ *query=0; /* now cut off the hostname at the ? */ } else if(!path[0]) { /* if there's no path set, use a single slash */ strcpy(path, "/"); } /* If the URL is malformatted (missing a '/' after hostname before path) we * insert a slash here. The only letter except '/' we accept to start a path * is '?'. */ if(path[0] == '?') { /* We need this function to deal with overlapping memory areas. We know that the memory area 'path' points to is 'urllen' bytes big and that is bigger than the path. Use +1 to move the zero byte too. */ memmove(&path[1], path, strlen(path)+1); path[0] = '/'; } /************************************************************* * Parse a user name and password in the URL and strip it out * of the host name *************************************************************/ result = parse_url_userpass(data, conn, user, passwd); if(result != CURLE_OK) return result; if(conn->host.name[0] == '[') { /* This looks like an IPv6 address literal. See if there is an address scope. */ char *percent = strstr (conn->host.name, "%25"); if(percent) { char *endp; unsigned long scope = strtoul (percent + 3, &endp, 10); if(*endp == ']') { /* The address scope was well formed. Knock it out of the hostname. */ memmove(percent, endp, strlen(endp)+1); if(!data->state.this_is_a_follow) /* Don't honour a scope given in a Location: header */ conn->scope = (unsigned int)scope; } else infof(data, "Invalid IPv6 address format\n"); } } if(data->set.scope) /* Override any scope that was set above. */ conn->scope = data->set.scope; /* Remove the fragment part of the path. Per RFC 2396, this is always the last part of the URI. We are looking for the first '#' so that we deal gracefully with non conformant URI such as http://example.com#foo#bar. */ fragment = strchr(path, '#'); if(fragment) { *fragment = 0; /* we know the path part ended with a fragment, so we know the full URL string does too and we need to cut it off from there so it isn't used over proxy */ fragment = strchr(data->change.url, '#'); if(fragment) *fragment = 0; } /* * So if the URL was A://B/C#D, * protop is A * conn->host.name is B * data->state.path is /C */ return findprotocol(data, conn, protop); }
/* * Parse URL and fill in the relevant members of the connection struct. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L3573-L3808
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
setup_range
static CURLcode setup_range(struct SessionHandle *data) { struct UrlState *s = &data->state; s->resume_from = data->set.set_resume_from; if(s->resume_from || data->set.str[STRING_SET_RANGE]) { if(s->rangestringalloc) free(s->range); if(s->resume_from) s->range = aprintf("%" FORMAT_OFF_TU "-", s->resume_from); else s->range = strdup(data->set.str[STRING_SET_RANGE]); s->rangestringalloc = (s->range)?TRUE:FALSE; if(!s->range) return CURLE_OUT_OF_MEMORY; /* tell ourselves to fetch this range */ s->use_range = TRUE; /* enable range download */ } else s->use_range = FALSE; /* disable range download */ return CURLE_OK; }
/* * If we're doing a resumed transfer, we need to setup our stuff * properly. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L3814-L3839
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
setup_connection_internals
static CURLcode setup_connection_internals(struct connectdata *conn) { const struct Curl_handler * p; CURLcode result; conn->socktype = SOCK_STREAM; /* most of them are TCP streams */ /* Scan protocol handler table. */ /* Perform setup complement if some. */ p = conn->handler; if(p->setup_connection) { result = (*p->setup_connection)(conn); if(result != CURLE_OK) return result; p = conn->handler; /* May have changed. */ } if(conn->port < 0) /* we check for -1 here since if proxy was detected already, this was very likely already set to the proxy port */ conn->port = p->defport; conn->remote_port = (unsigned short)conn->given->defport; return CURLE_OK; }
/*************************************************************** * Setup connection internals specific to the requested protocol. * This MUST get called after proxy magic has been figured out. ***************************************************************/
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L3846-L3874
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
check_noproxy
static bool check_noproxy(const char* name, const char* no_proxy) { /* no_proxy=domain1.dom,host.domain2.dom * (a comma-separated list of hosts which should * not be proxied, or an asterisk to override * all proxy variables) */ size_t tok_start; size_t tok_end; const char* separator = ", "; size_t no_proxy_len; size_t namelen; char *endptr; if(no_proxy && no_proxy[0]) { if(Curl_raw_equal("*", no_proxy)) { return TRUE; } /* NO_PROXY was specified and it wasn't just an asterisk */ no_proxy_len = strlen(no_proxy); endptr = strchr(name, ':'); if(endptr) namelen = endptr - name; else namelen = strlen(name); for(tok_start = 0; tok_start < no_proxy_len; tok_start = tok_end + 1) { while(tok_start < no_proxy_len && strchr(separator, no_proxy[tok_start]) != NULL) { /* Look for the beginning of the token. */ ++tok_start; } if(tok_start == no_proxy_len) break; /* It was all trailing separator chars, no more tokens. */ for(tok_end = tok_start; tok_end < no_proxy_len && strchr(separator, no_proxy[tok_end]) == NULL; ++tok_end) /* Look for the end of the token. */ ; /* To match previous behaviour, where it was necessary to specify * ".local.com" to prevent matching "notlocal.com", we will leave * the '.' off. */ if(no_proxy[tok_start] == '.') ++tok_start; if((tok_end - tok_start) <= namelen) { /* Match the last part of the name to the domain we are checking. */ const char *checkn = name + namelen - (tok_end - tok_start); if(Curl_raw_nequal(no_proxy + tok_start, checkn, tok_end - tok_start)) { if((tok_end - tok_start) == namelen || *(checkn - 1) == '.') { /* We either have an exact match, or the previous character is a . * so it is within the same domain, so no proxy for this host. */ return TRUE; } } } /* if((tok_end - tok_start) <= namelen) */ } /* for(tok_start = 0; tok_start < no_proxy_len; tok_start = tok_end + 1) */ } /* NO_PROXY was specified and it wasn't just an asterisk */ return FALSE; }
/**************************************************************** * Checks if the host is in the noproxy list. returns true if it matches * and therefore the proxy should NOT be used. ****************************************************************/
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L3881-L3949
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
parse_proxy
static CURLcode parse_proxy(struct SessionHandle *data, struct connectdata *conn, char *proxy) { char *prox_portno; char *endofprot; /* We use 'proxyptr' to point to the proxy name from now on... */ char *proxyptr; char *portptr; char *atsign; /* We do the proxy host string parsing here. We want the host name and the * port name. Accept a protocol:// prefix */ /* Parse the protocol part if present */ endofprot = strstr(proxy, "://"); if(endofprot) { proxyptr = endofprot+3; if(checkprefix("socks5h", proxy)) conn->proxytype = CURLPROXY_SOCKS5_HOSTNAME; else if(checkprefix("socks5", proxy)) conn->proxytype = CURLPROXY_SOCKS5; else if(checkprefix("socks4a", proxy)) conn->proxytype = CURLPROXY_SOCKS4A; else if(checkprefix("socks4", proxy) || checkprefix("socks", proxy)) conn->proxytype = CURLPROXY_SOCKS4; /* Any other xxx:// : change to http proxy */ } else proxyptr = proxy; /* No xxx:// head: It's a HTTP proxy */ /* Is there a username and password given in this proxy url? */ atsign = strchr(proxyptr, '@'); if(atsign) { char proxyuser[MAX_CURL_USER_LENGTH]; char proxypasswd[MAX_CURL_PASSWORD_LENGTH]; proxypasswd[0] = 0; if(1 <= sscanf(proxyptr, "%" MAX_CURL_USER_LENGTH_TXT"[^:@]:" "%" MAX_CURL_PASSWORD_LENGTH_TXT "[^@]", proxyuser, proxypasswd)) { CURLcode res = CURLE_OK; /* found user and password, rip them out. note that we are unescaping them, as there is otherwise no way to have a username or password with reserved characters like ':' in them. */ Curl_safefree(conn->proxyuser); conn->proxyuser = curl_easy_unescape(data, proxyuser, 0, NULL); if(!conn->proxyuser) res = CURLE_OUT_OF_MEMORY; else { Curl_safefree(conn->proxypasswd); conn->proxypasswd = curl_easy_unescape(data, proxypasswd, 0, NULL); if(!conn->proxypasswd) res = CURLE_OUT_OF_MEMORY; } if(CURLE_OK == res) { conn->bits.proxy_user_passwd = TRUE; /* enable it */ atsign++; /* the right side of the @-letter */ if(atsign) proxyptr = atsign; /* now use this instead */ else res = CURLE_OUT_OF_MEMORY; } if(res) return res; } } /* start scanning for port number at this point */ portptr = proxyptr; /* detect and extract RFC2732-style IPv6-addresses */ if(*proxyptr == '[') { char *ptr = ++proxyptr; /* advance beyond the initial bracket */ while(*ptr && (ISXDIGIT(*ptr) || (*ptr == ':') || (*ptr == '%') || (*ptr == '.'))) ptr++; if(*ptr == ']') /* yeps, it ended nicely with a bracket as well */ *ptr++ = 0; else infof(data, "Invalid IPv6 address format\n"); portptr = ptr; /* Note that if this didn't end with a bracket, we still advanced the * proxyptr first, but I can't see anything wrong with that as no host * name nor a numeric can legally start with a bracket. */ } /* Get port number off proxy.server.com:1080 */ prox_portno = strchr(portptr, ':'); if(prox_portno) { *prox_portno = 0x0; /* cut off number from host name */ prox_portno ++; /* now set the local port number */ conn->port = strtol(prox_portno, NULL, 10); } else { if(proxyptr[0]=='/') /* If the first character in the proxy string is a slash, fail immediately. The following code will otherwise clear the string which will lead to code running as if no proxy was set! */ return CURLE_COULDNT_RESOLVE_PROXY; /* without a port number after the host name, some people seem to use a slash so we strip everything from the first slash */ atsign = strchr(proxyptr, '/'); if(atsign) *atsign = 0x0; /* cut off path part from host name */ if(data->set.proxyport) /* None given in the proxy string, then get the default one if it is given */ conn->port = data->set.proxyport; } /* now, clone the cleaned proxy host name */ conn->proxy.rawalloc = strdup(proxyptr); conn->proxy.name = conn->proxy.rawalloc; if(!conn->proxy.rawalloc) return CURLE_OUT_OF_MEMORY; return CURLE_OK; }
/* * If this is supposed to use a proxy, we need to figure out the proxy * host name, so that we can re-use an existing connection * that may exist registered to the same proxy host. * proxy will be freed before this function returns. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L4046-L4179
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
parse_proxy_auth
static CURLcode parse_proxy_auth(struct SessionHandle *data, struct connectdata *conn) { char proxyuser[MAX_CURL_USER_LENGTH]=""; char proxypasswd[MAX_CURL_PASSWORD_LENGTH]=""; if(data->set.str[STRING_PROXYUSERNAME] != NULL) { strncpy(proxyuser, data->set.str[STRING_PROXYUSERNAME], MAX_CURL_USER_LENGTH); proxyuser[MAX_CURL_USER_LENGTH-1] = '\0'; /*To be on safe side*/ } if(data->set.str[STRING_PROXYPASSWORD] != NULL) { strncpy(proxypasswd, data->set.str[STRING_PROXYPASSWORD], MAX_CURL_PASSWORD_LENGTH); proxypasswd[MAX_CURL_PASSWORD_LENGTH-1] = '\0'; /*To be on safe side*/ } conn->proxyuser = curl_easy_unescape(data, proxyuser, 0, NULL); if(!conn->proxyuser) return CURLE_OUT_OF_MEMORY; conn->proxypasswd = curl_easy_unescape(data, proxypasswd, 0, NULL); if(!conn->proxypasswd) return CURLE_OUT_OF_MEMORY; return CURLE_OK; }
/* * Extract the user and password from the authentication string */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L4184-L4210
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
parse_url_userpass
static CURLcode parse_url_userpass(struct SessionHandle *data, struct connectdata *conn, char *user, char *passwd) { /* At this point, we're hoping all the other special cases have * been taken care of, so conn->host.name is at most * [user[:password]]@]hostname * * We need somewhere to put the embedded details, so do that first. */ char *ptr=strchr(conn->host.name, '@'); char *userpass = conn->host.name; user[0] =0; /* to make everything well-defined */ passwd[0]=0; /* We will now try to extract the * possible user+password pair in a string like: * ftp://user:password@ftp.my.site:8021/README */ if(ptr != NULL) { /* there's a user+password given here, to the left of the @ */ conn->host.name = ++ptr; /* So the hostname is sane. Only bother interpreting the * results if we could care. It could still be wasted * work because it might be overtaken by the programmatically * set user/passwd, but doing that first adds more cases here :-( */ conn->bits.userpwd_in_url = TRUE; if(data->set.use_netrc != CURL_NETRC_REQUIRED) { /* We could use the one in the URL */ conn->bits.user_passwd = TRUE; /* enable user+password */ if(*userpass != ':') { /* the name is given, get user+password */ sscanf(userpass, "%" MAX_CURL_USER_LENGTH_TXT "[^:@]:" "%" MAX_CURL_PASSWORD_LENGTH_TXT "[^@]", user, passwd); } else /* no name given, get the password only */ sscanf(userpass, ":%" MAX_CURL_PASSWORD_LENGTH_TXT "[^@]", passwd); if(user[0]) { char *newname=curl_easy_unescape(data, user, 0, NULL); if(!newname) return CURLE_OUT_OF_MEMORY; if(strlen(newname) < MAX_CURL_USER_LENGTH) strcpy(user, newname); /* if the new name is longer than accepted, then just use the unconverted name, it'll be wrong but what the heck */ free(newname); } if(passwd[0]) { /* we have a password found in the URL, decode it! */ char *newpasswd=curl_easy_unescape(data, passwd, 0, NULL); if(!newpasswd) return CURLE_OUT_OF_MEMORY; if(strlen(newpasswd) < MAX_CURL_PASSWORD_LENGTH) strcpy(passwd, newpasswd); free(newpasswd); } } } return CURLE_OK; }
/* CURL_DISABLE_PROXY */ /* * * Parse a user name and password in the URL and strip it out of the host name * * Inputs: data->set.use_netrc (CURLOPT_NETRC) * conn->host.name * * Outputs: (almost :- all currently undefined) * conn->bits.user_passwd - non-zero if non-default passwords exist * user - non-zero length if defined * passwd - ditto * conn->host.name - remove user name and password */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L4226-L4297
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
parse_remote_port
static CURLcode parse_remote_port(struct SessionHandle *data, struct connectdata *conn) { char *portptr; char endbracket; /* Note that at this point, the IPv6 address cannot contain any scope suffix as that has already been removed in the parseurlandfillconn() function */ if((1 == sscanf(conn->host.name, "[%*45[0123456789abcdefABCDEF:.]%c", &endbracket)) && (']' == endbracket)) { /* this is a RFC2732-style specified IP-address */ conn->bits.ipv6_ip = TRUE; conn->host.name++; /* skip over the starting bracket */ portptr = strchr(conn->host.name, ']'); if(portptr) { *portptr++ = '\0'; /* zero terminate, killing the bracket */ if(':' != *portptr) portptr = NULL; /* no port number available */ } } else { #ifdef ENABLE_IPV6 struct in6_addr in6; if(Curl_inet_pton(AF_INET6, conn->host.name, &in6) > 0) { /* This is a numerical IPv6 address, meaning this is a wrongly formatted URL */ failf(data, "IPv6 numerical address used in URL without brackets"); return CURLE_URL_MALFORMAT; } #endif portptr = strrchr(conn->host.name, ':'); } if(data->set.use_port && data->state.allow_port) { /* if set, we use this and ignore the port possibly given in the URL */ conn->remote_port = (unsigned short)data->set.use_port; if(portptr) *portptr = '\0'; /* cut off the name there anyway - if there was a port number - since the port number is to be ignored! */ if(conn->bits.httpproxy) { /* we need to create new URL with the new port number */ char *url; char type[12]=""; if(conn->bits.type_set) snprintf(type, sizeof(type), ";type=%c", data->set.prefer_ascii?'A': (data->set.ftp_list_only?'D':'I')); /* * This synthesized URL isn't always right--suffixes like ;type=A are * stripped off. It would be better to work directly from the original * URL and simply replace the port part of it. */ url = aprintf("%s://%s%s%s:%hu%s%s%s", conn->given->scheme, conn->bits.ipv6_ip?"[":"", conn->host.name, conn->bits.ipv6_ip?"]":"", conn->remote_port, data->state.slash_removed?"/":"", data->state.path, type); if(!url) return CURLE_OUT_OF_MEMORY; if(data->change.url_alloc) { Curl_safefree(data->change.url); data->change.url_alloc = FALSE; } data->change.url = url; data->change.url_alloc = TRUE; } } else if(portptr) { /* no CURLOPT_PORT given, extract the one from the URL */ char *rest; unsigned long port; port=strtoul(portptr+1, &rest, 10); /* Port number must be decimal */ if(rest != (portptr+1) && *rest == '\0') { /* The colon really did have only digits after it, * so it is either a port number or a mistake */ if(port > 0xffff) { /* Single unix standard says port numbers are * 16 bits long */ failf(data, "Port number too large: %lu", port); return CURLE_URL_MALFORMAT; } *portptr = '\0'; /* cut off the name there */ conn->remote_port = curlx_ultous(port); } else if(!port) /* Browser behavior adaptation. If there's a colon with no digits after, just cut off the name there which makes us ignore the colon and just use the default port. Firefox and Chrome both do that. */ *portptr = '\0'; } return CURLE_OK; }
/************************************************************* * Figure out the remote port number and fix it in the URL * * No matter if we use a proxy or not, we have to figure out the remote * port number of various reasons. * * To be able to detect port number flawlessly, we must not confuse them * IPv6-specified addresses in the [0::1] style. (RFC2732) * * The conn->host.name is currently [user:passwd@]host[:port] where host * could be a hostname, IPv4 address or IPv6 address. * * The port number embedded in the URL is replaced, if necessary. *************************************************************/
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L4313-L4416
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
override_userpass
static void override_userpass(struct SessionHandle *data, struct connectdata *conn, char *user, char *passwd) { if(data->set.str[STRING_USERNAME] != NULL) { strncpy(user, data->set.str[STRING_USERNAME], MAX_CURL_USER_LENGTH); user[MAX_CURL_USER_LENGTH-1] = '\0'; /*To be on safe side*/ } if(data->set.str[STRING_PASSWORD] != NULL) { strncpy(passwd, data->set.str[STRING_PASSWORD], MAX_CURL_PASSWORD_LENGTH); passwd[MAX_CURL_PASSWORD_LENGTH-1] = '\0'; /*To be on safe side*/ } conn->bits.netrc = FALSE; if(data->set.use_netrc != CURL_NETRC_IGNORED) { if(Curl_parsenetrc(conn->host.name, user, passwd, data->set.str[STRING_NETRC_FILE])) { infof(data, "Couldn't find host %s in the " DOT_CHAR "netrc file; using defaults\n", conn->host.name); } else { /* set bits.netrc TRUE to remember that we got the name from a .netrc file, so that it is safe to use even if we followed a Location: to a different host or similar. */ conn->bits.netrc = TRUE; conn->bits.user_passwd = TRUE; /* enable user+password */ } } }
/* * Override a user name and password from the URL with that in the * CURLOPT_USERPWD option or a .netrc file, if applicable. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L4422-L4453
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
set_userpass
static CURLcode set_userpass(struct connectdata *conn, const char *user, const char *passwd) { /* If our protocol needs a password and we have none, use the defaults */ if((conn->handler->flags & PROTOPT_NEEDSPWD) && !conn->bits.user_passwd) { conn->user = strdup(CURL_DEFAULT_USER); if(conn->user) conn->passwd = strdup(CURL_DEFAULT_PASSWORD); else conn->passwd = NULL; /* This is the default password, so DON'T set conn->bits.user_passwd */ } else { /* store user + password, zero-length if not set */ conn->user = strdup(user); if(conn->user) conn->passwd = strdup(passwd); else conn->passwd = NULL; } if(!conn->user || !conn->passwd) return CURLE_OUT_OF_MEMORY; return CURLE_OK; }
/* * Set password so it's available in the connection. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L4458-L4484
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
resolve_server
static CURLcode resolve_server(struct SessionHandle *data, struct connectdata *conn, bool *async) { CURLcode result=CURLE_OK; long timeout_ms = Curl_timeleft(data, NULL, TRUE); /************************************************************* * Resolve the name of the server or proxy *************************************************************/ if(conn->bits.reuse) /* We're reusing the connection - no need to resolve anything, and fix_hostname() was called already in create_conn() for the re-use case. */ *async = FALSE; else { /* this is a fresh connect */ int rc; struct Curl_dns_entry *hostaddr; /* set a pointer to the hostname we display */ fix_hostname(data, conn, &conn->host); if(!conn->proxy.name || !*conn->proxy.name) { /* If not connecting via a proxy, extract the port from the URL, if it is * there, thus overriding any defaults that might have been set above. */ conn->port = conn->remote_port; /* it is the same port */ /* Resolve target host right on */ rc = Curl_resolv_timeout(conn, conn->host.name, (int)conn->port, &hostaddr, timeout_ms); if(rc == CURLRESOLV_PENDING) *async = TRUE; else if(rc == CURLRESOLV_TIMEDOUT) result = CURLE_OPERATION_TIMEDOUT; else if(!hostaddr) { failf(data, "Couldn't resolve host '%s'", conn->host.dispname); result = CURLE_COULDNT_RESOLVE_HOST; /* don't return yet, we need to clean up the timeout first */ } } else { /* This is a proxy that hasn't been resolved yet. */ /* IDN-fix the proxy name */ fix_hostname(data, conn, &conn->proxy); /* resolve proxy */ rc = Curl_resolv_timeout(conn, conn->proxy.name, (int)conn->port, &hostaddr, timeout_ms); if(rc == CURLRESOLV_PENDING) *async = TRUE; else if(rc == CURLRESOLV_TIMEDOUT) result = CURLE_OPERATION_TIMEDOUT; else if(!hostaddr) { failf(data, "Couldn't resolve proxy '%s'", conn->proxy.dispname); result = CURLE_COULDNT_RESOLVE_PROXY; /* don't return yet, we need to clean up the timeout first */ } } DEBUGASSERT(conn->dns_entry == NULL); conn->dns_entry = hostaddr; } return result; }
/************************************************************* * Resolve the address of the server or proxy *************************************************************/
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L4489-L4560
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
reuse_conn
static void reuse_conn(struct connectdata *old_conn, struct connectdata *conn) { if(old_conn->proxy.rawalloc) free(old_conn->proxy.rawalloc); /* free the SSL config struct from this connection struct as this was allocated in vain and is targeted for destruction */ Curl_free_ssl_config(&old_conn->ssl_config); conn->data = old_conn->data; /* get the user+password information from the old_conn struct since it may * be new for this request even when we re-use an existing connection */ conn->bits.user_passwd = old_conn->bits.user_passwd; if(conn->bits.user_passwd) { /* use the new user name and password though */ Curl_safefree(conn->user); Curl_safefree(conn->passwd); conn->user = old_conn->user; conn->passwd = old_conn->passwd; old_conn->user = NULL; old_conn->passwd = NULL; } conn->bits.proxy_user_passwd = old_conn->bits.proxy_user_passwd; if(conn->bits.proxy_user_passwd) { /* use the new proxy user name and proxy password though */ Curl_safefree(conn->proxyuser); Curl_safefree(conn->proxypasswd); conn->proxyuser = old_conn->proxyuser; conn->proxypasswd = old_conn->proxypasswd; old_conn->proxyuser = NULL; old_conn->proxypasswd = NULL; } /* host can change, when doing keepalive with a proxy or if the case is different this time etc */ Curl_safefree(conn->host.rawalloc); conn->host=old_conn->host; /* persist connection info in session handle */ Curl_persistconninfo(conn); /* re-use init */ conn->bits.reuse = TRUE; /* yes, we're re-using here */ Curl_safefree(old_conn->user); Curl_safefree(old_conn->passwd); Curl_safefree(old_conn->proxyuser); Curl_safefree(old_conn->proxypasswd); Curl_safefree(old_conn->localdev); Curl_llist_destroy(old_conn->send_pipe, NULL); Curl_llist_destroy(old_conn->recv_pipe, NULL); Curl_llist_destroy(old_conn->pend_pipe, NULL); Curl_llist_destroy(old_conn->done_pipe, NULL); old_conn->send_pipe = NULL; old_conn->recv_pipe = NULL; old_conn->pend_pipe = NULL; old_conn->done_pipe = NULL; Curl_safefree(old_conn->master_buffer); }
/* * Cleanup the connection just allocated before we can move along and use the * previously existing one. All relevant data is copied over and old_conn is * ready for freeing once this function returns. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L4567-L4631
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
create_conn
static CURLcode create_conn(struct SessionHandle *data, struct connectdata **in_connect, bool *async) { CURLcode result=CURLE_OK; struct connectdata *conn; struct connectdata *conn_temp = NULL; size_t urllen; char user[MAX_CURL_USER_LENGTH]; char passwd[MAX_CURL_PASSWORD_LENGTH]; bool reuse; char *proxy = NULL; bool prot_missing = FALSE; *async = FALSE; /************************************************************* * Check input data *************************************************************/ if(!data->change.url) return CURLE_URL_MALFORMAT; /* First, split up the current URL in parts so that we can use the parts for checking against the already present connections. In order to not have to modify everything at once, we allocate a temporary connection data struct and fill in for comparison purposes. */ conn = allocate_conn(data); if(!conn) return CURLE_OUT_OF_MEMORY; /* We must set the return variable as soon as possible, so that our parent can cleanup any possible allocs we may have done before any failure */ *in_connect = conn; /* This initing continues below, see the comment "Continue connectdata * initialization here" */ /*********************************************************** * We need to allocate memory to store the path in. We get the size of the * full URL to be sure, and we need to make it at least 256 bytes since * other parts of the code will rely on this fact ***********************************************************/ #define LEAST_PATH_ALLOC 256 urllen=strlen(data->change.url); if(urllen < LEAST_PATH_ALLOC) urllen=LEAST_PATH_ALLOC; /* * We malloc() the buffers below urllen+2 to make room for 2 possibilities: * 1 - an extra terminating zero * 2 - an extra slash (in case a syntax like "www.host.com?moo" is used) */ Curl_safefree(data->state.pathbuffer); data->state.path = NULL; data->state.pathbuffer = malloc(urllen+2); if(NULL == data->state.pathbuffer) return CURLE_OUT_OF_MEMORY; /* really bad error */ data->state.path = data->state.pathbuffer; conn->host.rawalloc = malloc(urllen+2); if(NULL == conn->host.rawalloc) { Curl_safefree(data->state.pathbuffer); data->state.path = NULL; return CURLE_OUT_OF_MEMORY; } conn->host.name = conn->host.rawalloc; conn->host.name[0] = 0; result = parseurlandfillconn(data, conn, &prot_missing, user, passwd); if(result != CURLE_OK) return result; /************************************************************* * No protocol part in URL was used, add it! *************************************************************/ if(prot_missing) { /* We're guessing prefixes here and if we're told to use a proxy or if we're gonna follow a Location: later or... then we need the protocol part added so that we have a valid URL. */ char *reurl; reurl = aprintf("%s://%s", conn->handler->scheme, data->change.url); if(!reurl) { Curl_safefree(proxy); return CURLE_OUT_OF_MEMORY; } if(data->change.url_alloc) { Curl_safefree(data->change.url); data->change.url_alloc = FALSE; } data->change.url = reurl; data->change.url_alloc = TRUE; /* free this later */ } /************************************************************* * If the protocol can't handle url query strings, then cut * of the unhandable part *************************************************************/ if((conn->given->flags&PROTOPT_NOURLQUERY)) { char *path_q_sep = strchr(conn->data->state.path, '?'); if(path_q_sep) { /* according to rfc3986, allow the query (?foo=bar) also on protocols that can't handle it. cut the string-part after '?' */ /* terminate the string */ path_q_sep[0] = 0; } } #ifndef CURL_DISABLE_PROXY /************************************************************* * Extract the user and password from the authentication string *************************************************************/ if(conn->bits.proxy_user_passwd) { result = parse_proxy_auth(data, conn); if(result != CURLE_OK) return result; } /************************************************************* * Detect what (if any) proxy to use *************************************************************/ if(data->set.str[STRING_PROXY]) { proxy = strdup(data->set.str[STRING_PROXY]); /* if global proxy is set, this is it */ if(NULL == proxy) { failf(data, "memory shortage"); return CURLE_OUT_OF_MEMORY; } } if(data->set.str[STRING_NOPROXY] && check_noproxy(conn->host.name, data->set.str[STRING_NOPROXY])) { if(proxy) { free(proxy); /* proxy is in exception list */ proxy = NULL; } } else if(!proxy) proxy = detect_proxy(conn); if(proxy && (!*proxy || (conn->handler->flags & PROTOPT_NONETWORK))) { free(proxy); /* Don't bother with an empty proxy string or if the protocol doesn't work with network */ proxy = NULL; } /*********************************************************************** * If this is supposed to use a proxy, we need to figure out the proxy host * name, proxy type and port number, so that we can re-use an existing * connection that may exist registered to the same proxy host. ***********************************************************************/ if(proxy) { result = parse_proxy(data, conn, proxy); free(proxy); /* parse_proxy copies the proxy string */ if(result) return result; if((conn->proxytype == CURLPROXY_HTTP) || (conn->proxytype == CURLPROXY_HTTP_1_0)) { #ifdef CURL_DISABLE_HTTP /* asking for a HTTP proxy is a bit funny when HTTP is disabled... */ return CURLE_UNSUPPORTED_PROTOCOL; #else /* force this connection's protocol to become HTTP if not already compatible - if it isn't tunneling through */ if(!(conn->handler->protocol & CURLPROTO_HTTP) && !conn->bits.tunnel_proxy) conn->handler = &Curl_handler_http; conn->bits.httpproxy = TRUE; #endif } else conn->bits.httpproxy = FALSE; /* not a HTTP proxy */ conn->bits.proxy = TRUE; } else { /* we aren't using the proxy after all... */ conn->bits.proxy = FALSE; conn->bits.httpproxy = FALSE; conn->bits.proxy_user_passwd = FALSE; conn->bits.tunnel_proxy = FALSE; } #endif /* CURL_DISABLE_PROXY */ /************************************************************* * Setup internals depending on protocol. Needs to be done after * we figured out what/if proxy to use. *************************************************************/ result = setup_connection_internals(conn); if(result != CURLE_OK) { Curl_safefree(proxy); return result; } conn->recv[FIRSTSOCKET] = Curl_recv_plain; conn->send[FIRSTSOCKET] = Curl_send_plain; conn->recv[SECONDARYSOCKET] = Curl_recv_plain; conn->send[SECONDARYSOCKET] = Curl_send_plain; /*********************************************************************** * file: is a special case in that it doesn't need a network connection ***********************************************************************/ #ifndef CURL_DISABLE_FILE if(conn->handler->flags & PROTOPT_NONETWORK) { bool done; /* this is supposed to be the connect function so we better at least check that the file is present here! */ DEBUGASSERT(conn->handler->connect_it); result = conn->handler->connect_it(conn, &done); /* Setup a "faked" transfer that'll do nothing */ if(CURLE_OK == result) { conn->data = data; conn->bits.tcpconnect[FIRSTSOCKET] = TRUE; /* we are "connected */ ConnectionStore(data, conn); /* * Setup whatever necessary for a resumed transfer */ result = setup_range(data); if(result) { DEBUGASSERT(conn->handler->done); /* we ignore the return code for the protocol-specific DONE */ (void)conn->handler->done(conn, result, FALSE); return result; } Curl_setup_transfer(conn, -1, -1, FALSE, NULL, /* no download */ -1, NULL); /* no upload */ } return result; } #endif /************************************************************* * If the protocol is using SSL and HTTP proxy is used, we set * the tunnel_proxy bit. *************************************************************/ if((conn->given->flags&PROTOPT_SSL) && conn->bits.httpproxy) conn->bits.tunnel_proxy = TRUE; /************************************************************* * Figure out the remote port number and fix it in the URL *************************************************************/ result = parse_remote_port(data, conn); if(result != CURLE_OK) return result; /************************************************************* * Check for an overridden user name and password, then set it * for use *************************************************************/ override_userpass(data, conn, user, passwd); result = set_userpass(conn, user, passwd); if(result != CURLE_OK) return result; /* Get a cloned copy of the SSL config situation stored in the connection struct. But to get this going nicely, we must first make sure that the strings in the master copy are pointing to the correct strings in the session handle strings array! Keep in mind that the pointers in the master copy are pointing to strings that will be freed as part of the SessionHandle struct, but all cloned copies will be separately allocated. */ data->set.ssl.CApath = data->set.str[STRING_SSL_CAPATH]; data->set.ssl.CAfile = data->set.str[STRING_SSL_CAFILE]; data->set.ssl.CRLfile = data->set.str[STRING_SSL_CRLFILE]; data->set.ssl.issuercert = data->set.str[STRING_SSL_ISSUERCERT]; data->set.ssl.random_file = data->set.str[STRING_SSL_RANDOM_FILE]; data->set.ssl.egdsocket = data->set.str[STRING_SSL_EGDSOCKET]; data->set.ssl.cipher_list = data->set.str[STRING_SSL_CIPHER_LIST]; #ifdef USE_TLS_SRP data->set.ssl.username = data->set.str[STRING_TLSAUTH_USERNAME]; data->set.ssl.password = data->set.str[STRING_TLSAUTH_PASSWORD]; #endif if(!Curl_clone_ssl_config(&data->set.ssl, &conn->ssl_config)) return CURLE_OUT_OF_MEMORY; /************************************************************* * Check the current list of connections to see if we can * re-use an already existing one or if we have to create a * new one. *************************************************************/ /* reuse_fresh is TRUE if we are told to use a new connection by force, but we only acknowledge this option if this is not a re-used connection already (which happens due to follow-location or during a HTTP authentication phase). */ if(data->set.reuse_fresh && !data->state.this_is_a_follow) reuse = FALSE; else reuse = ConnectionExists(data, conn, &conn_temp); if(reuse) { /* * We already have a connection for this, we got the former connection * in the conn_temp variable and thus we need to cleanup the one we * just allocated before we can move along and use the previously * existing one. */ reuse_conn(conn, conn_temp); free(conn); /* we don't need this anymore */ conn = conn_temp; *in_connect = conn; /* set a pointer to the hostname we display */ fix_hostname(data, conn, &conn->host); infof(data, "Re-using existing connection! (#%ld) with host %s\n", conn->connection_id, conn->proxy.name?conn->proxy.dispname:conn->host.dispname); } else { /* * This is a brand new connection, so let's store it in the connection * cache of ours! */ conn->inuse = TRUE; ConnectionStore(data, conn); } /* Setup and init stuff before DO starts, in preparing for the transfer. */ do_init(conn); /* * Setup whatever necessary for a resumed transfer */ result = setup_range(data); if(result) return result; /* Continue connectdata initialization here. */ /* * Inherit the proper values from the urldata struct AFTER we have arranged * the persistent connection stuff */ conn->fread_func = data->set.fread_func; conn->fread_in = data->set.in; conn->seek_func = data->set.seek_func; conn->seek_client = data->set.seek_client; /************************************************************* * Resolve the address of the server or proxy *************************************************************/ result = resolve_server(data, conn, async); return result; }
/** * create_conn() sets up a new connectdata struct, or re-uses an already * existing one, and resolves host name. * * if this function returns CURLE_OK and *async is set to TRUE, the resolve * response will be coming asynchronously. If *async is FALSE, the name is * already resolved. * * @param data The sessionhandle pointer * @param in_connect is set to the next connection data pointer * @param async is set TRUE when an async DNS resolution is pending * @see Curl_setup_conn() * * *NOTE* this function assigns the conn->data pointer! */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L4649-L5019
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
Curl_setup_conn
CURLcode Curl_setup_conn(struct connectdata *conn, bool *protocol_done) { CURLcode result = CURLE_OK; struct SessionHandle *data = conn->data; Curl_pgrsTime(data, TIMER_NAMELOOKUP); if(conn->handler->flags & PROTOPT_NONETWORK) { /* nothing to setup when not using a network */ *protocol_done = TRUE; return result; } *protocol_done = FALSE; /* default to not done */ /* set proxy_connect_closed to false unconditionally already here since it is used strictly to provide extra information to a parent function in the case of proxy CONNECT failures and we must make sure we don't have it lingering set from a previous invoke */ conn->bits.proxy_connect_closed = FALSE; /* * Set user-agent. Used for HTTP, but since we can attempt to tunnel * basically anything through a http proxy we can't limit this based on * protocol. */ if(data->set.str[STRING_USERAGENT]) { Curl_safefree(conn->allocptr.uagent); conn->allocptr.uagent = aprintf("User-Agent: %s\r\n", data->set.str[STRING_USERAGENT]); if(!conn->allocptr.uagent) return CURLE_OUT_OF_MEMORY; } data->req.headerbytecount = 0; #ifdef CURL_DO_LINEEND_CONV data->state.crlf_conversions = 0; /* reset CRLF conversion counter */ #endif /* CURL_DO_LINEEND_CONV */ /* set start time here for timeout purposes in the connect procedure, it is later set again for the progress meter purpose */ conn->now = Curl_tvnow(); for(;;) { /* loop for CURL_SERVER_CLOSED_CONNECTION */ if(CURL_SOCKET_BAD == conn->sock[FIRSTSOCKET]) { /* Try to connect only if not already connected */ bool connected = FALSE; result = ConnectPlease(data, conn, &connected); if(result && !conn->ip_addr) { /* transport connection failure not related with authentication */ conn->bits.tcpconnect[FIRSTSOCKET] = FALSE; return result; } if(connected) { result = Curl_protocol_connect(conn, protocol_done); if(CURLE_OK == result) conn->bits.tcpconnect[FIRSTSOCKET] = TRUE; } else conn->bits.tcpconnect[FIRSTSOCKET] = FALSE; /* if the connection was closed by the server while exchanging authentication informations, retry with the new set authentication information */ if(conn->bits.proxy_connect_closed) { /* reset the error buffer */ if(data->set.errorbuffer) data->set.errorbuffer[0] = '\0'; data->state.errorbuf = FALSE; continue; } if(CURLE_OK != result) return result; } else { Curl_pgrsTime(data, TIMER_CONNECT); /* we're connected already */ Curl_pgrsTime(data, TIMER_APPCONNECT); /* we're connected already */ conn->bits.tcpconnect[FIRSTSOCKET] = TRUE; *protocol_done = TRUE; Curl_verboseconnect(conn); Curl_updateconninfo(conn, conn->sock[FIRSTSOCKET]); } /* Stop the loop now */ break; } conn->now = Curl_tvnow(); /* time this *after* the connect is done, we set this here perhaps a second time */ #ifdef __EMX__ /* * This check is quite a hack. We're calling _fsetmode to fix the problem * with fwrite converting newline characters (you get mangled text files, * and corrupted binary files when you download to stdout and redirect it to * a file). */ if((data->set.out)->_handle == NULL) { _fsetmode(stdout, "b"); } #endif return result; }
/* Curl_setup_conn() is called after the name resolve initiated in * create_conn() is all done. * * Curl_setup_conn() also handles reused connections * * conn->data MUST already have been setup fine (in create_conn) */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L5029-L5139
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
do_init
static CURLcode do_init(struct connectdata *conn) { struct SessionHandle *data = conn->data; struct SingleRequest *k = &data->req; conn->bits.done = FALSE; /* Curl_done() is not called yet */ conn->bits.do_more = FALSE; /* by default there's no curl_do_more() to use */ data->state.expect100header = FALSE; if(data->set.opt_no_body) /* in HTTP lingo, no body means using the HEAD request... */ data->set.httpreq = HTTPREQ_HEAD; else if(HTTPREQ_HEAD == data->set.httpreq) /* ... but if unset there really is no perfect method that is the "opposite" of HEAD but in reality most people probably think GET then. The important thing is that we can't let it remain HEAD if the opt_no_body is set FALSE since then we'll behave wrong when getting HTTP. */ data->set.httpreq = HTTPREQ_GET; /* NB: the content encoding software depends on this initialization */ Curl_easy_initHandleData(data); k->start = Curl_tvnow(); /* start time */ k->now = k->start; /* current time is now */ k->header = TRUE; /* assume header */ k->bytecount = 0; k->buf = data->state.buffer; k->uploadbuf = data->state.uploadbuffer; k->hbufp = data->state.headerbuff; k->ignorebody=FALSE; Curl_speedinit(data); Curl_pgrsSetUploadCounter(data, 0); Curl_pgrsSetDownloadCounter(data, 0); return CURLE_OK; }
/* * do_init() inits the readwrite session. This is inited each time (in the DO * function before the protocol-specific DO functions are invoked) for a * transfer, sometimes multiple times on the same SessionHandle. Make sure * nothing in here depends on stuff that are setup dynamically for the * transfer. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L5293-L5333
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
do_complete
static void do_complete(struct connectdata *conn) { conn->data->req.chunk=FALSE; conn->data->req.maxfd = (conn->sockfd>conn->writesockfd? conn->sockfd:conn->writesockfd)+1; Curl_pgrsTime(conn->data, TIMER_PRETRANSFER); }
/* * do_complete is called when the DO actions are complete. * * We init chunking and trailer bits to their default values here immediately * before receiving any header data for the current request in the pipeline. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L5341-L5347
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
Curl_do_more
CURLcode Curl_do_more(struct connectdata *conn, bool *completed) { CURLcode result=CURLE_OK; *completed = FALSE; if(conn->handler->do_more) result = conn->handler->do_more(conn, completed); if(!result && *completed) /* do_complete must be called after the protocol-specific DO function */ do_complete(conn); return result; }
/* * Curl_do_more() is called during the DO_MORE multi state. It is basically a * second stage DO state which (wrongly) was introduced to support FTP's * second connection. * * TODO: A future libcurl should be able to work away this state. * */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L5396-L5410
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
Curl_reset_reqproto
void Curl_reset_reqproto(struct connectdata *conn) { struct SessionHandle *data = conn->data; if(data->state.proto.generic && data->state.current_conn != conn) { free(data->state.proto.generic); data->state.proto.generic = NULL; } data->state.current_conn = conn; }
/* Called on connect, and if there's already a protocol-specific struct allocated for a different connection, this frees it that it can be setup properly later on. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/lib/url.c#L5415-L5423
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
Curl_SSL_Init_Application_a
int Curl_SSL_Init_Application_a(SSLInitApp * init_app) { int rc; unsigned int i; SSLInitApp ia; if (!init_app || !init_app->applicationID || !init_app->applicationIDLen) return SSL_Init_Application(init_app); memcpy((char *) &ia, (char *) init_app, sizeof ia); i = ia.applicationIDLen; if (!(ia.applicationID = malloc(i + 1))) { errno = ENOMEM; return SSL_ERROR_IO; } QadrtConvertA2E(ia.applicationID, init_app->applicationID, i, i); ia.applicationID[i] = '\0'; rc = SSL_Init_Application(&ia); free(ia.applicationID); init_app->localCertificateLen = ia.localCertificateLen; init_app->sessionType = ia.sessionType; return rc; }
/* ASCII wrappers for the SSL procedures. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/packages/OS400/os400sys.c#L347-L373
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
Curl_gss_convert_in_place
static int Curl_gss_convert_in_place(OM_uint32 * minor_status, gss_buffer_t buf) { unsigned int i; char * t; /* Convert `buf' in place, from EBCDIC to ASCII. If error, release the buffer and return -1. Else return 0. */ i = buf->length; if (i) { if (!(t = malloc(i))) { gss_release_buffer(minor_status, buf); if (minor_status) *minor_status = ENOMEM; return -1; } QadrtConvertE2A(t, buf->value, i, i); memcpy(buf->value, t, i); free(t); } return 0; }
/* ASCII wrappers for the GSSAPI procedures. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/packages/OS400/os400sys.c#L458-L486
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
convert_sockaddr
static int convert_sockaddr(struct sockaddr_storage * dstaddr, const struct sockaddr * srcaddr, int srclen) { const struct sockaddr_un * srcu; struct sockaddr_un * dstu; unsigned int i; unsigned int dstsize; /* Convert a socket address into job CCSID, if needed. */ if (!srcaddr || srclen < offsetof(struct sockaddr, sa_family) + sizeof srcaddr->sa_family || srclen > sizeof *dstaddr) { errno = EINVAL; return -1; } memcpy((char *) dstaddr, (char *) srcaddr, srclen); switch (srcaddr->sa_family) { case AF_UNIX: srcu = (const struct sockaddr_un *) srcaddr; dstu = (struct sockaddr_un *) dstaddr; dstsize = sizeof *dstaddr - offsetof(struct sockaddr_un, sun_path); srclen -= offsetof(struct sockaddr_un, sun_path); i = QadrtConvertA2E(dstu->sun_path, srcu->sun_path, dstsize - 1, srclen); dstu->sun_path[i] = '\0'; i += offsetof(struct sockaddr_un, sun_path); srclen = i; } return srclen; }
/* CURL_DISABLE_LDAP */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/packages/OS400/os400sys.c#L944-L978
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
tool_debug_cb
int tool_debug_cb(CURL *handle, curl_infotype type, unsigned char *data, size_t size, void *userdata) { struct Configurable *config = userdata; FILE *output = config->errors; const char *text; struct timeval tv; struct tm *now; char timebuf[20]; time_t secs; static time_t epoch_offset; static int known_offset; (void)handle; /* not used */ if(config->tracetime) { tv = tvnow(); if(!known_offset) { epoch_offset = time(NULL) - tv.tv_sec; known_offset = 1; } secs = epoch_offset + tv.tv_sec; now = localtime(&secs); /* not thread safe but we don't care */ snprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%06ld ", now->tm_hour, now->tm_min, now->tm_sec, (long)tv.tv_usec); } else timebuf[0] = 0; if(!config->trace_stream) { /* open for append */ if(curlx_strequal("-", config->trace_dump)) config->trace_stream = stdout; else if(curlx_strequal("%", config->trace_dump)) /* Ok, this is somewhat hackish but we do it undocumented for now */ config->trace_stream = config->errors; /* aka stderr */ else { config->trace_stream = fopen(config->trace_dump, "w"); config->trace_fopened = TRUE; } } if(config->trace_stream) output = config->trace_stream; if(!output) { warnf(config, "Failed to create/open output"); return 0; } if(config->tracetype == TRACE_PLAIN) { /* * This is the trace look that is similar to what libcurl makes on its * own. */ static const char * const s_infotype[] = { "*", "<", ">", "{", "}", "{", "}" }; size_t i; size_t st = 0; static bool newl = FALSE; static bool traced_data = FALSE; switch(type) { case CURLINFO_HEADER_OUT: if(size > 0) { for(i = 0; i < size - 1; i++) { if(data[i] == '\n') { /* LF */ if(!newl) { fprintf(output, "%s%s ", timebuf, s_infotype[type]); } (void)fwrite(data + st, i - st + 1, 1, output); st = i + 1; newl = FALSE; } } if(!newl) fprintf(output, "%s%s ", timebuf, s_infotype[type]); (void)fwrite(data + st, i - st + 1, 1, output); } newl = (size && (data[size - 1] != '\n')) ? TRUE : FALSE; traced_data = FALSE; break; case CURLINFO_TEXT: case CURLINFO_HEADER_IN: if(!newl) fprintf(output, "%s%s ", timebuf, s_infotype[type]); (void)fwrite(data, size, 1, output); newl = (size && (data[size - 1] != '\n')) ? TRUE : FALSE; traced_data = FALSE; break; case CURLINFO_DATA_OUT: case CURLINFO_DATA_IN: case CURLINFO_SSL_DATA_IN: case CURLINFO_SSL_DATA_OUT: if(!traced_data) { /* if the data is output to a tty and we're sending this debug trace to stderr or stdout, we don't display the alert about the data not being shown as the data _is_ shown then just not via this function */ if(!config->isatty || ((output != stderr) && (output != stdout))) { if(!newl) fprintf(output, "%s%s ", timebuf, s_infotype[type]); fprintf(output, "[data not shown]\n"); newl = FALSE; traced_data = TRUE; } } break; default: /* nada */ newl = FALSE; traced_data = FALSE; break; } return 0; } #ifdef CURL_DOES_CONVERSIONS /* Special processing is needed for CURLINFO_HEADER_OUT blocks * if they contain both headers and data (separated by CRLFCRLF). * We dump the header text and then switch type to CURLINFO_DATA_OUT. */ if((type == CURLINFO_HEADER_OUT) && (size > 4)) { size_t i; for(i = 0; i < size - 4; i++) { if(memcmp(&data[i], "\r\n\r\n", 4) == 0) { /* dump everything through the CRLFCRLF as a sent header */ text = "=> Send header"; dump(timebuf, text, output, data, i + 4, config->tracetype, type); data += i + 3; size -= i + 4; type = CURLINFO_DATA_OUT; data += 1; break; } } } #endif /* CURL_DOES_CONVERSIONS */ switch (type) { case CURLINFO_TEXT: fprintf(output, "%s== Info: %s", timebuf, data); default: /* in case a new one is introduced to shock us */ return 0; case CURLINFO_HEADER_OUT: text = "=> Send header"; break; case CURLINFO_DATA_OUT: text = "=> Send data"; break; case CURLINFO_HEADER_IN: text = "<= Recv header"; break; case CURLINFO_DATA_IN: text = "<= Recv data"; break; case CURLINFO_SSL_DATA_IN: text = "<= Recv SSL data"; break; case CURLINFO_SSL_DATA_OUT: text = "=> Send SSL data"; break; } dump(timebuf, text, output, data, size, config->tracetype, type); return 0; }
/* ** callback for CURLOPT_DEBUGFUNCTION */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_cb_dbg.c#L43-L213
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
tool_header_cb
size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata) { struct HdrCbData *hdrcbdata = userdata; struct OutStruct *outs = hdrcbdata->outs; struct OutStruct *heads = hdrcbdata->heads; const char *str = ptr; const size_t cb = size * nmemb; const char *end = (char*)ptr + cb; /* * Once that libcurl has called back tool_header_cb() the returned value * is checked against the amount that was intended to be written, if * it does not match then it fails with CURLE_WRITE_ERROR. So at this * point returning a value different from sz*nmemb indicates failure. */ size_t failure = (size * nmemb) ? 0 : 1; if(!heads->config) return failure; #ifdef DEBUGBUILD if(size * nmemb > (size_t)CURL_MAX_HTTP_HEADER) { warnf(heads->config, "Header data exceeds single call write limit!\n"); return failure; } #endif /* * Write header data when curl option --dump-header (-D) is given. */ if(heads->config->headerfile && heads->stream) { size_t rc = fwrite(ptr, size, nmemb, heads->stream); if(rc != cb) return rc; } /* * This callback sets the filename where output shall be written when * curl options --remote-name (-O) and --remote-header-name (-J) have * been simultaneously given and additionally server returns an HTTP * Content-Disposition header specifying a filename property. */ if(hdrcbdata->honor_cd_filename && (cb > 20) && checkprefix("Content-disposition:", str)) { const char *p = str + 20; /* look for the 'filename=' parameter (encoded filenames (*=) are not supported) */ for(;;) { char *filename; size_t len; while(*p && (p < end) && !ISALPHA(*p)) p++; if(p > end - 9) break; if(memcmp(p, "filename=", 9)) { /* no match, find next parameter */ while((p < end) && (*p != ';')) p++; continue; } p += 9; /* this expression below typecasts 'cb' only to avoid warning: signed and unsigned type in conditional expression */ len = (ssize_t)cb - (p - str); filename = parse_filename(p, len); if(filename) { outs->filename = filename; outs->alloc_filename = TRUE; outs->is_cd_filename = TRUE; outs->s_isreg = TRUE; outs->fopened = FALSE; outs->stream = NULL; hdrcbdata->honor_cd_filename = FALSE; break; } else return failure; } } return cb; }
/* ** callback for CURLOPT_HEADERFUNCTION */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_cb_hdr.c#L42-L130
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
tool_read_cb
size_t tool_read_cb(void *buffer, size_t sz, size_t nmemb, void *userdata) { ssize_t rc; struct InStruct *in = userdata; rc = read(in->fd, buffer, sz*nmemb); if(rc < 0) { if(errno == EAGAIN) { errno = 0; in->config->readbusy = TRUE; return CURL_READFUNC_PAUSE; } /* since size_t is unsigned we can't return negative values fine */ rc = 0; } in->config->readbusy = FALSE; return (size_t)rc; }
/* ** callback for CURLOPT_READFUNCTION */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_cb_rea.c#L37-L54
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
tool_seek_cb
int tool_seek_cb(void *userdata, curl_off_t offset, int whence) { struct InStruct *in = userdata; #if(CURL_SIZEOF_CURL_OFF_T > SIZEOF_OFF_T) && !defined(USE_WIN32_LARGE_FILES) /* The offset check following here is only interesting if curl_off_t is larger than off_t and we are not using the WIN32 large file support macros that provide the support to do 64bit seeks correctly */ if(offset > OUR_MAX_SEEK_O) { /* Some precaution code to work around problems with different data sizes to allow seeking >32bit even if off_t is 32bit. Should be very rare and is really valid on weirdo-systems. */ curl_off_t left = offset; if(whence != SEEK_SET) /* this code path doesn't support other types */ return CURL_SEEKFUNC_FAIL; if(LSEEK_ERROR == lseek(in->fd, 0, SEEK_SET)) /* couldn't rewind to beginning */ return CURL_SEEKFUNC_FAIL; while(left) { long step = (left > OUR_MAX_SEEK_O) ? OUR_MAX_SEEK_L : (long)left; if(LSEEK_ERROR == lseek(in->fd, step, SEEK_CUR)) /* couldn't seek forwards the desired amount */ return CURL_SEEKFUNC_FAIL; left -= step; } return CURL_SEEKFUNC_OK; } #endif if(LSEEK_ERROR == lseek(in->fd, offset, whence)) /* couldn't rewind, the reason is in errno but errno is just not portable enough and we don't actually care that much why we failed. We'll let libcurl know that it may try other means if it wants to. */ return CURL_SEEKFUNC_CANTSEEK; return CURL_SEEKFUNC_OK; }
/* ** callback for CURLOPT_SEEKFUNCTION ** ** Notice that this is not supposed to return the resulting offset. This ** shall only return CURL_SEEKFUNC_* return codes. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_cb_see.c#L47-L89
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
tool_ftruncate64
int tool_ftruncate64(int fd, curl_off_t where) { if(_lseeki64(fd, where, SEEK_SET) < 0) return -1; if(!SetEndOfFile((HANDLE)_get_osfhandle(fd))) return -1; return 0; }
/* * Truncate a file handle at a 64-bit position 'where'. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_cb_see.c#L119-L128
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
tool_write_cb
size_t tool_write_cb(void *buffer, size_t sz, size_t nmemb, void *userdata) { size_t rc; struct OutStruct *outs = userdata; struct Configurable *config = outs->config; /* * Once that libcurl has called back tool_write_cb() the returned value * is checked against the amount that was intended to be written, if * it does not match then it fails with CURLE_WRITE_ERROR. So at this * point returning a value different from sz*nmemb indicates failure. */ const size_t failure = (sz * nmemb) ? 0 : 1; if(!config) return failure; #ifdef DEBUGBUILD if(config->include_headers) { if(sz * nmemb > (size_t)CURL_MAX_HTTP_HEADER) { warnf(config, "Header data size exceeds single call write limit!\n"); return failure; } } else { if(sz * nmemb > (size_t)CURL_MAX_WRITE_SIZE) { warnf(config, "Data size exceeds single call write limit!\n"); return failure; } } { /* Some internal congruency checks on received OutStruct */ bool check_fails = FALSE; if(outs->filename) { /* regular file */ if(!*outs->filename) check_fails = TRUE; if(!outs->s_isreg) check_fails = TRUE; if(outs->fopened && !outs->stream) check_fails = TRUE; if(!outs->fopened && outs->stream) check_fails = TRUE; if(!outs->fopened && outs->bytes) check_fails = TRUE; } else { /* standard stream */ if(!outs->stream || outs->s_isreg || outs->fopened) check_fails = TRUE; if(outs->alloc_filename || outs->is_cd_filename || outs->init) check_fails = TRUE; } if(check_fails) { warnf(config, "Invalid output struct data for write callback\n"); return failure; } } #endif if(!outs->stream) { FILE *file; if(!outs->filename || !*outs->filename) { warnf(config, "Remote filename has no length!\n"); return failure; } if(outs->is_cd_filename) { /* don't overwrite existing files */ file = fopen(outs->filename, "rb"); if(file) { fclose(file); warnf(config, "Refusing to overwrite %s: %s\n", outs->filename, strerror(EEXIST)); return failure; } } /* open file for writing */ file = fopen(outs->filename, "wb"); if(!file) { warnf(config, "Failed to create the file %s: %s\n", outs->filename, strerror(errno)); return failure; } outs->s_isreg = TRUE; outs->fopened = TRUE; outs->stream = file; outs->bytes = 0; outs->init = 0; } rc = fwrite(buffer, sz, nmemb, outs->stream); if((sz * nmemb) == rc) /* we added this amount of data to the output */ outs->bytes += (sz * nmemb); if(config->readbusy) { config->readbusy = FALSE; curl_easy_pause(config->easy, CURLPAUSE_CONT); } if(config->nobuffer) { /* output buffering disabled */ int res = fflush(outs->stream); if(res) return failure; } return rc; }
/* ** callback for CURLOPT_WRITEFUNCTION */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_cb_wrt.c#L38-L151
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
convert_to_network
CURLcode convert_to_network(char *buffer, size_t length) { /* translate from the host encoding to the network encoding */ char *input_ptr, *output_ptr; size_t res, in_bytes, out_bytes; /* open an iconv conversion descriptor if necessary */ if(outbound_cd == (iconv_t)-1) { outbound_cd = iconv_open(CURL_ICONV_CODESET_OF_NETWORK, CURL_ICONV_CODESET_OF_HOST); if(outbound_cd == (iconv_t)-1) { return CURLE_CONV_FAILED; } } /* call iconv */ input_ptr = output_ptr = buffer; in_bytes = out_bytes = length; res = iconv(outbound_cd, &input_ptr, &in_bytes, &output_ptr, &out_bytes); if((res == (size_t)-1) || (in_bytes != 0)) { return CURLE_CONV_FAILED; } return CURLE_OK; }
/* * convert_to_network() is a curl tool function to convert * from the host encoding to ASCII on non-ASCII platforms. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_convert.c#L49-L73
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
convert_from_network
CURLcode convert_from_network(char *buffer, size_t length) { /* translate from the network encoding to the host encoding */ char *input_ptr, *output_ptr; size_t res, in_bytes, out_bytes; /* open an iconv conversion descriptor if necessary */ if(inbound_cd == (iconv_t)-1) { inbound_cd = iconv_open(CURL_ICONV_CODESET_OF_HOST, CURL_ICONV_CODESET_OF_NETWORK); if(inbound_cd == (iconv_t)-1) { return CURLE_CONV_FAILED; } } /* call iconv */ input_ptr = output_ptr = buffer; in_bytes = out_bytes = length; res = iconv(inbound_cd, &input_ptr, &in_bytes, &output_ptr, &out_bytes); if((res == (size_t)-1) || (in_bytes != 0)) { return CURLE_CONV_FAILED; } return CURLE_OK; }
/* * convert_from_network() is a curl tool function * for performing ASCII conversions on non-ASCII platforms. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_convert.c#L79-L103
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
convert_char
char convert_char(curl_infotype infotype, char this_char) { /* determine how this specific character should be displayed */ switch(infotype) { case CURLINFO_DATA_IN: case CURLINFO_DATA_OUT: case CURLINFO_SSL_DATA_IN: case CURLINFO_SSL_DATA_OUT: /* data, treat as ASCII */ if((this_char >= 0x20) && (this_char < 0x7f)) { /* printable ASCII hex value: convert to host encoding */ (void)convert_from_network(&this_char, 1); } else { /* non-printable ASCII, use a replacement character */ return UNPRINTABLE_CHAR; } /* fall through to default */ default: /* treat as host encoding */ if(ISPRINT(this_char) && (this_char != '\t') && (this_char != '\r') && (this_char != '\n')) { /* printable characters excluding tabs and line end characters */ return this_char; } break; } /* non-printable, use a replacement character */ return UNPRINTABLE_CHAR; }
/* HAVE_ICONV */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_convert.c#L116-L147
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
create_dir_hierarchy
CURLcode create_dir_hierarchy(const char *outfile, FILE *errors) { char *tempdir; char *tempdir2; char *outdup; char *dirbuildup; CURLcode result = CURLE_OK; outdup = strdup(outfile); if(!outdup) return CURLE_OUT_OF_MEMORY; dirbuildup = malloc(strlen(outfile) + 1); if(!dirbuildup) { Curl_safefree(outdup); return CURLE_OUT_OF_MEMORY; } dirbuildup[0] = '\0'; tempdir = strtok(outdup, DIR_CHAR); while(tempdir != NULL) { tempdir2 = strtok(NULL, DIR_CHAR); /* since strtok returns a token for the last word even if not ending with DIR_CHAR, we need to prune it */ if(tempdir2 != NULL) { size_t dlen = strlen(dirbuildup); if(dlen) sprintf(&dirbuildup[dlen], "%s%s", DIR_CHAR, tempdir); else { if(0 != strncmp(outdup, DIR_CHAR, 1)) strcpy(dirbuildup, tempdir); else sprintf(dirbuildup, "%s%s", DIR_CHAR, tempdir); } if(access(dirbuildup, F_OK) == -1) { if(-1 == mkdir(dirbuildup,(mode_t)0000750)) { show_dir_errno(errors, dirbuildup); result = CURLE_WRITE_ERROR; break; /* get out of loop */ } } } tempdir = tempdir2; } Curl_safefree(dirbuildup); Curl_safefree(outdup); return result; }
/* * Create the needed directory hierarchy recursively in order to save * multi-GETs in file output, ie: * curl "http://my.site/dir[1-5]/file[1-5].txt" -o "dir#1/file#2.txt" * should create all the dir* automagically */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_dirhie.c#L94-L144
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
FindWin32CACert
CURLcode FindWin32CACert(struct Configurable *config, const char *bundle_file) { CURLcode result = CURLE_OK; /* search and set cert file only if libcurl supports SSL */ if(curlinfo->features & CURL_VERSION_SSL) { DWORD res_len; DWORD buf_tchar_size = PATH_MAX + 1; DWORD buf_bytes_size = sizeof(TCHAR) * buf_tchar_size; char *ptr = NULL; char *buf = malloc(buf_bytes_size); if(!buf) return CURLE_OUT_OF_MEMORY; buf[0] = '\0'; res_len = SearchPathA(NULL, bundle_file, NULL, buf_tchar_size, buf, &ptr); if(res_len > 0) { Curl_safefree(config->cacert); config->cacert = strdup(buf); if(!config->cacert) result = CURLE_OUT_OF_MEMORY; } Curl_safefree(buf); } return result; }
/* * Function to find CACert bundle on a Win32 platform using SearchPath. * (SearchPath is already declared via inclusions done in setup header file) * (Use the ASCII version instead of the unicode one!) * The order of the directories it searches is: * 1. application's directory * 2. current working directory * 3. Windows System directory (e.g. C:\windows\system32) * 4. Windows Directory (e.g. C:\windows) * 5. all directories along %PATH% * * For WinXP and later search order actually depends on registry value: * HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\SafeProcessSearchMode */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_doswin.c#L265-L294
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
easysrc_free
static void easysrc_free(void) { curl_slist_free_all(easysrc_decl); easysrc_decl = NULL; curl_slist_free_all(easysrc_data); easysrc_data = NULL; curl_slist_free_all(easysrc_code); easysrc_code = NULL; curl_slist_free_all(easysrc_toohard); easysrc_toohard = NULL; curl_slist_free_all(easysrc_clean); easysrc_clean = NULL; }
/* Clean up all source code if we run out of memory */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_easysrc.c#L78-L90
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
easysrc_add
CURLcode easysrc_add(struct curl_slist **plist, const char *line) { CURLcode ret = CURLE_OK; struct curl_slist *list = curl_slist_append(*plist, line); if(!list) { easysrc_free(); ret = CURLE_OUT_OF_MEMORY; } else *plist = list; return ret; }
/* Add a source line to the main code or remarks */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_easysrc.c#L93-L105
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
formparse
int formparse(struct Configurable *config, const char *input, struct curl_httppost **httppost, struct curl_httppost **last_post, bool literal_value) { /* nextarg MUST be a string in the format 'name=contents' and we'll build a linked list with the info */ char name[256]; char *contents = NULL; char type_major[128]; char type_minor[128]; char *contp; const char *type = NULL; char *sep; if((1 == sscanf(input, "%255[^=]=", name)) && ((contp = strchr(input, '=')) != NULL)) { /* the input was using the correct format */ /* Allocate the contents */ contents = strdup(contp+1); if(!contents) { fprintf(config->errors, "out of memory\n"); return 1; } contp = contents; if('@' == contp[0] && !literal_value) { /* we use the @-letter to indicate file name(s) */ struct multi_files *multi_start = NULL; struct multi_files *multi_current = NULL; char *ptr = contp; char *end = ptr + strlen(ptr); do { /* since this was a file, it may have a content-type specifier at the end too, or a filename. Or both. */ char *filename = NULL; char *word_end; bool semicolon; type = NULL; ++ptr; contp = get_param_word(&ptr, &word_end); semicolon = (';' == *ptr) ? TRUE : FALSE; *word_end = '\0'; /* terminate the contp */ /* have other content, continue parse */ while(semicolon) { /* have type or filename field */ ++ptr; while(*ptr && (ISSPACE(*ptr))) ++ptr; if(checkprefix("type=", ptr)) { /* set type pointer */ type = &ptr[5]; /* verify that this is a fine type specifier */ if(2 != sscanf(type, "%127[^/]/%127[^;,\n]", type_major, type_minor)) { warnf(config, "Illegally formatted content-type field!\n"); Curl_safefree(contents); FreeMultiInfo(&multi_start, &multi_current); return 2; /* illegal content-type syntax! */ } /* now point beyond the content-type specifier */ sep = (char *)type + strlen(type_major)+strlen(type_minor)+1; /* there's a semicolon following - we check if it is a filename specified and if not we simply assume that it is text that the user wants included in the type and include that too up to the next sep. */ ptr = sep; if(*sep==';') { if(!checkprefix(";filename=", sep)) { ptr = sep + 1; (void)get_param_word(&ptr, &sep); semicolon = (';' == *ptr) ? TRUE : FALSE; } } else semicolon = FALSE; if(*sep) *sep = '\0'; /* zero terminate type string */ } else if(checkprefix("filename=", ptr)) { ptr += 9; filename = get_param_word(&ptr, &word_end); semicolon = (';' == *ptr) ? TRUE : FALSE; *word_end = '\0'; } else { /* unknown prefix, skip to next block */ char *unknown = NULL; unknown = get_param_word(&ptr, &word_end); semicolon = (';' == *ptr) ? TRUE : FALSE; if(*unknown) { *word_end = '\0'; warnf(config, "skip unknown form field: %s\n", unknown); } } } /* now ptr point to comma or string end */ /* if type == NULL curl_formadd takes care of the problem */ if(*contp && !AddMultiFiles(contp, type, filename, &multi_start, &multi_current)) { warnf(config, "Error building form post!\n"); Curl_safefree(contents); FreeMultiInfo(&multi_start, &multi_current); return 3; } /* *ptr could be '\0', so we just check with the string end */ } while(ptr < end); /* 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 *start = multi_start; unsigned int i, count = 0; while(start) { start = start->next; ++count; } forms = malloc((count+1)*sizeof(struct curl_forms)); if(!forms) { fprintf(config->errors, "Error building form post!\n"); Curl_safefree(contents); FreeMultiInfo(&multi_start, &multi_current); return 4; } for(i = 0, start = multi_start; i < count; ++i, start = start->next) { forms[i].option = start->form.option; forms[i].value = start->form.value; } forms[count].option = CURLFORM_END; FreeMultiInfo(&multi_start, &multi_current); if(curl_formadd(httppost, last_post, CURLFORM_COPYNAME, name, CURLFORM_ARRAY, forms, CURLFORM_END) != 0) { warnf(config, "curl_formadd failed!\n"); Curl_safefree(forms); Curl_safefree(contents); return 5; } Curl_safefree(forms); } } else { struct curl_forms info[4]; int i = 0; char *ct = literal_value ? NULL : strstr(contp, ";type="); info[i].option = CURLFORM_COPYNAME; info[i].value = name; i++; if(ct) { info[i].option = CURLFORM_CONTENTTYPE; info[i].value = &ct[6]; i++; ct[0] = '\0'; /* zero terminate here */ } if(contp[0]=='<' && !literal_value) { info[i].option = CURLFORM_FILECONTENT; info[i].value = contp+1; i++; info[i].option = CURLFORM_END; if(curl_formadd(httppost, last_post, CURLFORM_ARRAY, info, CURLFORM_END ) != 0) { warnf(config, "curl_formadd failed, possibly the file %s is bad!\n", contp+1); Curl_safefree(contents); return 6; } } else { #ifdef CURL_DOES_CONVERSIONS if(convert_to_network(contp, strlen(contp))) { warnf(config, "curl_formadd failed!\n"); Curl_safefree(contents); return 7; } #endif info[i].option = CURLFORM_COPYCONTENTS; info[i].value = contp; i++; info[i].option = CURLFORM_END; if(curl_formadd(httppost, last_post, CURLFORM_ARRAY, info, CURLFORM_END) != 0) { warnf(config, "curl_formadd failed!\n"); Curl_safefree(contents); return 8; } } } } else { warnf(config, "Illegally formatted input field!\n"); return 1; } Curl_safefree(contents); return 0; }
/*************************************************************************** * * formparse() * * Reads a 'name=value' parameter and builds the appropriate linked list. * * Specify files to upload with 'name=@filename', or 'name=@"filename"' * in case the filename contain ',' or ';'. Supports specified * given Content-Type of the files. Such as ';type=<content-type>'. * * If literal_value is set, any initial '@' or '<' in the value string * loses its special meaning, as does any embedded ';type='. * * You may specify more than one file for a single name (field). Specify * multiple files by writing it like: * * 'name=@filename,filename2,filename3' * * or use double-quotes quote the filename: * * 'name=@"filename","filename2","filename3"' * * If you want content-types specified for each too, write them like: * * 'name=@filename;type=image/gif,filename2,filename3' * * If you want custom headers added for a single part, write them in a separate * file and do like this: * * 'name=foo;headers=@headerfile' or why not * 'name=@filemame;headers=@headerfile' * * To upload a file, but to fake the file name that will be included in the * formpost, do like this: * * 'name=@filename;filename=/dev/null' or quote the faked filename like: * 'name=@filename;filename="play, play, and play.txt"' * * If filename/path contains ',' or ';', it must be quoted by double-quotes, * else curl will fail to figure out the correct filename. if the filename * tobe quoted contains '"' or '\', '"' and '\' must be escaped by backslash. * * This function uses curl_formadd to fulfill it's job. Is heavily based on * the old curl_formparse code. * ***************************************************************************/
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_formparse.c#L143-L360
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
hugehelp
void hugehelp(void) { unsigned char* buf; int status,headerlen; z_stream z; /* Make sure no gzip options are set */ if (hugehelpgz[3] & 0xfe) return; headerlen = 10; memset(&z, 0, sizeof(z_stream)); z.zalloc = (alloc_func)zalloc_func; z.zfree = (free_func)zfree_func; z.avail_in = (unsigned int)(sizeof(hugehelpgz) - headerlen); z.next_in = (unsigned char *)hugehelpgz + headerlen; if (inflateInit2(&z, -MAX_WBITS) != Z_OK) return; buf = malloc(BUF_SIZE); if (buf) { while(1) { z.avail_out = BUF_SIZE; z.next_out = buf; status = inflate(&z, Z_SYNC_FLUSH); if (status == Z_OK || status == Z_STREAM_END) { fwrite(buf, BUF_SIZE - z.avail_out, 1, stdout); if (status == Z_STREAM_END) break; } else break; /* Error */ } free(buf); } inflateEnd(&z); }
/* Decompress and send to stdout a gzip-compressed buffer */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_hugehelp.c#L7718-L7755
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
get_libcurl_info
CURLcode get_libcurl_info(void) { static struct proto_name_pattern { const char *proto_name; long proto_pattern; } const possibly_built_in[] = { { "dict", CURLPROTO_DICT }, { "file", CURLPROTO_FILE }, { "ftp", CURLPROTO_FTP }, { "ftps", CURLPROTO_FTPS }, { "gopher", CURLPROTO_GOPHER }, { "http", CURLPROTO_HTTP }, { "https", CURLPROTO_HTTPS }, { "imap", CURLPROTO_IMAP }, { "imaps", CURLPROTO_IMAPS }, { "ldap", CURLPROTO_LDAP }, { "ldaps", CURLPROTO_LDAPS }, { "pop3", CURLPROTO_POP3 }, { "pop3s", CURLPROTO_POP3S }, { "rtmp", CURLPROTO_RTMP }, { "rtsp", CURLPROTO_RTSP }, { "scp", CURLPROTO_SCP }, { "sftp", CURLPROTO_SFTP }, { "smtp", CURLPROTO_SMTP }, { "smtps", CURLPROTO_SMTPS }, { "telnet", CURLPROTO_TELNET }, { "tftp", CURLPROTO_TFTP }, { NULL, 0 } }; struct proto_name_pattern const *p; const char *const *proto; /* Pointer to libcurl's run-time version information */ curlinfo = curl_version_info(CURLVERSION_NOW); if(!curlinfo) return CURLE_FAILED_INIT; /* Build CURLPROTO_* bit pattern with libcurl's built-in protocols */ built_in_protos = 0; if(curlinfo->protocols) { for(proto = curlinfo->protocols; *proto; proto++) { for(p = possibly_built_in; p->proto_name; p++) { if(curlx_raw_equal(*proto, p->proto_name)) { built_in_protos |= p->proto_pattern; break; } } } } return CURLE_OK; }
/* * libcurl_info_init: retrieves run-time information about libcurl, * setting a global pointer 'curlinfo' to libcurl's run-time info * struct, and a global bit pattern 'built_in_protos' composed of * CURLPROTO_* bits indicating which protocols are actually built * into library being used. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_libinfo.c#L47-L99
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
main_checkfds
static void main_checkfds(void) { #ifdef HAVE_PIPE int fd[2] = { STDIN_FILENO, STDIN_FILENO }; while(fd[0] == STDIN_FILENO || fd[0] == STDOUT_FILENO || fd[0] == STDERR_FILENO || fd[1] == STDIN_FILENO || fd[1] == STDOUT_FILENO || fd[1] == STDERR_FILENO) if(pipe(fd) < 0) return; /* Out of handles. This isn't really a big problem now, but will be when we try to create a socket later. */ close(fd[0]); close(fd[1]); #endif }
/* * Ensure that file descriptors 0, 1 and 2 (stdin, stdout, stderr) are * open before starting to run. Otherwise, the first three network * sockets opened by curl could be used for input sources, downloaded data * or error logs as they will effectively be stdin, stdout and/or stderr. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_main.c#L64-L80
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
main
int main(int argc, char *argv[]) { int res; struct Configurable config; memset(&config, 0, sizeof(struct Configurable)); config.errors = stderr; /* default errors to stderr */ main_checkfds(); #if defined(HAVE_SIGNAL) && defined(SIGPIPE) (void)signal(SIGPIPE, SIG_IGN); #endif res = operate(&config, argc, argv); #ifdef __SYMBIAN32__ if(config.showerror) tool_pressanykey(); #endif free_config_fields(&config); #ifdef __NOVELL_LIBC__ if(getenv("_IN_NETWARE_BASH_") == NULL) tool_pressanykey(); #endif #ifdef __VMS vms_special_exit(res, vms_show); #else return res; #endif }
/* ** curl tool main function. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_main.c#L85-L119
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
check_hash
static int check_hash(const char *filename, const metalink_digest_def *digest_def, const unsigned char *digest, FILE *error) { unsigned char *result; digest_context *dctx; int check_ok, flags, fd; flags = O_RDONLY; #ifdef O_BINARY /* O_BINARY is required in order to avoid binary EOF in text mode */ flags |= O_BINARY; #endif fd = open(filename, flags); if(fd == -1) { fprintf(error, "Metalink: validating (%s) [%s] FAILED (%s)\n", filename, digest_def->hash_name, strerror(errno)); return -1; } dctx = Curl_digest_init(digest_def->dparams); if(!dctx) { fprintf(error, "Metalink: validating (%s) [%s] FAILED (%s)\n", filename, digest_def->hash_name, "failed to initialize hash algorithm"); close(fd); return -2; } result = malloc(digest_def->dparams->digest_resultlen); while(1) { unsigned char buf[4096]; ssize_t len = read(fd, buf, sizeof(buf)); if(len == 0) { break; } else if(len == -1) { fprintf(error, "Metalink: validating (%s) [%s] FAILED (%s)\n", filename, digest_def->hash_name, strerror(errno)); Curl_digest_final(dctx, result); close(fd); return -1; } Curl_digest_update(dctx, buf, (unsigned int)len); } Curl_digest_final(dctx, result); check_ok = memcmp(result, digest, digest_def->dparams->digest_resultlen) == 0; /* sha*sum style verdict output */ if(check_ok) fprintf(error, "Metalink: validating (%s) [%s] OK\n", filename, digest_def->hash_name); else fprintf(error, "Metalink: validating (%s) [%s] FAILED (digest mismatch)\n", filename, digest_def->hash_name); free(result); close(fd); return check_ok; }
/* * Check checksum of file denoted by filename. The expected hash value * is given in hex_hash which is hex-encoded string. * * This function returns 1 if it succeeds or one of the following * integers: * * 0: * Checksum didn't match. * -1: * Could not open file; or could not read data from file. * -2: * Hash algorithm not available. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_metalink.c#L537-L596
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
check_hex_digest
static int check_hex_digest(const char *hex_digest, const metalink_digest_def *digest_def) { size_t i; for(i = 0; hex_digest[i]; ++i) { char c = hex_digest[i]; if(!(('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'))) { return 0; } } return digest_def->dparams->digest_resultlen * 2 == i; }
/* Returns nonzero if hex_digest is properly formatted; that is each letter is in [0-9A-Za-z] and the length of the string equals to the result length of digest * 2. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_metalink.c#L644-L656
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
check_content_type
static int check_content_type(const char *content_type, const char *media_type) { const char *ptr = content_type; size_t media_type_len = strlen(media_type); for(; *ptr && (*ptr == ' ' || *ptr == '\t'); ++ptr); if(!*ptr) { return 0; } return Curl_raw_nequal(ptr, media_type, media_type_len) && (*(ptr+media_type_len) == '\0' || *(ptr+media_type_len) == ' ' || *(ptr+media_type_len) == '\t' || *(ptr+media_type_len) == ';'); }
/* * Returns nonzero if content_type includes mediatype. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_metalink.c#L821-L832
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
FreeMultiInfo
void FreeMultiInfo(struct multi_files **multi_first, struct multi_files **multi_last) { struct multi_files *next; struct multi_files *item = *multi_first; while(item) { next = item->next; Curl_safefree(item); item = next; } *multi_first = NULL; if(multi_last) *multi_last = NULL; }
/* * FreeMultiInfo: Free the items of the list. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_mfiles.c#L112-L126
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
warnf
void warnf(struct Configurable *config, const char *fmt, ...) { if(!config->mute) { va_list ap; int len; char *ptr; char print_buffer[256]; va_start(ap, fmt); len = vsnprintf(print_buffer, sizeof(print_buffer), fmt, ap); va_end(ap); ptr = print_buffer; while(len > 0) { fputs(WARN_PREFIX, config->errors); if(len > (int)WARN_TEXTWIDTH) { int cut = WARN_TEXTWIDTH-1; while(!ISSPACE(ptr[cut]) && cut) { cut--; } if(0 == cut) /* not a single cutting position was found, just cut it at the max text width then! */ cut = WARN_TEXTWIDTH-1; (void)fwrite(ptr, cut + 1, 1, config->errors); fputs("\n", config->errors); ptr += cut+1; /* skip the space too */ len -= cut; } else { fputs(ptr, config->errors); len = 0; } } } }
/* * Emit warning formatted message on configured 'errors' stream unless * mute (--silent) was selected. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_msgs.c#L41-L79
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
helpf
void helpf(FILE *errors, const char *fmt, ...) { va_list ap; if(fmt) { va_start(ap, fmt); fputs("curl: ", errors); /* prefix it */ vfprintf(errors, fmt, ap); va_end(ap); } fprintf(errors, "curl: try 'curl --help' " #ifdef USE_MANUAL "or 'curl --manual' " #endif "for more information\n"); }
/* * Emit help formatted message on given stream. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_msgs.c#L85-L99
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
list_engines
void list_engines(const struct curl_slist *engines) { puts("Build-time engines:"); if(!engines) { puts(" <none>"); return; } for(; engines; engines = engines->next) printf(" %s\n", engines->data); }
/* * Print list of OpenSSL supported engines */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_operhlp.c#L53-L62
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
get_url_file_name
CURLcode get_url_file_name(char **filename, const char *url) { const char *pc; *filename = NULL; /* Find and get the remote file name */ pc = strstr(url, "://"); if(pc) pc += 3; else pc = url; pc = strrchr(pc, '/'); if(pc) { /* duplicate the string beyond the slash */ pc++; if(*pc) { *filename = strdup(pc); if(!*filename) return CURLE_OUT_OF_MEMORY; } } /* in case we built debug enabled, we allow an environment variable * named CURL_TESTDIR to prefix the given file name to put it into a * specific directory */ #ifdef DEBUGBUILD { char *tdir = curlx_getenv("CURL_TESTDIR"); if(tdir) { char buffer[512]; /* suitably large */ snprintf(buffer, sizeof(buffer), "%s/%s", tdir, *filename); Curl_safefree(*filename); *filename = strdup(buffer); /* clone the buffer */ curl_free(tdir); } } #endif return CURLE_OK; }
/* Extracts the name portion of the URL. * Returns a pointer to a heap-allocated string or NULL if * no name part, at location indicated by first argument. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_operhlp.c#L156-L198
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
main_init
CURLcode main_init(void) { #if defined(__DJGPP__) || defined(__GO32__) /* stop stat() wasting time */ _djstat_flags |= _STAT_INODE | _STAT_EXEC_MAGIC | _STAT_DIRSIZE; #endif return curl_global_init(CURL_GLOBAL_DEFAULT); }
/* * 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. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_operhlp.c#L205-L213
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
main_free
void main_free(void) { curl_global_cleanup(); convert_cleanup(); #ifdef USE_METALINK metalink_cleanup(); #endif }
/* * This is the main global destructor for the app. Call this after * _all_ libcurl usage is done. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_operhlp.c#L219-L226
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
str2num
ParameterError str2num(long *val, const char *str) { if(str) { char *endptr; long num = strtol(str, &endptr, 10); if((endptr != str) && (endptr == str + strlen(str))) { *val = num; return PARAM_OK; /* Ok */ } } return PARAM_BAD_NUMERIC; /* badness */ }
/* * Parse the string and write the long in the given address. Return PARAM_OK * on success, otherwise a parameter specific error enum. * * Since this function gets called with the 'nextarg' pointer from within the * getparameter a lot, we must check it for NULL before accessing the str * data. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_paramhlp.c#L157-L168
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
str2unum
ParameterError str2unum(long *val, const char *str) { if(str[0]=='-') return PARAM_NEGATIVE_NUMERIC; /* badness */ return str2num(val, str); }
/* * Parse the string and write the long in the given address. Return PARAM_OK * on success, otherwise a parameter error enum. ONLY ACCEPTS POSITIVE NUMBERS! * * Since this function gets called with the 'nextarg' pointer from within the * getparameter a lot, we must check it for NULL before accessing the str * data. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_paramhlp.c#L179-L184
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
proto2num
long proto2num(struct Configurable *config, long *val, const char *str) { char *buffer; const char *sep = ","; char *token; static struct sprotos { const char *name; long bit; } const protos[] = { { "all", CURLPROTO_ALL }, { "http", CURLPROTO_HTTP }, { "https", CURLPROTO_HTTPS }, { "ftp", CURLPROTO_FTP }, { "ftps", CURLPROTO_FTPS }, { "scp", CURLPROTO_SCP }, { "sftp", CURLPROTO_SFTP }, { "telnet", CURLPROTO_TELNET }, { "ldap", CURLPROTO_LDAP }, { "ldaps", CURLPROTO_LDAPS }, { "dict", CURLPROTO_DICT }, { "file", CURLPROTO_FILE }, { "tftp", CURLPROTO_TFTP }, { "imap", CURLPROTO_IMAP }, { "imaps", CURLPROTO_IMAPS }, { "pop3", CURLPROTO_POP3 }, { "pop3s", CURLPROTO_POP3S }, { "smtp", CURLPROTO_SMTP }, { "smtps", CURLPROTO_SMTPS }, { "rtsp", CURLPROTO_RTSP }, { "gopher", CURLPROTO_GOPHER }, { NULL, 0 } }; if(!str) return 1; buffer = strdup(str); /* because strtok corrupts it */ if(!buffer) return 1; for(token = strtok(buffer, sep); token; token = strtok(NULL, sep)) { enum e_action { allow, deny, set } action = allow; struct sprotos const *pp; /* Process token modifiers */ while(!ISALNUM(*token)) { /* may be NULL if token is all modifiers */ switch (*token++) { case '=': action = set; break; case '-': action = deny; break; case '+': action = allow; break; default: /* Includes case of terminating NULL */ Curl_safefree(buffer); return 1; } } for(pp=protos; pp->name; pp++) { if(curlx_raw_equal(token, pp->name)) { switch (action) { case deny: *val &= ~(pp->bit); break; case allow: *val |= pp->bit; break; case set: *val = pp->bit; break; } break; } } if(!(pp->name)) { /* unknown protocol */ /* If they have specified only this protocol, we say treat it as if no protocols are allowed */ if(action == set) *val = 0; warnf(config, "unrecognized protocol '%s'\n", token); } } Curl_safefree(buffer); return 0; }
/* * Parse the string and modify the long in the given address. Return * non-zero on failure, zero on success. * * The string is a list of protocols * * Since this function gets called with the 'nextarg' pointer from within the * getparameter a lot, we must check it for NULL before accessing the str * data. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_paramhlp.c#L197-L290
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
str2offset
ParameterError str2offset(curl_off_t *val, const char *str) { char *endptr; if(str[0] == '-') /* offsets aren't negative, this indicates weird input */ return PARAM_NEGATIVE_NUMERIC; #if(CURL_SIZEOF_CURL_OFF_T > CURL_SIZEOF_LONG) *val = curlx_strtoofft(str, &endptr, 0); if((*val == CURL_OFF_T_MAX || *val == CURL_OFF_T_MIN) && (ERRNO == ERANGE)) return PARAM_BAD_NUMERIC; #else *val = strtol(str, &endptr, 0); if((*val == LONG_MIN || *val == LONG_MAX) && ERRNO == ERANGE) return PARAM_BAD_NUMERIC; #endif if((endptr != str) && (endptr == str + strlen(str))) return PARAM_OK; return PARAM_BAD_NUMERIC; }
/** * Parses the given string looking for an offset (which may be a * larger-than-integer value). The offset CANNOT be negative! * * @param val the offset to populate * @param str the buffer containing the offset * @return PARAM_OK if successful, a parameter specific error enum if failure. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_paramhlp.c#L300-L320
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
parseconfig
int parseconfig(const char *filename, struct Configurable *config) { int res; FILE *file; char filebuffer[512]; bool usedarg; char *home; int rc = 0; if(!filename || !*filename) { /* NULL or no file name attempts to load .curlrc from the homedir! */ #ifndef __AMIGA__ filename = CURLRC; /* sensible default */ home = homedir(); /* portable homedir finder */ if(home) { if(strlen(home) < (sizeof(filebuffer) - strlen(CURLRC))) { snprintf(filebuffer, sizeof(filebuffer), "%s%s%s", home, DIR_CHAR, CURLRC); #ifdef WIN32 /* Check if the file exists - if not, try CURLRC in the same * directory as our executable */ file = fopen(filebuffer, "r"); if(file != NULL) { fclose(file); filename = filebuffer; } else { /* Get the filename of our executable. GetModuleFileName is * already declared via inclusions done in setup header file. * We assume that we are using the ASCII version here. */ int n = GetModuleFileName(0, filebuffer, sizeof(filebuffer)); if(n > 0 && n < (int)sizeof(filebuffer)) { /* We got a valid filename - get the directory part */ char *lastdirchar = strrchr(filebuffer, '\\'); if(lastdirchar) { size_t remaining; *lastdirchar = 0; /* If we have enough space, build the RC filename */ remaining = sizeof(filebuffer) - strlen(filebuffer); if(strlen(CURLRC) < remaining - 1) { snprintf(lastdirchar, remaining, "%s%s", DIR_CHAR, CURLRC); /* Don't bother checking if it exists - we do * that later */ filename = filebuffer; } } } } #else /* WIN32 */ filename = filebuffer; #endif /* WIN32 */ } Curl_safefree(home); /* we've used it, now free it */ } # else /* __AMIGA__ */ /* On AmigaOS all the config files are into env: */ filename = "ENV:" CURLRC; #endif } if(strcmp(filename,"-")) file = fopen(filename, "r"); else file = stdin; if(file) { char *line; char *aline; char *option; char *param; int lineno = 0; bool alloced_param; while(NULL != (aline = my_get_line(file))) { lineno++; line = aline; alloced_param=FALSE; /* line with # in the first non-blank column is a comment! */ while(*line && ISSPACE(*line)) line++; switch(*line) { case '#': case '/': case '\r': case '\n': case '*': case '\0': Curl_safefree(aline); continue; } /* the option keywords starts here */ option = line; while(*line && !ISSPACE(*line) && !ISSEP(*line)) line++; /* ... and has ended here */ if(*line) *line++ = '\0'; /* zero terminate, we have a local copy of the data */ #ifdef DEBUG_CONFIG fprintf(stderr, "GOT: %s\n", option); #endif /* pass spaces and separator(s) */ while(*line && (ISSPACE(*line) || ISSEP(*line))) line++; /* the parameter starts here (unless quoted) */ if(*line == '\"') { /* quoted parameter, do the quote dance */ line++; param = malloc(strlen(line) + 1); /* parameter */ if(!param) { /* out of memory */ Curl_safefree(aline); rc = 1; break; } alloced_param = TRUE; (void)unslashquote(line, param); } else { param = line; /* parameter starts here */ while(*line && !ISSPACE(*line)) line++; *line = '\0'; /* zero terminate */ } if(param && !*param) { /* do this so getparameter can check for required parameters. Otherwise it always thinks there's a parameter. */ if(alloced_param) Curl_safefree(param); param = NULL; } #ifdef DEBUG_CONFIG fprintf(stderr, "PARAM: \"%s\"\n",(param ? param : "(null)")); #endif res = getparameter(option, param, &usedarg, config); if(param && *param && !usedarg) /* we passed in a parameter that wasn't used! */ res = PARAM_GOT_EXTRA_PARAMETER; if(res != PARAM_OK) { /* the help request isn't really an error */ if(!strcmp(filename, "-")) { filename = (char *)"<stdin>"; } if(PARAM_HELP_REQUESTED != res) { const char *reason = param2text(res); warnf(config, "%s:%d: warning: '%s' %s\n", filename, lineno, option, reason); } } if(alloced_param) Curl_safefree(param); Curl_safefree(aline); } if(file != stdin) fclose(file); } else rc = 1; /* couldn't open the file */ return rc; }
/* return 0 on everything-is-fine, and non-zero otherwise */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_parsecfg.c#L44-L226
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
tool_setopt_enum
CURLcode tool_setopt_enum(CURL *curl, struct Configurable *config, const char *name, CURLoption tag, const NameValue *nvlist, long lval) { CURLcode ret = CURLE_OK; bool skip = FALSE; ret = curl_easy_setopt(curl, tag, lval); if(!lval) skip = TRUE; if(config->libcurl && !skip && !ret) { /* we only use this for real if --libcurl was used */ const NameValue *nv = NULL; for(nv=nvlist; nv->name; nv++) { if(nv->value == lval) break; /* found it */ } if(! nv->name) { /* If no definition was found, output an explicit value. * This could happen if new values are defined and used * but the NameValue list is not updated. */ CODE2("curl_easy_setopt(hnd, %s, %ldL);", name, lval); } else { CODE2("curl_easy_setopt(hnd, %s, (long)%s);", name, nv->name); } } nomem: return ret; }
/* setopt wrapper for enum types */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_setopt.c#L213-L243
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
tool_setopt_flags
CURLcode tool_setopt_flags(CURL *curl, struct Configurable *config, const char *name, CURLoption tag, const NameValue *nvlist, long lval) { CURLcode ret = CURLE_OK; bool skip = FALSE; ret = curl_easy_setopt(curl, tag, lval); if(!lval) skip = TRUE; if(config->libcurl && !skip && !ret) { /* we only use this for real if --libcurl was used */ char preamble[80]; /* should accommodate any symbol name */ long rest = lval; /* bits not handled yet */ const NameValue *nv = NULL; snprintf(preamble, sizeof(preamble), "curl_easy_setopt(hnd, %s, ", name); for(nv=nvlist; nv->name; nv++) { if((nv->value & ~ rest) == 0) { /* all value flags contained in rest */ rest &= ~ nv->value; /* remove bits handled here */ CODE3("%s(long)%s%s", preamble, nv->name, rest ? " |" : ");"); if(!rest) break; /* handled them all */ /* replace with all spaces for continuation line */ sprintf(preamble, "%*s", strlen(preamble), ""); } } /* If any bits have no definition, output an explicit value. * This could happen if new bits are defined and used * but the NameValue list is not updated. */ if(rest) CODE2("%s%ldL);", preamble, rest); } nomem: return ret; }
/* setopt wrapper for flags */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_setopt.c#L246-L285
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
tool_setopt_bitmask
CURLcode tool_setopt_bitmask(CURL *curl, struct Configurable *config, const char *name, CURLoption tag, const NameValueUnsigned *nvlist, long lval) { CURLcode ret = CURLE_OK; bool skip = FALSE; ret = curl_easy_setopt(curl, tag, lval); if(!lval) skip = TRUE; if(config->libcurl && !skip && !ret) { /* we only use this for real if --libcurl was used */ char preamble[80]; unsigned long rest = (unsigned long)lval; const NameValueUnsigned *nv = NULL; snprintf(preamble, sizeof(preamble), "curl_easy_setopt(hnd, %s, ", name); for(nv=nvlist; nv->name; nv++) { if((nv->value & ~ rest) == 0) { /* all value flags contained in rest */ rest &= ~ nv->value; /* remove bits handled here */ CODE3("%s(long)%s%s", preamble, nv->name, rest ? " |" : ");"); if(!rest) break; /* handled them all */ /* replace with all spaces for continuation line */ sprintf(preamble, "%*s", strlen(preamble), ""); } } /* If any bits have no definition, output an explicit value. * This could happen if new bits are defined and used * but the NameValue list is not updated. */ if(rest) CODE2("%s%luUL);", preamble, rest); } nomem: return ret; }
/* setopt wrapper for bitmasks */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_setopt.c#L288-L328
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
tool_setopt_httppost
CURLcode tool_setopt_httppost(CURL *curl, struct Configurable *config, const char *name, CURLoption tag, struct curl_httppost *post) { CURLcode ret = CURLE_OK; char *escaped = NULL; bool skip = FALSE; ret = curl_easy_setopt(curl, tag, post); if(!post) skip = TRUE; if(config->libcurl && !skip && !ret) { struct curl_httppost *pp, *p; int i; /* May use several httppost lists, if multiple POST actions */ i = ++ easysrc_form_count; DECL1("struct curl_httppost *post%d;", i); DATA1("post%d = NULL;", i); CLEAN1("curl_formfree(post%d);", i); CLEAN1("post%d = NULL;", i); if(i == 1) DECL0("struct curl_httppost *postend;"); DATA0("postend = NULL;"); for(p=post; p; p=p->next) { DATA1("curl_formadd(&post%d, &postend,", i); DATA1(" CURLFORM_COPYNAME, \"%s\",", p->name); for(pp=p; pp; pp=pp->more) { /* May be several files uploaded for one name; * these are linked through the 'more' pointer */ Curl_safefree(escaped); escaped = c_escape(pp->contents); if(!escaped) { ret = CURLE_OUT_OF_MEMORY; goto nomem; } if(pp->flags & HTTPPOST_FILENAME) { /* file upload as for -F @filename */ DATA1(" CURLFORM_FILE, \"%s\",", escaped); } else if(pp->flags & HTTPPOST_READFILE) { /* content from file as for -F <filename */ DATA1(" CURLFORM_FILECONTENT, \"%s\",", escaped); } else DATA1(" CURLFORM_COPYCONTENTS, \"%s\",", escaped); if(pp->showfilename) { Curl_safefree(escaped); escaped = c_escape(pp->showfilename); if(!escaped) { ret = CURLE_OUT_OF_MEMORY; goto nomem; } DATA1(" CURLFORM_FILENAME, \"%s\",", escaped); } if(pp->contenttype) { Curl_safefree(escaped); escaped = c_escape(pp->contenttype); if(!escaped) { ret = CURLE_OUT_OF_MEMORY; goto nomem; } DATA1(" CURLFORM_CONTENTTYPE, \"%s\",", escaped); } } DATA0(" CURLFORM_END);"); } CODE2("curl_easy_setopt(hnd, %s, post%d);", name, i); } nomem: Curl_safefree(escaped); return ret; }
/* setopt wrapper for CURLOPT_HTTPPOST */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_setopt.c#L331-L404
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
tool_setopt_slist
CURLcode tool_setopt_slist(CURL *curl, struct Configurable *config, const char *name, CURLoption tag, struct curl_slist *list) { CURLcode ret = CURLE_OK; char *escaped = NULL; bool skip = FALSE; ret = curl_easy_setopt(curl, tag, list); if(!list) skip = TRUE; if(config->libcurl && !skip && !ret) { struct curl_slist *s; int i; /* May need several slist variables, so invent name */ i = ++ easysrc_slist_count; DECL1("struct curl_slist *slist%d;", i); DATA1("slist%d = NULL;", i); CLEAN1("curl_slist_free_all(slist%d);", i); CLEAN1("slist%d = NULL;", i); for(s=list; s; s=s->next) { Curl_safefree(escaped); escaped = c_escape(s->data); if(!escaped) { ret = CURLE_OUT_OF_MEMORY; goto nomem; } DATA3("slist%d = curl_slist_append(slist%d, \"%s\");", i, i, escaped); } CODE2("curl_easy_setopt(hnd, %s, slist%d);", name, i); } nomem: Curl_safefree(escaped); return ret; }
/* setopt wrapper for curl_slist options */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_setopt.c#L407-L443
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
tool_setopt
CURLcode tool_setopt(CURL *curl, bool str, struct Configurable *config, const char *name, CURLoption tag, ...) { va_list arg; char buf[256]; const char *value = NULL; bool remark = FALSE; bool skip = FALSE; bool escape = FALSE; char *escaped = NULL; CURLcode ret = CURLE_OK; va_start(arg, tag); if(tag < CURLOPTTYPE_OBJECTPOINT) { /* Value is expected to be a long */ long lval = va_arg(arg, long); long defval = 0L; const NameValue *nv = NULL; for(nv=setopt_nv_CURLNONZERODEFAULTS; nv->name; nv++) { if(!strcmp(name, nv->name)) { defval = nv->value; break; /* found it */ } } snprintf(buf, sizeof(buf), "%ldL", lval); value = buf; ret = curl_easy_setopt(curl, tag, lval); if(lval == defval) skip = TRUE; } else if(tag < CURLOPTTYPE_OFF_T) { /* Value is some sort of object pointer */ void *pval = va_arg(arg, void *); /* function pointers are never printable */ if(tag >= CURLOPTTYPE_FUNCTIONPOINT) { if(pval) { value = "functionpointer"; remark = TRUE; } else skip = TRUE; } else if(pval && str) { value = (char *)pval; escape = TRUE; } else if(pval) { value = "objectpointer"; remark = TRUE; } else skip = TRUE; ret = curl_easy_setopt(curl, tag, pval); } else { /* Value is expected to be curl_off_t */ curl_off_t oval = va_arg(arg, curl_off_t); snprintf(buf, sizeof(buf), "(curl_off_t)%" CURL_FORMAT_CURL_OFF_T, oval); value = buf; ret = curl_easy_setopt(curl, tag, oval); if(!oval) skip = TRUE; } va_end(arg); if(config->libcurl && !skip && !ret) { /* we only use this for real if --libcurl was used */ if(remark) REM2("%s set to a %s", name, value); else { if(escape) { escaped = c_escape(value); if(!escaped) { ret = CURLE_OUT_OF_MEMORY; goto nomem; } CODE2("curl_easy_setopt(hnd, %s, \"%s\");", name, escaped); } else CODE2("curl_easy_setopt(hnd, %s, %s);", name, value); } } nomem: Curl_safefree(escaped); return ret; }
/* generic setopt wrapper for all other options. * Some type information is encoded in the tag value. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_setopt.c#L447-L543
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
glob_set
static GlobCode glob_set(URLGlob *glob, char *pattern, size_t pos, int *amount) { /* processes a set expression with the point behind the opening '{' ','-separated elements are collected until the next closing '}' */ URLPattern *pat; GlobCode res; bool done = FALSE; char* buf = glob->glob_buffer; pat = &glob->pattern[glob->size / 2]; /* patterns 0,1,2,... correspond to size=1,3,5,... */ pat->type = UPTSet; pat->content.Set.size = 0; pat->content.Set.ptr_s = 0; pat->content.Set.elements = NULL; if(++glob->size > (GLOB_PATTERN_NUM*2)) { snprintf(glob->errormsg, sizeof(glob->errormsg), "too many globs used\n"); return GLOB_ERROR; } while(!done) { switch (*pattern) { case '\0': /* URL ended while set was still open */ snprintf(glob->errormsg, sizeof(glob->errormsg), "unmatched brace at pos %zu\n", pos); return GLOB_ERROR; case '{': case '[': /* no nested expressions at this time */ snprintf(glob->errormsg, sizeof(glob->errormsg), "nested braces not supported at pos %zu\n", pos); return GLOB_ERROR; case ',': case '}': /* set element completed */ *buf = '\0'; if(pat->content.Set.elements) { char **new_arr = realloc(pat->content.Set.elements, (pat->content.Set.size + 1) * sizeof(char*)); if(!new_arr) { short elem; for(elem = 0; elem < pat->content.Set.size; elem++) Curl_safefree(pat->content.Set.elements[elem]); Curl_safefree(pat->content.Set.elements); pat->content.Set.ptr_s = 0; pat->content.Set.size = 0; } pat->content.Set.elements = new_arr; } else pat->content.Set.elements = malloc(sizeof(char*)); if(!pat->content.Set.elements) { snprintf(glob->errormsg, sizeof(glob->errormsg), "out of memory\n"); return GLOB_NO_MEM; } pat->content.Set.elements[pat->content.Set.size] = strdup(glob->glob_buffer); if(!pat->content.Set.elements[pat->content.Set.size]) { short elem; for(elem = 0; elem < pat->content.Set.size; elem++) Curl_safefree(pat->content.Set.elements[elem]); Curl_safefree(pat->content.Set.elements); pat->content.Set.ptr_s = 0; pat->content.Set.size = 0; snprintf(glob->errormsg, sizeof(glob->errormsg), "out of memory\n"); return GLOB_NO_MEM; } ++pat->content.Set.size; if(*pattern == '}') { /* entire set pattern completed */ int wordamount; /* always check for a literal (may be "") between patterns */ res = glob_word(glob, ++pattern, ++pos, &wordamount); if(res) { short elem; for(elem = 0; elem < pat->content.Set.size; elem++) Curl_safefree(pat->content.Set.elements[elem]); Curl_safefree(pat->content.Set.elements); pat->content.Set.ptr_s = 0; pat->content.Set.size = 0; return res; } *amount = pat->content.Set.size * wordamount; done = TRUE; continue; } buf = glob->glob_buffer; ++pattern; ++pos; break; case ']': /* illegal closing bracket */ snprintf(glob->errormsg, sizeof(glob->errormsg), "illegal pattern at pos %zu\n", pos); return GLOB_ERROR; case '\\': /* escaped character, skip '\' */ if(pattern[1]) { ++pattern; ++pos; } /* intentional fallthrough */ default: *buf++ = *pattern++; /* copy character to set element */ ++pos; } } return GLOB_OK; }
/* returned number of strings */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_urlglob.c#L49-L165
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
tool_tvdiff
long tool_tvdiff(struct timeval newer, struct timeval older) { return (newer.tv_sec-older.tv_sec)*1000+ (newer.tv_usec-older.tv_usec)/1000; }
/* * Make sure that the first argument is the more recent time, as otherwise * we'll get a weird negative time-diff back... * * Returns: the time difference in number of milliseconds. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_util.c#L113-L117
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
tool_tvdiff_secs
double tool_tvdiff_secs(struct timeval newer, struct timeval older) { if(newer.tv_sec != older.tv_sec) return (double)(newer.tv_sec-older.tv_sec)+ (double)(newer.tv_usec-older.tv_usec)/1000000.0; else return (double)(newer.tv_usec-older.tv_usec)/1000000.0; }
/* * Same as tool_tvdiff but with full usec resolution. * * Returns: the time difference in seconds with subsecond resolution. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_util.c#L124-L131
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
tool_tvlong
long tool_tvlong(struct timeval t1) { return t1.tv_sec; }
/* return the number of seconds in the given input timeval struct */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_util.c#L134-L137
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
is_vms_shell
int is_vms_shell(void) { char *shell; /* Have we checked the shell yet? */ if(vms_shell >= 0) return vms_shell; shell = getenv("SHELL"); /* No shell, means DCL */ if(shell == NULL) { vms_shell = 1; return 1; } /* Have to make sure some one did not set shell to DCL */ if(strcmp(shell, "DCL") == 0) { vms_shell = 1; return 1; } vms_shell = 0; return 0; }
/* VMS has a DCL shell and and also has Unix shells ported to it. * When curl is running under a Unix shell, we want it to be as much * like Unix as possible. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_vms.c#L48-L72
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
vms_special_exit
void vms_special_exit(int code, int vms_show) { int vms_code; /* The Posix exit mode is only available after VMS 7.0 */ #if __CRTL_VER >= 70000000 if(is_vms_shell() == 0) { decc$__posix_exit(code); } #endif if(code > CURL_LAST) { /* If CURL_LAST exceeded then */ vms_code = CURL_LAST; /* curlmsg.h is out of sync. */ } else { vms_code = vms_cond[code] | vms_show; } decc$exit(vms_code); }
/* * VMS has two exit() routines. When running under a Unix style shell, then * Unix style and the __posix_exit() routine is used. * * When running under the DCL shell, then the VMS encoded codes and decc$exit() * is used. * * We can not use exit() or return a code from main() because the actual * routine called depends on both the compiler version, compile options, and * feature macro settings, and one of the exit routines is hidden at compile * time. * * Since we want Curl to work properly under the VMS DCL shell and Unix * shells under VMS, this routine should compile correctly regardless of * the settings. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_vms.c#L91-L109
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
decc_init
static void decc_init(void) { int feat_index; int feat_value; int feat_value_max; int feat_value_min; int i; int sts; /* Set the global flag to indicate that LIB$INITIALIZE worked. */ decc_init_done = 1; /* Loop through all items in the decc_feat_array[]. */ for(i = 0; decc_feat_array[i].name != NULL; i++) { /* Get the feature index. */ feat_index = decc$feature_get_index( decc_feat_array[i].name); if(feat_index >= 0) { /* Valid item. Collect its properties. */ feat_value = decc$feature_get_value( feat_index, 1); feat_value_min = decc$feature_get_value( feat_index, 2); feat_value_max = decc$feature_get_value( feat_index, 3); if((decc_feat_array[i].value >= feat_value_min) && (decc_feat_array[i].value <= feat_value_max)) { /* Valid value. Set it if necessary. */ if(feat_value != decc_feat_array[i].value) { sts = decc$feature_set_value( feat_index, 1, decc_feat_array[i].value); } } else { /* Invalid DECC feature value. */ printf(" INVALID DECC FEATURE VALUE, %d: %d <= %s <= %d.\n", feat_value, feat_value_min, decc_feat_array[i].name, feat_value_max); } } else { /* Invalid DECC feature name. */ printf(" UNKNOWN DECC FEATURE: %s.\n", decc_feat_array[i].name); } } }
/* LIB$INITIALIZE initialization function. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_vms.c#L147-L192
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
fwrite_xattr
int fwrite_xattr(CURL *curl, int fd) { int i = 0; int err = 0; /* loop through all xattr-curlinfo pairs and abort on a set error */ while(err == 0 && mappings[i].attr != NULL) { char *value = NULL; CURLcode rc = curl_easy_getinfo(curl, mappings[i].info, &value); if(rc == CURLE_OK && value) { #ifdef HAVE_FSETXATTR_6 err = fsetxattr(fd, mappings[i].attr, value, strlen(value), 0, 0); #elif defined(HAVE_FSETXATTR_5) err = fsetxattr(fd, mappings[i].attr, value, strlen(value), 0); #endif } i++; } return err; }
/* store metadata from the curl request alongside the downloaded * file using extended attributes */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/src/tool_xattr.c#L50-L68
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
elapsed
static int elapsed(struct timeval *before, struct timeval *after) { ssize_t result; result = (after->tv_sec - before->tv_sec) * 1000000 + after->tv_usec - before->tv_usec; if (result < 0) result = 0; return curlx_sztosi(result); }
/* return the number of microseconds between two time stamps */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/tests/libtest/lib1501.c#L37-L48
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
test
int test(char *URL) { CURL *c = NULL; CURLM *m = NULL; int res = 0; int running; start_test_timing(); global_init(CURL_GLOBAL_ALL); easy_init(c); easy_setopt(c, CURLOPT_URL, URL); multi_init(m); multi_add_handle(m, c); for(;;) { struct timeval timeout; fd_set fdread, fdwrite, fdexcep; int maxfd = -99; timeout.tv_sec = 0; timeout.tv_usec = 100000L; /* 100 ms */ multi_perform(m, &running); abort_on_test_timeout(); if(!running) break; /* done */ FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); abort_on_test_timeout(); } test_cleanup: /* proper cleanup sequence - type PA */ curl_multi_remove_handle(m, c); curl_multi_cleanup(m); curl_easy_cleanup(c); curl_global_cleanup(); return res; }
/* * Get a single URL without select(). */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/curl/tests/libtest/lib502.c#L34-L91
4389085c8ce35cff887a4cc18fc47d1133d89ffb