#include #include #include #include #include #include #include #include #include #include "playtree.h" #include "libmpdemux/stream.h" #include "mp_msg.h" extern play_tree_t* asx_parser_build_tree(char* buffer); static char* buffer = NULL; static int buffer_size = 0, buffer_end = 0; play_tree_t* parse_asx(stream_t* stream) { int r; int comments = 0,read = 1,eof = 0; mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying asx...\n"); while(1) { if(read && eof) // Eof reached before anything useful return NULL; if(read) { if(buffer_size - buffer_end < 50) buffer_size += 255; buffer = (char*)realloc(buffer,buffer_size*sizeof(char)); if(buffer == NULL) { mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",buffer_size*sizeof(char)); buffer_size = buffer_end = 0; return NULL; } r = stream_read(stream,buffer+buffer_end,buffer_size-buffer_end-1); if(r < 0) { mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't read from stream r=%d\n",r); return NULL; } else if(r == 0) eof = 1; buffer_end += r; buffer[buffer_end] = '\0'; } if(comments) { // Jump comments int e; char* end = strstr(buffer,"-->"); if(!end) { if(buffer[buffer_end-1] != '-') buffer_end = 0; // Drop buffer content if last char isn't '-' continue; } comments = 0; e = end - buffer + 3; if(e >= buffer_end) { // > seems impossible buffer_end = 0; // Drop buffer content read = 1; continue; } buffer_end -= e; memmove(buffer,end+3,buffer_end); // Drop comments continue; } for(r= 0 ; r < buffer_end ; r++) { if(strchr(" \n\r\t",buffer[r]) != NULL) // Jump space continue; if(buffer[r] != '<') { mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"First char isn't '<' but '%c'\n",buffer[r]); mp_msg(MSGT_PLAYTREE,MSGL_DBG3,"Buffer = [%s]\n",buffer); return NULL; } break; // Stop on first '<' } if(r > buffer_end-4) { // We need more if(r > 0) { // Drop unuseful beggining buffer_end -= r; memmove(buffer,&buffer[r],buffer_end); } read = 1; continue; } if(strncmp(&buffer[r],"