-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi All,
This is a quick patch against 0.8.6.CVS which adds the following support to
the proxy_string and proxy_string_after settings. It removed the %s %d
requirement and instead adds the following labels for use in generating a
proxy string:
%ADDRESS% - Server Address
%PORT% - Server Port
%PASSWORD% - Server Password
%USERNAME% - Connection user name.
%VHOST% - Special: If user name is specified as <user>@<vhost> then
%USERNAME% will be set to <user> and %VHOST% will be set to
<vhost>
An example string_proxy_after for a BNC proxy would be:
"VIP %VHOST%\nIDENT %USERNAME%\nCONN %ADDRESS% %PORT% %PASSWORD%"
Any or all the labels can be left out as needed.
This patch is pretty crude, mainly because I got annoyed with the settings
today so through it together but figured there may be some interest in it.
It's only been tested again a BNC proxy at the moment. Comments appreciated.
- --
Snowy "Snowpony" Angelique Cerise Maslov -- http://snowy.org/email.signature
PGP (GnuPG) fingerprint = 5280 6EBC D281 A9D2 564B E274 B2EC 54C3 8325 CECD
Email not addressed/CCd to [EMAIL PROTECTED] BOUNCE. READ URL for disclaimer!
"Ignorance killed the cat, sir. Curiosity was framed." ---C.J. Cherryh
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: For info see http://quantumlab.net/pine_privacy_guard/
iD8DBQE/vfpbsuxUw4Mlzs0RAhuLAKCAQ8CzJUW14vrOLOc3kI7SISCseQCffAjs
x78tL82J7IsRy9OMuOTTJpE=
=g3TF
-----END PGP SIGNATURE-----
diff -ur irssi-0.8.6.CVS/src/core/servers-setup.c irssi-snowy/src/core/servers-setup.c
--- irssi-0.8.6.CVS/src/core/servers-setup.c 2002-08-27 09:00:07.000000000 +1000
+++ irssi-snowy/src/core/servers-setup.c 2003-11-21 21:23:41.000000000 +1000
@@ -520,8 +520,8 @@
settings_add_bool("proxy", "use_proxy", FALSE);
settings_add_str("proxy", "proxy_address", "");
settings_add_int("proxy", "proxy_port", 6667);
- settings_add_str("proxy", "proxy_string", "CONNECT %s %d");
- settings_add_str("proxy", "proxy_string_after", "");
+ settings_add_str("proxy", "proxy_string", "");
+ settings_add_str("proxy", "proxy_string_after", "VIP %VHOST%\nIDENT
%USERNAME%\nCONN %ADDRESS% %PORT% %PASSWORD%");
settings_add_str("proxy", "proxy_password", "");
setupservers = NULL;
diff -ur irssi-0.8.6.CVS/src/irc/core/irc-servers.c
irssi-snowy/src/irc/core/irc-servers.c
--- irssi-0.8.6.CVS/src/irc/core/irc-servers.c 2003-06-26 05:45:02.000000000 +1000
+++ irssi-snowy/src/irc/core/irc-servers.c 2003-11-21 18:15:08.000000000 +1000
@@ -40,6 +40,8 @@
#include "settings.h"
+#include <string.h>
+
#define DEFAULT_MAX_KICKS 1
#define DEFAULT_MAX_MODES 3
#define DEFAULT_MAX_WHOIS 4
@@ -95,10 +97,118 @@
g_free(str);
}
+int replace_string(char *source, char *dest, char *search, char *replace)
+{
+ char *position; // Current position
+ char *occurances; // Position of next Occurance in search
+ int number = 0; // Number of Occurances replaced
+
+ // Validity Check on input, hopefully we really are pointing to
+ // something otherwise we are going to SEGV badly ;)
+ if (!source || !dest || !search || !replace) {
+ return -1;
+ }
+ // Clear the destination buffer
+ dest[0] = '\0';
+ // Start from the beginning
+ position = source;
+ // Find the first occurance of search
+ occurances = strstr(position, search);
+ // Loop through all instances in source
+ while (occurances) {
+ // Copy the text preceeding the current occurance or search
+ strncat(dest, position, occurances - position);
+ // Append replace to the end of the destination buffer
+ strcat(dest, replace);
+ // Increase the starting point so we don't find the same occurance over
+ // and over again
+ position = occurances + strlen(search);
+ // Find the next occurance if it exists
+ occurances = strstr(position, search);
+ // Increment the occurance count
+ number++;
+ }
+
+ // finally append anything after the last occurance to the destination buffer
+ strcat(dest, position);
+ // return the occurance count
+ return number;
+}
+
+int make_proxy_string(IRC_SERVER_CONNECT_REC *conn, char *string) {
+ // This is ugly - probably should dynamically allocate this
+ // stuff. Then again sending more than 1k on a proxy_string
+ // would probably be overkill anyways.
+ char value[101]; // 100 + NULL
+ char temp[101]; // 100 + NULL
+ char input[1025]; // 1024 + NULL
+ char output[1025]; // 1024 + NULL
+ char *pointer;
+ int sz;
+
+ // Let's make sure we have some parameters at least
+ if(!string || !conn) {
+ return -1;
+ }
+
+ // Make sure everything is reset to defaults.
+ value[0] = '\0';
+ temp[0] = '\0';
+ input[0] = '\0';
+ output[0] = '\0';
+ pointer = (char *) NULL;
+ sz = 0;
+
+ // Initialise Input
+ strncpy(&input[0],string,1024);
+
+ // Search and Replace : Server Address
+ snprintf(&value[0],100,"%%ADDRESS%%");
+ replace_string(&input[0],&output[0],&value[0],conn->address);
+ strncpy(&input[0],&output[0],1024);
+
+ // Search and Replace : Server Port
+ snprintf(&value[0],100,"%%PORT%%");
+ snprintf(&temp[0],100,"%i",conn->port);
+ replace_string(&input[0],&output[0],&value[0],&temp[0]);
+ strncpy(&input[0],&output[0],1024);
+
+ // Search and Replace : Server Password
+ snprintf(&value[0],100,"%%PASSWORD%%");
+ replace_string(&input[0],&output[0],&value[0],conn->password);
+ strncpy(&input[0],&output[0],1024);
+
+ // Search and Replace : Username (special case)
+ if(!strstr(conn->username,"@")) {
+ snprintf(&value[0],100,"%%USERNAME%%");
+ replace_string(&input[0],&output[0],&value[0],conn->username);
+ strncpy(&input[0],&output[0],1024);
+ }
+ else {
+ pointer = strstr(conn->username,"@");
+ sz = strlen(conn->username) - strlen(pointer);
+ if(sz > 100) {
+ sz=100;
+ }
+ strncpy(&temp[0],conn->username,sz);
+ snprintf(&value[0],100,"%%USERNAME%%");
+ replace_string(&input[0],&output[0],&value[0],&temp[0]);
+ strncpy(&input[0],&output[0],1024);
+ strncpy(&temp[0],++pointer,100);
+ snprintf(&value[0],100,"%%VHOST%%");
+ replace_string(&input[0],&output[0],&value[0],&temp[0]);
+ strncpy(&input[0],&output[0],1024);
+ }
+ // Copy result out.
+ strncpy(string,&output[0],1024);
+ return 0;
+}
+
static void server_init(IRC_SERVER_REC *server)
{
IRC_SERVER_CONNECT_REC *conn;
char hostname[100], *address, *ptr, *username;
+ char finalstring[1025];
g_return_if_fail(server != NULL);
@@ -108,9 +218,11 @@
*conn->proxy_password != '\0')
irc_send_cmdv(server, "PASS %s", conn->proxy_password);
- if (conn->proxy != NULL && conn->proxy_string != NULL)
- irc_send_cmdv(server, conn->proxy_string, conn->address, conn->port);
-
+ if (conn->proxy != NULL && conn->proxy_string != NULL) {
+ snprintf(&finalstring[0],1024,"%s",conn->proxy_string);
+ make_proxy_string(conn,&finalstring[0]);
+ irc_send_cmdv(server, &finalstring[0]);
+ };
if (conn->password != NULL && *conn->password != '\0') {
/* send password */
server->cmdcount = 0;
@@ -153,8 +265,9 @@
server->cmdcount = 0;
if (conn->proxy != NULL && conn->proxy_string_after != NULL) {
- irc_send_cmdv(server, conn->proxy_string_after,
- conn->address, conn->port);
+ snprintf(&finalstring[0],1024,"%s",conn->proxy_string_after);
+ make_proxy_string(conn,&finalstring[0]);
+ irc_send_cmdv(server, &finalstring[0]);
}
server->cmdcount = 0;
diff -ur irssi-0.8.6.CVS/src/irc/core/irc-servers.h
irssi-snowy/src/irc/core/irc-servers.h
--- irssi-0.8.6.CVS/src/irc/core/irc-servers.h 2002-10-10 12:00:03.000000000 +1000
+++ irssi-snowy/src/irc/core/irc-servers.h 2003-11-21 16:07:29.000000000 +1000
@@ -108,6 +108,9 @@
like "#a,#b,#c,#d x,b_chan_key,x,x" or just "#e,#f,#g" */
char *irc_server_get_channels(IRC_SERVER_REC *server);
+/* String Replace for Proxy String */
+int replace_string(char *source, char *dest, char *search, char *replace);
+
/* INTERNAL: */
void irc_server_send_data(IRC_SERVER_REC *server, const char *data, int len);