
#include<stdio.h>
#include<netinet/in.h>
#include<stdlib.h>
#include<pthread.h>

#include"sitar.h"
#include"sitar_scan.h"
#include<almemsys/almemsys.h>


// extern struct scan_buf sb;


int scan_malloc_set(private_data_t *pd)
{
#ifdef MALLOC_BUG
printf("MALLOC: scan_malloc_set():\n");
#endif

if((pd->sb.swap = (char *)calloc(BUF_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->sb.ch_stat = (char *)calloc(IP_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->sb.ch_prot = (char *)calloc(IP_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->sb.ch_host = (char *)calloc(BUF_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->sb.ch_port = (char *)calloc(IP_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->sb.ch_port_h = (char *)calloc(IP_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->sb.ch_port_m = (char *)calloc(IP_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->sb.ch_timeout = (char *)calloc(IP_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->sb.ch_timeout_h = (char *)calloc(IP_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->sb.ch_timeout_m = (char *)calloc(IP_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->sb.ch_data = (char *)calloc(BUF_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->sb.ch_info = (char *)calloc(BUF_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->sb.ch_free1 = (char *)calloc(BUF_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->sb.ch_free2 = (char *)calloc(BUF_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->sb.ch_free3 = (char *)calloc(BUF_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->sb.ch_free4 = (char *)calloc(BUF_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->sb.ch_tool = (char *)calloc(IP_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->sb.ch_com = (char *)calloc(IP_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->sb.ch_plai = (char *)calloc(IP_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->sb.swap_2 = (char *)calloc(BUF_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->sb.scan_all = (char *)calloc(BUF_LEN, sizeof(char)))==NULL){ m_exit(1);}

if((pd->db.swap = (char *)calloc(BUF_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->db.swap1 = (char *)calloc(BUF_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->db.swap2 = (char *)calloc(BUF_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->db.server = (char *)calloc(BUF_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->db.username = (char *)calloc(BUF_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->db.passwd = (char *)calloc(BUF_LEN, sizeof(char)))==NULL){ m_exit(1);}
if((pd->db.database = (char *)calloc(BUF_LEN, sizeof(char)))==NULL){ m_exit(1);}

return 0;
}





int scan_malloc_free(private_data_t *pd)
{

#ifdef FREE_BUG
printf("FREE: scan_malloc_free():\n");
#endif

free(pd->sb.swap);
free(pd->sb.ch_stat);
free(pd->sb.ch_prot);
free(pd->sb.ch_host);
free(pd->sb.ch_port);
free(pd->sb.ch_port_h);
free(pd->sb.ch_port_m);
free(pd->sb.ch_timeout);
free(pd->sb.ch_timeout_h);
free(pd->sb.ch_timeout_m);
free(pd->sb.ch_data);
free(pd->sb.ch_info);
free(pd->sb.ch_free1);
free(pd->sb.ch_free2);
free(pd->sb.ch_free3);
free(pd->sb.ch_free4);
free(pd->sb.ch_tool);
free(pd->sb.ch_com);
free(pd->sb.ch_plai);
free(pd->sb.swap_2);
free(pd->sb.scan_all);

free(pd->db.swap);
free(pd->db.swap1);
free(pd->db.swap2);
free(pd->db.server);
free(pd->db.username);
free(pd->db.passwd);
free(pd->db.database);

return 0;
}



int db_malloc_null(private_data_t *pd)
{

pd->db.swap = null_free(pd->db.swap);
pd->db.swap1 = null_free(pd->db.swap1);
pd->db.swap2 = null_free(pd->db.swap2);
pd->db.server = null_free(pd->db.server);
pd->db.username = null_free(pd->db.username);
pd->db.passwd = null_free(pd->db.passwd);
pd->db.database = null_free(pd->db.database);

return 0;
}


int scan_malloc_null(private_data_t *pd)
{

#ifdef FREE_BUG
printf("FREE: scan_malloc_free():\n");
#endif

pd->sb.swap = null_free(pd->sb.swap);
pd->sb.ch_stat = null_free(pd->sb.ch_stat);
pd->sb.ch_prot = null_free(pd->sb.ch_prot);
pd->sb.ch_host = null_free(pd->sb.ch_host);
pd->sb.ch_port = null_free(pd->sb.ch_port);
pd->sb.ch_port_h = null_free(pd->sb.ch_port_h);
pd->sb.ch_port_m = null_free(pd->sb.ch_port_m);
pd->sb.ch_timeout = null_free(pd->sb.ch_timeout);
pd->sb.ch_timeout_h = null_free(pd->sb.ch_timeout_h);
pd->sb.ch_timeout_m = null_free(pd->sb.ch_timeout_m);
pd->sb.ch_data = null_free(pd->sb.ch_data);
pd->sb.ch_info = null_free(pd->sb.ch_info);
pd->sb.ch_free1 = null_free(pd->sb.ch_free1);
pd->sb.ch_free2 = null_free(pd->sb.ch_free2);
pd->sb.ch_free3 = null_free(pd->sb.ch_free3);
pd->sb.ch_free4 = null_free(pd->sb.ch_free4);
pd->sb.ch_tool = null_free(pd->sb.ch_tool);
pd->sb.ch_com = null_free(pd->sb.ch_com);
pd->sb.ch_plai = null_free(pd->sb.ch_plai);
pd->sb.swap_2 = null_free(pd->sb.swap_2);
pd->sb.scan_all = null_free(pd->sb.scan_all);

db_malloc_null(pd);

return 0;
}







