~ubuntu-branches/ubuntu/maverick/transmission/maverick-updates

« back to all changes in this revision

Viewing changes to third-party/miniupnp/miniwget.c

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson, Krzysztof Klimonda, Chris Coulson
  • Date: 2009-09-09 09:06:11 UTC
  • mfrom: (1.1.27 upstream)
  • Revision ID: james.westby@ubuntu.com-20090909090611-09ai2hyo66h1dhv8
Tags: 1.74-0ubuntu1
[ Krzysztof Klimonda ]
* Merge from debian unstable, remaining changes:
  - debian/control:
    + Added replaces & provides clutch (now included as part of transmission).
    + add liblaunchpad-integration to Build-Depends
  - debian/rules:
    + Create a PO template during package build.
  - debian/patches/01_lpi.patch:
    + Integrate Transmission with Launchpad
  - debian/patches/20_add_X-Ubuntu-Gettext-Domain.diff:
    + Add X-Ubuntu-Gettext-Domain to .desktop file.
* debian/control:
  - add lsb-release to Build-Depends
* This includes the QT client in transmission-qt.

[ Chris Coulson ]
* Update to new upstream version 1.74 (LP: #418367):
  - Better data recovery in the case of an OS or Transmission crash
  - If a data file is moved, stop the torrent instead of redownloading 
    it (LP: #419304).
  - Fix bug that didn't list some peers in the resume file and in PEX
  - More helpful torrent error messages
  - DHT now honors the bind-address-ipv4 configuration option
  - Fix Debian build error with miniupnpc
  - Fix Cygwin build error with strtold
  - Update to a newer snapshot of miniupnpc
  - Fix crash that occurred when adding torrents on some desktops
  - Synchronize the statusbar's and torrent list's speeds
  - Fix the Properties dialog's "Origin" field for multiple torrents
* debian/rules, debian/control:
  - Don't run autoreconf at build time and don't build-dep on libtool.
* debian/control:
  - transmission-common replaces transmission-gtk (<< 1.74) rather than
    (<= 1.73-1).
* Refreshed patches:
  - 01_lpi.patch.
  - dont_build_libevent.patch.
  - qt_client_use_system_libevent.patch.
* Dropped patches not needed anymore:
  - updateminiupnpcstrings_double_escape_slash.patch
* Added 99_autoreconf.patch for autotools update.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: miniwget.c,v 1.22 2009/02/28 10:36:35 nanard Exp $ */
 
1
/* $Id: miniwget.c,v 1.25 2009/08/07 14:44:51 nanard Exp $ */
2
2
/* Project : miniupnp
3
3
 * Author : Thomas Bernard
4
 
 * Copyright (c) 2005 Thomas Bernard
 
4
 * Copyright (c) 2005-2009 Thomas Bernard
5
5
 * This software is subject to the conditions detailed in the
6
6
 * LICENCE file provided in this distribution.
7
7
 * */
24
24
#include <netdb.h>
25
25
#include <netinet/in.h>
26
26
#include <arpa/inet.h>
 
27
#include <errno.h>
27
28
#define closesocket close
 
29
#define MINIUPNPC_IGNORE_EINTR
28
30
#endif
29
31
#if defined(__sun) || defined(sun)
30
32
#define MIN(x,y) (((x)<(y))?(x):(y))
44
46
    int s;
45
47
        struct sockaddr_in dest;
46
48
        struct hostent *hp;
 
49
        int n;
 
50
        int len;
 
51
        int sent;
 
52
#ifdef MINIUPNPC_SET_SOCKET_TIMEOUT
 
53
        struct timeval timeout;
 
54
#endif
47
55
        *size = 0;
48
56
        hp = gethostbyname(host);
49
57
        if(hp==NULL)
60
68
                perror("socket");
61
69
                return NULL;
62
70
        }
 
71
#ifdef MINIUPNPC_SET_SOCKET_TIMEOUT
 
72
        /* setting a 3 seconds timeout for the connect() call */
 
73
        timeout.tv_sec = 3;
 
74
        timeout.tv_usec = 0;
 
75
        if(setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(struct timeval)) < 0)
 
76
        {
 
77
                perror("setsockopt");
 
78
        }
 
79
        timeout.tv_sec = 3;
 
80
        timeout.tv_usec = 0;
 
81
        if(setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(struct timeval)) < 0)
 
82
        {
 
83
                perror("setsockopt");
 
84
        }
 
85
#endif
63
86
        dest.sin_family = AF_INET;
64
87
        dest.sin_port = htons(port);
65
 
        if(connect(s, (struct sockaddr *)&dest, sizeof(struct sockaddr_in))<0)
 
88
#ifdef MINIUPNPC_IGNORE_EINTR
 
89
        do {
 
90
#endif
 
91
                n = connect(s, (struct sockaddr *)&dest, sizeof(struct sockaddr_in));
 
92
#ifdef MINIUPNPC_IGNORE_EINTR
 
93
        } while(n < 0 && errno == EINTR);
 
94
#endif
 
95
        if(n<0)
66
96
        {
67
97
                perror("connect");
68
98
                closesocket(s);
73
103
        if(addr_str)
74
104
        {
75
105
                struct sockaddr_in saddr;
76
 
                socklen_t len;
 
106
                socklen_t saddrlen;
77
107
 
78
 
                len = sizeof(saddr);
79
 
                getsockname(s, (struct sockaddr *)&saddr, &len);
 
108
                saddrlen = sizeof(saddr);
 
109
                if(getsockname(s, (struct sockaddr *)&saddr, &saddrlen) < 0)
 
110
                {
 
111
                        perror("getsockname");
 
112
                }
 
113
                else
 
114
                {
80
115
#ifndef WIN32
81
 
                inet_ntop(AF_INET, &saddr.sin_addr, addr_str, addr_str_len);
 
116
                        inet_ntop(AF_INET, &saddr.sin_addr, addr_str, addr_str_len);
82
117
#else
83
118
        /* using INT WINAPI WSAAddressToStringA(LPSOCKADDR, DWORD, LPWSAPROTOCOL_INFOA, LPSTR, LPDWORD);
84
119
     * But his function make a string with the port :  nn.nn.nn.nn:port */
87
122
                {
88
123
                    printf("WSAAddressToStringA() failed : %d\n", WSAGetLastError());
89
124
                }*/
90
 
                strncpy(addr_str, inet_ntoa(saddr.sin_addr), addr_str_len);
 
125
                        strncpy(addr_str, inet_ntoa(saddr.sin_addr), addr_str_len);
91
126
#endif
 
127
                }
92
128
#ifdef DEBUG
93
129
                printf("address miniwget : %s\n", addr_str);
94
130
#endif
95
131
        }
96
132
 
97
 
        snprintf(buf, sizeof(buf),
 
133
        len = snprintf(buf, sizeof(buf),
98
134
                 "GET %s HTTP/1.1\r\n"
99
135
                             "Host: %s:%d\r\n"
100
136
                                 "Connection: Close\r\n"
102
138
 
103
139
                                 "\r\n",
104
140
                    path, host, port);
105
 
        /*write(s, buf, strlen(buf));*/
106
 
        send(s, buf, strlen(buf), 0);
107
 
        {
108
 
                int n, headers=1;
 
141
        sent = 0;
 
142
        /* sending the HTTP request */
 
143
        while(sent < len)
 
144
        {
 
145
                n = send(s, buf+sent, len-sent, 0);
 
146
                if(n < 0)
 
147
                {
 
148
                        perror("send");
 
149
                        closesocket(s);
 
150
                        return NULL;
 
151
                }
 
152
                else
 
153
                {
 
154
                        sent += n;
 
155
                }
 
156
        }
 
157
        {
 
158
                int headers=1;
109
159
                char * respbuffer = NULL;
110
160
                int allreadyread = 0;
111
161
                /*while((n = recv(s, buf, 2048, 0)) > 0)*/
116
166
                                int i=0;
117
167
                                while(i<n-3)
118
168
                                {
 
169
                                        /* searching for the end of the HTTP headers */
119
170
                                        if(buf[i]=='\r' && buf[i+1]=='\n'
120
171
                                           && buf[i+2]=='\r' && buf[i+3]=='\n')
121
172
                                        {
122
173
                                                headers = 0;    /* end */
123
174
                                                if(i<n-4)
124
175
                                                {
 
176
                                                        /* Copy the content into respbuffet */
125
177
                                                        respbuffer = (char *)realloc((void *)respbuffer, 
126
178
                                                                                                                 allreadyread+(n-i-4));
127
179
                                                        memcpy(respbuffer+allreadyread, buf + i + 4, n-i-4);