Browse Source

manter buffer não completados para completa-los próximo

master
Rodgger 2 years ago
parent
commit
c4cea4ead4
  1. 46
      src/net.c
  2. 3
      src/parse_action.c
  3. 2
      src/parse_action.h
  4. 3
      src/parse_event.c
  5. 3
      src/parse_event.h

46
src/net.c

@ -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

3
src/parse_action.c

@ -7,7 +7,7 @@
* \param buffer
* \return void
*/
void parse_response(AMI *ami, const char *buffer){
void parse_response(AMI *ami, const char *buffer, int *incomplete){
char *end_response = "\r\n\r";
char *p_end = NULL;
@ -18,6 +18,7 @@ void parse_response(AMI *ami, const char *buffer){
p_end = strstr(buffer, end_response);
if( !p_end ){
*incomplete = 1;
return ;
}

2
src/parse_action.h

@ -8,7 +8,7 @@
* \param substring inicio da resposta
*
*/
void parse_response(AMI *ami, const char *buffer);
void parse_response(AMI *ami, const char *buffer, int *incomplete);
#endif

3
src/parse_event.c

@ -8,13 +8,14 @@
* \param ami
* \return diferente de NULL significa que o evento será completado na proxima revc
*/
void parse_event(AMI *ami, char *buffer){
void parse_event(AMI *ami, char *buffer, int *incomplete){
char *end_event = "\r\n\r";
char *p_end = NULL;
EVENT *p_event = NULL;
p_end = strstr(buffer, end_event);
if( !p_end ){
*incomplete = 1;
return;
}

3
src/parse_event.h

@ -3,13 +3,12 @@
#define PARSE_EVENT_H 1
/*!
* Colocar cada evento dentro da estrutura Event.
* \param substring
* \param ami
* \return diferente de NULL significa que o evento será completado na proxima revc
*/
void parse_event(AMI *ami, char *buffer);
void parse_event(AMI *ami, char *buffer, int *incomplete);
#endif

Loading…
Cancel
Save