+ //REMOTE USER (Buddy):
+
+ //Get buddy alias
+ const char* remote_alias = purple_buddy_get_alias(buddy);
+ if(remote_alias == NULL) remote_alias = "";
+
+ //Get buddy group
+ PurpleGroup *group = purple_buddy_get_group(buddy);
+ const char *from_group = group != NULL ? purple_group_get_name(group) : ""; //return empty string if not in group
+
+ //Get protocol ID
+ const char *protocol_id = purple_account_get_protocol_id(account);
+ if(!strncmp(protocol_id,PROTOCOL_PREFIX,strlen(PROTOCOL_PREFIX))) protocol_id += strlen(PROTOCOL_PREFIX); //trim out PROTOCOL_PREFIX (eg.: "prpl-irc" => "irc")
+
+ //Get status
+ PurpleStatus *status = purple_account_get_active_status(account);
+ PurpleStatusType *type = purple_status_get_type(status);
+
+ //Get status id
+ const char *status_id = NULL;
+ status_id = purple_primitive_get_id_from_type(purple_status_type_get_primitive(type));
+
+ //Get status message
+ const char *status_msg = NULL;
+ if (purple_status_type_get_attr(type, "message") != NULL) {
+ status_msg = purple_status_get_attr_string(status, "message");
+ } else {
+ status_msg = (char *) purple_savedstatus_get_message(purple_savedstatus_get_current());
+ }
+
+ //Export variables to environment
+ setenv(ENV_PREFIX "ACTION", "IM", 1); //what happend: im, chat, show setting dialog, event, etc...
+ setenv(ENV_PREFIX "MSG", message, 1); //text of the message
+ setenv(ENV_PREFIX "PROTOCOL", protocol_id, 1); //protocol used to deliver the message. eg.: xmpp, irc,...
+ 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 "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,...
+ setenv(ENV_PREFIX "L_STATUS_MSG", status_msg, 1); //status message set by local user
+
+ //Launch job on background
+ answerscripts_job *job = (answerscripts_job*) malloc(sizeof(answerscripts_job));
+ job->pipe = popen(hook_script, "r");
+ if(job->pipe == NULL) {
+ fprintf(stderr,"Can't execute %s\n", hook_script);
+ return;
+ }
+ job->conv = conv;
+
+ #ifndef __WIN32__
+ int fflags = fcntl(fileno(job->pipe), F_GETFL, 0);
+ fcntl(fileno(job->pipe), F_SETFL, fflags | O_NONBLOCK);