Пример #1
0
/* PROTO */
void
input_set_away(char *arg)
{
	if (conn->conn == NULL)
		return;

	if (conn->isaway) {
		conn->isaway = 0;
		free(conn->awaymsg);
		conn->awaymsg = NULL;

		imcomm_set_unaway(conn->conn);
		printf("\n");
		b_echostr_s();
		printf("You are no longer away.\n");
		return;
	} else {
		printf("\n");
		b_echostr_s();
		printf("You are now away: %s\n", arg);
		conn->isaway = 1;
		imcomm_set_away(conn->conn, arg);
		conn->awaymsg = strdup(arg);
		return;
	}
}
Пример #2
0
void input_manual_otr_verify(char *arg) {
    char *msg, *temp, *sn;

    if (conn->conn == NULL)
        return;

    printf("\n");
    sn = arg;

    struct BuddyList *buddy = find_buddy(sn);
    if (buddy) {
        if (buddy->otr_context) {
            char human_hash[OTRL_PRIVKEY_FPRINT_HUMAN_LEN];
            otrl_privkey_hash_to_human(human_hash,
                                       buddy->otr_context->active_fingerprint-> fingerprint);

            b_echostr_s();
            otrl_context_set_trust(
                buddy->otr_context->active_fingerprint,
                "verified");
            printf("[OTR] Manually trusting fingerprint %s from %s\n", human_hash, sn);
        }
    }
    b_echostr_s();
    printf("[OTR] No OTR context found for %s\n", sn);
}
Пример #3
0
void input_send_smp_request(char *arg) {
    char *msg, *temp, *sn;

    if (conn->conn == NULL)
        return;

    printf("\n");
    temp = strchr(arg, ' ');

    if (temp == NULL) {
        b_echostr_s();
        printf("No request to send.\n");
        return;
    }
    if (strlen(temp + 1) == 0) {
        b_echostr_s();
        printf("No request to send.\n");
        return;
    }
    msg = temp + 1;

    sn = malloc(temp - arg + 1);
    sn[temp - arg] = 0;
    strncpy(sn, arg, temp - arg);

    struct BuddyList *buddy = find_buddy(sn);
    if (buddy) {
        if (buddy->otr_context) {
            b_echostr_s();
        }
    }
    b_echostr_s();
    printf("[OTR] No OTR context found for %s\n", sn);
}
Пример #4
0
/* PROTO */
void
buddy_profile(void *c, const char *who, const char *msg)
{
	char           *ptext;
	long            days, hours, minutes;
	struct BuddyList *trav;
	char           *sname;
#ifdef DUMP_PROFILE
	FILE           *profile_dump;
#endif

	sname = simplify_sn(who);
	eraseline();

	for (trav = buddylist; trav; trav = trav->next) {
		if (strcmp(trav->sn, sname) == 0) {
			if (trav->idle) {
				b_echostr_s();
				printf("[%s] Idle: ", who);
				days = trav->idletime / 1440;
				hours = (trav->idletime % 1440) / 60;
				minutes = trav->idletime % 60;
				if (days > 0)
					printf("%ld days, ", days);
				if (hours > 0)
					printf("%ld hour%s, ", hours, (hours != 1 ? "s" : ""));

				printf("%ld minute%s\n", minutes,
				       (minutes != 1 ? "s" : ""));
				break;
			}
		}
	}

	b_echostr_s();
	printf("[%s] Info:\n", who);

	free(sname);

	ptext = strip_html(msg);
	prettyprint_echostr(ptext, PROFILE_ECHOSTR);

	free(ptext);

#ifdef DUMP_PROFILE
	if ((profile_dump = fopen(PROFILE_DUMP_PATH, "w")) != NULL) {
		fprintf(profile_dump, "%s", msg);
		fclose(profile_dump);
	}
#endif

	show_prompt();
}
Пример #5
0
/* PROTO */
void
input_set_invisible(char *arg)
{
	if (conn->isinvisible) {
		imcomm_set_invisible(conn->conn, 0);
		conn->isinvisible = 0;
		printf("\n");
		b_echostr_s();
		printf("You are now visible.\n");
	} else {
		imcomm_set_invisible(conn->conn, 1);
		conn->isinvisible = 1;
		printf("\n");
		b_echostr_s();
		printf("You are now invisible.\n");
	}
}
Пример #6
0
void input_show_otr(char *arg) {
    if (conn->conn == NULL)
        return;

    printf("\n");
    if (strlen(arg) <= 0) {
        check_key_gen_state();
        return;
    } else {
        b_echostr_s();
        struct BuddyList *buddy = find_buddy(arg);
        if (buddy) {
            printf("[OTR] status for %s\n", arg);
            printf("  local otr: ");
            switch (buddy->otr) {
            case -1:
                printf("disabled\n");
                break;
            case 0:
                printf("inactive\n");
                break;
            case 1:
                printf("active\n");
                break;
            default:
                printf("error\n");
                break;
            }
            if (buddy->otr_context) {
                if (buddy->otr_context->active_fingerprint) {
                    char human_hash[OTRL_PRIVKEY_FPRINT_HUMAN_LEN];
                    otrl_privkey_hash_to_human(human_hash,
                                               buddy->otr_context->active_fingerprint->fingerprint);
                    int ret = otrl_context_is_fingerprint_trusted(buddy->otr_context->active_fingerprint);
                    printf("  fingerprint: %s (%s)\n", human_hash, ret ? "trusted" : "untrusted");
                }
                printf("  context state: ");
                switch (buddy->otr_context->msgstate) {
                case OTRL_MSGSTATE_ENCRYPTED:
                    printf("encrypted\n");
                    break;
                case OTRL_MSGSTATE_PLAINTEXT:
                    printf("plaintext\n");
                    break;
                case OTRL_MSGSTATE_FINISHED:
                    printf("finished\n");
                    break;
                default:
                    printf("error\n");
                    break;
                }
            }
        } else {
            printf("[OTR] buddy not found %s\n", arg);
        }
        return;
    }
}
Пример #7
0
/* PROTO */
void
input_set_predefaway(char *arg)
{
	int             msgnum = 0, count;
	struct AwayMessages *tv;

	if (conn->conn == NULL)
		return;

	if (conn->awaymsgs == NULL) {
		printf("\n");
		b_echostr_s();
		printf("No away messages defined.\n");
		return;
	}
	if (arg[0] == 0) {
		printf("\n");
		b_echostr_s();
		printf("Defined messages:");
		for (tv = conn->awaymsgs, count = 0; tv != NULL;
		     tv = tv->next, count++) {
			printf("\n");
			b_echostr_s();
			printf("[%02d] \"%s\"", count, tv->message);
		}
	} else {
		msgnum = atoi(arg);
		for (tv = conn->awaymsgs, count = 0; tv != NULL;
		     tv = tv->next, count++) {
			if (count == msgnum) {
				printf("\n");
				b_echostr_s();
				printf("You are now away: %s", tv->message);
				conn->isaway = 1;
				imcomm_set_away(conn->conn, tv->message);
				conn->awaymsg = strdup(tv->message);
				break;
			}
		}
	}

	printf("\n");
}
Пример #8
0
/* PROTO */
void
input_add_buddy(char *arg)
{
	if (conn->conn == NULL)
		return;

	imcomm_im_add_buddy(conn->conn, arg);

	printf("\n");
	b_echostr_s();
	printf("Added buddy %s.\n", arg);
}
Пример #9
0
/* PROTO */
void
input_reload_profile(char *arg)
{
	if (conn->conn == NULL)
		return;

	printf("\n");
	b_echostr_s();

	printf("Reloading away messages and profile.\n");

	set_profile(conn->conn);
	read_away_messages();
}
Пример #10
0
/* PROTO */
void
input_show_buddies(char *arg)
{
	printf("\n");
	b_echostr_s();
	addts();
	printf(" %d buddies online:\n", conn->buddiesonline);

	if (arg[0] == 'f')
		display_buddylist();
	else
		display_buddylist_sorted();

}
Пример #11
0
/* PROTO */
void
input_delete_buddy(char *arg)
{
	if (conn->conn == NULL)
		return;

	imcomm_im_remove_buddy(conn->conn, arg);

	printf("\n");
	b_echostr_s();
	printf("Removed buddy %s.\n", arg);

	remove_from_list(arg);
}
Пример #12
0
void input_send_smp_response(char *arg) {
    char *msg, *temp, *sn;

    if (conn->conn == NULL)
        return;

    printf("\n");
    temp = strchr(arg, ' ');

    if (temp == NULL) {
        b_echostr_s();
        printf("No message to send.\n");
        return;
    }
    if (strlen(temp + 1) == 0) {
        b_echostr_s();
        printf("No message to send.\n");
        return;
    }
    msg = temp + 1;

    sn = malloc(temp - arg + 1);
    sn[temp - arg] = 0;
    strncpy(sn, arg, temp - arg);

    struct BuddyList *buddy = find_buddy(sn);
    if (buddy) {
        if (buddy->otr_context) {
            b_echostr_s();
            printf("[OTR] Responding to %s\n", sn);
            otrl_message_respond_smp(userstate, &ui_ops, NULL, buddy->otr_context, msg, strlen(msg));
            return;
        }
    }
    b_echostr_s();
    printf("[OTR] No OTR context found for %s\n", sn);
}
Пример #13
0
/* PROTO */
void
buddy_awaymsg(void *c, const char *who, const char *msg)
{
	char           *ptext;

	eraseline();
	b_echostr_s();
	printf("[%s] Away: ", who);
	ptext = strip_html(msg);
	prettyprint(ptext, 12 + strlen(who));

	if (ptext[0] == 0)
		printf("\n");

	free(ptext);
	show_prompt();
}
Пример #14
0
void input_stop_otr(char *arg) {
    if (conn->conn == NULL)
        return;

    printf("\n");
    b_echostr_s();
    struct BuddyList *buddy = find_buddy(arg);
    if (buddy) {
        if (buddy->otr == 1) {
            otrl_message_disconnect_all_instances(userstate, &ui_ops, NULL,
                                                  conn->username, otr_proto, buddy->sn);
            buddy->otr = 0;
            printf("[OTR] Ending OTR session with %s\n", buddy->sn);
        } else {
            printf("[OTR] No OTR session found with %s\n", buddy->sn);
        }
    } else {
        printf("[OTR] Buddy not found: %s\n", arg);
    }
}
Пример #15
0
/* 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();
}
Пример #16
0
/* PROTO */
void
input_reconnect(char *arg)
{
	struct ConnPtr *temp, *trav;

	eraseline();
	b_echostr_s();

	if (conn->timestamps) {
		addts();
		putchar(' ');
	}
	if (arg[0] != '\0') {
		if (conn->username) {
			free(conn->username);
			conn->username = NULL;
		}
		if (conn->password) {
			free(conn->password);
			conn->password = NULL;
		}
		printf("Reconnecting as %s...\n", arg);

		conn->username = strdup(arg);
		b_getpassword();
	} else {
		printf("Reconnecting...\n");
	}

	if (conn->conn != NULL) {

		delete_buddylist(buddylist);

		buddylist = NULL;
		conn->buddiesonline = 0;

		if (conn->clist->conn == conn->conn) {
			temp = conn->clist;
			conn->clist = conn->clist->next;
			if (temp->username)
				free(temp->username);

			free(temp);
		} else {
			for (trav = conn->clist; trav->next;) {
				if (trav->next->conn == conn->conn) {
					temp = trav->next;
					trav->next = trav->next->next;

					if (temp->username)
						free(temp->username);

					free(temp);
				}
			}
		}

		imcomm_delete_handle_now(conn->conn);

		conn->conn = NULL;
	}
	create_new_connection();

	if (conn->proxytype != PROXY_TYPE_NONE) {
		imcomm_set_proxy(conn->clist->conn, conn->proxytype, conn->proxy,
				 (uint16_t) conn->proxyport);
	}
	if (conn->oscarport != 0) {
		imcomm_set_oscar_port(conn->clist->conn, conn->oscarport);
	}
	imcomm_im_signon(conn->clist->conn, conn->username, conn->password);
	conn->conn = conn->clist->conn;

	if (conn->isaway)
		imcomm_set_away(conn->conn, conn->awaymsg);
}
Пример #17
0
/* 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();
}
Пример #18
0
/* 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);
}
Пример #19
0
/* PROTO */
void
input_paste(char *arg)
{
	char           *sn, *sendbuf, *pbuf;
	size_t          sendbuflen;
	ssize_t         pbuflen;
	uint16_t        maxmsgsize = imcomm_get_max_message_size(conn->conn);

	if (conn->conn == NULL)
		return;

	sn = arg;

	if (sn[0] == 0) {
		printf("\n");
		b_echostr_s();
		printf("No recipient specified.\n");
		return;
	}
	printf("\n");
	b_echostr_s();
	printf("Pasting to %s.\n", sn);
	b_echostr_s();
	printf("Enter '.' on a line by itself to send," " Ctrl-X to cancel.");

	pbuf = malloc(maxmsgsize + 1);
	sendbuf = malloc(maxmsgsize + 1);
	memset(sendbuf, 0, maxmsgsize + 1);

	sendbuflen = 0;

	/*
         * using fgets() produced strange results. had to resort to writing
         * my own input stuff.
         */

	while (1) {
		printf("\n-> ");
		fflush(stdout);

		pbuflen = bsf_getline(pbuf, maxmsgsize - 5);

		if (pbuflen == -1) {
			free(pbuf);
			free(sendbuf);
			printf("\n");
			return;
		}
		if (pbuflen == 1 && pbuf[0] == '.') {
			if (sendbuflen > 0) {
				imcomm_im_send_message(conn->conn, sn, sendbuf, 0);
			}
			break;
		}
		/*
	         * +4 is for "<br>"
	         */

		if (sendbuflen + pbuflen + 4 > maxmsgsize) {
			imcomm_im_send_message(conn->conn, sn, sendbuf, 0);
			memset(sendbuf, 0, maxmsgsize + 1);

			memcpy(sendbuf, pbuf, pbuflen);
			sendbuflen = pbuflen;
		} else {
#ifdef __OpenBSD__
			if (sendbuflen != 0) {
				strlcat(sendbuf, "<br>", maxmsgsize + 1);
				pbuflen += 4;
			}
			strlcat(sendbuf, pbuf, maxmsgsize + 1);
#else
			if (sendbuflen != 0) {
				strcat(sendbuf, "<br>");
				pbuflen += 4;
			}
			strcat(sendbuf, pbuf);
#endif
			sendbuflen += pbuflen;
		}
	}

	printf("\n");

	free(sendbuf);
	free(pbuf);
}