/* reads input data Copyright (C) 1999 Martin Vogt This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation. For more information look at the file COPYRIGHT in this package */ #include "httpInputStream.h" #ifndef INADDR_NONE #define INADDR_NONE 0xffffffff #endif #include using namespace std; static const char *httpstr="http://"; static char *strndup(char *src,int num) { char *dst; if(!(dst=(char *)malloc(num+1)))return NULL; dst[num]='\0'; return strncpy(dst, src, num); } static char *url2hostport(char *url,char **hname, unsigned long *hip,unsigned int *port) { char *cptr; struct hostent *myhostent; struct in_addr myaddr; int isip=1; if(!(strncmp(url,httpstr,7)))url+=7; cptr=url; while(*cptr && *cptr!=':' && *cptr!='/') { if((*cptr<'0' || *cptr>'9') && *cptr!='.')isip=0; cptr++; } if(!(*hname=strndup(url,cptr-url))) { *hname=NULL; return NULL; } if(!isip) { if (!(myhostent=gethostbyname(*hname)))return NULL; memcpy(&myaddr,myhostent->h_addr,sizeof(myaddr)); *hip=myaddr.s_addr; } else if((*hip=inet_addr(*hname))==INADDR_NONE)return NULL; if(!*cptr || *cptr=='/') { *port=80; return cptr; } *port=atoi(++cptr); while(*cptr && *cptr!='/')cptr++; return cptr; } HttpInputStream::HttpInputStream() { proxyurl=NULL; proxyip=0; lopen=false; byteCnt=0; } HttpInputStream::~HttpInputStream() { close(); } int HttpInputStream::open(const char* filename) { close(); if (filename == NULL) { return false; } /* int matchPos=InputStream::getPath(filename,"http"); if (matchPos=0) { return false; } */ char* filename2=strdup(filename); if((fp=http_open(filename2))==NULL) { cout << "seterrorcode(SOUND_ERROR_FILEOPENFAIL)"<