gnutls_datum.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation
00003  *
00004  * Author: Nikos Mavrogiannopoulos
00005  *
00006  * This file is part of GNUTLS.
00007  *
00008  * The GNUTLS library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation; either version 2.1 of
00011  * the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00021  * USA
00022  *
00023  */
00024 
00025 /* contains functions that make it easier to
00026  * write vectors of <size|data>. The destination size
00027  * should be preallocated (datum.size+(bits/8))
00028  */
00029 
00030 #include <gnutls_int.h>
00031 #include <gnutls_num.h>
00032 #include <gnutls_datum.h>
00033 #include <gnutls_errors.h>
00034 
00035 
00036 void
00037 MHD_gtls_write_datum16 (opaque * dest, MHD_gnutls_datum_t dat)
00038 {
00039   MHD_gtls_write_uint16 (dat.size, dest);
00040   if (dat.data != NULL)
00041     memcpy (&dest[2], dat.data, dat.size);
00042 }
00043 
00044 void
00045 MHD_gtls_write_datum24 (opaque * dest, MHD_gnutls_datum_t dat)
00046 {
00047   MHD_gtls_write_uint24 (dat.size, dest);
00048   if (dat.data != NULL)
00049     memcpy (&dest[3], dat.data, dat.size);
00050 }
00051 
00052 int
00053 MHD_gtls_set_datum_m (MHD_gnutls_datum_t * dat, const void *data,
00054                       size_t data_size, MHD_gnutls_alloc_function galloc_func)
00055 {
00056   if (data_size == 0 || data == NULL)
00057     {
00058       dat->data = NULL;
00059       dat->size = 0;
00060       return 0;
00061     }
00062 
00063   dat->data = galloc_func (data_size);
00064   if (dat->data == NULL)
00065     return GNUTLS_E_MEMORY_ERROR;
00066 
00067   dat->size = data_size;
00068   memcpy (dat->data, data, data_size);
00069 
00070   return 0;
00071 }
00072 
00073 void
00074 MHD_gtls_free_datum_m (MHD_gnutls_datum_t * dat,
00075                        MHD_gnutls_free_function gfree_func)
00076 {
00077   if (dat->data != NULL)
00078     gfree_func (dat->data);
00079 
00080   dat->data = NULL;
00081   dat->size = 0;
00082 }

Generated on Fri Feb 27 18:32:19 2009 for GNU libmicrohttpd by  doxygen 1.5.7.1