~ubuntu-branches/debian/experimental/tickr/experimental

« back to all changes in this revision

Viewing changes to src/tickr/tickr_socket.h

  • Committer: Package Import Robot
  • Author(s): Emmanuel Thomas-Maurin
  • Date: 2012-03-07 00:48:53 UTC
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: package-import@ubuntu.com-20120307004853-jsyb2z1pgaaeusq9
Tags: upstream-0.6.0
ImportĀ upstreamĀ versionĀ 0.6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      TICKR - GTK-based Feed Reader - Copyright (C) Emmanuel Thomas-Maurin 2009-2012
 
3
 *      <manutm007@gmail.com>
 
4
 *
 
5
 *      This program is free software: you can redistribute it and/or modify
 
6
 *      it under the terms of the GNU General Public License as published by
 
7
 *      the Free Software Foundation, either version 3 of the License, or
 
8
 *      (at your option) any later version.
 
9
 *
 
10
 *      This program is distributed in the hope that it will be useful,
 
11
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *      GNU General Public License for more details.
 
14
 *
 
15
 *      You should have received a copy of the GNU General Public License
 
16
 *      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
#ifndef INC_TICKR_SOCKET_H
 
20
#define INC_TICKR_SOCKET_H
 
21
 
 
22
#define USE_PROXY_FLAG                          get_use_proxy()
 
23
#define WARNING(a1, a2, a3, a4, a5, a6)         warning(a1, a2, a3, a4, a5, a6)
 
24
#define SOCK_OK                                 OK
 
25
 
 
26
/* check these 2 values - need more testing (1s / 0.5s / 0.1.s) */
 
27
#define SEND_RECV_TIMEOUT_SEC   1
 
28
#define SEND_RECV_TIMEOUT_USEC  0
 
29
 
 
30
#include <stdio.h>
 
31
#include <string.h>
 
32
#include <stdlib.h>
 
33
#include <errno.h>
 
34
#include <time.h>
 
35
#include <unistd.h>
 
36
#include <ctype.h>
 
37
#include <fcntl.h>
 
38
#ifndef G_OS_WIN32
 
39
# include <grp.h>
 
40
# include <pwd.h>
 
41
# include <sys/socket.h>
 
42
# include <netdb.h>
 
43
# include <arpa/inet.h>
 
44
# include <sys/select.h>
 
45
#else
 
46
# define _WIN32_WINNT   0x0501  /* win version = xp or higher */
 
47
# include <winsock2.h>
 
48
# include <ws2tcpip.h>
 
49
# include <rpcdce.h>
 
50
# include <iphlpapi.h>
 
51
# include <winreg.h>
 
52
# include <shlobj.h>
 
53
#endif
 
54
#include "../libetm-0.4.3/libetm.h"
 
55
 
 
56
#define CONNECT_TIMEOUT         5
 
57
#define RECV_CHUNK_LEN          (16 * 1024 - 1)
 
58
 
 
59
#ifndef G_OS_WIN32
 
60
typedef int sockt;
 
61
# define SOCK_CREATE_ERROR      -1      /* socket() */
 
62
# define SOCK_FUNC_ERROR        -1      /* setsockopt(), bind(), listen(), select(), connect(),
 
63
                                         * send(), recv(), fnctl(), ioctlsocket() */
 
64
# define CLOSE_SOCK(s)          close(s)
 
65
#else
 
66
typedef SOCKET sockt;
 
67
# define SOCK_CREATE_ERROR      INVALID_SOCKET
 
68
# define SOCK_FUNC_ERROR        SOCKET_ERROR
 
69
# define CLOSE_SOCK(s)          closesocket(s)
 
70
#endif
 
71
 
 
72
typedef enum {
 
73
        SOCK_ERROR = LIBETM_LASTERRORCODE + 1,
 
74
        SOCK_CANT_CONNECT,
 
75
        SOCK_SHOULD_BE_CLOSED,
 
76
 
 
77
        SELECT_ERROR,
 
78
        SELECT_TIMED_OUT,
 
79
        SELECT_TRUE,
 
80
        SELECT_FALSE,
 
81
 
 
82
        SEND_ERROR,
 
83
        RECV_ERROR,
 
84
 
 
85
        CONNECTION_CLOSED_BY_SERVER,
 
86
 
 
87
        SOCKET_LASTERRORCODE
 
88
} socket_error_code;
 
89
 
 
90
#define FPRINTF_FFLUSH_2(a1, a2);               {fprintf(a1, a2);fflush(a1);}
 
91
#define FPRINTF_FFLUSH_3(a1, a2, a3);           {fprintf(a1, a2, a3);fflush(a1);}
 
92
#define FPRINTF_FFLUSH_4(a1, a2, a3, a4);       {fprintf(a1, a2, a3, a4);fflush(a1);}
 
93
 
 
94
/*
 
95
 * open stream socket in non-blocking mode and connect to host
 
96
 * return socket fd (> 0) / SOCK_CREATE_ERROR (-1 on Linux) if error
 
97
 */
 
98
sockt           connect_to_host(const char *, const char *);
 
99
 
 
100
int             writable_data_is_available_on_socket(sockt);
 
101
 
 
102
int             readable_data_is_available_on_socket(sockt);
 
103
 
 
104
/*
 
105
 * return n bytes sent or SOCK_FUNC_ERROR (-1 on Linux) if error (connection
 
106
 * closed by server or ?)
 
107
 */
 
108
int             send_full(sockt, const char *);
 
109
 
 
110
/*
 
111
 * return response = recv_full(socket, &bytes_received, &status) or NULL if error
 
112
 * -> status = SOCK_OK, CONNECTION_CLOSED_BY_SERVER, RECV_ERROR or SOCK_SHOULD_BE_CLOSED
 
113
 * -> allocate memory for response (must be freed afterwards with free2() if != NULL)
 
114
 */
 
115
char            *recv_full(sockt, int *, int *);
 
116
 
 
117
#ifdef G_OS_WIN32
 
118
const char      *win32_error_msg(int);
 
119
#endif
 
120
 
 
121
const char      *sock_error_message();
 
122
#endif /* INC_TICKR_SOCKET_H */