static int aPGSQL_connect(struct ast_channel *chan, void *data) {
- char *ptrptr;
char *s1,*s4;
char s[100];
char *optionstring;
int res;
PGconn *karoto;
int id;
+ char *stringp=NULL;
res=0;
l=strlen(data)+2;
s1=malloc(l);
strncpy(s1,data,l);
- strtok_r(s1," ",&ptrptr); // eat the first token, we already know it :P
- var=strtok_r(NULL," ",&ptrptr);
- optionstring=strtok_r(NULL,"\n",&ptrptr);
+ stringp=s1;
+ strsep(&stringp," "); // eat the first token, we already know it :P
+ var=strsep(&stringp," ");
+ optionstring=strsep(&stringp,"\n");
karoto = PQconnectdb(optionstring);
if (PQstatus(karoto) == CONNECTION_BAD) {
static int aPGSQL_query(struct ast_channel *chan, void *data) {
- char *ptrptr;
char *s1,*s2,*s3,*s4,*s5;
char s[100];
char *querystring;
PGconn *karoto;
PGresult *PGSQLres;
int id,id1;
+ char *stringp=NULL;
res=0;
s1=malloc(l);
s2=malloc(l);
strcpy(s1,data);
- strtok_r(s1," ",&ptrptr); // eat the first token, we already know it :P
- s3=strtok_r(NULL," ",&ptrptr);
+ stringp=s1;
+ strsep(&stringp," "); // eat the first token, we already know it :P
+ s3=strsep(&stringp," ");
while (1) { // ugly trick to make branches with break;
var=s3;
- s4=strtok_r(NULL," ",&ptrptr);
+ s4=strsep(&stringp," ");
id=atoi(s4);
- querystring=strtok_r(NULL,"\n",&ptrptr);
+ querystring=strsep(&stringp,"\n");
if ((karoto=find_identifier(id,AST_PGSQL_ID_CONNID))==NULL) {
ast_log(LOG_WARNING,"Invalid connection identifier %d passed in aPGSQL_query\n",id);
res=-1;
static int aPGSQL_fetch(struct ast_channel *chan, void *data) {
- char *ptrptr;
char *s1,*s2,*s3,*s4,*s5,*s6,*s7;
char s[100];
char *var;
int nres;
struct ast_var_t *variables;
struct varshead *headp;
+ char *stringp=NULL;
headp=&chan->varshead;
s1=malloc(l);
s2=malloc(l);
strcpy(s1,data);
- strtok_r(s1," ",&ptrptr); // eat the first token, we already know it :P
- s3=strtok_r(NULL," ",&ptrptr);
+ stringp=s1;
+ strsep(&stringp," "); // eat the first token, we already know it :P
+ s3=strsep(&stringp," ");
while (1) { // ugly trick to make branches with break;
var=s3; // fetchid
fnd=0;
pbx_builtin_setvar_helper(chan,s3,s7);
}
- s4=strtok_r(NULL," ",&ptrptr);
+ s4=strsep(&stringp," ");
id=atoi(s4); // resultid
if ((PGSQLres=find_identifier(id,AST_PGSQL_ID_RESID))==NULL) {
ast_log(LOG_WARNING,"Invalid result identifier %d passed in aPGSQL_fetch\n",id);
nres=PQnfields(PGSQLres);
ast_log(LOG_WARNING,"ast_PGSQL_fetch : nres = %d i = %d ;\n",nres,i);
for (j=0;j<nres;j++) {
- s5=strtok_r(NULL," ",&ptrptr);
+ s5=strsep(&stringp," ");
if (s5==NULL) {
ast_log(LOG_WARNING,"ast_PGSQL_fetch : More tuples (%d) than variables (%d)\n",nres,j);
break;
static int aPGSQL_reset(struct ast_channel *chan, void *data) {
- char *ptrptr;
char *s1,*s3;
int l;
PGconn *karoto;
int id;
+ char *stringp=NULL;
l=strlen(data)+2;
s1=malloc(l);
strcpy(s1,data);
- strtok_r(s1," ",&ptrptr); // eat the first token, we already know it :P
- s3=strtok_r(NULL," ",&ptrptr);
+ stringp=s1;
+ strsep(&stringp," "); // eat the first token, we already know it :P
+ s3=strsep(&stringp," ");
id=atoi(s3);
if ((karoto=find_identifier(id,AST_PGSQL_ID_CONNID))==NULL) {
ast_log(LOG_WARNING,"Invalid connection identifier %d passed in aPGSQL_reset\n",id);
static int aPGSQL_clear(struct ast_channel *chan, void *data) {
- char *ptrptr;
char *s1,*s3;
int l;
PGresult *karoto;
int id;
+ char *stringp=NULL;
l=strlen(data)+2;
s1=malloc(l);
strcpy(s1,data);
- strtok_r(s1," ",&ptrptr); // eat the first token, we already know it :P
- s3=strtok_r(NULL," ",&ptrptr);
+ stringp=s1;
+ strsep(&stringp," "); // eat the first token, we already know it :P
+ s3=strsep(&stringp," ");
id=atoi(s3);
if ((karoto=find_identifier(id,AST_PGSQL_ID_RESID))==NULL) {
ast_log(LOG_WARNING,"Invalid result identifier %d passed in aPGSQL_clear\n",id);
static int aPGSQL_disconnect(struct ast_channel *chan, void *data) {
- char *ptrptr;
char *s1,*s3;
int l;
PGconn *karoto;
int id;
+ char *stringp=NULL;
l=strlen(data)+2;
s1=malloc(l);
strcpy(s1,data);
- strtok_r(s1," ",&ptrptr); // eat the first token, we already know it :P
- s3=strtok_r(NULL," ",&ptrptr);
+ stringp=s1;
+ strsep(&stringp," "); // eat the first token, we already know it :P
+ s3=strsep(&stringp," ");
id=atoi(s3);
if ((karoto=find_identifier(id,AST_PGSQL_ID_CONNID))==NULL) {
ast_log(LOG_WARNING,"Invalid connection identifier %d passed in aPGSQL_disconnect\n",id);