Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Matt R.

Pages: [1]
1
Other Yate server issues / Re: External Module Communication
« on: October 03, 2017, 12:20:51 PM »
Solved!

This is so stupid. I assumed that including a newline in fprintf would flush, but it doesn't. Adding a fflush(stdout) fixed it.

Programming.

2
Other Yate server issues / Re: External Module Communication
« on: September 29, 2017, 07:52:04 AM »
I have read the PHP scripts, specifically libyate.php which includes the following function call for this scenario: _yate_print("%%<message:$id:$handled:$name:$retval$params\n");. I'm interested in working out this very basic communication issue before moving forward and implementing any of the library functions available in the PHP scripts.

Adding extra :s did not help.

When executing both the original shell script (echo.sh) and the C code I've posted, I can successfully log to stderr the exact same output (except ID obviously). I'm interested in understanding why this is not working from my C code when written to stdout. I am writing a newline at the end of the message, as specified by the docs. Could this be some kind of encoding issue? This example is so simple we should be able to deduce the problem without resorting to a library.

echo.sh stderr log:

Code: [Select]
%%<message:0x7fca99a4a9d0.1560637037:true:
C code stderr log:

Code: [Select]
%%<message:0x7fca99a4a9d0.1511079866:true:

3
Other Yate server issues / Re: External Module Communication
« on: September 29, 2017, 05:34:56 AM »
Hi Monica,

Can you please explain what you mean and indicate the difference between the shell script and the C code?

As I understand it, this line in the shell script acknowledges the message by replying to the server over stdout.

Code: [Select]
echo "$REPLY" | sed 's/^[^:]*:\([^:]*\):.*$/%%<message:\1:true:/;'
How is this line in my C code different?

Code: [Select]
fprintf(stdout, "%%%%<message:%s:true:\n", curToken);

4
Other Yate server issues / [SOLVED] External Module Communication
« on: September 28, 2017, 09:16:41 PM »
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.

Code: [Select]
#!/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.

Code: [Select]
#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:

Code: [Select]
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.

Pages: [1]