Files at this revision

API Documentation at this revision

Comitter:
FrankWeissenborn
Date:
Sun Jan 30 21:33:12 2011 +0000
Parent:
6:be954c212733
Commit message:
Added: GetPath Problem: Memory leak (after 5-6 tune in)

Changed in this revision

Shoutcast.cpp Show annotated file Show diff for this revision Revisions of this file
Shoutcast.h Show annotated file Show diff for this revision Revisions of this file
--- a/Shoutcast.cpp	Fri Jan 28 11:53:55 2011 +0000
+++ b/Shoutcast.cpp	Sun Jan 30 21:33:12 2011 +0000
@@ -158,7 +158,7 @@
     return GetChannel(name, length, _currentChannel);
 }
 
-int Shoutcast::TuneIn(IpAddr* address, int* port) {
+int Shoutcast::TuneIn(IpAddr* address, int* port, char * path, const int length) {
     char buf[10];
     sprintf(buf,"%d",GetChannelId(_currentChannel));
      
@@ -176,7 +176,7 @@
         return 1;
     }
     _currentAddress = 0;
-    return GetAddressData(address,port,0);
+    return GetAddressData(address,port,path,length,0);
 }
 
 
@@ -373,9 +373,9 @@
     char * cp;
     char * cp2;
     IpAddr addr;
+    int k=0;
     while(!finished) {
         finished = (fgets(_big_buffer, _big_buffer_size-1, _fpin) == NULL);
-        
         //suchen nach 
         cp = strstr(_big_buffer,"=http://");
         if(cp!= NULL)
@@ -397,12 +397,26 @@
                 }
                 else
                 {
-                cp = NULL;
-                finished = true;
+                    cp = NULL;
                 }
                 int port = atoi(cp2+1);
-                fprintf(_fpout, "%d %d %d %d %d\r\n",
-                       addr[0],addr[1],addr[2],addr[3],port);
+                cp = strstr(cp2+1,"/");
+                if(cp == NULL)
+                {
+                    _small_buffer[0] = '/';
+                    _small_buffer[1] = 0x00;
+                }
+                else
+                {
+                    int j=0;
+                    while(cp[j]!=0x0a)
+                        j++;
+                    
+                    cp[j] = 0x00;
+                    strcpy (_small_buffer,cp);
+                }
+                fprintf(_fpout, "%d %d %d %d %d %s\r\n",
+                       addr[0],addr[1],addr[2],addr[3],port,_small_buffer);
                 _maxAddress++;
             }
         }
@@ -415,6 +429,7 @@
     return 0;
 }
 int Shoutcast::ResolveDNSRequest(IpAddr* addr, char * url){
+//TODO: instanzvaraible, setOnReplay im Konstruktor
     DNSRequest * request = new DNSRequest();
     request->setOnReply(this, &Shoutcast::onReply);
 
@@ -439,7 +454,7 @@
      return 0;
 }
 
-int Shoutcast::GetAddressData(IpAddr* address, int* port, int addressNumber) {
+int Shoutcast::GetAddressData(IpAddr* address, int* port, char * path, const int length, int addressNumber) {
 
     if(_maxAddress == 0) return -1;
     if(addressNumber > _maxAddress) return -1;
@@ -452,11 +467,11 @@
     while(!finished) {
         finished = (fgets(_big_buffer, _big_buffer_size-1, _fpin) == NULL);
         if(line == addressNumber){
-            int ip1 = 0;int ip2 = 0;int ip3 = 0;int ip4 = 0;int p = 0;
-            sscanf (_big_buffer,"%d %d %d %d %d",&ip1,&ip2,&ip3,&ip4,&p);
+            int ip1 = 0;int ip2 = 0;int ip3 = 0;int ip4 = 0;
+            sscanf (_big_buffer,"%d %d %d %d %d %s",&ip1,&ip2,&ip3,&ip4,port,path);
             IpAddr server = IpAddr(ip1,ip2,ip3,ip4);
             *address = server;
-            *port = p;
+            //*path = _small_buffer[0]; //TODO: Length
             finished = true;
         }
         line++;
@@ -472,7 +487,7 @@
              completed_dns=-1;
      };
 
-int Shoutcast::GetNextAddress(IpAddr* address, int* port)
+int Shoutcast::GetNextAddress(IpAddr* address, int* port, char * path, const int length)
 {
     if(_currentAddress < _maxAddress - 1 )
     {
@@ -482,14 +497,14 @@
     {
         _currentAddress = 0;
     }
-    return GetAddressData(address,port,_currentAddress);
+    return GetAddressData(address,port,path,length,_currentAddress);
     
 }
-int Shoutcast::GetCurrAddress(IpAddr* address, int* port)
+int Shoutcast::GetCurrAddress(IpAddr* address, int* port, char * path, const int length)
 {
-    return GetAddressData(address,port,_currentAddress);
+    return GetAddressData(address,port,path,length,_currentAddress);
 }
-int Shoutcast::GetPrevAddress(IpAddr* address, int* port)
+int Shoutcast::GetPrevAddress(IpAddr* address, int* port, char * path, const int length)
 {
     if(_currentAddress > 0 )
     {
@@ -499,5 +514,5 @@
     {
         _currentAddress = _maxAddress - 1;
     }
-    return GetAddressData(address,port,_currentAddress);
+    return GetAddressData(address,port,path,length,_currentAddress);
 }
\ No newline at end of file
--- a/Shoutcast.h	Fri Jan 28 11:53:55 2011 +0000
+++ b/Shoutcast.h	Sun Jan 30 21:33:12 2011 +0000
@@ -67,10 +67,10 @@
      * @param port pointer to port.
      * @return 0, all okay -1, error 1, error parsing pls
      */
-    int TuneIn(IpAddr* address, int* port);
-    int GetNextAddress(IpAddr* address, int* port);
-    int GetCurrAddress(IpAddr* address, int* port);
-    int GetPrevAddress(IpAddr* address, int* port);
+    int TuneIn(IpAddr* address, int* port, char * path, const int length);
+    int GetNextAddress(IpAddr* address, int* port, char * path, const int length);
+    int GetCurrAddress(IpAddr* address, int* port, char * path, const int length);
+    int GetPrevAddress(IpAddr* address, int* port, char * path, const int length);
     
     
     
@@ -79,7 +79,7 @@
     int ParseChannelList(const char* channelList);
     int ParsePls();
     int GetChannel(char* name, int length, int channelNumber);
-    int GetAddressData(IpAddr* address, int* port, int addressNumber);
+    int GetAddressData(IpAddr* address, int* port,char * path, const int length, int addressNumber);
     void onReply(DNSReply reply);
     int ResolveDNSRequest(IpAddr* addr, char * url);
     int GetChannelId(int channelNumber);