Skip to content

Commit

Permalink
AIM logging (both in and out) now works
Browse files Browse the repository at this point in the history
Disabled 'addbuddy' and 'delbuddy' for AIM in prep. for beta release
  since it doesn't work yet
  • Loading branch information
James M. Kretchmar committed Jun 5, 2003
1 parent 5789230 commit aac889a
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 47 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Expand Up @@ -89,6 +89,8 @@ $Id$
'isloginout' and 'isprivate' are now message attributes
improved 'info' function lists seperate info for zephyr, aim and
also prints all message attributes
AIM logging (both in and out) now works
Disabled 'addbuddy' and 'delbuddy' for aim since it doesn't work yet

1.2.8
Class pings are displayed differently now
Expand Down
4 changes: 4 additions & 0 deletions commands.c
Expand Up @@ -891,6 +891,8 @@ char *owl_command_addbuddy(int argc, char **argv, char *buff)
owl_function_makemsg("addbuddy: You must be logged into aim to use this command.");
return(NULL);
}
owl_function_makemsg("This function is not yet operational. Stay tuned.");
return(NULL);
owl_aim_addbuddy(argv[2]);
owl_function_makemsg("%s added as AIM buddy for %s", argv[2], owl_global_get_aim_screenname(&g));
} else if (!strcasecmp(argv[1], "zephyr")) {
Expand All @@ -915,6 +917,8 @@ char *owl_command_delbuddy(int argc, char **argv, char *buff)
owl_function_makemsg("delbuddy: You must be logged into aim to use this command.");
return(NULL);
}
owl_function_makemsg("This function is not yet operational. Stay tuned.");
return(NULL);
owl_aim_delbuddy(argv[2]);
owl_function_makemsg("%s deleted as AIM buddy for %s", argv[2], owl_global_get_aim_screenname(&g));
} else if (!strcasecmp(argv[1], "zephyr")) {
Expand Down
7 changes: 2 additions & 5 deletions functions.c
Expand Up @@ -295,7 +295,7 @@ void owl_function_zwrite(char *line)
if (owl_global_is_logging(&g) && owl_zwrite_is_personal(&z)) {
j=owl_zwrite_get_numrecips(&z);
for (i=0; i<j; i++) {
owl_log_outgoing(owl_zwrite_get_recip_n(&z, i),
owl_log_outgoing_zephyr(owl_zwrite_get_recip_n(&z, i),
owl_editwin_get_text(owl_global_get_typwin(&g)));
}
}
Expand All @@ -316,13 +316,10 @@ void owl_function_aimwrite(char *to)
owl_function_make_outgoing_aim(owl_editwin_get_text(owl_global_get_typwin(&g)), to);
}

/* not yet */
#if 0
/* log it if we have logging turned on */
if (owl_global_is_logging(&g)) {
owl_log_outgoing(to, owl_editwin_get_text(owl_global_get_typwin(&g)));
owl_log_outgoing_aim(to, owl_editwin_get_text(owl_global_get_typwin(&g)));
}
#endif
}


Expand Down
147 changes: 109 additions & 38 deletions logging.c
Expand Up @@ -6,7 +6,7 @@

static const char fileIdent[] = "$Id$";

void owl_log_outgoing(char *to, char *text) {
void owl_log_outgoing_zephyr(char *to, char *text) {
FILE *file;
char filename[MAXPATHLEN], *logpath;
char *tobuff, *ptr;
Expand Down Expand Up @@ -53,36 +53,92 @@ void owl_log_outgoing(char *to, char *text) {
owl_free(tobuff);
}

void owl_log_outgoing_aim(char *to, char *text) {
FILE *file;
char filename[MAXPATHLEN], *logpath;
char *tobuff, *ptr;

tobuff=owl_sprintf("aim:%s", to);

/* expand ~ in path names */
logpath = owl_util_substitute(owl_global_get_logpath(&g), "~",
owl_global_get_homedir(&g));

snprintf(filename, MAXPATHLEN, "%s/%s", logpath, tobuff);
file=fopen(filename, "a");
if (!file) {
owl_function_makemsg("Unable to open file for outgoing logging");
owl_free(logpath);
return;
}
fprintf(file, "OUTGOING (owl): %s\n%s\n", tobuff, text);
if (text[strlen(text)-1]!='\n') {
fprintf(file, "\n");
}
fclose(file);

snprintf(filename, MAXPATHLEN, "%s/all", logpath);
owl_free(logpath);
file=fopen(filename, "a");
if (!file) {
owl_function_makemsg("Unable to open file for outgoing logging");
return;
}
fprintf(file, "OUTGOING (owl): %s\n%s\n", tobuff, text);
if (text[strlen(text)-1]!='\n') {
fprintf(file, "\n");
}
fclose(file);

owl_free(tobuff);
}

void owl_log_incoming(owl_message *m) {
FILE *file, *allfile;
char filename[MAXPATHLEN], allfilename[MAXPATHLEN], *logpath;
char *frombuff, *ptr, *from, *buff, *tmp;
int len, ch, i, personal;

/* we only do zephyrs right now */
if (!owl_message_is_type_zephyr(m)) return;

/* check for nolog */
if (!strcasecmp(owl_message_get_opcode(m), "nolog") ||
!strcasecmp(owl_message_get_instance(m), "nolog")) return;

if (owl_message_is_personal(m)) {
personal=1;
if (!owl_global_is_logging(&g)) return;
/* this is kind of a mess */
if (owl_message_is_type_zephyr(m)) {
if (owl_message_is_personal(m)) {
personal=1;
if (!owl_global_is_logging(&g)) return;
} else {
personal=0;
if (!owl_global_is_classlogging(&g)) return;
}
} else {
personal=0;
if (!owl_global_is_classlogging(&g)) return;
if (owl_message_is_private(m)) {
personal=1;
if (!owl_global_is_logging(&g)) return;
} else {
personal=0;
if (!owl_global_is_classlogging(&g)) return;
}
}

if (personal) {
from=frombuff=owl_strdup(owl_message_get_sender(m));
/* chop off a local realm */
ptr=strchr(frombuff, '@');
if (ptr && !strncmp(ptr+1, ZGetRealm(), strlen(ZGetRealm()))) {
*ptr='\0';
if (owl_message_is_type_zephyr(m)) {
/* chop off a local realm for personal zephyr messages */
if (personal) {
if (owl_message_is_type_zephyr(m)) {
from=frombuff=owl_strdup(owl_message_get_sender(m));
ptr=strchr(frombuff, '@');
if (ptr && !strncmp(ptr+1, ZGetRealm(), strlen(ZGetRealm()))) {
*ptr='\0';
}
}
} else {
/* we assume zephyr for now */
from=frombuff=owl_strdup(owl_message_get_class(m));
}
} else {
from=frombuff=owl_strdup(owl_message_get_class(m));
} else if (owl_message_is_type_aim(m)) {
/* we do not yet handle chat rooms */
from=frombuff=owl_sprintf("aim:%s", owl_message_get_sender(m));
}

/* check for malicious sender formats */
Expand Down Expand Up @@ -133,31 +189,46 @@ void owl_log_incoming(owl_message *m) {
}
}

tmp=short_zuser(owl_message_get_sender(m));

fprintf(file, "Class: %s Instance: %s", owl_message_get_class(m), owl_message_get_instance(m));
if (strcmp(owl_message_get_opcode(m), "")) fprintf(file, " Opcode: %s", owl_message_get_opcode(m));
fprintf(file, "\n");
fprintf(file, "Time: %s Host: %s\n", owl_message_get_timestr(m), owl_message_get_hostname(m));
ptr=owl_zephyr_get_zsig(owl_message_get_notice(m), &i);
buff=owl_malloc(i+10);
memcpy(buff, ptr, i);
buff[i]='\0';
fprintf(file, "From: %s <%s>\n\n", buff, tmp);
fprintf(file, "%s\n", owl_message_get_body(m));
/* write to the main file */
if (owl_message_is_type_zephyr(m)) {
tmp=short_zuser(owl_message_get_sender(m));
fprintf(file, "Class: %s Instance: %s", owl_message_get_class(m), owl_message_get_instance(m));
if (strcmp(owl_message_get_opcode(m), "")) fprintf(file, " Opcode: %s", owl_message_get_opcode(m));
fprintf(file, "\n");
fprintf(file, "Time: %s Host: %s\n", owl_message_get_timestr(m), owl_message_get_hostname(m));
ptr=owl_zephyr_get_zsig(owl_message_get_notice(m), &i);
buff=owl_malloc(i+10);
memcpy(buff, ptr, i);
buff[i]='\0';
fprintf(file, "From: %s <%s>\n\n", buff, tmp);
fprintf(file, "%s\n", owl_message_get_body(m));
} else if (owl_message_is_type_aim(m)) {
fprintf(file, "From: <%s> To: <%s>\n", owl_message_get_sender(m), owl_message_get_recipient(m));
fprintf(file, "Time: %s\n\n", owl_message_get_timestr(m));
fprintf(file, "%s\n\n", owl_message_get_body(m));
}
fclose(file);

/* if it's a personal message, also write to the 'all' file */
if (personal) {
fprintf(allfile, "Class: %s Instance: %s", owl_message_get_class(m), owl_message_get_instance(m));
if (strcmp(owl_message_get_opcode(m), "")) fprintf(allfile, " Opcode: %s", owl_message_get_opcode(m));
fprintf(allfile, "\n");
fprintf(allfile, "Time: %s Host: %s\n", owl_message_get_timestr(m), owl_message_get_hostname(m));
fprintf(allfile, "From: %s <%s>\n\n", buff, tmp);
fprintf(allfile, "%s\n", owl_message_get_body(m));
fclose(allfile);
if (owl_message_is_type_zephyr(m)) {
fprintf(allfile, "Class: %s Instance: %s", owl_message_get_class(m), owl_message_get_instance(m));
if (strcmp(owl_message_get_opcode(m), "")) fprintf(allfile, " Opcode: %s", owl_message_get_opcode(m));
fprintf(allfile, "\n");
fprintf(allfile, "Time: %s Host: %s\n", owl_message_get_timestr(m), owl_message_get_hostname(m));
fprintf(allfile, "From: %s <%s>\n\n", buff, tmp);
fprintf(allfile, "%s\n", owl_message_get_body(m));
fclose(allfile);
} else {
fprintf(file, "From: <%s> To: <%s>\n", owl_message_get_sender(m), owl_message_get_recipient(m));
fprintf(file, "Time: %s\n\n", owl_message_get_timestr(m));
fprintf(file, "%s\n\n", owl_message_get_body(m));
}
}

owl_free(tmp);
owl_free(buff);
if (owl_message_is_type_zephyr(m)) {
owl_free(tmp);
owl_free(buff);
}
owl_free(frombuff);
}
5 changes: 2 additions & 3 deletions owl.c
Expand Up @@ -296,7 +296,7 @@ int main(int argc, char **argv, char **env) {
}
}

/* grab incoming zephyrs */
/* Grab incoming messages. */
newmsgs=0;
zpendcount=0;
while(ZPending() || owl_global_messagequeue_pending(&g)) {
Expand Down Expand Up @@ -347,7 +347,7 @@ int main(int argc, char **argv, char **env) {
owl_view_consider_message(owl_global_get_current_view(&g), m);

/* do we need to autoreply? */
if (owl_global_is_zaway(&g)) {
if (owl_message_is_type_zephyr(m) && owl_global_is_zaway(&g)) {
owl_zephyr_zaway(m);
}

Expand All @@ -369,7 +369,6 @@ int main(int argc, char **argv, char **env) {
if (owl_global_is_burningears(&g) && owl_message_is_burningears(m)) {
char *buff;
buff = owl_sprintf("@i(Burning ears message on class %s)", owl_message_get_class(m));
/* owl_function_makemsg(buff); */
owl_function_adminmsg(buff, "");
owl_free(buff);
owl_function_beep();
Expand Down
3 changes: 2 additions & 1 deletion owl_prototypes.h
Expand Up @@ -566,7 +566,8 @@ extern void owl_list_free_all(owl_list *l, void (*elefree)(void *));
extern void owl_list_free_simple(owl_list *l);

/* -------------------------------- logging.c -------------------------------- */
extern void owl_log_outgoing(char *to, char *text);
extern void owl_log_outgoing_zephyr(char *to, char *text);
extern void owl_log_outgoing_aim(char *to, char *text);
extern void owl_log_incoming(owl_message *m);

/* -------------------------------- mainwin.c -------------------------------- */
Expand Down

0 comments on commit aac889a

Please sign in to comment.