1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-09 03:03:12 +02:00

Add SASL authentication in IRC plugin (task #8829), add function "string_encode_base64" in plugin API, fix bug with base64 encoding

New options for IRC servers:
- sasl_mechanism (only "plain" for now)
- sasl_username
- sasl_password
This commit is contained in:
Sebastien Helleu
2010-02-15 11:51:44 +01:00
parent 34272b7e4d
commit 341551f2f2
26 changed files with 925 additions and 115 deletions
+1 -62
View File
@@ -99,67 +99,6 @@ network_end ()
#endif
}
/*
* network_convbase64_8x3_to_6x4 : convert 3 bytes of 8 bits in 4 bytes of 6 bits
*/
void
network_convbase64_8x3_to_6x4 (const char *from, char *to)
{
unsigned char base64_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz0123456789+/";
to[0] = base64_table [ (from[0] & 0xfc) >> 2 ];
to[1] = base64_table [ ((from[0] & 0x03) << 4) + ((from[1] & 0xf0) >> 4) ];
to[2] = base64_table [ ((from[1] & 0x0f) << 2) + ((from[2] & 0xc0) >> 6) ];
to[3] = base64_table [ from[2] & 0x3f ];
}
/*
* network_base64encode: encode a string in base64
*/
void
network_base64encode (const char *from, char *to)
{
const char *f;
char *t;
int from_len;
from_len = strlen (from);
f = from;
t = to;
while (from_len >= 3)
{
network_convbase64_8x3_to_6x4 (f, t);
f += 3 * sizeof (*f);
t += 4 * sizeof (*t);
from_len -= 3;
}
if (from_len > 0)
{
char rest[3] = { 0, 0, 0 };
switch (from_len)
{
case 1 :
rest[0] = f[0];
network_convbase64_8x3_to_6x4 (rest, t);
t[2] = t[3] = '=';
break;
case 2 :
rest[0] = f[0];
rest[1] = f[1];
network_convbase64_8x3_to_6x4 (rest, t);
t[3] = '=';
break;
}
t[4] = 0;
}
}
/*
* network_pass_httpproxy: establish connection/authentification to an
* http proxy
@@ -182,7 +121,7 @@ network_pass_httpproxy (struct t_proxy *proxy, int sock, const char *address,
CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME]),
(CONFIG_STRING(proxy->options[PROXY_OPTION_PASSWORD])) ?
CONFIG_STRING(proxy->options[PROXY_OPTION_PASSWORD]) : "");
network_base64encode (authbuf, authbuf_base64);
string_encode_base64 (authbuf, strlen (authbuf), authbuf_base64);
n = snprintf (buffer, sizeof (buffer),
"CONNECT %s:%d HTTP/1.0\r\nProxy-Authorization: Basic %s\r\n\r\n",
address, port, authbuf_base64);
+62
View File
@@ -1271,3 +1271,65 @@ string_format_size (unsigned long size)
return strdup (str_size);
}
/*
* string_convbase64_8x3_to_6x4 : convert 3 bytes of 8 bits in 4 bytes of 6 bits
*/
void
string_convbase64_8x3_to_6x4 (const char *from, char *to)
{
unsigned char base64_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz0123456789+/";
to[0] = base64_table [ (from[0] & 0xfc) >> 2 ];
to[1] = base64_table [ ((from[0] & 0x03) << 4) + ((from[1] & 0xf0) >> 4) ];
to[2] = base64_table [ ((from[1] & 0x0f) << 2) + ((from[2] & 0xc0) >> 6) ];
to[3] = base64_table [ from[2] & 0x3f ];
}
/*
* string_encode_base64: encode a string in base64
* length is number of bytes in "from" to convert
* (commonly strlen(from))
*/
void
string_encode_base64 (const char *from, int length, char *to)
{
const char *ptr_from;
char *ptr_to;
ptr_from = from;
ptr_to = to;
while (length >= 3)
{
string_convbase64_8x3_to_6x4 (ptr_from, ptr_to);
ptr_from += 3 * sizeof (*ptr_from);
ptr_to += 4 * sizeof (*ptr_to);
length -= 3;
}
if (length > 0)
{
char rest[3] = { 0, 0, 0 };
switch (length)
{
case 1 :
rest[0] = ptr_from[0];
string_convbase64_8x3_to_6x4 (rest, ptr_to);
ptr_to[2] = ptr_to[3] = '=';
break;
case 2 :
rest[0] = ptr_from[0];
rest[1] = ptr_from[1];
string_convbase64_8x3_to_6x4 (rest, ptr_to);
ptr_to[3] = '=';
break;
}
ptr_to[4] = 0;
}
else
ptr_to[0] = '\0';
}
+1
View File
@@ -56,5 +56,6 @@ extern char *string_iconv_from_internal (const char *charset,
const char *string);
extern void string_iconv_fprintf (FILE *file, const char *data, ...);
extern char *string_format_size (unsigned long size);
extern void string_encode_base64 (const char *from, int length, char *to);
#endif /* wee-string.h */