Example #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;
	}
}
Example #2
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");
}
Example #3
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);
}
Example #4
0
status_t
AIMProtocol::Process(BMessage* msg)
{
	switch (msg->what) {
		case IM_MESSAGE: {
			int32 im_what = 0;
 
			msg->FindInt32("im_what", &im_what);

			switch (im_what) {
				case IM_SET_OWN_STATUS: {
					int32 status = msg->FindInt32("status");

					BString status_msg("");
					msg->FindString("message", &status_msg);
					char* smsg = strdup(status_msg.String());

					switch (status) {
						case CAYA_ONLINE:
							if (!fOnline)
								A_LogOn();
							else
								imcomm_set_unaway(fIMCommHandle);
							break;
						case CAYA_AWAY:
							imcomm_set_away(fIMCommHandle, smsg);
							break;
						case CAYA_CUSTOM_STATUS:
							//imcomm_set_away(fIMCommHandle, smsg);
							//UnsupportedOperation(); ?
							break;
						case CAYA_DO_NOT_DISTURB:
							imcomm_set_away(fIMCommHandle, smsg);
							//UnsupportedOperation(); ?
							break;
						case CAYA_OFFLINE:
							LogOff();
							break;
						default:
							break;
					}

					free(smsg);

					BMessage msg(IM_MESSAGE);
					msg.AddInt32("im_what", IM_STATUS_SET);
					msg.AddString("protocol", kProtocolSignature);
					msg.AddInt32("status", status);
					gServerMsgr->SendMessage(&msg);
					break;
				}
				case IM_SET_NICKNAME:
					UnsupportedOperation();
					break;
				case IM_SEND_MESSAGE: {
					const char* buddy = msg->FindString("id");
					const char* sms = msg->FindString("body");
					imcomm_im_send_message(fIMCommHandle, buddy, sms, 0);

					// XXX send a message to let caya know we did it
					BMessage msg(IM_MESSAGE);
					msg.AddInt32("im_what", IM_MESSAGE_SENT);
					msg.AddString("protocol", kProtocolSignature);
					msg.AddString("id", buddy);
					msg.AddString("body", sms);

					gServerMsgr->SendMessage(&msg);
					break;
				}
				case IM_REGISTER_CONTACTS: {
					const char* buddy = NULL;
					char *buddy_copy;

					for (int32 i = 0; msg->FindString("id", i, &buddy) == B_OK; i++) {
						buddy_copy = strdup(buddy);
						imcomm_im_add_buddy(fIMCommHandle, buddy_copy);
						free(buddy_copy);
					}
					break;
				}
				case IM_UNREGISTER_CONTACTS: {
					const char* buddy = NULL;

					for (int32 i = 0; msg->FindString("id", i, &buddy) == B_OK; i++)
						imcomm_im_remove_buddy(fIMCommHandle, buddy);
					break;
				}
				case IM_USER_STARTED_TYPING:
					//UnsupportedOperation();
					break;
				case IM_USER_STOPPED_TYPING:
					//UnsupportedOperation();
					break;
				case IM_GET_CONTACT_INFO:
					UnsupportedOperation();
					break;
				case IM_ASK_AUTHORIZATION:
				case IM_AUTHORIZATION_RECEIVED:
				case IM_AUTHORIZATION_REQUEST:
				case IM_AUTHORIZATION_RESPONSE:
				case IM_CONTACT_AUTHORIZED:
					UnsupportedOperation();
					break;
				case IM_SPECIAL_TO_PROTOCOL:
						UnsupportedOperation();
					break;
				default:
					return B_ERROR;
			}
			break;
		}
		default:
			// We don't handle this what code
			return B_ERROR;
	}

    return B_OK;
}