aboutsummaryrefslogtreecommitdiff
path: root/src/psycstore/gnunet-service-psycstore.c
diff options
context:
space:
mode:
authorGabor X Toth <*@tg-x.net>2013-09-03 22:33:21 +0000
committerGabor X Toth <*@tg-x.net>2013-09-03 22:33:21 +0000
commiteb9556bf2983ca19a5cbcf7cf460a0b2509b290a (patch)
tree285d31e951f7ecf9308b22257adcadd5b07d80ea /src/psycstore/gnunet-service-psycstore.c
parent37bafa60a6f0e447cb5b61547404f0902fa7ad41 (diff)
downloadgnunet-eb9556bf2983ca19a5cbcf7cf460a0b2509b290a.tar.gz
gnunet-eb9556bf2983ca19a5cbcf7cf460a0b2509b290a.zip
PSYCstore SQLite backend; API fixes/enhancements
Diffstat (limited to 'src/psycstore/gnunet-service-psycstore.c')
-rw-r--r--src/psycstore/gnunet-service-psycstore.c59
1 files changed, 55 insertions, 4 deletions
diff --git a/src/psycstore/gnunet-service-psycstore.c b/src/psycstore/gnunet-service-psycstore.c
index d8f7a2690..5bc35d227 100644
--- a/src/psycstore/gnunet-service-psycstore.c
+++ b/src/psycstore/gnunet-service-psycstore.c
@@ -101,27 +101,72 @@ send_result_code (struct GNUNET_SERVER_Client *client,
101 uint32_t result_code, 101 uint32_t result_code,
102 const char *emsg) 102 const char *emsg)
103{ 103{
104 struct GNUNET_PSYCSTORE_ResultCodeMessage *rcm; 104 struct ResultCodeMessage *rcm;
105 size_t elen; 105 size_t elen;
106 106
107 if (NULL == emsg) 107 if (NULL == emsg)
108 elen = 0; 108 elen = 0;
109 else 109 else
110 elen = strlen (emsg) + 1; 110 elen = strlen (emsg) + 1;
111 rcm = GNUNET_malloc (sizeof (struct GNUNET_PSYCSTORE_ResultCodeMessage) + elen); 111 rcm = GNUNET_malloc (sizeof (struct ResultCodeMessage) + elen);
112 rcm->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_CODE); 112 rcm->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_CODE);
113 rcm->header.size = htons (sizeof (struct GNUNET_PSYCSTORE_ResultCodeMessage) + elen); 113 rcm->header.size = htons (sizeof (struct ResultCodeMessage) + elen);
114 rcm->result_code = htonl (result_code); 114 rcm->result_code = htonl (result_code);
115 memcpy (&rcm[1], emsg, elen); 115 memcpy (&rcm[1], emsg, elen);
116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
117 "Sending result %d (%s) to client\n", 117 "Sending result %d (%s) to client\n",
118 (int) result_code, 118 (int) result_code,
119 emsg); 119 emsg);
120 GNUNET_SERVER_notification_context_unicast (nc, client, &rcm->header, GNUNET_NO); 120 GNUNET_SERVER_notification_context_unicast (nc, client, &rcm->header,
121 GNUNET_NO);
121 GNUNET_free (rcm); 122 GNUNET_free (rcm);
122} 123}
123 124
124 125
126static void
127handle_membership_store (void *cls,
128 struct GNUNET_SERVER_Client *client,
129 const struct GNUNET_MessageHeader *message)
130{
131 const struct MembershipStoreMessage *msg =
132 (const struct MembershipStoreMessage *) message;
133
134 int res = db->membership_store (db->cls, msg->channel_key, msg->slave_key,
135 msg->did_join, msg->announced_at,
136 msg->effective_since, msg->group_generation);
137
138 if (res != GNUNET_OK)
139 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
140 _("Failed to store membership information!\n"));
141
142 send_result_code (client, res, NULL);
143}
144
145
146static void
147handle_membership_test (void *cls,
148 struct GNUNET_SERVER_Client *client,
149 const struct GNUNET_MessageHeader *message)
150{
151 const struct MembershipTestMessage *msg =
152 (const struct MembershipTestMessage *) message;
153
154 int res = db->membership_test (db->cls, msg->channel_key, msg->slave_key,
155 msg->message_id);
156 switch (res)
157 {
158 case GNUNET_YES:
159 case GNUNET_NO:
160 break;
161 default:
162 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
163 _("Failed to test membership!\n"));
164 }
165
166 send_result_code (client, res, NULL);
167}
168
169
125/** 170/**
126 * Handle PSYCstore clients. 171 * Handle PSYCstore clients.
127 * 172 *
@@ -135,6 +180,12 @@ run (void *cls,
135 const struct GNUNET_CONFIGURATION_Handle *c) 180 const struct GNUNET_CONFIGURATION_Handle *c)
136{ 181{
137 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 182 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
183 {&handle_membership_store, NULL,
184 GNUNET_MESSAGE_TYPE_PSYCSTORE_MEMBERSHIP_STORE,
185 sizeof (struct MembershipStoreMessage)},
186 {&handle_membership_test, NULL,
187 GNUNET_MESSAGE_TYPE_PSYCSTORE_MEMBERSHIP_TEST,
188 sizeof (struct MembershipTestMessage)},
138 {NULL, NULL, 0, 0} 189 {NULL, NULL, 0, 0}
139 }; 190 };
140 191