Add announcement message.
[gnutls.git] / libextra / gnutls_extra.c
blob57ebb818e93f2bfb3a479d6646620e130a33e8d0
1 /*
2 * Copyright (C) 2001, 2004, 2005, 2007, 2008, 2009, 2010 Free Software
3 * Foundation, Inc.
5 * Author: Nikos Mavrogiannopoulos
7 * This file is part of GNUTLS-EXTRA.
9 * GNUTLS-EXTRA is free software: you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation, either version 3 of the
12 * License, or (at your option) any later version.
14 * GNUTLS-EXTRA is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see
21 * <http://www.gnu.org/licenses/>.
24 #include <gnutls_int.h>
25 #include <gnutls_errors.h>
26 #include <gnutls_extensions.h>
27 #include <gnutls_algorithms.h>
28 #include <ext_inner_application.h>
29 #ifdef USE_LZO
30 # ifdef USE_MINILZO
31 # include "minilzo/minilzo.h"
32 # elif HAVE_LZO_LZO1X_H
33 # include <lzo/lzo1x.h>
34 # elif HAVE_LZO1X_H
35 # include <lzo1x.h>
36 # endif
37 #endif
38 #include <gnutls/extra.h>
40 #ifdef USE_LZO
41 #include <gnutls_compress.h>
43 /* the number of the compression algorithms available in the compression
44 * structure.
46 extern int _gnutls_comp_algorithms_size;
48 typedef int (*LZO_FUNC) ();
49 extern LZO_FUNC _gnutls_lzo1x_decompress_safe;
50 extern LZO_FUNC _gnutls_lzo1x_1_compress;
52 extern gnutls_compression_entry _gnutls_compression_algorithms[];
54 static int
55 _gnutls_add_lzo_comp (void)
57 int i;
59 /* find the last element */
60 for (i = 0; i < _gnutls_comp_algorithms_size; i++)
62 if (_gnutls_compression_algorithms[i].name == NULL)
63 break;
66 if (_gnutls_compression_algorithms[i].name == NULL
67 && (i < _gnutls_comp_algorithms_size - 1))
69 _gnutls_compression_algorithms[i].name = "GNUTLS_COMP_LZO";
70 _gnutls_compression_algorithms[i].id = GNUTLS_COMP_LZO;
71 _gnutls_compression_algorithms[i].num = 0xf2;
73 _gnutls_compression_algorithms[i + 1].name = 0;
75 /* Now enable the lzo functions: */
76 _gnutls_lzo1x_decompress_safe = lzo1x_decompress_safe;
77 _gnutls_lzo1x_1_compress = lzo1x_1_compress;
79 return 0; /* ok */
83 return GNUTLS_E_MEMORY_ERROR;
85 #endif
87 static int _gnutls_init_extra = 0;
89 /**
90 * gnutls_global_init_extra - initializes the global state of gnutls-extra
92 * This function initializes the global state of gnutls-extra library
93 * to defaults.
95 * Note that gnutls_global_init() has to be called before this
96 * function. If this function is not called then the gnutls-extra
97 * library will not be usable.
99 * This function is not thread safe, see the discussion for
100 * gnutls_global_init() on how to deal with that.
102 * Returns: On success, %GNUTLS_E_SUCCESS (zero) is returned,
103 * otherwise an error code is returned.
106 gnutls_global_init_extra (void)
108 int ret;
110 /* If the version of libgnutls != version of
111 * libextra, then do not initialize the library.
112 * This is because it may break things.
114 if (strcmp (gnutls_check_version (NULL), VERSION) != 0)
116 return GNUTLS_E_LIBRARY_VERSION_MISMATCH;
119 _gnutls_init_extra++;
121 if (_gnutls_init_extra != 1)
122 return 0;
124 ret = gnutls_ext_register (GNUTLS_EXTENSION_INNER_APPLICATION,
125 "INNER_APPLICATION",
126 GNUTLS_EXT_TLS,
127 _gnutls_inner_application_recv_params,
128 _gnutls_inner_application_send_params);
129 if (ret != GNUTLS_E_SUCCESS)
130 return ret;
132 /* Initialize the LZO library
134 #ifdef USE_LZO
135 if (lzo_init () != LZO_E_OK)
136 return GNUTLS_E_LZO_INIT_FAILED;
138 /* Add the LZO compression method in the list of compression
139 * methods.
141 ret = _gnutls_add_lzo_comp ();
142 if (ret < 0)
144 gnutls_assert ();
145 return ret;
147 #endif
149 return 0;
153 * gnutls_extra_check_version - checks the libgnutls-extra version
154 * @req_version: version string to compare with, or %NULL.
156 * Check GnuTLS Extra Library version.
158 * See %GNUTLS_EXTRA_VERSION for a suitable @req_version string.
160 * Return value: Check that the version of the library is at
161 * minimum the one given as a string in @req_version and return the
162 * actual version string of the library; return %NULL if the
163 * condition is not met. If %NULL is passed to this function no
164 * check is done and only the version string is returned.
166 const char *
167 gnutls_extra_check_version (const char *req_version)
169 if (!req_version || strverscmp (req_version, VERSION) <= 0)
170 return VERSION;
172 return NULL;