Workaround for x86_64: inhibit ANSW_AGENT*
[mirrors/libpurple-core-answerscripts.git] / answerscripts.c
index b13113f016873a1f7aa6c0602b62e64d92d40b9d..e8a2ff309d88e71e103bf28bb6abece73968694f 100755 (executable)
@@ -62,6 +62,7 @@ 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: */
        PurpleBuddy *buddy = purple_find_buddy(account, who);
+       PurplePresence *presence = purple_buddy_get_presence(buddy);
 
        //Get message
        message = purple_markup_strip_html(buffer);
@@ -71,22 +72,6 @@ static void received_im_msg_cb(PurpleAccount *account, char *who, char *buffer,
        const char* local_name = (char *) purple_account_get_name_for_display(account);
 
        //REMOTE USER (Buddy):
-       //Here are prototypes of some functions interesting to implement github feature request #3
-       //const char *  purple_contact_get_alias (PurpleContact *contact)
-       /*
-       const char* remote_name = purple_buddy_get_name(buddy); //correct name to display for a blist chat
-       const char* remote_alias_only = purple_buddy_get_alias_only(buddy); //NULL
-       const char* remote_server_alias = purple_buddy_get_server_alias(buddy); //NULL
-       const char* remote_contact_alias = purple_buddy_get_contact_alias(buddy);       //NULL
-       const char* remote_local_alias = purple_buddy_get_local_alias(buddy);   //buddy's alias; buddy's contact alias; buddy's user name.
-       */
-       /*
-       setenv(ENV_PREFIX "REMOTE_NAME", remote_name, 1);       //???
-       setenv(ENV_PREFIX "REMOTE_ALIAS_ONLY", remote_alias_only, 1);   //buggy
-       setenv(ENV_PREFIX "REMOTE_SERVER_ALIAS", remote_server_alias, 1);       //buggy
-       setenv(ENV_PREFIX "REMOTE_CONTACT_ALIAS", remote_contact_alias, 1);     //buggy
-       setenv(ENV_PREFIX "REMOTE_LOCAL_ALIAS", remote_local_alias, 1); //???
-       */
 
        //Get buddy alias
        const char* remote_alias = purple_buddy_get_alias(buddy);
@@ -103,10 +88,16 @@ static void received_im_msg_cb(PurpleAccount *account, char *who, char *buffer,
        //Get status
        PurpleStatus *status = purple_account_get_active_status(account);
        PurpleStatusType *type = purple_status_get_type(status);
+       //remote
+       PurpleStatus *r_status = purple_presence_get_active_status(presence);
+       PurpleStatusType *r_status_type =       purple_status_get_type(r_status);
 
        //Get status id
        const char *status_id = NULL;
        status_id = purple_primitive_get_id_from_type(purple_status_type_get_primitive(type));
+       //remote
+       const char *r_status_id = NULL;
+       r_status_id = purple_primitive_get_id_from_type(purple_status_type_get_primitive(r_status_type));
 
        //Get status message
        const char *status_msg = NULL;
@@ -115,6 +106,13 @@ static void received_im_msg_cb(PurpleAccount *account, char *who, char *buffer,
        } else {
                status_msg = (char *) purple_savedstatus_get_message(purple_savedstatus_get_current());
        }
+       //remote
+       const char *r_status_msg = NULL;
+       if (purple_status_type_get_attr(r_status_type, "message") != NULL) {
+               r_status_msg = purple_status_get_attr_string(r_status, "message");
+       } else {
+               r_status_msg = "";
+       }
 
        //Export variables to environment
        setenv(ENV_PREFIX "ACTION", "IM", 1);   //what happend: im, chat, show setting dialog, event, etc...
@@ -123,6 +121,8 @@ static void received_im_msg_cb(PurpleAccount *account, char *who, char *buffer,
        setenv(ENV_PREFIX "R_NAME", who, 1);    //ID of remote user - "buddy"
        setenv(ENV_PREFIX "R_GROUP", from_group, 1);    //group which contains that buddy OR empty string
        setenv(ENV_PREFIX "R_ALIAS", remote_alias, 1);  //buddy's alias, server alias, contact alias, username OR empty string
+       setenv(ENV_PREFIX "R_STATUS", r_status_id, 1);  //unique ID of remote user's status. eg.: available, away,...
+       setenv(ENV_PREFIX "R_STATUS_MSG", r_status_msg, 1);     //status message set by your buddy
        setenv(ENV_PREFIX "L_NAME", local_name, 1);     //ID of local user
        setenv(ENV_PREFIX "L_ALIAS", local_alias, 1);   //Alias of local user OR empty string
        setenv(ENV_PREFIX "L_STATUS", status_id, 1);    //unique ID of local user's status. eg.: available, away,...
@@ -199,8 +199,12 @@ static PurplePluginInfo info = {
 
 static void init_plugin(PurplePlugin * plugin) {
        //Export static environment variables
-       setenv(ENV_PREFIX "L_AGENT", (char *) purple_core_get_ui(), 1); //ID of IM client used with answerscripts
-       setenv(ENV_PREFIX "L_AGENT_VERSION", (char *) purple_core_get_version(), 1);    //Version of client
+       #ifndef __x86_64__ //Workaround for x86_64 (where this causes problems pro unknown reason)
+               const char * core_ui = purple_core_get_ui() != 0 ? (const char *) purple_core_get_ui() : "";
+               const char * core_version = purple_core_get_version() != 0 ? (const char *) purple_core_get_version() : "";
+               setenv(ENV_PREFIX "L_AGENT", (char *) core_ui, 1);      //ID of IM client used with answerscripts
+               setenv(ENV_PREFIX "L_AGENT_VERSION", (char *) core_version, 1); //Version of client
+       #endif
 }
 
 PURPLE_INIT_PLUGIN(autoanswer, init_plugin, info)
This page took 0.100822 seconds and 4 git commands to generate.