~ubuntu-branches/debian/sid/tickr/sid

« back to all changes in this revision

Viewing changes to src/tickr/tickr_socket.c

  • Committer: Package Import Robot
  • Author(s): Emmanuel Thomas-Maurin
  • Date: 2012-06-04 14:23:24 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20120604142324-j6ycu0cw6vvoahhy
Tags: 0.6.1-1
* Add: 'quick setup' thing (in tickr_quicksetup.c) which is launched
  at program startup if config file doesn't exist.

* Little improvements in layout of 'feed picker win' and 'preferences
  win'.

* Fix a segfault that happens when trying to export params and no
  config file exists yet.

* Make several windows that should not be resized by user, unresizable.

* Fix Launchpad bug #1007346: When 'window always-on-top' is disabled,
  'visible on all user desktops' stops working.

* If mouse wheel scrolling applies to speed (or feed), then Ctrl +
  mouse wheel scrolling applies to feed (or speed.)

* No real code changes in libetm, only in comments, so no need for a
  new version number.

* Update tickr_helptext.c and tickr.1 (man page.)

* Add new cli option 'no-ui' (similar to 'instance-id') used by new
  IF_UI_ALLOWED macro and remove all #if USE_GUI occurences.

* In tickr_list.c, free listfname before using it. Fixed by swapping 2
  lines:
    warning(FALSE, 4, "Can't save URL list ", listfname, ...);
    l_str_free(listfname);

* Use/add #define
    FONT_MAXLEN         68
    ARBITRARY_TASKBAR_HEIGHT    25
  to replace a few 'magic' numeric values.

* Rename: rss_title/description(_delimiter) ->
    item_title/description(_delimiter)
  then add new param: feed_title(_delimiter). Now we have:
  feed title / item title / item description.

* Use table in resource properties window.

* Fix a bug in f_list_load_from_file() in tickr_list.c which
  uncorrectly retrieves any feed title string containing TITLE_TAG_CHAR
  when TITLE_TAG_CHAR has not been removed from string first, for
  instance: 'NYT > World' -> ' World'.

* New param: disable left-click.

* Add 'check for updates' feature.

* Launch 'import OPML file' if feed list doesn't exist.

* Remove code changing get_params()->disable_popups value in
    START/END_PAUSE_TICKER_WHILE_OPENING
  macros which prevents this setting to be saved and add
    START/END_PAUSE_TICKER_ENABLE_POPUPS_WHILE_OPENING
  new macros. Which ones to use depends on context.

* Move:
    #ifdef G_OS_WIN32
    extern FILE *stdout_fp, *stderr_fp;
    #endif
  from *.c into tickr.h.

* Default always-on-top setting changed to 'n' (so that tickr is not
  intrusive by default.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include "tickr.h"
20
20
#include "tickr_socket.h"
21
21
 
22
 
#ifdef G_OS_WIN32
23
 
extern FILE     *stdout_fp, *stderr_fp;
24
 
#endif
25
 
 
26
22
/*
27
 
 *can use IPv4 or IPv6
 
23
 * Can use IPv4 or IPv6
28
24
 */
29
25
#ifndef G_OS_WIN32
30
26
static void *get_in_addr(struct sockaddr *s_a)
37
33
#endif
38
34
 
39
35
/*
40
 
 * open stream socket in non-blocking mode and connect to host
41
 
 * return socket fd (> 0) / SOCK_CREATE_ERROR (-1 on Linux) if error
 
36
 * Open stream socket in non-blocking mode and connect to host.
 
37
 * Return socket fd (> 0) / SOCK_CREATE_ERROR (-1 on Linux) if error.
42
38
 */
43
39
sockt connect_to_host(const char *host, const char *portnum_str)
44
40
{
48
44
#else
49
45
        u_long                  i_mode = 1;     /* != 0 to enable non-blocking mode */
50
46
#endif
51
 
        struct addrinfo         hints, *server_info, *ptr;
 
47
        struct addrinfo hints, *server_info, *ptr;
52
48
        fd_set                  read_set, write_set;
53
49
        struct timeval          timeout;
54
50
        int                     s_opt_value;
82
78
/*#ifdef VERBOSE_OUTPUT
83
79
        FPRINTF_FFLUSH_2(STD_OUT, "Done\n");
84
80
#endif*/
85
 
        /* we get a list */
 
81
        /* We get a list */
86
82
        for (ptr = server_info; ptr != NULL; ptr = ptr->ai_next) {
87
 
                /* create socket */
 
83
                /* Create socket */
88
84
                if ((sock = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol)) == SOCK_CREATE_ERROR) {
89
85
                        FPRINTF_FFLUSH_3(STD_ERR, "Error: %s\n", sock_error_message());
90
86
                        continue;
91
87
                }
92
 
                /* set socket in non-blocking mode */
 
88
                /* Set socket in non-blocking mode */
93
89
#ifndef G_OS_WIN32
94
90
                if ((i = fcntl(sock, F_GETFL, 0)) == SOCK_FUNC_ERROR) {
95
91
                        FPRINTF_FFLUSH_3(STD_ERR, "fcntl() error: %s\n", sock_error_message());
107
103
                        break;
108
104
                }
109
105
#endif
110
 
                /* get IP addr from server_info */
 
106
                /* Get IP addr from server_info */
111
107
#ifdef VERBOSE_OUTPUT
112
108
#ifndef G_OS_WIN32
113
109
                inet_ntop(ptr->ai_family, get_in_addr((struct sockaddr *)ptr->ai_addr),
115
111
                /*FPRINTF_FFLUSH_4(STD_OUT, "Connecting to %s (%s) ...\n", ipa_str, host);*/
116
112
                FPRINTF_FFLUSH_4(STD_OUT, "Connecting to %s (%s) ... ", ipa_str, host);
117
113
#else
118
 
                /* available only on vista and above but we don't really need that (do we?) so disabled
 
114
                /* Available only on Vista and above but we don't really need that (do we?) so disabled.
119
115
                InetNtop(ptr->ai_family, get_in_addr((struct sockaddr *)ptr->ai_addr), s, sizeof(s));*/
120
116
                /*FPRINTF_FFLUSH_3(STD_OUT, "Connecting to %s ...\n", host);*/
121
117
                FPRINTF_FFLUSH_3(STD_OUT, "Connecting to %s ... ", host);
122
118
#endif
123
119
#endif
124
 
                /* connect */
 
120
                /* Connect */
125
121
                if ((i = connect(sock, ptr->ai_addr, ptr->ai_addrlen)) == SOCK_FUNC_ERROR &&
126
122
#ifndef G_OS_WIN32
127
123
                                errno == EINPROGRESS) {
128
124
#else
129
125
                                WSAGetLastError() == WSAEWOULDBLOCK) {
130
126
#endif
131
 
                        /* as socket is in non-blocking mode, we must use select() */
 
127
                        /* As socket is in non-blocking mode, we must use select() */
132
128
                        FD_ZERO(&read_set);
133
129
                        FD_ZERO(&write_set);
134
130
                        FD_SET(sock, &read_set);
222
218
}
223
219
 
224
220
/*
225
 
 * return n bytes sent or SOCK_FUNC_ERROR (-1 on Linux) if error (connection
 
221
 * Return n bytes sent or SOCK_FUNC_ERROR (-1 on Linux) if error (connection
226
222
 * closed by server or ?)
227
223
 */
228
224
int send_full(sockt sock, const char *str)
237
233
                                if (len == 0)
238
234
                                        break;
239
235
                        } else {
240
 
                                /* something to do? */
 
236
                                /* Something to do ? */
241
237
                        }
242
238
                } else {
243
239
                        j = SOCK_FUNC_ERROR;
260
256
}
261
257
 
262
258
/*
263
 
 * return response = recv_full(socket, &bytes_received, &status) or NULL if error
264
 
 * -> status = SOCK_OK, CONNECTION_CLOSED_BY_SERVER, RECV_ERROR or SOCK_SHOULD_BE_CLOSED
265
 
 * -> allocate memory for response (must be freed afterwards with free2() if != NULL)
 
259
 * Return response = recv_full(socket, &bytes_received, &status) or NULL if error.
 
260
 * -> status = SOCK_OK, CONNECTION_CLOSED_BY_SERVER, RECV_ERROR or SOCK_SHOULD_BE_CLOSED.
 
261
 * -> allocate memory for response (must be freed afterwards with free2() if != NULL).
266
262
 */
267
263
char *recv_full(sockt sock, int *bytes_received, int *status)
268
264
{