aboutsummaryrefslogtreecommitdiff
path: root/src/regex/regex_api_announce.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/regex/regex_api_announce.c')
-rw-r--r--src/regex/regex_api_announce.c99
1 files changed, 50 insertions, 49 deletions
diff --git a/src/regex/regex_api_announce.c b/src/regex/regex_api_announce.c
index 3b5801994..318d73263 100644
--- a/src/regex/regex_api_announce.c
+++ b/src/regex/regex_api_announce.c
@@ -29,12 +29,13 @@
29#include "gnunet_regex_service.h" 29#include "gnunet_regex_service.h"
30#include "regex_ipc.h" 30#include "regex_ipc.h"
31 31
32#define LOG(kind, ...) GNUNET_log_from(kind, "regex-api", __VA_ARGS__) 32#define LOG(kind, ...) GNUNET_log_from (kind, "regex-api", __VA_ARGS__)
33 33
34/** 34/**
35 * Handle to store cached data about a regex announce. 35 * Handle to store cached data about a regex announce.
36 */ 36 */
37struct GNUNET_REGEX_Announcement { 37struct GNUNET_REGEX_Announcement
38{
38 /** 39 /**
39 * Connection to the regex service. 40 * Connection to the regex service.
40 */ 41 */
@@ -69,7 +70,7 @@ struct GNUNET_REGEX_Announcement {
69 * @param a REGEX to announce. 70 * @param a REGEX to announce.
70 */ 71 */
71static void 72static void
72announce_reconnect(struct GNUNET_REGEX_Announcement *a); 73announce_reconnect (struct GNUNET_REGEX_Announcement *a);
73 74
74 75
75/** 76/**
@@ -80,14 +81,14 @@ announce_reconnect(struct GNUNET_REGEX_Announcement *a);
80 * @param error error code 81 * @param error error code
81 */ 82 */
82static void 83static void
83announce_mq_error_handler(void *cls, 84announce_mq_error_handler (void *cls,
84 enum GNUNET_MQ_Error error) 85 enum GNUNET_MQ_Error error)
85{ 86{
86 struct GNUNET_REGEX_Announcement *a = cls; 87 struct GNUNET_REGEX_Announcement *a = cls;
87 88
88 GNUNET_MQ_destroy(a->mq); 89 GNUNET_MQ_destroy (a->mq);
89 a->mq = NULL; 90 a->mq = NULL;
90 announce_reconnect(a); 91 announce_reconnect (a);
91} 92}
92 93
93 94
@@ -97,31 +98,31 @@ announce_mq_error_handler(void *cls,
97 * @param a REGEX to announce. 98 * @param a REGEX to announce.
98 */ 99 */
99static void 100static void
100announce_reconnect(struct GNUNET_REGEX_Announcement *a) 101announce_reconnect (struct GNUNET_REGEX_Announcement *a)
101{ 102{
102 struct GNUNET_MQ_Envelope *env; 103 struct GNUNET_MQ_Envelope *env;
103 struct AnnounceMessage *am; 104 struct AnnounceMessage *am;
104 size_t slen; 105 size_t slen;
105 106
106 a->mq = GNUNET_CLIENT_connect(a->cfg, 107 a->mq = GNUNET_CLIENT_connect (a->cfg,
107 "regex", 108 "regex",
108 NULL, 109 NULL,
109 &announce_mq_error_handler, 110 &announce_mq_error_handler,
110 a); 111 a);
111 if (NULL == a->mq) 112 if (NULL == a->mq)
112 return; 113 return;
113 slen = strlen(a->regex) + 1; 114 slen = strlen (a->regex) + 1;
114 env = GNUNET_MQ_msg_extra(am, 115 env = GNUNET_MQ_msg_extra (am,
115 slen, 116 slen,
116 GNUNET_MESSAGE_TYPE_REGEX_ANNOUNCE); 117 GNUNET_MESSAGE_TYPE_REGEX_ANNOUNCE);
117 am->compression = htons(a->compression); 118 am->compression = htons (a->compression);
118 am->reserved = htons(0); 119 am->reserved = htons (0);
119 am->refresh_delay = GNUNET_TIME_relative_hton(a->refresh_delay); 120 am->refresh_delay = GNUNET_TIME_relative_hton (a->refresh_delay);
120 GNUNET_memcpy(&am[1], 121 GNUNET_memcpy (&am[1],
121 a->regex, 122 a->regex,
122 slen); 123 slen);
123 GNUNET_MQ_send(a->mq, 124 GNUNET_MQ_send (a->mq,
124 env); 125 env);
125} 126}
126 127
127 128
@@ -136,35 +137,35 @@ announce_reconnect(struct GNUNET_REGEX_Announcement *a)
136 * Must be freed by calling #GNUNET_REGEX_announce_cancel(). 137 * Must be freed by calling #GNUNET_REGEX_announce_cancel().
137 */ 138 */
138struct GNUNET_REGEX_Announcement * 139struct GNUNET_REGEX_Announcement *
139GNUNET_REGEX_announce(const struct GNUNET_CONFIGURATION_Handle *cfg, 140GNUNET_REGEX_announce (const struct GNUNET_CONFIGURATION_Handle *cfg,
140 const char *regex, 141 const char *regex,
141 struct GNUNET_TIME_Relative refresh_delay, 142 struct GNUNET_TIME_Relative refresh_delay,
142 uint16_t compression) 143 uint16_t compression)
143{ 144{
144 struct GNUNET_REGEX_Announcement *a; 145 struct GNUNET_REGEX_Announcement *a;
145 size_t slen; 146 size_t slen;
146 147
147 slen = strlen(regex) + 1; 148 slen = strlen (regex) + 1;
148 if (slen + sizeof(struct AnnounceMessage) >= GNUNET_MAX_MESSAGE_SIZE) 149 if (slen + sizeof(struct AnnounceMessage) >= GNUNET_MAX_MESSAGE_SIZE)
149 { 150 {
150 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 151 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
151 _("Regex `%s' is too long!\n"), 152 _ ("Regex `%s' is too long!\n"),
152 regex); 153 regex);
153 GNUNET_break(0); 154 GNUNET_break (0);
154 return NULL; 155 return NULL;
155 } 156 }
156 a = GNUNET_new(struct GNUNET_REGEX_Announcement); 157 a = GNUNET_new (struct GNUNET_REGEX_Announcement);
157 a->cfg = cfg; 158 a->cfg = cfg;
158 a->refresh_delay = refresh_delay; 159 a->refresh_delay = refresh_delay;
159 a->compression = compression; 160 a->compression = compression;
160 a->regex = GNUNET_strdup(regex); 161 a->regex = GNUNET_strdup (regex);
161 announce_reconnect(a); 162 announce_reconnect (a);
162 if (NULL == a->mq) 163 if (NULL == a->mq)
163 { 164 {
164 GNUNET_free(a->regex); 165 GNUNET_free (a->regex);
165 GNUNET_free(a); 166 GNUNET_free (a);
166 return NULL; 167 return NULL;
167 } 168 }
168 return a; 169 return a;
169} 170}
170 171
@@ -175,11 +176,11 @@ GNUNET_REGEX_announce(const struct GNUNET_CONFIGURATION_Handle *cfg,
175 * @param a handle returned by a previous #GNUNET_REGEX_announce() call. 176 * @param a handle returned by a previous #GNUNET_REGEX_announce() call.
176 */ 177 */
177void 178void
178GNUNET_REGEX_announce_cancel(struct GNUNET_REGEX_Announcement *a) 179GNUNET_REGEX_announce_cancel (struct GNUNET_REGEX_Announcement *a)
179{ 180{
180 GNUNET_MQ_destroy(a->mq); 181 GNUNET_MQ_destroy (a->mq);
181 GNUNET_free(a->regex); 182 GNUNET_free (a->regex);
182 GNUNET_free(a); 183 GNUNET_free (a);
183} 184}
184 185
185/* end of regex_api_announce.c */ 186/* end of regex_api_announce.c */