OSDN Git Service

Remove the set cpu count option as it doesn't do anything now
[handbrake-jp/handbrake-jp-git.git] / libhb / update.c
index d19a054..9f72523 100644 (file)
@@ -30,36 +30,55 @@ static void UpdateFunc( void * _data )
 {
 
     hb_update_t * data = (hb_update_t *) _data;
-       
-    /* New code to handle the hb_query stuff */
-    char* hb_query;
-    if( HB_BUILD % 100 )
-    {  
-        hb_query = "GET /appcast_unstable.xml HTTP/1.0\r\nHost: handbrake.fr\r\n\r\n";
-        hb_log("Using http://handbrake.fr/appcast_unstable.xml");
-    }
-       else 
-       {
-        hb_query = "GET /appcast.xml HTTP/1.0\r\nHost: handbrake.fr\r\n\r\n";
-        hb_log("Using http://handbrake.fr/appcast.xml");
-    }
 
-       // Grab the data from the web server
-    hb_net_t * net;
+    char* const url  = HB_PROJECT_URL_APPCAST;
+    char* const urlz = url + strlen( HB_PROJECT_URL_APPCAST ); /* marks null-term */
+    char        url_host[64];
+    char        url_path[128];
+    char        query[256];
+
+       hb_net_t * net;
     int        ret;
     char       buf[4096];
     char     * cur, * end;
     int        size;
-    int        stable;
-    char       stable_str[16];
+    int        i_vers;
+    char       s_vers[32]; /* must be no larger than hb_handle_s.version */
     int        i;
 
-    if( !( net = hb_net_open( "handbrake.fr", 80 ) ) )
+    /* Setup hb_query and hb_query_two with the correct appcast file */
+    hb_log( "Using %s", url );
+
+    /* extract host part */
+    cur = strstr( HB_PROJECT_URL_APPCAST, "//" );
+    if( !cur || cur+2 > urlz )
+        goto error;
+    cur += 2;
+
+    end = strstr( cur, "/" );
+    if( !end || end > urlz )
+        goto error;
+
+    memset( url_host, 0, sizeof(url_host) );
+    strncpy( url_host, cur, (end-cur) );
+
+    /* extract path part */
+    memset( url_path, 0, sizeof(url_path) );
+    strncpy( url_path, end, (urlz-end) );
+
+    if( !strlen( url_path ))
+        goto error;
+
+    memset( query, 0, sizeof(query) );
+    snprintf( query, sizeof(query), "GET %s HTTP/1.0\r\nHost: %s\r\n\r\n", url_path, url_host );
+
+    /* Grab the data from the web server */
+    if( !( net = hb_net_open( url_host, 80 ) ) )
     {
         goto error;
     }
 
-    if( hb_net_send( net, hb_query ) < 0 )
+    if( hb_net_send( net, query ) < 0 )
     {
         hb_log("Error: Unable to connect to server");
         hb_net_close( &net );
@@ -86,7 +105,6 @@ static void UpdateFunc( void * _data )
     cur += 9;
     if( size < 15 || strncmp( cur, "200 OK", 6 ) )
     {
-        /* Something went wrong */
         hb_log("Error: We did not get a 200 OK from the server. \n");
         goto error;
     }
@@ -109,8 +127,6 @@ static void UpdateFunc( void * _data )
         goto error;
     }
        
-       // Version Checking Here
-       
     /*
      * Find the <cli> tag
      * Scan though each character of the buffer until we find that the first 4 characters of "cur" are "<cli"
@@ -123,7 +139,7 @@ static void UpdateFunc( void * _data )
             break;
         }
                 
-        // If the CLI tag has not been found in the first 768 characters, or the end is reached, something bad happened.
+        /* If the CLI tag has not been found in the first 768 characters, or the end is reached, something bad happened.*/
         if (( i > 768) || ( cur >= end ))
                {
             hb_log("Error: Did not find the <cli> tag in the expected maximum amount of characters into the file. \n");
@@ -148,11 +164,12 @@ static void UpdateFunc( void * _data )
         goto error;
     }
        
-    stable = strtol( cur, &cur, 10 );
-               
+    /* Stable HB_PROJECT_BUILD */
+    i_vers = strtol( cur, &cur, 10 );
+
     if( cur >= end )
     {
-     hb_log("Error: Unexpected end of buffer! \n");
+        hb_log("Error: Unexpected end of buffer! \n");
         goto error;
     }
        
@@ -167,31 +184,32 @@ static void UpdateFunc( void * _data )
         hb_log("Error: Unexpected end of buffer! Could not get version number. \n");
         goto error;
     }
-    memset( stable_str, 0, sizeof( stable_str ) );
-    for( i = 0;   i < sizeof( stable_str ) - 1 && cur < end && *cur != '"'; i++, cur++ )
+    memset( s_vers, 0, sizeof( s_vers ) );
+    for( i = 0;   i < sizeof( s_vers ) - 1 && cur < end && *cur != '"'; i++, cur++ )
     {
-        stable_str[i] = *cur;
+        s_vers[i] = *cur;
                
-        // If the version number is longer than 7 characters, or the end is reached, something has gone wrong.
-        if (( i > 7) || ( cur >= end ))
+        /* If the CLI tag has not been found in the first 768 characters, or the end is reached, something bad happened.*/
+        if (( cur >= end ))
         {
             hb_log("Error: Version number too long, or end of buffer reached. \n");
             goto error;
         }
     }
-       
+
     if( cur >= end )
     {
         goto error;
     }
-       
-    hb_log( "latest stable: %s, build %d", stable_str, stable );
-       
-       // Return the build information
-    if( stable > HB_BUILD )
+
+    /* Print the version information */
+    hb_log( "latest: %s, build %d", s_vers, i_vers );
+
+    /* Return the build information */
+    if( i_vers > HB_PROJECT_BUILD )
     {
-        memcpy( data->version, stable_str, sizeof( stable_str ) );
-        *(data->build) = stable;
+        memcpy( data->version, s_vers, sizeof(s_vers) );
+        *(data->build) = i_vers;
     }
 
 error: