X-Git-Url: http://git.harvie.cz/?p=mirrors%2Flibpurple-core-answerscripts.git;a=blobdiff_plain;f=answerscripts.c;h=e3f070a2ea65d98c2807324f5bc2f596f86390d5;hp=7c7da4e1cf2de3c1ae8d4a9460183614c05355bf;hb=d852a69454e41e5c4d354b509da04c7dfd5e80ad;hpb=4c3335b4ed3c610750eb0b0886a44743ced2b78c diff --git a/answerscripts.c b/answerscripts.c index 7c7da4e..e3f070a 100755 --- a/answerscripts.c +++ b/answerscripts.c @@ -19,11 +19,24 @@ #define RESPONSE_LINE_LENGTH 4096 #define HOOK_SCRIPT "answerscripts.exe" +#ifdef PTHREAD + #include +#endif + char *buff = NULL; char *hook_script = NULL; char response[RESPONSE_LINE_LENGTH+1]; int i; +void *answerscripts_process_message(void *conv) { + FILE* pipe = popen(hook_script, "r"); //TODO: process scripts and send response asynchronously + while (pipe && fgets(response, RESPONSE_LINE_LENGTH, pipe)) { + for(i=0;response[i];i++) if(response[i]=='\n') response[i]=0; + purple_conv_im_send(purple_conversation_get_im_data((PurpleConversation *)conv), response); + } + pclose(pipe); +} + static void received_im_msg_cb(PurpleAccount * account, char *who, char *buffer, PurpleConversation * conv, PurpleMessageFlags flags, @@ -38,12 +51,14 @@ void *data) { setenv("PURPLE_FROM", who, 1); setenv("PURPLE_MSG", buff, 1); - FILE* pipe = popen(hook_script, "r"); //TODO: process scripts and send response asynchronously - while (pipe && fgets(response, RESPONSE_LINE_LENGTH, pipe)) { - for(i=0;response[i];i++) if(response[i]=='\n') response[i]=0; - purple_conv_im_send(purple_conversation_get_im_data(conv), response); - } - pclose(pipe); + #ifndef PTHREAD + answerscripts_process_message((void *)conv); + #else + pthread_t t; + puts("new thread..."); + pthread_create(&t, NULL, answerscripts_process_message, (void *)conv); + puts("new thread created!"); + #endif }