void send_connect_request_message() { PurpleAccount* account=purple_buddy_get_account(PURPLE_BUDDY(client_node)); PurpleConversation *conv=purple_conversation_new (PURPLE_CONV_TYPE_IM, account, purple_buddy_get_name (PURPLE_BUDDY(client_node))); PurpleConvIm *im = purple_conversation_get_im_data(conv); const char* remote_message="sharedesk|request_connection|$SERVER_IP|$PORT|" "\nPlease start a vnc connection. Sample command line:" "\n$CLIENT_CMD" "\n|||"; GRegex *port_regex1=g_regex_new("[$]CLIENT_CMD",0,0,NULL); char* msg1=g_regex_replace(port_regex1,remote_message,-1,0,purple_prefs_get_string(PREF_CLIENT_COMMAND_LINE),0,NULL); GRegex *port_regex2=g_regex_new("[$]PORT",0,0,NULL); char* msg2=g_regex_replace(port_regex2,msg1,-1,0,purple_value_get_string(port),0,NULL); GRegex *port_regex3=g_regex_new("[$]SERVER_IP",0,0,NULL); char* msg3=g_regex_replace(port_regex3,msg2,-1,0,purple_value_get_string(server_ip),0,NULL); purple_conv_im_send(im, msg3); g_free(msg3); g_free(msg2); g_free(msg1); g_free(port_regex1); g_free(port_regex2); g_free(port_regex3); }
/* ------------------ * send public key to other person in conversation * ------------------ */ static void menu_action_sendkey_cb(PurpleConversation *conv, void* data) { // check if user selected a main key const char* fpr = purple_prefs_get_string(PREF_MY_KEY); if (fpr == NULL) fpr = ""; if (strcmp(fpr,"") != 0) { char* key = NULL; // get key key = get_key_armored(fpr); if (key != NULL) { // send key PurpleConvIm* im_data = purple_conversation_get_im_data(conv); if (im_data != NULL) { purple_conv_im_send_with_flags(im_data,key,PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_INVISIBLE | PURPLE_MESSAGE_RAW ); purple_conversation_write(conv,"","Public key sent!",PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG,time(NULL)); } } }else { purple_conversation_write(conv,"","You haven't selected a personal key yet.",PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG,time(NULL)); } }
//Callback function to send autoreply when buzz is received static void buzz_cb(PurpleAccount *account, char *who, PurpleConversation *conv, guint type) { PurpleConvIm *im = purple_conversation_get_im_data(conv); const char *msg = purple_prefs_get_string(REPLY_MSG); purple_conv_im_send(im, msg); }
static void received_im_msg(PurpleAccount *account, char *sender, char *message, PurpleConversation *conv, PurpleMessageFlags flags) { if (conv==NULL) { conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, sender); } printf("(%s) %s (%s): %s\n", purple_utf8_strftime("%H:%M:%S", NULL), sender, purple_conversation_get_name(conv), message); purple_conv_im_send(purple_conversation_get_im_data(conv), "THE GAME"); }
static int purple_buddy_msg( struct im_connection *ic, char *who, char *message, int flags ) { PurpleConversation *conv; if( ( conv = purple_find_conversation_with_account( PURPLE_CONV_TYPE_IM, who, ic->proto_data ) ) == NULL ) { conv = purple_conversation_new( PURPLE_CONV_TYPE_IM, ic->proto_data, who ); } purple_conv_im_send( purple_conversation_get_im_data( conv ), message ); return 1; }
void run_lua(PurpleConversation *conv, msg_metadata_t msg) { lua_State *L; L = luaL_newstate(); luaL_openlibs(L); char lua_path[50]; get_plugin_lua(lua_path); if (luaL_loadfile(L, lua_path)) { lua_close(L); return; } if (lua_pcall(L, 0, 0, 0)) { lua_close(L); return; } lua_getglobal(L, "autorespond"); lua_newtable(L); push_val_to_lua_t(L, "text", msg.text); push_val_to_lua_t(L, "protocol_id", msg.protocol_id); push_val_to_lua_t(L, "remote_from_group", msg.remote_from_group); push_val_to_lua_t(L, "remote_username", msg.remote_username); push_val_to_lua_t(L, "remote_alias", msg.remote_alias); push_val_to_lua_t(L, "remote_status_id", msg.remote_status_id); push_val_to_lua_t(L, "remote_status_msg", msg.remote_status_msg); push_val_to_lua_t(L, "local_username", msg.local_username); push_val_to_lua_t(L, "local_alias", msg.local_alias); push_val_to_lua_t(L, "local_status_id", msg.local_status_id); push_val_to_lua_t(L, "local_status_msg", msg.local_status_msg); if (lua_pcall(L, 1, 1, 0)) /* Run function, !!! NRETURN=1 !!! */ { lua_close(L); return; } const char* resp = lua_tostring(L, -1); if(resp) { purple_conv_im_send(purple_conversation_get_im_data(conv), resp); } lua_close(L); }
static void pipe_handle_message(struct purple_message *message) { LM_DBG("handling message cmd\n"); PurpleAccount *account = NULL; extern_account_t *accounts = NULL; extern_user_t *users = NULL; int naccounts = 0, nusers = 0; int i, j; PurpleConversation *conv = NULL; LM_DBG("calling find_accounts(\"%s\", &naccounts)\n", message->from); accounts = find_accounts(message->from, &naccounts); LM_DBG("found %d extra account(s) for <%s>", naccounts, message->from); LM_DBG("calling find_users(\"%s\", &nusers)\n", message->to); users = find_users(message->to, &nusers); LM_DBG("found %d extra user(s) for <%s>", nusers, message->to); for (i = 0; i < naccounts; i++) { LM_DBG("calling client_find_account(\"%s\")\n", accounts[i].username); account = client_find_account(&accounts[i]); if ((account) && purple_account_is_connected(account)) { //enable_account(account); for (j = 0; j < nusers; j++) { if (!strcmp(accounts[i].protocol, users[j].protocol)) { LM_DBG("mathing protocol found: %s\n", accounts[i].protocol); conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, users[j].username, account); if (conv == NULL) conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, users[j].username); purple_conv_im_send(purple_conversation_get_im_data(conv), message->body); break; } } } else if (account == NULL) LM_DBG("not account found neither created\n"); else if (purple_account_is_disconnected(account)) LM_DBG("account is disconnected cannot send message\n"); } if (accounts) extern_account_free(accounts, naccounts); if (users) extern_user_free(users, nusers); }
static int purple_buddy_msg(struct im_connection *ic, char *who, char *message, int flags) { PurpleConversation *conv; struct purple_data *pd = ic->proto_data; if (!strncmp(who, PURPLE_REQUEST_HANDLE, sizeof(PURPLE_REQUEST_HANDLE) - 1)) { guint request_id = atoi(who + sizeof(PURPLE_REQUEST_HANDLE)); purple_request_input_callback(request_id, ic, message, who); return 1; } if ((conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, who, pd->account)) == NULL) { conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, pd->account, who); } purple_conv_im_send(purple_conversation_get_im_data(conv), message); return 1; }
xmlnode * _h_elim_message ( const char *name , const char *id , SEXP_VALUE *args , gpointer data ) { fprintf(stderr, "(elim-debug entered _h_elim_message)"); ASSERT_ALISTP( args, id, name ); elim_ping(); const char *aname = ALIST_VAL_STR( args, "account-name" ); const char *proto = ALIST_VAL_STR( args, "im-protocol" ); gpointer auid = ALIST_VAL_PTR( args, "account-uid" ); PurpleAccount *acct = auid ? find_acct_by_uid( auid ) : purple_accounts_find( aname, proto ); if( !acct ) { sexp_val_free( args ); return response_error( ENXIO, id, name, "unknown account" ); } PurpleConversationType pt = PURPLE_CONV_TYPE_UNKNOWN; gpointer cuid = ALIST_VAL_PTR( args, "conv-uid" ); const char *cname = ALIST_VAL_STR( args, "conv-name" ); PurpleConversation *pc = find_conv_by_acct_uid( acct, cuid ); if ( pc ) pt = purple_conversation_get_type( pc ); else { pt = PURPLE_CONV_TYPE_ANY; pc = purple_find_conversation_with_account( pt, cname, acct ); if( !pc ) { pt = PURPLE_CONV_TYPE_IM; pc = purple_conversation_new( pt, acct, cname ); } else { pt = purple_conversation_get_type( pc ); } } if( !pc ) { sexp_val_free( args ); return response_error( ENXIO, id, name, "new conversation failed" ); } PurpleConvIm *pci = NULL; PurpleConvChat *pcc = NULL; const char *msg = ALIST_VAL_STRING( args, "text" ); char *esc = g_markup_escape_text( msg, -1 ); int len = strlen( esc ); switch( pt ) { case PURPLE_CONV_TYPE_IM: pci = purple_conversation_get_im_data( pc ); purple_conv_im_send( pci, esc ); break; case PURPLE_CONV_TYPE_CHAT: pcc = purple_conversation_get_chat_data( pc ); purple_conv_chat_send( pcc, esc ); break; default: g_free ( esc ); sexp_val_free( args ); return response_error( EINVAL, id, name, "unknown conversation type" ); } xmlnode *rval = xnode_new( "alist" ); AL_INT( rval, "bytes" , len ); AL_PTR( rval, "conv-uid" , pc ); AL_STR( rval, "conv-name", purple_conversation_get_name(pc) ); g_free ( esc ); sexp_val_free( args ); fprintf(stderr, "(elim-debug leaving _h_elim_message)"); return response_value( 0, id, name, rval ); }
void IMInvoker::send(void *userdata, const std::string event) { // we are in the thread that manages all of libpurple EventContext* ctx = (EventContext*)userdata; if (!ctx) return; if (!ctx->instance || !ctx->instance->_account) { ctx->instance->returnErrorExecution("No account available"); delete(ctx); return; } if (iequals(ctx->sendReq.name, "im.send")) { std::string receiver; Event::getParam(ctx->sendReq.params, "receiver", receiver); Data data; Event::getParam(ctx->sendReq.params, "data", data); #if LIBPURPLE_VERSION_MAJOR >= 3 PurpleIMConversation* conv = purple_im_conversation_new(ctx->instance->_account, receiver.c_str()); if (ctx->sendReq.content.length() > 0) purple_conversation_send(PURPLE_CONVERSATION(conv), ctx->sendReq.content.c_str()); #else PurpleConversation* conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, ctx->instance->_account, receiver.c_str()); if (ctx->sendReq.content.length() > 0) purple_conv_im_send(purple_conversation_get_im_data(conv), ctx->sendReq.content.c_str()); #endif #if 0 if (data.binary) { PurpleConnection *gc = purple_account_get_connection(ctx->instance->_account); PurplePlugin *prpl; PurplePluginProtocolInfo *prpl_info; if (gc) { prpl = purple_connection_get_prpl(gc); prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); // if (prpl_info && prpl_info->new_xfer) { // PurpleXfer* xfer = (prpl_info->new_xfer)(purple_account_get_connection(ctx->instance->_account), receiver.c_str()); // purple_xfer_set_local_filename(xfer, "/Users/sradomski/Documents/W3C Standards.pdf"); // purple_xfer_set_filename(xfer, "asdfadsf.pdf"); // purple_xfer_request(xfer); // purple_xfer_request_accepted(xfer, "/Users/sradomski/Documents/W3C Standards.pdf"); // } //Set the filename // purple_xfer_set_local_filename(xfer, [[fileTransfer localFilename] UTF8String]); // purple_xfer_set_filename(xfer, [[[fileTransfer localFilename] lastPathComponent] UTF8String]); // xfer->ui_data // purple_xfer_request(xfer); serv_send_file(gc, "sradomski@localhost", "/Users/sradomski/Documents/W3C Standards.pdf"); // if (prpl_info->send_file && (prpl_info->can_receive_file && prpl_info->can_receive_file(gc, receiver.c_str()))) { // prpl_info->send_file(gc, receiver.c_str(), "/Users/sradomski/Documents/W3C Standards.pdf"); // } // prpl_info->send_raw(gc, data.binary->data, data.binary->size); } } #endif } else if (iequals(ctx->sendReq.name, "im.buddy.add")) { std::string buddyName; Event::getParam(ctx->sendReq.params, "name", buddyName); std::string reqMsg; Event::getParam(ctx->sendReq.params, "msg", reqMsg); PurpleBuddy* buddy = purple_buddy_new(ctx->instance->_account, buddyName.c_str(), NULL); purple_blist_add_buddy(buddy, NULL, NULL, NULL); #if LIBPURPLE_VERSION_MAJOR >= 3 purple_account_add_buddy(ctx->instance->_account, buddy, reqMsg.c_str()); #else purple_account_add_buddy(ctx->instance->_account, buddy); #endif } else if (iequals(ctx->sendReq.name, "im.buddy.remove")) { std::string buddyName; Event::getParam(ctx->sendReq.params, "name", buddyName); #if LIBPURPLE_VERSION_MAJOR >= 3 PurpleBuddy* buddy = purple_blist_find_buddy(ctx->instance->_account, buddyName.c_str()); if (PURPLE_IS_BUDDY(buddy)) { purple_account_remove_buddy(ctx->instance->_account, buddy, purple_buddy_get_group(buddy)); purple_blist_remove_buddy(buddy); } #else PurpleBuddy* buddy = purple_find_buddy(ctx->instance->_account, buddyName.c_str()); purple_account_remove_buddy(ctx->instance->_account, buddy, purple_buddy_get_group(buddy)); purple_blist_remove_buddy(buddy); #endif } delete(ctx); }