Hello
I wrote a plugin. It is supposed to forward messages that I recieve from
user1 to user2. I have most of it striaghtened out. If I make the recieving
user (user2) myself, (i.e. I send messages that user1 sends to me to the
screen name that I am loged on to), then the plugin works fine.
The problem occurs when I try to send a message which I have recieved from
user1 to user2, where user2 is someone other than myself. I get a dialog
propt asking me if I want to direct connect to user2. I don't want to direct
connect to user2! Anyway, even if I click the yes button on the dialog box,
it refuses to direct connect me.
My theory to this whole thing is that I am sending over the wrong connection.
I have not too much knowledge of gaim, so that could be the case. I have
read the HACKING file, read about PRPLS, and looked at the multi.h file, yet
I am still a bit confused as to how the gaim_connections work.
Code in question
typedef struct {
char **handle; //array of strings pointing to aim screen names
size_t count;
} snarray;
snarray read_from;
snarray write_to;
/* checks to see if a person is on the reroute list */
int is_on_list(char *who)
{
int i;
for (i = 0; i<read_from.count; i++) {
if (!(strcasecmp(read_from.handle[i], who)))
return 1;
}
return 0;
}
/* send messages from one person to another*/
static void reroute(struct gaim_connection *gc, char **who,
char **text, guint32 *flags)
{
int i;
size_t sn_size, text_size, buf_size;
char buf[MAX_MESSAGE];
char *pbuf, *temp;
char temp_text[MAX_MESSAGE];
if (!(is_on_list(*who)))
return;
sn_size = strlen(*who);
text_size = strlen(*text);
if (sn_size + text_size > MAX_MESSAGE - 3) {
/* -3 because of terminating nul and ": " between name and text*/
strncpy(temp_text, *text, MAX_MESSAGE - 3 - sn_size);
*(temp_text + MAX_MESSAGE -2 -sn_size) = 0; // nul terminator
} else {
strcpy(temp_text, *text);
}
pbuf = stpcpy(buf, *who);
pbuf = stpcpy(pbuf, ": ");
strcpy (pbuf, *text);
buf_size = strlen(buf);
if ( buf_size > MAX_MESSAGE )
buf_size = MAX_MESSAGE;
for (i = 0; i < write_to.count; i++) {
if (strcmp(*who, write_to.handle[i]))
/*can I send a message to a different user over the same gc that I used to
**recieve a message from another user?*/
serv_send_im(gc, write_to.handle[i], buf, buf_size, *flags);
}
}
char *gaim_plugin_init(GModule *handle)
{
load_config(); //function reads in screen names who need messages forwarded
gaim_signal_connect(handle, event_im_recv, reroute, NULL);
}
thank you very much
--
-James Leddy (iustitia)
|