diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/oauth.c | 6 | ||||
| -rw-r--r-- | lib/oauth2.c | 18 | 
2 files changed, 23 insertions, 1 deletions
| diff --git a/lib/oauth.c b/lib/oauth.c index 4f431ed6..23353c61 100644 --- a/lib/oauth.c +++ b/lib/oauth.c @@ -133,6 +133,9 @@ void oauth_params_del( GSList **params, const char *key )  	int key_len = strlen( key );  	GSList *l, *n; +	if( params == NULL ) +		return NULL; +	  	for( l = *params; l; l = n )  	{  		n = l->next; @@ -157,6 +160,9 @@ const char *oauth_params_get( GSList **params, const char *key )  	int key_len = strlen( key );  	GSList *l; +	if( params == NULL ) +		return NULL; +	  	for( l = *params; l; l = l->next )  	{  		if( strncmp( (char*) l->data, key, key_len ) == 0 && diff --git a/lib/oauth2.c b/lib/oauth2.c index 93891317..4a9d256c 100644 --- a/lib/oauth2.c +++ b/lib/oauth2.c @@ -102,17 +102,33 @@ static void oauth2_access_token_done( struct http_request *req )  {  	struct oauth2_access_token_data *cb_data = req->data;  	char *atoken = NULL, *rtoken = NULL; +	const char *content_type;  	if( getenv( "BITLBEE_DEBUG" ) && req->reply_body )  		printf( "%s\n", req->reply_body ); -	if( req->status_code == 200 ) +	content_type = get_rfc822_header( req->reply_headers, "Content-Type", 0 ); +	 +	if( req->status_code != 200 ) +	{ +	} +	else if( strstr( content_type, "application/json" ) )  	{  		atoken = oauth2_json_dumb_get( req->reply_body, "access_token" );  		rtoken = oauth2_json_dumb_get( req->reply_body, "refresh_token" );  		if( getenv( "BITLBEE_DEBUG" ) )  			printf( "Extracted atoken=%s rtoken=%s\n", atoken, rtoken );  	} +	else +	{ +		/* Facebook use their own odd format here, seems to be URL-encoded. */ +		GSList *p_in = NULL; +		 +		oauth_params_parse( &p_in, req->reply_body ); +		atoken = g_strdup( oauth_params_get( &p_in, "access_token" ) ); +		rtoken = g_strdup( oauth_params_get( &p_in, "refresh_token" ) ); +		oauth_params_free( &p_in ); +	}  	cb_data->func( cb_data->data, atoken, rtoken );  	g_free( atoken );  	g_free( rtoken ); | 
