/* PROTO */ void input_send_message(char *arg) { char *msg, *msg_strip, *temp, *sn; char *fullmsg; size_t fullmsg_len; int offset; if (conn->conn == NULL) return; temp = strchr(arg, ' '); if (temp == NULL) { printf("\n"); b_echostr_s(); printf("No message to send.\n"); return; } if (strlen(temp + 1) == 0) { printf("\nNo message to send.\n"); return; } if (conn->netspeak_filter) msg = undo_netspeak(temp + 1); else msg = temp + 1; sn = malloc(temp - arg + 1); sn[temp - arg] = 0; strncpy(sn, arg, temp - arg); fullmsg_len = strlen(msg) + strlen(SEND_FORMAT_BEGIN) + strlen(SEND_FORMAT_END) + 1; fullmsg = malloc(fullmsg_len + 1); snprintf(fullmsg, fullmsg_len, "%s%s%s", SEND_FORMAT_BEGIN, msg, SEND_FORMAT_END); imcomm_im_send_message(conn->conn, sn, fullmsg, 0); free(fullmsg); eraseline(); if (conn->timestamps) { addts(); putchar(' '); offset = 13; } else { offset = 2; } offset += strlen(sn) + 2; set_color(COLOR_OUTGOING_IM); printf("->%s", sn); set_color(0); printf(": "); msg_strip = strip_html(msg); wordwrap_print(msg_strip, offset); free(msg_strip); if (conn->lastsn != NULL) free(conn->lastsn); conn->lastsn = strdup(sn); log_event(EVENT_IMSEND, sn, msg); free(sn); if (conn->netspeak_filter) free(msg); }
/* 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(); }