示例#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
文件: AIM.cpp 项目: Barrett17/Caya
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;
}