Note the variables in extensions.conf and agi

I am a beginner studying asterisk.

Call agi in dianplan extensions.conf and query mysql

I’d like to bring that back. agi is written in C.

The contents of a2.c are

#include “/usr/include/mysql/mysql.h”
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
MYSQL con = mysql_init(NULL);
MYSQL_RES
result;
MYSQL_ROW row;
int stat;
if (con == NULL)
{
fprintf(stderr, “%s\n”, mysql_error(con));
exit(1);
}

if (mysql_real_connect(con, “localhost”, “root”, “summitP3101!”, “parkgolf”, 0, NULL, 0) == NULL)
{
fprintf(stderr, “%s\n”, mysql_error(con));
mysql_close(con);
exit(1);
}

if (mysql_query(con, “select * from attread”))
{
fprintf(stderr, “%s\n”, mysql_error(con));
mysql_close(con);
exit(1);
}

result = mysql_store_result(con);
while( (row = mysql_fetch_row(result)) != NULL)
{
printf(“%s %s %s\n”,row[0],row[1],row[2]);
}
mysql_free_result(result);
mysql_close(con);
return 0;
}

Here, row[0], row[1]… I want to read the values ​​from extension.conf.
I’m asking for help because I don’t know how.

The MySQL code looks correct. I’m assuming you can run it from a shell and it displays the expected output.

You need an AGI library for C. I wrote one about 20 years ago. You’re welcome to try it. I don’t know if anybody other than me has used it.

If this doesn’t meet your needs, Google is your friend.

The important thing to remember about an AGI is that STDIN and STDOUT are for interacting with Asterisk, not for displaying values or progress messages.

It’s a simple protocol, but nobody gets it right the first time :slight_smile:

For your immediate need, you’d call something like:

agi_set_variable(channel_variable_name, value);
or
agi_set_variable("client-id", row[0]);

and then in your dialplan:

same = n, verbose(1,  The client id is ${client-id})

assuming I didn’t make any typing errors.