aboutsummaryrefslogtreecommitdiff
path: root/src/util/mq.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/mq.c')
-rw-r--r--src/util/mq.c81
1 files changed, 71 insertions, 10 deletions
diff --git a/src/util/mq.c b/src/util/mq.c
index dbcce704d..eaac85575 100644
--- a/src/util/mq.c
+++ b/src/util/mq.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012-2017 GNUnet e.V. 3 Copyright (C) 2012-2017 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software: you can redistribute it and/or modify it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20 18
21/** 19/**
@@ -1071,6 +1069,32 @@ GNUNET_MQ_set_options (struct GNUNET_MQ_Handle *mq,
1071 1069
1072 1070
1073/** 1071/**
1072 * Obtain message contained in envelope.
1073 *
1074 * @param env the envelope
1075 * @return message contained in the envelope
1076 */
1077const struct GNUNET_MessageHeader *
1078GNUNET_MQ_env_get_msg (const struct GNUNET_MQ_Envelope *env)
1079{
1080 return env->mh;
1081}
1082
1083
1084/**
1085 * Return next envelope in queue.
1086 *
1087 * @param env a queued envelope
1088 * @return next one, or NULL
1089 */
1090const struct GNUNET_MQ_Envelope *
1091GNUNET_MQ_env_next (const struct GNUNET_MQ_Envelope *env)
1092{
1093 return env->next;
1094}
1095
1096
1097/**
1074 * Register function to be called whenever @a mq is being 1098 * Register function to be called whenever @a mq is being
1075 * destroyed. 1099 * destroyed.
1076 * 1100 *
@@ -1190,6 +1214,43 @@ GNUNET_MQ_copy_handlers (const struct GNUNET_MQ_MessageHandler *handlers)
1190 1214
1191 1215
1192/** 1216/**
1217 * Copy an array of handlers, appending AGPL handler.
1218 *
1219 * Useful if the array has been delared in local memory and needs to be
1220 * persisted for future use.
1221 *
1222 * @param handlers Array of handlers to be copied. Can be NULL (nothing done).
1223 * @param agpl_handler function to call for AGPL handling
1224 * @param agpl_cls closure for @a agpl_handler
1225 * @return A newly allocated array of handlers.
1226 * Needs to be freed with #GNUNET_free.
1227 */
1228struct GNUNET_MQ_MessageHandler *
1229GNUNET_MQ_copy_handlers2 (const struct GNUNET_MQ_MessageHandler *handlers,
1230 GNUNET_MQ_MessageCallback agpl_handler,
1231 void *agpl_cls)
1232{
1233 struct GNUNET_MQ_MessageHandler *copy;
1234 unsigned int count;
1235
1236 if (NULL == handlers)
1237 return NULL;
1238 count = GNUNET_MQ_count_handlers (handlers);
1239 copy = GNUNET_new_array (count + 2,
1240 struct GNUNET_MQ_MessageHandler);
1241 GNUNET_memcpy (copy,
1242 handlers,
1243 count * sizeof (struct GNUNET_MQ_MessageHandler));
1244 copy[count].mv = NULL;
1245 copy[count].cb = agpl_handler;
1246 copy[count].cls = agpl_cls;
1247 copy[count].type = GNUNET_MESSAGE_TYPE_REQUEST_AGPL;
1248 copy[count].expected_size = sizeof (struct GNUNET_MessageHeader);
1249 return copy;
1250}
1251
1252
1253/**
1193 * Count the handlers in a handler array. 1254 * Count the handlers in a handler array.
1194 * 1255 *
1195 * @param handlers Array of handlers to be counted. 1256 * @param handlers Array of handlers to be counted.