<commit_before>/*
    This file is part of libcapwap.

    libcapwap is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    libcapwap is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.

*/

#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include "conn.h"
#include "capwap.h"
#include "sock.h"

#include "cw_log.h"

/**
 * function
 * @retval 1 Success
 * @retval 0 failure, conslt errno for more details
 */
struct conn * conn_create(int sock, struct sockaddr * addr, int qsize)
{
	struct conn * conn; 
	conn = malloc(sizeof (struct conn));
	if (!conn)
		return NULL;

	memset(conn,0,sizeof(struct conn));

	conn->sock=sock;

	if (addr)
		sock_copyaddr(&conn->addr,addr);

//	printf("AF IN: %i\n",addr->sa_family);
//	char str[200] ;
//	sock_addrtostr((struct sockaddr*)&conn->addr,str,200);
//	printf("CONN CREATOR: %s\n",str);

	conn->fragman = fragman_create();
	if (conn->fragman==NULL){
		conn_destroy(conn);
		return NULL;
	}

	conn->qsize=qsize;
	if (qsize != 0){
		if (!(conn->q=malloc( sizeof(uint8_t *) * qsize))){
			conn_destroy(conn);
			return NULL;
		}
		conn->qrpos=-1;
		if (sem_init(&conn->q_sem,0,0)!=0){
			cw_log(LOG_ERR,"sem_init %s",strerror(errno));
			conn_destroy(conn);
			return NULL;
		};
		conn->recv_packet=conn_q_recv_packet;
	}
	else
		conn->recv_packet = conn_recv_packet;


//	conn->process_message=process_message;
//	conn->pmsgarg=pmsgarg;

	conn->last_seqnum_received=-1;
	conn->mtu=1500;

	conn->send_packet = conn_send_packet;

	conn->cur_packet=0;
	conn->recv_timeout=1;

	conn->seqnum=-1;
	conn->write = conn->send_packet;
	conn->read = conn->recv_packet;


	return conn;
}


/*
void conn_destroy(struct conn * conn)
{
	if (conn->fragman)
		fragman_destroy(conn->fragman);
	if (conn->q)
		free (conn->q);

	free(conn);
}
*/

/*
void connn_get_next_seqnum(struct conn * conn)
{
	return (++conn->seqnum)&0xff;
}
*/<commit_msg>Some cleanup<commit_after>/*
    This file is part of libcapwap.

    libcapwap is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    libcapwap is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.

*/

#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include "conn.h"
#include "sock.h"

#include "cw_log.h"

/**
 * function
 * @retval 1 Success
 * @retval 0 failure, conslt errno for more details
 */
struct conn * conn_create(int sock, struct sockaddr * addr, int qsize)
{
	struct conn * conn; 
	conn = malloc(sizeof (struct conn));
	if (!conn)
		return NULL;

	memset(conn,0,sizeof(struct conn));

	conn->sock=sock;

	if (addr)
		sock_copyaddr(&conn->addr,addr);

//	printf("AF IN: %i\n",addr->sa_family);
//	char str[200] ;
//	sock_addrtostr((struct sockaddr*)&conn->addr,str,200);
//	printf("CONN CREATOR: %s\n",str);

	conn->fragman = fragman_create();
	if (conn->fragman==NULL){
		conn_destroy(conn);
		return NULL;
	}

	conn->qsize=qsize;
	if (qsize != 0){
		if (!(conn->q=malloc( sizeof(uint8_t *) * qsize))){
			conn_destroy(conn);
			return NULL;
		}
		conn->qrpos=-1;
		if (sem_init(&conn->q_sem,0,0)!=0){
			cw_log(LOG_ERR,"sem_init %s",strerror(errno));
			conn_destroy(conn);
			return NULL;
		};
		conn->recv_packet=conn_q_recv_packet;
	}
	else
		conn->recv_packet = conn_recv_packet;


	conn->last_seqnum_received=-1;
	conn->mtu=1500;

	conn->send_packet = conn_send_packet;

	conn->cur_packet=0;
	conn->recv_timeout=1;

	conn->seqnum=-1;
	conn->write = conn->send_packet;
	conn->read = conn->recv_packet;


	return conn;
}


{'fraction_non_alphanumeric': 0.13817119748371154, 'fraction_numerical': 0.011008762075937992, 'mean_word_length': 3.8762322015334063, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 62, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7104185', 'n_tokens_mistral': 1681, 'n_tokens_neox': 1567, 'n_words': 435}