|
|
|
@ -274,8 +274,10 @@ int ami_communication_ami(AMI *ami){
|
|
|
|
|
|
|
|
|
|
int bytes = 0; |
|
|
|
|
char more_buffer[MAX_BUFFER_NET + MAX_BUFFER_NET]; |
|
|
|
|
char buffer_old[MAX_BUFFER_NET]; |
|
|
|
|
int i = 0; |
|
|
|
|
int timeout = 2; |
|
|
|
|
int incomplete = 0; |
|
|
|
|
|
|
|
|
|
while(1){ |
|
|
|
|
struct pollfd pfd[1]; |
|
|
|
@ -308,31 +310,17 @@ int ami_communication_ami(AMI *ami){
|
|
|
|
|
timeout = 2; |
|
|
|
|
i = 0; |
|
|
|
|
|
|
|
|
|
if(ami->net.imcomplete_net == 0){ |
|
|
|
|
bytes = recv(ami->net.sock, ami->net.buffer_net, MAX_BUFFER_NET - 1, 0); |
|
|
|
|
ami->net.buffer_net[bytes] = '\0'; |
|
|
|
|
bytes = recv(ami->net.sock, ami->net.buffer_net, MAX_BUFFER_NET - 1, 0); |
|
|
|
|
ami->net.buffer_net[bytes] = '\0'; |
|
|
|
|
|
|
|
|
|
// verifica se o final bloco
|
|
|
|
|
if(bytes >= (MAX_BUFFER_NET - 1) ){ |
|
|
|
|
ami->net.imcomplete_net = 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
buffer = ami->net.buffer_net; |
|
|
|
|
} |
|
|
|
|
if(ami->net.imcomplete_net == 1){ |
|
|
|
|
// receber o restante do bloco
|
|
|
|
|
strcpy(more_buffer, ami->net.buffer_net); |
|
|
|
|
bytes = recv(ami->net.sock, ami->net.buffer_net, MAX_BUFFER_NET - 1, 0); |
|
|
|
|
ami->net.buffer_net[bytes] = '\0'; |
|
|
|
|
strcat(more_buffer, ami->net.buffer_net); |
|
|
|
|
|
|
|
|
|
ami->net.imcomplete_net = 0; |
|
|
|
|
|
|
|
|
|
if( incomplete == 1){ |
|
|
|
|
strcpy( more_buffer, buffer_old ); |
|
|
|
|
strcat( more_buffer, ami->net.buffer_net ); |
|
|
|
|
buffer = more_buffer; |
|
|
|
|
incomplete = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(ami->net.pause == 1){ |
|
|
|
|
continue; |
|
|
|
|
else{ |
|
|
|
|
buffer = ami->net.buffer_net; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if( ami->asterisk.is_logged == 0 ){ |
|
|
|
@ -349,14 +337,24 @@ int ami_communication_ami(AMI *ami){
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(ami->net.pause == 1){ |
|
|
|
|
incomplete = 0; |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char *block = NULL; |
|
|
|
|
block = define_block(buffer, &buffer); |
|
|
|
|
while(block){ |
|
|
|
|
if(!strncmp(block, "Response: ", 10)){ |
|
|
|
|
parse_response(ami, block); |
|
|
|
|
parse_response(ami, block, &incomplete); |
|
|
|
|
} |
|
|
|
|
else if(!strncmp(block, "Event: ", 7)){ |
|
|
|
|
parse_event(ami, block); |
|
|
|
|
parse_event(ami, block, &incomplete); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(incomplete == 1){ |
|
|
|
|
strcpy( buffer_old, block ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
block = define_block(NULL, &buffer); // próximo bloco
|
|
|
|
|