I would like to make an application that handles calls similar to an IVR but with some extra audio processing. I am having the hardest time getting external module communication to work.
This basic example from scripts/echo.sh shows the output of %%<message:<ID>:true:\n being written to stdout. It works perfectly fine, echoing the message on stderr (visible in Yate logs) and accepts a call.
#!/bin/sh
read -r REPLY
echo "$REPLY" | sed 's/^[^:]*:\([^:]*\):.*$/%%<message:\1:true:/;'
echo "$REPLY" | sed 's/^[^:]*:\([^:]*\):.*$/%%<message:\1:true:/;' >&2
(sleep 1; cat) <&3 >&4
I would like to do the same thing in C, although skip piping audio from FD3 to FD4 for simplicity's' sake.
#include <stdio.h>
#include <string.h>
#include <unistd.h>
char commandBuf[4096];
char messageID[256];
int main(void) {
if( fgets(commandBuf, 4096, stdin) == NULL ) {
fprintf(stderr, "No command received.\n" );
return 1;
}
fprintf( stderr, "COMMAND %s\n", commandBuf); // Debug the command, logs correctly to Yate log
char* tokens = strdup(commandBuf);
char* curToken;
int curTokenIdx = 0;
while( (curToken = strsep(&tokens, ":")) != NULL ) {
fprintf(stderr, "TOKEN: %s\n", curToken ); // Tokens are correctly separated and logged
if(curTokenIdx == 1) break; // Stop when we've reached the ID
curTokenIdx++;
}
fprintf(stdout, "%%%%<message:%s:true:\n", curToken); // Send the message command to Yate
fprintf(stderr, "%%%%<message:%s:true:\n", curToken); // Log what we sent
sleep(20);
return 0;
}
As far as I can tell this should work. The debug messages all indicate that the %%<message:<ID>:true: command was sent to Yate. However, I'm getting the following logs:
Sep 28 22:34:12 yate[9443]: 2017-09-28_22:34:12.933304 <extmodule:WARN> Message 0x7fca8803fdc0 'call.execute' did not return in 10000 msec [0x7fca7c0f5500]
Sep 28 22:34:12 yate[9443]: 2017-09-28_22:34:12.933413 <WARN> ExtMod 'testmodule' did not handle call message
What is causing this? My program, as far as I can tell, is outputting the exact same output as the shell script, which works just fine.
Thanks for your help.