aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-06-06 00:32:36 +0200
committerChristian Grothoff <christian@grothoff.org>2018-06-06 00:32:36 +0200
commit90e29258a5339d232ea1b22f3f83d61701b52358 (patch)
tree1dcdab00bbbafdc3a30c82c390f66af0d82ecba2 /src/util
parente13828526819ba1b37877950b8cef75a4c7787b4 (diff)
downloadgnunet-90e29258a5339d232ea1b22f3f83d61701b52358.tar.gz
gnunet-90e29258a5339d232ea1b22f3f83d61701b52358.zip
changes for AGPL handling
Diffstat (limited to 'src/util')
-rw-r--r--src/util/mq.c37
-rw-r--r--src/util/service.c40
2 files changed, 73 insertions, 4 deletions
diff --git a/src/util/mq.c b/src/util/mq.c
index 81a42e0c6..bf8f95790 100644
--- a/src/util/mq.c
+++ b/src/util/mq.c
@@ -1216,6 +1216,43 @@ GNUNET_MQ_copy_handlers (const struct GNUNET_MQ_MessageHandler *handlers)
1216 1216
1217 1217
1218/** 1218/**
1219 * Copy an array of handlers, appending AGPL handler.
1220 *
1221 * Useful if the array has been delared in local memory and needs to be
1222 * persisted for future use.
1223 *
1224 * @param handlers Array of handlers to be copied. Can be NULL (nothing done).
1225 * @param agpl_handler function to call for AGPL handling
1226 * @param agpl_cls closure for @a agpl_handler
1227 * @return A newly allocated array of handlers.
1228 * Needs to be freed with #GNUNET_free.
1229 */
1230struct GNUNET_MQ_MessageHandler *
1231GNUNET_MQ_copy_handlers2 (const struct GNUNET_MQ_MessageHandler *handlers,
1232 GNUNET_MQ_MessageCallback agpl_handler,
1233 void *agpl_cls)
1234{
1235 struct GNUNET_MQ_MessageHandler *copy;
1236 unsigned int count;
1237
1238 if (NULL == handlers)
1239 return NULL;
1240 count = GNUNET_MQ_count_handlers (handlers);
1241 copy = GNUNET_new_array (count + 2,
1242 struct GNUNET_MQ_MessageHandler);
1243 GNUNET_memcpy (copy,
1244 handlers,
1245 count * sizeof (struct GNUNET_MQ_MessageHandler));
1246 copy[count].mv = NULL;
1247 copy[count].cb = agpl_handler;
1248 copy[count].cls = agpl_cls;
1249 copy[count].type = GNUNET_MESSAGE_TYPE_REQUEST_AGPL;
1250 copy[count].expected_size = sizeof (struct GNUNET_MessageHeader);
1251 return copy;
1252}
1253
1254
1255/**
1219 * Count the handlers in a handler array. 1256 * Count the handlers in a handler array.
1220 * 1257 *
1221 * @param handlers Array of handlers to be counted. 1258 * @param handlers Array of handlers to be counted.
diff --git a/src/util/service.c b/src/util/service.c
index 1156093f4..ae1809950 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -1572,6 +1572,36 @@ teardown_service (struct GNUNET_SERVICE_Handle *sh)
1572 1572
1573 1573
1574/** 1574/**
1575 * Function to return link to AGPL source upon request.
1576 *
1577 * @param cls closure with the identification of the client
1578 * @param msg AGPL request
1579 */
1580static void
1581return_agpl (void *cls,
1582 const struct GNUNET_MessageHeader *msg)
1583{
1584 struct GNUNET_SERVICE_Client *client = cls;
1585 struct GNUNET_MQ_Handle *mq;
1586 struct GNUNET_MQ_Envelope *env;
1587 struct GNUNET_MessageHeader *res;
1588 size_t slen;
1589
1590 slen = strlen (GNUNET_AGPL_URL) + 1;
1591 env = GNUNET_MQ_msg_extra (res,
1592 GNUNET_MESSAGE_TYPE_RESPONSE_AGPL,
1593 slen);
1594 memcpy (&res[1],
1595 GNUNET_AGPL_URL,
1596 slen);
1597 mq = GNUNET_SERVICE_client_get_mq (client);
1598 GNUNET_MQ_send (mq,
1599 env);
1600 GNUNET_SERVICE_client_continue (client);
1601}
1602
1603
1604/**
1575 * Low-level function to start a service if the scheduler 1605 * Low-level function to start a service if the scheduler
1576 * is already running. Should only be used directly in 1606 * is already running. Should only be used directly in
1577 * special cases. 1607 * special cases.
@@ -1623,7 +1653,9 @@ GNUNET_SERVICE_start (const char *service_name,
1623 sh->connect_cb = connect_cb; 1653 sh->connect_cb = connect_cb;
1624 sh->disconnect_cb = disconnect_cb; 1654 sh->disconnect_cb = disconnect_cb;
1625 sh->cb_cls = cls; 1655 sh->cb_cls = cls;
1626 sh->handlers = GNUNET_MQ_copy_handlers (handlers); 1656 sh->handlers = GNUNET_MQ_copy_handlers2 (handlers,
1657 &return_agpl,
1658 NULL);
1627 if (GNUNET_OK != setup_service (sh)) 1659 if (GNUNET_OK != setup_service (sh))
1628 { 1660 {
1629 GNUNET_free_non_null (sh->handlers); 1661 GNUNET_free_non_null (sh->handlers);
@@ -1723,9 +1755,9 @@ GNUNET_SERVICE_run_ (int argc,
1723 struct GNUNET_GETOPT_CommandLineOption service_options[] = { 1755 struct GNUNET_GETOPT_CommandLineOption service_options[] = {
1724 GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename), 1756 GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename),
1725 GNUNET_GETOPT_option_flag ('d', 1757 GNUNET_GETOPT_option_flag ('d',
1726 "daemonize", 1758 "daemonize",
1727 gettext_noop ("do daemonize (detach from terminal)"), 1759 gettext_noop ("do daemonize (detach from terminal)"),
1728 &do_daemonize), 1760 &do_daemonize),
1729 GNUNET_GETOPT_option_help (NULL), 1761 GNUNET_GETOPT_option_help (NULL),
1730 GNUNET_GETOPT_option_loglevel (&loglev), 1762 GNUNET_GETOPT_option_loglevel (&loglev),
1731 GNUNET_GETOPT_option_logfile (&logfile), 1763 GNUNET_GETOPT_option_logfile (&logfile),