~ubuntu-branches/ubuntu/breezy/orbit2/breezy

« back to all changes in this revision

Viewing changes to src/orb/orb-core/orbhttp.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-09-06 16:37:02 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050906163702-hrqi0ctymth53bnn
Tags: 1:2.12.4-0ubuntu1
* New upstream version.
* debian/patches/100-compile-name-server.patch:
  - updated.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <string.h>
23
23
 
24
24
#include <stdlib.h>
25
 
#include <unistd.h>
26
 
#include <sys/socket.h>
27
 
#include <netinet/in.h>
28
 
#include <arpa/inet.h>
29
 
#include <netdb.h>
 
25
#ifdef HAVE_UNISTD_H
 
26
#  include <unistd.h>
 
27
#endif
 
28
 
 
29
#ifdef HAVE_WINSOCK2_H
 
30
#  include <winsock2.h>
 
31
#  ifndef _WINSOCKAPI_
 
32
#    define _WINSOCKAPI_
 
33
#  endif
 
34
#else /* !HAVE_WINSOCK2_H */
 
35
#  ifdef HAVE_SYS_SOCKET_H
 
36
#    include <sys/socket.h>
 
37
#  endif
 
38
#  ifdef HAVE_NETINET_IN_H
 
39
#    include <netinet/in.h>
 
40
#  endif
 
41
#  ifdef HAVE_ARPA_INET_H
 
42
#    include <arpa/inet.h>
 
43
#  endif
 
44
#  include <netdb.h>
 
45
#endif /* !HAVE_WINSOCK2_H */
 
46
 
30
47
#include <fcntl.h> 
31
48
#include <errno.h>
32
 
#include <sys/time.h>
33
 
#include <sys/select.h>
 
49
#ifdef HAVE_SYS_TIME_H
 
50
#  include <sys/time.h>
 
51
#endif
 
52
#ifdef HAVE_SYS_SELECT_H
 
53
#  include <sys/select.h>
 
54
#endif
34
55
#include <string.h>
35
56
 
 
57
 
36
58
#define CHECK_URI(str) \
37
 
(!strncmp(str, "IOR:", 4) \
 
59
(!strncmp(str, "IOR:", strlen("IOR:")) \
38
60
 || !strncmp(str, "iiop://", strlen("iiop://")) \
39
61
 || !strncmp(str, "iioploc://", strlen("iioploc://")))
40
62
 
55
77
#define ORB_HTTP_MAX_REDIR      10
56
78
 
57
79
#define ORB_HTTP_CHUNK  4096
 
80
#define ORB_TEMP_BUF_SIZE 4096
58
81
 
59
82
#define ORB_HTTP_CLOSED 0
60
83
#define ORB_HTTP_WRITE  1
93
116
 */
94
117
 
95
118
static void
96
 
orbHTTPInit(void)
 
119
orbHTTPInit (void)
97
120
{
98
 
    const char *env;
99
 
 
100
 
    if (initialized)
101
 
        return;
102
 
 
103
 
    if (proxy == NULL) {
104
 
        proxyPort = 80;
105
 
        env = getenv("no_proxy");
106
 
        if (env != NULL)
107
 
            goto done;
108
 
        if((env = getenv("http_proxy"))
109
 
           || (env = getenv("HTTP_PROXY")))
110
 
          orbHTTPScanProxy(env);
111
 
    }
112
 
done:
113
 
    initialized = 1;
 
121
        const char *env;
 
122
 
 
123
        if (initialized)
 
124
                return;
 
125
 
 
126
        if (!proxy) {
 
127
                proxyPort = 80;
 
128
                env = g_getenv ("no_proxy");
 
129
                if (env)
 
130
                        goto done;
 
131
                if ((env = g_getenv ("http_proxy")) ||
 
132
                    (env = g_getenv ("HTTP_PROXY")))
 
133
                        orbHTTPScanProxy (env);
 
134
        }
 
135
 done:
 
136
        initialized = 1;
114
137
}
115
138
 
116
139
/**
123
146
 */
124
147
 
125
148
static void
126
 
orbHTTPScanURL(orbHTTPCtxtPtr ctxt, const char *URL) {
 
149
orbHTTPScanURL (orbHTTPCtxtPtr ctxt, const char *URL)
 
150
{
127
151
    const char *cur = URL;
128
 
    char buf[4096];
 
152
    char buf[ORB_TEMP_BUF_SIZE];
129
153
    int index = 0;
130
154
    int port = 0;
131
155
 
203
227
 */
204
228
 
205
229
static void
206
 
orbHTTPScanProxy(const char *URL)
 
230
orbHTTPScanProxy (const char *URL)
207
231
{
208
 
    const char *cur = URL;
209
 
    char buf[4096];
210
 
    int index = 0;
211
 
    int port = 0;
 
232
        const char *cur = URL;
 
233
        char buf[ORB_TEMP_BUF_SIZE];
 
234
        int index;
 
235
        int port = 0;
212
236
 
213
 
    if (proxy != NULL) { 
214
 
        g_free(proxy);
 
237
        g_free (proxy);
215
238
        proxy = NULL;
216
 
    }
217
 
    if (proxyPort != 0) { 
218
 
        proxyPort = 0;
219
 
    }
 
239
 
 
240
        if (proxyPort != 0) 
 
241
                proxyPort = 0;
 
242
 
220
243
#ifdef DEBUG_HTTP
221
 
    if (URL == NULL)
222
 
        printf("Removing HTTP proxy info\n");
223
 
    else
224
 
        printf("Using HTTP proxy %s\n", URL);
 
244
        if (!URL)
 
245
                printf ("Removing HTTP proxy info\n");
 
246
        else
 
247
                printf ("Using HTTP proxy %s\n", URL);
225
248
#endif
226
 
    if (URL == NULL) return;
227
 
    buf[index] = 0;
228
 
    while (*cur != 0) {
229
 
        if ((cur[0] == ':') && (cur[1] == '/') && (cur[2] == '/')) {
230
 
            buf[index] = 0;
231
 
            index = 0;
232
 
            cur += 3;
233
 
            break;
234
 
        }
235
 
        buf[index++] = *cur++;
236
 
    }
237
 
    if (*cur == 0) return;
238
 
 
239
 
    buf[index] = 0;
240
 
    while (1) {
241
 
        if (cur[0] == ':') {
242
 
            buf[index] = 0;
243
 
            proxy = g_strdup(buf);
244
 
            index = 0;
245
 
            cur += 1;
246
 
            while ((*cur >= '0') && (*cur <= '9')) {
247
 
                port *= 10;
248
 
                port += *cur - '0';
249
 
                cur++;
250
 
            }
251
 
            if (port != 0) proxyPort = port;
252
 
            while ((cur[0] != '/') && (*cur != 0)) 
253
 
                cur++;
254
 
            break;
255
 
        }
256
 
        if ((*cur == '/') || (*cur == 0)) {
257
 
            buf[index] = 0;
258
 
            proxy = g_strdup(buf);
259
 
            index = 0;
260
 
            break;
261
 
        }
262
 
        buf[index++] = *cur++;
263
 
    }
 
249
        if (!URL)
 
250
                return;
 
251
 
 
252
        index = 0;
 
253
        buf [index] = 0;
 
254
        while (*cur != '\0') {
 
255
                if ((cur[0] == ':') && (cur[1] == '/') && (cur[2] == '/')) {
 
256
                        buf[index] = 0;
 
257
                        index = 0;
 
258
                        cur += 3;
 
259
                        break;
 
260
                }
 
261
                buf[index++] = *cur++;
 
262
        }
 
263
        if (*cur == '\0')
 
264
                return;
 
265
 
 
266
        buf[index] = 0;
 
267
        while (1) {
 
268
                if (cur[0] == ':') {
 
269
                        buf[index] = 0;
 
270
                        proxy = g_strdup(buf);
 
271
                        index = 0;
 
272
                        cur += 1;
 
273
                        while ((*cur >= '0') && (*cur <= '9')) {
 
274
                                port *= 10;
 
275
                                port += *cur - '0';
 
276
                                cur++;
 
277
                        }
 
278
                        if (port != 0) proxyPort = port;
 
279
                        while ((cur[0] != '/') && (*cur != 0)) 
 
280
                                cur++;
 
281
                        break;
 
282
                }
 
283
                if ((*cur == '/') || (*cur == '\0')) {
 
284
                        buf[index] = 0;
 
285
                        proxy = g_strdup(buf);
 
286
                        index = 0;
 
287
                        break;
 
288
                }
 
289
                buf[index++] = *cur++;
 
290
        }
264
291
}
265
292
 
266
293
/**
340
367
    fd_set rfd;
341
368
    struct timeval tv;
342
369
 
 
370
#define ORB_HTTP_DYN_BUFSIZE 65000
343
371
 
344
372
    while (ctxt->state & ORB_HTTP_READ) {
345
373
        if (ctxt->in == NULL) {
346
 
            ctxt->in = (char *) g_malloc(65000 * sizeof(char));
347
 
            if (ctxt->in == NULL) {
348
 
                ctxt->last = -1;
349
 
                return(-1);
350
 
            }
351
 
            ctxt->inlen = 65000;
 
374
            ctxt->in = (char *) g_malloc(ORB_HTTP_DYN_BUFSIZE * sizeof(char));
 
375
            ctxt->inlen = ORB_HTTP_DYN_BUFSIZE;
352
376
            ctxt->inptr = ctxt->content = ctxt->inrptr = ctxt->in;
353
377
        }
354
378
        if (ctxt->inrptr > ctxt->in + ORB_HTTP_CHUNK) {
367
391
 
368
392
            ctxt->inlen *= 2;
369
393
            ctxt->in = (char *) g_realloc(ctxt->in, ctxt->inlen);
370
 
            if (ctxt->in == NULL) {
371
 
                ctxt->last = -1;
372
 
                return(-1);
373
 
            }
374
394
            ctxt->inptr = ctxt->in + d_inptr;
375
395
            ctxt->content = ctxt->in + d_content;
376
396
            ctxt->inrptr = ctxt->in + d_inrptr;
412
432
 
413
433
static char *
414
434
orbHTTPReadLine(orbHTTPCtxtPtr ctxt) {
415
 
    char buf[4096];
 
435
    char buf[ORB_TEMP_BUF_SIZE];
416
436
    char *bp=buf;
417
437
    
418
 
    while(bp - buf < 4095) {
 
438
    while(bp - buf < (ORB_TEMP_BUF_SIZE-1)) {
419
439
        if(ctxt->inrptr == ctxt->inptr) {
420
440
            if (orbHTTPRecv(ctxt) == 0) {
421
441
                if (bp == buf)
433
453
        if(*bp != '\r')
434
454
            bp++;
435
455
    }
436
 
    buf[4095] = 0;
 
456
    buf[ORB_TEMP_BUF_SIZE-1] = 0;
437
457
    return(g_strdup(buf));
438
458
}
439
459
 
534
554
    
535
555
#ifdef _WINSOCKAPI_
536
556
    {
537
 
        long levents = FD_READ | FD_WRITE | FD_ACCEPT |
538
 
                       FD_CONNECT | FD_CLOSE ;
539
557
        int rv = 0 ;
540
558
        u_long one = 1;
541
559
 
680
698
static void*
681
699
orbHTTPOpen(const char *URL) {
682
700
    orbHTTPCtxtPtr ctxt;
683
 
    char buf[4096];
 
701
    char buf[ORB_TEMP_BUF_SIZE];
684
702
    int ret;
685
703
    char *p;
686
704
    int head;
854
872
orb_http_resolve(const char *URL)
855
873
{
856
874
    orbHTTPCtxtPtr ctxt;
857
 
    char buf[4096];
 
875
    char buf[ORB_TEMP_BUF_SIZE];
858
876
    int len_read, len;
859
877
    char *content_type, *retval = NULL;
860
878