added "c++ guards" to library headers
[syren.git] / src / syren_tcp.h
blobdfd23a8b6df71e0e6d45de159fb0e6e67707d837
1 /*
2 Syren -- a lightweight downloader for Linux/BSD/MacOSX
3 inspired by Axel Copyright 2001-2002 Wilmer van der Gaast
4 version 0.0.6 (atomic alien)
5 coded by Ketmar // Vampire Avalon
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License with
18 the Debian GNU/Linux distribution in file /usr/doc/copyright/GPL;
19 if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 Suite 330, Boston, MA 02111-1307 USA
23 Syren tcp utilities
25 #ifndef _SYREN_TCP_H
26 #define _SYREN_TCP_H
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
33 #include "syren_os.h"
34 #include "syren_common.h"
35 #include "syren_msg.h"
38 typedef struct {
39 #ifdef SYOPT_ALLOW_HTTPS
40 int usessl;
41 void *sslinfo;
42 #endif
43 int fd;
44 int errCode; /* 0: no error */
45 } TSySocket;
48 #define SY_TCP_DONT_ALLOWPARTIAL 0
49 #define SY_TCP_ALLOWPARTIAL 1
52 /* returns allocated string or NULL */
53 char *SyTCPGetLastErrorMsg (TSySocket *fd);
55 /* put interface IP address to `ip' */
56 TSyResult SyGetIFIP (char *ip, const char *iface);
58 /* initialize socket */
59 TSyResult SyTCPInitSocket (TSySocket *fd);
60 #ifdef SYOPT_ALLOW_HTTPS
61 TSyResult SyTCPInitSSL (TSySocket *fd, int timeout);
62 #endif
63 TSyResult SyTCPCloseSocket (TSySocket *fd);
65 /* create a TCP connection; fd must not be initialized */
66 TSyResult SyTCPConnect (TSySocket *fd, char *hostname, int port, const char *iface, int timeout, const TSyPrintStr *pfn);
67 TSyResult SyTCPSend (TSySocket *fd, const void *buf, int bufSize);
68 TSyResult SyTCPSendStr (TSySocket *fd, const char *str);
69 /* <0: received (-res) bytes; read error */
70 int SyTCPReceiveEx (TSySocket *fd, void *buf, int bufSize, int allowPartial);
71 /* <0: received (-res) bytes; read error */
72 int SyTCPReceive (TSySocket *fd, void *buf, int bufSize);
74 char *SyTCPReceiveStrEx (TSySocket *fd, int maxSize, char *dest);
75 /* return NULL if string was too big */
76 char *SyTCPReceiveStr (TSySocket *fd, int maxSize);
78 TSyResult SyTCPSendLine (const TSyPrintStr *pfn, int printLine, TSySocket *fd, const char *fmt, ...);
80 /* return NULL if string was too big or on error;
81 tries to receive all headers
83 char *SyTCPReceiveHdrs (TSySocket *fd, int maxSize);
86 #ifdef __cplusplus
88 #endif
90 #endif