{
FILE *infile;
int skipline = 0; // Skip the first in the file, it throws off the detection
- char line[100], *SipLoc, Channel[25], Location[25], State[9], Application[25], EndPoint[8], Ret[50], inp;
+ char line[100], *SipLoc, Channel[25], Location[25], State[9], Application[25], EndPoint[8], Ret[50];
int i = 0, ChannelInt = 0, ZapLine = 0;
struct Line Lines[32]; // Setup 32 lines, ZAP 1-32 (memory is cheap)
system("asterisk -rx \"show channels\" > /tmp/asterisk.state"); // Crappy CLI way to do it
infile = fopen("/tmp/asterisk.state", "r");
+
+ for (i = 0; i < 100; i++) {
+ line[i] = ' ';
+ }
+ line[99] = '\0';
+
while (fgets(line, 100, infile) != NULL) {
if (strstr(line, "Zap") != NULL) {
for (i = 0; i < strlen(line); i++) {
memcpy(EndPoint, Application + 13, 7);
EndPoint[7] = '\0';
-
if (strstr(Application, "Bridged Call") != NULL) {
// Subtract 48 from the character value to get the int
// value. Subtract one more because arrays start at 0.
} else {
EndPoint[0] = '\0';
}
-
ChannelInt = (int) (Channel[4]) - 49;
strcpy(Lines[ChannelInt].Channel, Channel);
- strcpy(Lines[ChannelInt].EndPoint, EndPoint);
Lines[ChannelInt].active = 1;
}
} else {
fclose(infile);
ZapLine -= 1;
- if (Lines[ZapLine].active == 1) {
+ if (ZapLine < 0 || ZapLine > 31) {
+ memset(Ret, ' ', 50);
+ Ret[0] = '\0';
+ strcat(Ret, "Invalid ZAP #");
+ SetResult(&result, R_STRING, &Ret);
+ } else if (Lines[ZapLine].active == 1) {
memset(Ret, ' ', 50);
Ret[0] = '\0';
strcat(Ret, Lines[ZapLine].Channel);
strcat(Ret, ": inactive");
SetResult(&result, R_STRING, &Ret);
}
-
return;
}