Logo Search packages:      
Sourcecode: dctc version File versions  Download package

factory.h

/* DCTC - a Direct Connect text clone for Linux
 * Copyright (C) 2001 Eric Prevoteau
 *
 * factory.h: Copyright (C) Eric Prevoteau <www@ac2i.tzo.com>
 *
 * This program 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 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
/*
$Id: factory.h,v 1.3 2003/05/31 13:50:14 ericprev Exp $
*/

#ifndef __FACTORY_H__
#define __FACTORY_H__

#include <glib.h>

/**************************************************/
/* set of functions to build/unbuild ed2k packets */
/**************************************************/

typedef struct
{
      GByteArray *gba;

      /* location of a guint32 containing the size of the array defined by 2 positions */
      int packet_size_at_pos;
      int packet_size_begin_at_pos;
      int packet_size_end_at_pos;
} PACKET_BUILD;

/*******************************/
/* create a new packet builder */
/*******************************/
PACKET_BUILD *ed2k_pb_new(void);

/*******************************************************/
/* set the packet size guint32 at the current position */
/*******************************************************/
void ed2k_pb_set_size_location(PACKET_BUILD *pb);

/***********************************************************/
/* set the location of the first byte to count in the size */
/***********************************************************/
void ed2k_pb_set_size_begin_location(PACKET_BUILD *pb);

/************************************************************/
/* set the location of the first byte to ignore in the size */
/************************************************************/
void ed2k_pb_set_size_end_location(PACKET_BUILD *pb);

/*******************************/
/* append a byte to the packet */
/*******************************/
void ed2k_pb_add_byte(PACKET_BUILD *pb, guint8 v8);

/******************************************/
/* append an array of bytes to the packet */
/******************************************/
void ed2k_pb_add_bytes(PACKET_BUILD *pb, guint8 *v8, int v8_size);

/**********************************************************/
/* append a guint16 in little endian format to the packet */
/**********************************************************/
void ed2k_pb_add_lsb_2bytes(PACKET_BUILD *pb, guint16 v16);

/**********************************************************/
/* append a guint32 in little endian format to the packet */
/**********************************************************/
void ed2k_pb_add_lsb_4bytes(PACKET_BUILD *pb, guint32 v32);

/********************************************************************************/
/* add the given string prefixed by a guint16 containing its size to the packet */
/********************************************************************************/
void ed2k_pb_add_string(PACKET_BUILD *pb, char *string, int string_len);

/****************************************************************/
/* destroy the packet builder, compute packet size if it exists */
/* and return the built packet                                  */
/* if the size exists and limit is not defined, the begin_pos   */
/* will be the first byte and the end_pos is after the last byte*/
/****************************************************************/
GByteArray *ed2k_pb_end(PACKET_BUILD *pb);


/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

guint32 take_lsb_4bytes(guint8 *addr);
guint16 take_lsb_2bytes(guint8 *addr);

#endif

Generated by  Doxygen 1.6.0   Back to index