
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<netdb.h>
#include<unistd.h>
#include<sys/socket.h>
#include<netinet/in_systm.h>
#include<netinet/in.h>
#include<netinet/ip.h>
#include<arpa/inet.h>
#include<fcntl.h>

#include<sys/stat.h>
#include<errno.h>

#include"sitar_scan.h"
#include"sitar_com.h"
#include<almemsys/almemsys.h>
#include"jpreturn.h"


// char * check_recvdata(char *, char *, int *);


char * check_recvdata(char * recvdata, char * data, int * ret)
{
int dret;
int count = 0;
int inc = 0;
char * swap;

dret = 0;

if((swap = (char *)calloc(BUF_DEFLEN, sizeof(char)))==NULL){ exit(1);}

* ret = -1;
for(count = 0; inc == 0; count++){
   data[count] = recvdata[count];
   if(data[count] == '\n'){
      inc = 1;
      }
   if(count >= BUF_LEN){
      inc = 1;
      }
   }
if(count > 1){
   count = count - 2;
   data[count] = (char)0x00;

   #ifdef URL_BUG
   printf("-1--%s---\n", data);
   #endif
   swap = delim_get(data, swap, ' ', &dret, 1);
   #ifdef URL_BUG
   printf("-2--%s---\n", swap);
   #endif
   if(3 == (int)strlen(swap)){
      if('2' == swap[0]){
         #ifdef URL_BUG
         printf("-200--%c---\n", swap[0]);
         #endif
         * ret = 2;
         }
      else if('3' == swap[0]){
         #ifdef URL_BUG
         printf("-300--%c---\n", swap[0]);
         #endif
         * ret = 3;
         }
      else if('1' == swap[0]){
         #ifdef URL_BUG
         printf("-100--%c---\n", swap[0]);
         #endif
         * ret = -1;
         }
      else if('4' == swap[0]){
         #ifdef URL_BUG
         printf("-400--%c---\n", swap[0]);
         #endif
         * ret = -1;
         }
      else if('5' == swap[0]){
         #ifdef URL_BUG
         printf("-500--%c---\n", swap[0]);
         #endif
         * ret = -1;
         }
      else{
         #ifdef URL_BUG
         printf("-other--%c---\n", swap[0]);
         #endif
         * ret = -1;
         }
      }
   else{
      * ret = -1;
      }
   }

else{
   data = safe_sprintf(data, BUF_MAX, "%s", URL_1);
   * ret = -1;
   } 

free(swap);

return(data);
}




