int isOggUrl(const char *url) { if (strncmp(url, OGG_PROTOCOL, strlen(OGG_PROTOCOL)) == 0) { BufferThreadData * pThreadData = 0; if (strcmp(url, lastUrlChecked) == 0) return lastUrlOgg; strcpy(lastUrlChecked, url); if (stricmp(url + strlen(url) - 4, ".ogg") == 0) return lastUrlOgg = 1; pThreadData = createBufferThreadData(); if (!httpConnect(url, pThreadData, 0, FALSE)) { free(pThreadData); return lastUrlOgg = 0; } closesocket(pThreadData->tcpSocket); if (strcmp(getHttpResponseHeader(pThreadData, "Content-Type"), OGG_MIME_TYPE) == 0) return lastUrlOgg = 1; free(pThreadData); } return lastUrlOgg = 0; }
void * httpStartBuffering(const char *url, OggVorbis_File *oggVorbisFile, BOOL showMessages) { vorbis_info *vi = NULL; ov_callbacks callbacks = {httpRead, httpSeek, httpClose, httpTell}; BufferThreadData * pThreadData = createBufferThreadData(); if (!httpConnect(url, pThreadData, 1, showMessages)) return 0; pThreadData->bufferThreadHandle = (HANDLE)_beginthread(BufferThread, 0, (void *)(pThreadData)); if (ov_open_callbacks(pThreadData, oggVorbisFile, NULL, 0, callbacks) < 0) { showError("ov_open_callbacks failed in httpstream. :-("); pThreadData->killBufferThread = 1; return 0; } return (void *) pThreadData; }
void * httpStartBuffering( const char* url, BOOL showMessages ) { BufferThreadData * pThreadData = createBufferThreadData(); // open the connection if ( !httpConnect( url, pThreadData, 1, showMessages ) ) { // free the allocated buffer data free( pThreadData ); // failed to open the URL return NULL; } // create the receive data thread pThreadData->bufferThreadHandle = (HANDLE)_beginthread( BufferThread, 0, (void *)( pThreadData ) ); // return the return (void *) pThreadData; }
int IsUrl( const char *filename ) { BufferThreadData* pThreadData = NULL; char url[ 4096 ] = { '\0', }; strcpy( url, filename ); // Check to see if the filename starts with "http://" or looks like a URL. if ( 0 != strncmp( url, MP3_PROTOCOL, strlen( MP3_PROTOCOL ) ) ) { char* colon = NULL; char* slash = NULL; char* dot = NULL; colon = strchr( url, ':' ); slash = strchr( url, '/' ); dot = strchr( url, '.' ); if ( dot && (( dot < slash ) || ( dot < colon ) ) ) { _snprintf( url, 4096, "http://%s", url ); } } if ( 0 == strncmp( url, MP3_PROTOCOL, strlen( MP3_PROTOCOL ) ) ) { if ( 0 == strcmp( url, lastUrlChecked ) ) { return lastUrl; } strcpy( lastUrlChecked, url ); // Can we get away without connecting? if ( 0 == stricmp( url + strlen( url ) - 4, ".mp3" ) ) { return lastUrl = 1; } pThreadData = createBufferThreadData(); // try to make a connection if ( !httpConnect( url, pThreadData, 0, FALSE ) ) { // failed to connect free( pThreadData ); return lastUrl = 0; } // close the connection closesocket( pThreadData->tcpSocket ); // if ( NULL != strstr( MP3_MIME_TYPE, getHttpResponseHeader( pThreadData, "Content-Type" ) ) ) { // ok response lastUrl = 1; } // else // { // lastUrl = 0; // } // free thread data buffer free( pThreadData ); return lastUrl; } return 0; }