diff options
| author | Wilmer van der Gaast <wilmer@gaast.net> | 2011-12-26 11:51:19 +0100 | 
|---|---|---|
| committer | Wilmer van der Gaast <wilmer@gaast.net> | 2011-12-26 11:51:19 +0100 | 
| commit | 5f40da79f78e444f08387ce53da1b2e471c8552f (patch) | |
| tree | ceded3c147f55b819e11503e91cc4d9e75bbcd43 /lib/misc.c | |
| parent | 96f954df218e81f5580257c319b91217dac2f4bf (diff) | |
| parent | 644b8080349d7d42ca89946acc207592fd0acc2d (diff) | |
Merging oauth-xmpp branch, which adds support for OAuth2 authentication
against some XMPP services (Google Talk, Facebook and Microsoft's MSN-XMPP
gateway).
Diffstat (limited to 'lib/misc.c')
| -rw-r--r-- | lib/misc.c | 55 | 
1 files changed, 55 insertions, 0 deletions
| @@ -728,3 +728,58 @@ char **split_command_parts( char *command )  	return cmd;  } + +char *get_rfc822_header( char *text, char *header, int len ) +{ +	int hlen = strlen( header ), i; +	char *ret; +	 +	if( text == NULL ) +		return NULL; +	 +	if( len == 0 ) +		len = strlen( text ); +	 +	i = 0; +	while( ( i + hlen ) < len ) +	{ +		/* Maybe this is a bit over-commented, but I just hate this part... */ +		if( g_strncasecmp( text + i, header, hlen ) == 0 ) +		{ +			/* Skip to the (probable) end of the header */ +			i += hlen; +			 +			/* Find the first non-[: \t] character */ +			while( i < len && ( text[i] == ':' || text[i] == ' ' || text[i] == '\t' ) ) i ++; +			 +			/* Make sure we're still inside the string */ +			if( i >= len ) return( NULL ); +			 +			/* Save the position */ +			ret = text + i; +			 +			/* Search for the end of this line */ +			while( i < len && text[i] != '\r' && text[i] != '\n' ) i ++; +			 +			/* Make sure we're still inside the string */ +			if( i >= len ) return( NULL ); +			 +			/* Copy the found data */ +			return( g_strndup( ret, text + i - ret ) ); +		} +		 +		/* This wasn't the header we were looking for, skip to the next line. */ +		while( i < len && ( text[i] != '\r' && text[i] != '\n' ) ) i ++; +		while( i < len && ( text[i] == '\r' || text[i] == '\n' ) ) i ++; +		 +		/* End of headers? */ +		if( ( i >= 4 && strncmp( text + i - 4, "\r\n\r\n", 4 ) == 0 ) || +		    ( i >= 2 && ( strncmp( text + i - 2, "\n\n", 2 ) == 0 ||    +		                  strncmp( text + i - 2, "\r\r", 2 ) == 0 ) ) ) +		{ +			break; +		} +	} +	 +	return NULL; +} | 
