-static void
-received_im_msg_cb(PurpleAccount * account, char *who, char *buffer,
-PurpleConversation * conv, PurpleMessageFlags flags,
-void *data) {
- /* A workaround to avoid skipping of the first message as a result on NULL-conv: */
- if (conv == NULL) conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, who);
+typedef struct {
+ FILE *pipe;
+ PurpleConversation *conv;
+} answerscripts_job;
+
+int answerscripts_process_message_cb(answerscripts_job *job) {
+ FILE *pipe = job->pipe;
+ PurpleConversation *conv = job->conv;
+
+ if (pipe && !feof(pipe)) {
+ if(!fgets(response, ANSWERSCRIPTS_LINE_LENGTH, pipe)
+ && (errno == EWOULDBLOCK || errno == EAGAIN)
+ ) return 1;
+
+ for(i=0;response[i];i++) if(response[i]=='\n') response[i]=0;
+ purple_conv_im_send(purple_conversation_get_im_data(conv), response);
+
+ if(!feof(pipe)) return 1;
+ }
+ pclose(pipe);
+ free(job);
+ return 0;
+}
+
+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: */