Initial revision
[libcurl.git] / lib / sendf.c
blobcd29dcfb7c45c879e13dfd2569d03bd23ee12a13
1 /*****************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * The contents of this file are subject to the Mozilla Public License
9 * Version 1.0 (the "License"); you may not use this file except in
10 * compliance with the License. You may obtain a copy of the License at
11 * http://www.mozilla.org/MPL/
13 * Software distributed under the License is distributed on an "AS IS"
14 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
15 * License for the specific language governing rights and limitations
16 * under the License.
18 * The Original Code is Curl.
20 * The Initial Developer of the Original Code is Daniel Stenberg.
22 * Portions created by the Initial Developer are Copyright (C) 1998.
23 * All Rights Reserved.
25 * ------------------------------------------------------------
26 * Main author:
27 * - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
29 * http://curl.haxx.nu
31 * $Source: /cvsroot/curl/curl/lib/sendf.c,v $
32 * $Revision: 1.1 $
33 * $Date: 1999-12-29 14:21:35 $
34 * $Author: bagder $
35 * $State: Exp $
36 * $Locker: $
38 * ------------------------------------------------------------
39 ****************************************************************************/
41 #include <stdio.h>
42 #include <stdarg.h>
43 #include <stdlib.h>
45 #include "setup.h"
47 #ifdef HAVE_UNISTD_H
48 #include <unistd.h>
49 #endif
50 #if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
51 #include <winsock.h>
52 #endif
54 #include <curl/curl.h>
55 #include "urldata.h"
57 #include <curl/mprintf.h>
59 /* infof() is for info message along the way */
61 void infof(struct UrlData *data, char *fmt, ...)
63 va_list ap;
64 if(data->conf & CONF_VERBOSE) {
65 va_start(ap, fmt);
66 fputs("* ", data->err);
67 vfprintf(data->err, fmt, ap);
68 va_end(ap);
72 /* failf() is for messages stating why we failed, the LAST one will be
73 returned for the user (if requested) */
75 void failf(struct UrlData *data, char *fmt, ...)
77 va_list ap;
78 va_start(ap, fmt);
79 if(data->errorbuffer)
80 vsprintf(data->errorbuffer, fmt, ap);
81 else /* no errorbuffer receives this, write to data->err instead */
82 vfprintf(data->err, fmt, ap);
83 va_end(ap);
86 /* sendf() sends the formated data to the server */
88 int sendf(int fd, struct UrlData *data, char *fmt, ...)
90 size_t bytes_written;
91 char *s;
92 va_list ap;
93 va_start(ap, fmt);
94 s = mvaprintf(fmt, ap);
95 va_end(ap);
96 if(!s)
97 return 0; /* failure */
98 if(data->conf & CONF_VERBOSE)
99 fprintf(data->err, "> %s", s);
100 #ifndef USE_SSLEAY
101 bytes_written = swrite(fd, s, strlen(s));
102 #else
103 if (data->use_ssl) {
104 bytes_written = SSL_write(data->ssl, s, strlen(s));
105 } else {
106 bytes_written = swrite(fd, s, strlen(s));
108 #endif /* USE_SSLEAY */
109 free(s); /* free the output string */
110 return(bytes_written);