~ubuntu-branches/ubuntu/lucid/mpg123/lucid

« back to all changes in this revision

Viewing changes to src/httpget.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2009-12-21 00:11:29 UTC
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: james.westby@ubuntu.com-20091221001129-gsbnzbenceqv4pjt
Tags: upstream-1.10.0
ImportĀ upstreamĀ versionĀ 1.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
int debunk_mime(const char* mime)
86
86
{
87
87
        int i,j;
 
88
        size_t len;
88
89
        int r = 0;
 
90
        char *aux;
 
91
        /* Watch out for such: "audio/x-mpegurl; charset=utf-8" */
 
92
        aux = strchr(mime, ';');
 
93
        if(aux != NULL)
 
94
        {
 
95
                fprintf(stderr, "Warning: additional info in content-type ignored (%s)\n", aux+1);
 
96
                /* Just compare up to before the ";". */
 
97
                len = aux-mime;
 
98
        }
 
99
        /* Else, compare the whole string -- including the end. */
 
100
        else len = strlen(mime)+1;
 
101
 
89
102
        for(i=0; mimes[i]    != NULL; ++i)
90
103
        for(j=0; mimes[i][j] != NULL; ++j)
91
 
        if(!strcmp(mimes[i][j], mime)) goto debunk_result;
 
104
        if(!strncasecmp(mimes[i][j], mime, len)) goto debunk_result;
92
105
 
93
106
debunk_result:
94
107
        if(mimes[i] != NULL)
442
455
        if(!mpg123_copy_string(request_url, purl)) return FALSE;
443
456
 
444
457
        /* We may strip it down to a prefix ot totally. */
445
 
        if(strncmp(response->p, "Location: http://", 17))
 
458
        if(strncasecmp(response->p, "Location: http://", 17))
446
459
        { /* OK, only partial strip, need prefix for relative path. */
447
460
                char* ptmp = NULL;
448
461
                /* though it's not RFC (?), accept relative URIs as wget does */
483
496
        int sock = -1;
484
497
        int oom  = 0;
485
498
        int relocate, numrelocs = 0;
 
499
        int got_location = FALSE;
486
500
        FILE *myfile;
487
501
        /*
488
502
                workaround for http://www.global24music.com/rautemusik/files/extreme/isdn.pls
589
603
                { \
590
604
                        error("readstring failed"); \
591
605
                        http_failure; \
592
 
                }
 
606
                } \
 
607
                if(param.verbose > 2) fprintf(stderr, "HTTP in: %s", response.p);
593
608
                safe_readstring;
594
 
                if(param.verbose > 2)   fprintf(stderr, "HTTP response: %s",response.p);
595
609
 
596
610
                {
597
611
                        char *sptr;
612
626
                        }
613
627
                }
614
628
 
 
629
                /* If we are relocated, we need to look out for a Location header. */
 
630
                got_location = FALSE;
 
631
 
615
632
                do
616
633
                {
617
634
                        safe_readstring; /* Think about that: Should we really error out when we get nothing? Could be that the server forgot the trailing empty line... */
618
 
                        if (!strncmp(response.p, "Location: ", 10))
 
635
                        if (!strncasecmp(response.p, "Location: ", 10))
619
636
                        { /* It is a redirection! */
620
637
                                if(!resolve_redirect(&response, &request_url, &purl)){ oom=1, http_failure; }
621
638
 
624
641
                                        warning("relocated to very same place! trying request again without host port");
625
642
                                        try_without_port = 1;
626
643
                                }
 
644
                                got_location = TRUE;
627
645
                        }
628
646
                        else
629
647
                        { /* We got a header line (or the closing empty line). */
643
661
                                }
644
662
                        }
645
663
                } while(response.p[0] != '\r' && response.p[0] != '\n');
646
 
        } while(relocate && purl.fill && numrelocs++ < HTTP_MAX_RELOCATIONS);
 
664
        } while(relocate && got_location && purl.fill && numrelocs++ < HTTP_MAX_RELOCATIONS);
647
665
        if(relocate)
648
666
        {
649
 
                fprintf (stderr, "Too many HTTP relocations.\n");
 
667
                if(!got_location)
 
668
                error("Server meant to redirect but failed to provide a location!");
 
669
                else
 
670
                error1("Too many HTTP relocations (%i).", numrelocs);
 
671
 
650
672
                http_failure;
651
673
        }
652
674