PurpleWhiteboard *silcpurple_wb_init_ch(SilcPurple sg, SilcChannelEntry channel) { PurpleWhiteboard *wb; SilcPurpleWb wbs; wb = purple_whiteboard_get_session(sg->account, channel->channel_name); if (!wb) wb = purple_whiteboard_create(sg->account, channel->channel_name, 0); if (!wb) return NULL; if (!wb->proto_data) { wbs = silc_calloc(1, sizeof(*wbs)); if (!wbs) return NULL; wbs->type = 1; wbs->u.channel = channel; wbs->width = SILCPURPLE_WB_WIDTH; wbs->height = SILCPURPLE_WB_HEIGHT; wbs->brush_size = SILCPURPLE_WB_BRUSH_SMALL; wbs->brush_color = SILCPURPLE_WB_COLOR_BLACK; wb->proto_data = wbs; /* Start the whiteboard */ purple_whiteboard_start(wb); purple_whiteboard_clear(wb); } return wb; }
void silcpurple_wb_receive_ch(SilcClient client, SilcClientConnection conn, SilcClientEntry sender, SilcChannelEntry channel, SilcMessagePayload payload, SilcMessageFlags flags, const unsigned char *message, SilcUInt32 message_len) { SilcPurple sg; PurpleConnection *gc; PurpleWhiteboard *wb; SilcPurpleWb wbs; gc = client->application; sg = gc->proto_data; wb = purple_whiteboard_get_session(sg->account, channel->channel_name); if (!wb) { /* Ask user if they want to open the whiteboard */ silcpurple_wb_request(client, message, message_len, sender, channel); return; } wbs = wb->proto_data; silcpurple_wb_parse(wbs, wb, (unsigned char *)message, message_len); }
static int yahoo_doodle_accept_request(PurpleRequestAcceptData *data) { PurpleWhiteboard *wb; PurpleAccount *account; account = purple_connection_get_account(data->gc); wb = purple_whiteboard_get_session(account, data->from); /* If a session with the remote user doesn't exist */ if(wb == NULL) { doodle_session *ds; wb = purple_whiteboard_create(account, data->from, DOODLE_STATE_REQUESTED); ds = wb->proto_data; ds->imv_key = g_strdup(data->imv_key); yahoo_doodle_command_send_ready(data->gc, data->from, data->imv_key); } /* TODO Might be required to clear the canvas of an existing doodle * session at this point */ return 0; }
PurpleWhiteboard *silcpurple_wb_init(SilcPurple sg, SilcClientEntry client_entry) { SilcClientConnection conn; PurpleWhiteboard *wb; SilcPurpleWb wbs; conn = sg->conn; wb = purple_whiteboard_get_session(sg->account, client_entry->nickname); if (!wb) wb = purple_whiteboard_create(sg->account, client_entry->nickname, 0); if (!wb) return NULL; if (!wb->proto_data) { wbs = silc_calloc(1, sizeof(*wbs)); if (!wbs) return NULL; wbs->type = 0; wbs->u.client = client_entry; wbs->width = SILCPURPLE_WB_WIDTH; wbs->height = SILCPURPLE_WB_HEIGHT; wbs->brush_size = SILCPURPLE_WB_BRUSH_SMALL; wbs->brush_color = SILCPURPLE_WB_COLOR_BLACK; wb->proto_data = wbs; /* Start the whiteboard */ purple_whiteboard_start(wb); purple_whiteboard_clear(wb); } return wb; }
void yahoo_doodle_initiate(PurpleConnection *gc, const char *name) { PurpleAccount *account; char *to = (char*)name; PurpleWhiteboard *wb; g_return_if_fail(gc); g_return_if_fail(name); account = purple_connection_get_account(gc); wb = purple_whiteboard_get_session(account, to); if(wb == NULL) { /* Insert this 'session' in the list. At this point, it's only a * requested session. */ wb = purple_whiteboard_create(account, to, DOODLE_STATE_REQUESTING); } /* NOTE Perhaps some careful handling of remote assumed established * sessions */ yahoo_doodle_command_send_ready(gc, to, DOODLE_IMV_KEY); yahoo_doodle_command_send_request(gc, to, DOODLE_IMV_KEY); }
static void yahoo_doodle_command_got_draw(PurpleConnection *gc, const char *from, const char *message) { PurpleAccount *account; PurpleWhiteboard *wb; char **tokens; int i; GList *d_list = NULL; /* a local list of drawing info */ g_return_if_fail(message != NULL); purple_debug_info("yahoo", "doodle: Got Draw (%s)\n", from); purple_debug_info("yahoo", "doodle: Draw message: %s\n", message); account = purple_connection_get_account(gc); /* Only handle this if local client requested Doodle session (else local * client would have sent one) */ wb = purple_whiteboard_get_session(account, from); if(wb == NULL) return; /* TODO Functionalize * Convert drawing packet message to an integer list */ /* Check to see if the message begans and ends with quotes */ if((message[0] != '\"') || (message[strlen(message) - 1] != '\"')) return; /* Ignore the inital quotation mark. */ message += 1; tokens = g_strsplit(message, ",", 0); /* Traverse and extract all integers divided by commas */ for (i = 0; tokens[i] != NULL; i++) { int last = strlen(tokens[i]) - 1; if (tokens[i][last] == '"') tokens[i][last] = '\0'; d_list = g_list_prepend(d_list, GINT_TO_POINTER(atoi(tokens[i]))); } d_list = g_list_reverse(d_list); g_strfreev(tokens); yahoo_doodle_draw_stroke(wb, d_list); /* goodle_doodle_session_set_canvas_as_icon(ds); */ g_list_free(d_list); }
static void yahoo_doodle_command_got_ready(PurpleConnection *gc, const char *from, const char *imv_key) { PurpleAccount *account; PurpleWhiteboard *wb; purple_debug_info("yahoo", "doodle: Got Ready(%s)\n", from); account = purple_connection_get_account(gc); /* Only handle this if local client requested Doodle session (else local * client would have sent one) */ wb = purple_whiteboard_get_session(account, from); if(wb == NULL) return; if(wb->state == DOODLE_STATE_REQUESTING) { doodle_session *ds = wb->proto_data; purple_whiteboard_start(wb); wb->state = DOODLE_STATE_ESTABLISHED; yahoo_doodle_command_send_confirm(gc, from, imv_key); /* Let's steal the imv_key and reuse it */ g_free(ds->imv_key); ds->imv_key = g_strdup(imv_key); } else if(wb->state == DOODLE_STATE_ESTABLISHED) { /* TODO Ask whether to save picture too */ purple_whiteboard_clear(wb); } /* NOTE Not sure about this... I am trying to handle if the remote user * already thinks we're in a session with them (when their chat message * contains the doodle imv key) */ else if(wb->state == DOODLE_STATE_REQUESTED) { /* purple_whiteboard_start(wb); */ yahoo_doodle_command_send_ready(gc, from, imv_key); } }
static void yahoo_doodle_command_got_request(PurpleConnection *gc, const char *from, const char *imv_key) { PurpleAccount *account; PurpleWhiteboard *wb; purple_debug_info("yahoo", "doodle: Got Request (%s)\n", from); account = purple_connection_get_account(gc); /* Only handle this if local client requested Doodle session (else local * client would have sent one) */ wb = purple_whiteboard_get_session(account, from); /* If a session with the remote user doesn't exist */ if(wb == NULL) { doodle_session *ds; /* Ask user if they wish to accept the request for a doodle session */ /* TODO Ask local user to start Doodle session with remote user */ /* NOTE This if/else statement won't work right--must use dialog * results */ /* char dialog_message[64]; g_sprintf(dialog_message, "%s is requesting to start a Doodle session with you.", from); purple_notify_message(NULL, PURPLE_NOTIFY_MSG_INFO, "Doodle", dialog_message, NULL, NULL, NULL); */ wb = purple_whiteboard_new(account, from, DOODLE_STATE_REQUESTED); ds = purple_whiteboard_get_protocol_data(wb); ds->imv_key = g_strdup(imv_key); yahoo_doodle_command_send_ready(gc, from, imv_key); } /* TODO Might be required to clear the canvas of an existing doodle * session at this point */ }
static void yahoo_doodle_command_got_confirm(PurpleConnection *gc, const char *from) { PurpleAccount *account; PurpleWhiteboard *wb; purple_debug_info("yahoo", "doodle: Got Confirm (%s)\n", from); /* Get the doodle session */ account = purple_connection_get_account(gc); /* Only handle this if local client requested Doodle session (else local * client would have sent one) */ wb = purple_whiteboard_get_session(account, from); if(wb == NULL) return; /* TODO Combine the following IF's? */ /* Check if we requested a doodle session */ /*if(wb->state == DOODLE_STATE_REQUESTING) { wb->state = DOODLE_STATE_ESTABLISHED; purple_whiteboard_start(wb); yahoo_doodle_command_send_confirm(gc, from); }*/ /* Check if we accepted a request for a doodle session */ if(wb->state == DOODLE_STATE_REQUESTED) { wb->state = DOODLE_STATE_ESTABLISHED; purple_whiteboard_start(wb); } }
void yahoo_doodle_command_got_shutdown(PurpleConnection *gc, const char *from) { PurpleAccount *account; PurpleWhiteboard *wb; g_return_if_fail(from != NULL); purple_debug_info("yahoo", "doodle: Got Shutdown (%s)\n", from); account = purple_connection_get_account(gc); /* Only handle this if local client requested Doodle session (else local * client would have sent one) */ wb = purple_whiteboard_get_session(account, from); if(wb == NULL) return; /* TODO Ask if user wants to save picture before the session is closed */ wb->state = DOODLE_STATE_CANCELLED; purple_whiteboard_destroy(wb); }
static void yahoo_doodle_command_got_clear(PurpleConnection *gc, const char *from) { PurpleAccount *account; PurpleWhiteboard *wb; purple_debug_info("yahoo", "doodle: Got Clear (%s)\n", from); account = purple_connection_get_account(gc); /* Only handle this if local client requested Doodle session (else local * client would have sent one) */ wb = purple_whiteboard_get_session(account, from); if(wb == NULL) return; if(wb->state == DOODLE_STATE_ESTABLISHED) { /* TODO Ask user whether to save the image before clearing it */ purple_whiteboard_clear(wb); } }