1 /* $Id: update.c,v 1.7 2005/03/26 23:04:14 titer Exp $
3 This file is part of the HandBrake source code.
4 Homepage: <http://handbrake.m0k.org/>.
5 It may be used under the terms of the GNU General Public License. */
9 #define HB_URL "handbrake.m0k.org"
10 #define HB_QUERY "GET /LATEST HTTP/1.0\r\nHost: " HB_URL "\r\n\r\n"
19 static void UpdateFunc( void * );
21 hb_thread_t
* hb_update_init( int * build
, char * version
)
23 hb_update_t
* data
= calloc( sizeof( hb_update_t
), 1 );
25 data
->version
= version
;
27 return hb_thread_init( "update", UpdateFunc
, data
,
31 static void UpdateFunc( void * _data
)
33 hb_update_t
* data
= (hb_update_t
*) _data
;
38 char * cur
, * end
, * p
;
41 char stable_str
[16], unstable_str
[16];
44 if( !( net
= hb_net_open( HB_URL
, 80 ) ) )
49 if( hb_net_send( net
, HB_QUERY
) < 0 )
56 memset( buf
, 0, 1024 );
59 ret
= hb_net_recv( net
, &buf
[size
], sizeof( buf
) - size
);
69 end
= &buf
[sizeof( buf
)];
71 /* Make sure we got it */
73 if( size
< 15 || strncmp( cur
, "200 OK", 6 ) )
75 /* Something went wrong */
80 /* Find the end of the headers and the beginning of the content */
81 for( ; &cur
[3] < end
; cur
++ )
83 if( cur
[0] == '\r' && cur
[1] == '\n' &&
84 cur
[2] == '\r' && cur
[3] == '\n' )
96 stable
= strtol( cur
, &p
, 10 );
102 memset( stable_str
, 0, sizeof( stable_str
) );
104 i
< sizeof( stable_str
) - 1 && cur
< end
&& *cur
!= '\n';
107 stable_str
[i
] = *cur
;
110 hb_log( "latest stable: %s, build %d", stable_str
, stable
);
118 unstable
= strtol( cur
, &p
, 10 );
124 memset( unstable_str
, 0, sizeof( unstable_str
) );
126 i
< sizeof( unstable_str
) - 1 && cur
< end
&& *cur
!= '\n';
129 unstable_str
[i
] = *cur
;
132 hb_log( "latest unstable: %s, build %d", unstable_str
, unstable
);
136 /* We are runnning an unstable build */
137 if( unstable
> HB_BUILD
)
139 memcpy( data
->version
, unstable_str
, sizeof( unstable_str
) );
140 *(data
->build
) = unstable
;
145 /* We are runnning an stable build */
146 if( stable
> HB_BUILD
)
148 memcpy( data
->version
, stable_str
, sizeof( stable_str
) );
149 *(data
->build
) = stable
;