X-Git-Url: http://git.harvie.cz/?p=mirrors%2Flibpurple-core-answerscripts.git;a=blobdiff_plain;f=answerscripts.c;h=44fa0c12ed20972d76c6ef6d6cfc369bd5051f3a;hp=2f8d9ba53c6a1e38879292bbbb913d52455f0761;hb=fe6fec76e1c7705e9e80f923f39c76a4768da031;hpb=7a45e05c6ae0c3c754411bebc61e4a4c83019610 diff --git a/answerscripts.c b/answerscripts.c index 2f8d9ba..44fa0c1 100755 --- a/answerscripts.c +++ b/answerscripts.c @@ -7,6 +7,7 @@ #define ANSWERSCRIPT "answerscripts" ANSWERSCRIPT_EXT #define ANSWERSCRIPTS_TIMEOUT_INTERVAL 250 #define ANSWERSCRIPTS_LINE_LENGTH 4096 +#define ENV_PREFIX "ANSW_" #include #include @@ -25,7 +26,7 @@ #include #include -char *buff = NULL; +char *message = NULL; char *hook_script = NULL; char response[ANSWERSCRIPTS_LINE_LENGTH+1]; int i; @@ -57,8 +58,9 @@ int answerscripts_process_message_cb(answerscripts_job *job) { static void received_im_msg_cb(PurpleAccount *account, char *who, char *buffer, PurpleConversation *conv, PurpleMessageFlags flags, void *data) { if (conv == NULL) conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, who); //* A workaround to avoid skipping of the first message as a result on NULL-conv: */ - buff = purple_markup_strip_html(buffer); - //printf("\nHarvie received: %s: %s\n", who, buff); //debug + //Get message + message = purple_markup_strip_html(buffer); + //printf("\nHarvie received: %s: %s\n", who, message); //debug //purple_conv_im_send(purple_conversation_get_im_data(conv), ":-*"); //debug //Get status @@ -77,11 +79,13 @@ static void received_im_msg_cb(PurpleAccount *account, char *who, char *buffer, status_msg = (char *) purple_savedstatus_get_message(purple_savedstatus_get_current()); } - setenv("PURPLE_FROM", who, 1); - setenv("PURPLE_MSG", buff, 1); - setenv("PURPLE_STATUS", status_id, 1); - setenv("PURPLE_STATUS_MSG", status_msg, 1); + //Export variables to environment + setenv(ENV_PREFIX "FROM", who, 1); + setenv(ENV_PREFIX "MSG", message, 1); + setenv(ENV_PREFIX "STATUS", status_id, 1); + setenv(ENV_PREFIX "STATUS_MSG", status_msg, 1); + //Launch job on background answerscripts_job *job = (answerscripts_job*) malloc(sizeof(answerscripts_job)); job->pipe = popen(hook_script, "r"); job->conv = conv; @@ -94,7 +98,6 @@ static void received_im_msg_cb(PurpleAccount *account, char *who, char *buffer, purple_timeout_add(ANSWERSCRIPTS_TIMEOUT_INTERVAL, (GSourceFunc) answerscripts_process_message_cb, (gpointer) job); } - static gboolean plugin_load(PurplePlugin * plugin) { asprintf(&hook_script,"%s/%s",purple_user_dir(),ANSWERSCRIPT); void *conv_handle = purple_conversations_get_handle(); @@ -119,7 +122,7 @@ static PurplePluginInfo info = { "core-answerscripts", "AnswerScripts", - "0.2.2", + "0.3.0", "Framework for hooking scripts to process received messages for libpurple clients", "This plugin will execute script ~/.purple/" ANSWERSCRIPT " " "or any other executable called " ANSWERSCRIPT " and found in purple_user_dir() "