/* PROTO */ void getmessage(void *c, const char *who, const int automessage, const char *message) { const char *msgin = message; char *msg = NULL, *tempmsg = NULL; char *sname; struct Waiting *wtemp, *wptr = NULL; int offset, foundWaiting = 0; int otr_message = 0; if (conn->otr) { struct BuddyList *buddy = NULL; buddy = find_buddy(who); if (buddy) { if (buddy->otr != -1) { char *newmsg; int ret = otrl_message_receiving(userstate, &ui_ops, NULL, conn->username, otr_proto, buddy->sn, msgin, &newmsg, NULL, &buddy->otr_context, NULL, NULL); if (ret) { #ifdef DEBUG b_echostr_s(); printf("[OTR] debug: internal msg %s\n", msgin); #endif return; } else { if (newmsg) { msgin = strdup(newmsg); otrl_message_free(newmsg); if (buddy->otr_context->msgstate == OTRL_MSGSTATE_ENCRYPTED) otr_message = 1; } } } } } tempmsg = strip_html(msgin); if (tempmsg == NULL) return; if (strlen(tempmsg) == 0) { free(tempmsg); return; } if (conn->netspeak_filter) { msg = undo_netspeak(tempmsg); free(tempmsg); } else { msg = tempmsg; } if (msg == NULL) return; if (strlen(msg) == 0) { free(msg); return; } if (conn->istyping == 0) { if (conn->lastsn != NULL) free(conn->lastsn); conn->lastsn = simplify_sn(who); } sname = simplify_sn(who); if (waiting == NULL) { waiting = malloc(sizeof(struct Waiting)); wptr = waiting; } else { for (wtemp = waiting; wtemp != NULL; wtemp = wtemp->next) if (imcomm_compare_nicks(c, wtemp->sn, who)) { foundWaiting = 1; wptr = wtemp; break; } if (!foundWaiting) { for (wtemp = waiting; wtemp->next != NULL; wtemp = wtemp->next); wtemp->next = malloc(sizeof(struct Waiting)); wptr = wtemp->next; } } if (!foundWaiting) { wptr->sn = strdup(who); wptr->next = NULL; if (conn->isaway && !automessage) { if ((conn->respond_idle_only && conn->isidle) || (!conn->respond_idle_only)) { imcomm_im_send_message(c, who, conn->awaymsg, 1); eraseline(); b_echostr_s(); if (conn->timestamps) { addts(); putchar(' '); } printf("Sent auto-response to %s.\n", who); show_prompt(); } } } #ifdef MESSAGE_QUEUE if (conn->isaway) wptr->mqueue = addToMQueue(wptr->mqueue, msg, who); #endif /* MESSAGE_QUEUE */ eraseline(); if (conn->bell_on_incoming) putchar('\a'); if (conn->timestamps) { addts(); putchar(' '); offset = 11; } else { offset = 0; } offset += strlen(who) + 2; if (automessage) { set_color(COLOR_AUTORESPONSE); printf("*AUTO RESPONSE* "); set_color(0); offset += 16; } set_color(COLOR_INCOMING_IM); if (!otr_message) printf("%s", who); else { offset += 5; printf("(otr)%s", who); } set_color(0); printf(": "); wordwrap_print(msg, offset); if (automessage) log_event(EVENT_IM_AUTORESPONSE, sname, msg); else log_event(EVENT_IM, sname, msg); free(msg); free(sname); show_prompt(); }
/* PROTO */ void getmessage(void *c, const char *who, const int automessage, const char *message) { char *msg, *tempmsg; char *sname; struct Waiting *wtemp, *wptr = NULL; int offset, foundWaiting = 0; tempmsg = strip_html(message); if (tempmsg == NULL) return; if (strlen(tempmsg) == 0) { free(tempmsg); return; } if (conn->netspeak_filter) { msg = undo_netspeak(tempmsg); free(tempmsg); } else { msg = tempmsg; } if (msg == NULL) return; if (strlen(msg) == 0) { free(msg); return; } if (conn->istyping == 0) { if (conn->lastsn != NULL) free(conn->lastsn); conn->lastsn = simplify_sn(who); } sname = simplify_sn(who); if (waiting == NULL) { waiting = malloc(sizeof(struct Waiting)); wptr = waiting; } else { for (wtemp = waiting; wtemp != NULL; wtemp = wtemp->next) if (imcomm_compare_nicks(c, wtemp->sn, who)) { foundWaiting = 1; wptr = wtemp; break; } if (!foundWaiting) { for (wtemp = waiting; wtemp->next != NULL; wtemp = wtemp->next); wtemp->next = malloc(sizeof(struct Waiting)); wptr = wtemp->next; } } if (!foundWaiting) { wptr->sn = strdup(who); wptr->next = NULL; if (conn->isaway && !automessage) { if ((conn->respond_idle_only && conn->isidle) || (!conn->respond_idle_only)) { imcomm_im_send_message(c, who, conn->awaymsg, 1); eraseline(); b_echostr_s(); if (conn->timestamps) { addts(); putchar(' '); } printf("Sent auto-response to %s.\n", who); show_prompt(); } } } #ifdef MESSAGE_QUEUE if (conn->isaway) wptr->mqueue = addToMQueue(wptr->mqueue, msg, who); #endif /* MESSAGE_QUEUE */ eraseline(); if (conn->bell_on_incoming) putchar('\a'); if (conn->timestamps) { addts(); putchar(' '); offset = 11; } else { offset = 0; } offset += strlen(who) + 2; if (automessage) { set_color(COLOR_AUTORESPONSE); printf("*AUTO RESPONSE* "); set_color(0); offset += 16; } set_color(COLOR_INCOMING_IM); printf("%s", who); set_color(0); printf(": "); wordwrap_print(msg, offset); if (automessage) log_event(EVENT_IM_AUTORESPONSE, sname, msg); else log_event(EVENT_IM, sname, msg); free(msg); free(sname); show_prompt(); }