aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs_list_indexed.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/fs_list_indexed.c')
-rw-r--r--src/fs/fs_list_indexed.c146
1 files changed, 68 insertions, 78 deletions
diff --git a/src/fs/fs_list_indexed.c b/src/fs/fs_list_indexed.c
index fec127763..1eb290f11 100644
--- a/src/fs/fs_list_indexed.c
+++ b/src/fs/fs_list_indexed.c
@@ -76,8 +76,7 @@ struct GetIndexedContext
76 * @param msg message with indexing information 76 * @param msg message with indexing information
77 */ 77 */
78static void 78static void
79handle_index_info (void *cls, 79handle_index_info (void *cls, const struct GNUNET_MessageHeader *msg)
80 const struct GNUNET_MessageHeader *msg)
81{ 80{
82 struct GetIndexedContext *gic = cls; 81 struct GetIndexedContext *gic = cls;
83 const struct IndexInfoMessage *iim; 82 const struct IndexInfoMessage *iim;
@@ -85,64 +84,58 @@ handle_index_info (void *cls,
85 const char *filename; 84 const char *filename;
86 85
87 if (NULL == msg) 86 if (NULL == msg)
88 { 87 {
89 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 88 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
90 _("Failed to receive response for `%s' request from `%s' service.\n"), 89 _
91 "GET_INDEXED", 90 ("Failed to receive response for `%s' request from `%s' service.\n"),
92 "fs"); 91 "GET_INDEXED", "fs");
93 GNUNET_SCHEDULER_add_continuation (gic->cont, 92 GNUNET_SCHEDULER_add_continuation (gic->cont, gic->cont_cls,
94 gic->cont_cls, 93 GNUNET_SCHEDULER_REASON_TIMEOUT);
95 GNUNET_SCHEDULER_REASON_TIMEOUT); 94 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
96 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO); 95 GNUNET_free (gic);
97 GNUNET_free (gic); 96 return;
98 return; 97 }
99 }
100 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END) 98 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END)
101 { 99 {
102 /* normal end-of-list */ 100 /* normal end-of-list */
103 GNUNET_SCHEDULER_add_continuation (gic->cont, 101 GNUNET_SCHEDULER_add_continuation (gic->cont,
104 gic->cont_cls, 102 gic->cont_cls,
105 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 103 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
106 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO); 104 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
107 GNUNET_free (gic); 105 GNUNET_free (gic);
108 return; 106 return;
109 } 107 }
110 msize = ntohs (msg->size); 108 msize = ntohs (msg->size);
111 iim = (const struct IndexInfoMessage*) msg; 109 iim = (const struct IndexInfoMessage *) msg;
112 filename = (const char*) &iim[1]; 110 filename = (const char *) &iim[1];
113 if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY) || 111 if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY) ||
114 (msize <= sizeof (struct IndexInfoMessage)) || 112 (msize <= sizeof (struct IndexInfoMessage)) ||
115 (filename[msize-sizeof (struct IndexInfoMessage) -1] != '\0') ) 113 (filename[msize - sizeof (struct IndexInfoMessage) - 1] != '\0'))
116 { 114 {
117 /* bogus reply */ 115 /* bogus reply */
118 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 116 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
119 _("Failed to receive valid response for `%s' request from `%s' service.\n"), 117 _
120 "GET_INDEXED", 118 ("Failed to receive valid response for `%s' request from `%s' service.\n"),
121 "fs"); 119 "GET_INDEXED", "fs");
122 GNUNET_SCHEDULER_add_continuation (gic->cont, 120 GNUNET_SCHEDULER_add_continuation (gic->cont, gic->cont_cls,
123 gic->cont_cls, 121 GNUNET_SCHEDULER_REASON_TIMEOUT);
124 GNUNET_SCHEDULER_REASON_TIMEOUT); 122 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
125 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO); 123 GNUNET_free (gic);
126 GNUNET_free (gic); 124 return;
127 return; 125 }
128 } 126 if (GNUNET_OK != gic->iterator (gic->iterator_cls, filename, &iim->file_id))
129 if (GNUNET_OK != 127 {
130 gic->iterator (gic->iterator_cls, 128 GNUNET_SCHEDULER_add_continuation (gic->cont,
131 filename, 129 gic->cont_cls,
132 &iim->file_id)) 130 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
133 { 131 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
134 GNUNET_SCHEDULER_add_continuation (gic->cont, 132 GNUNET_free (gic);
135 gic->cont_cls, 133 return;
136 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 134 }
137 GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
138 GNUNET_free (gic);
139 return;
140 }
141 /* get more */ 135 /* get more */
142 GNUNET_CLIENT_receive (gic->client, 136 GNUNET_CLIENT_receive (gic->client,
143 &handle_index_info, 137 &handle_index_info,
144 gic, 138 gic, GNUNET_CONSTANTS_SERVICE_TIMEOUT);
145 GNUNET_CONSTANTS_SERVICE_TIMEOUT);
146} 139}
147 140
148 141
@@ -157,29 +150,26 @@ handle_index_info (void *cls,
157 * error) or "PREREQ_DONE" (on success) 150 * error) or "PREREQ_DONE" (on success)
158 * @param cont_cls closure for cont 151 * @param cont_cls closure for cont
159 */ 152 */
160void 153void
161GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h, 154GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
162 GNUNET_FS_IndexedFileProcessor iterator, 155 GNUNET_FS_IndexedFileProcessor iterator,
163 void *iterator_cls, 156 void *iterator_cls,
164 GNUNET_SCHEDULER_Task cont, 157 GNUNET_SCHEDULER_Task cont, void *cont_cls)
165 void *cont_cls)
166{ 158{
167 struct GNUNET_CLIENT_Connection *client; 159 struct GNUNET_CLIENT_Connection *client;
168 struct GetIndexedContext *gic; 160 struct GetIndexedContext *gic;
169 struct GNUNET_MessageHeader msg; 161 struct GNUNET_MessageHeader msg;
170 162
171 client = GNUNET_CLIENT_connect ("fs", 163 client = GNUNET_CLIENT_connect ("fs", h->cfg);
172 h->cfg);
173 if (NULL == client) 164 if (NULL == client)
174 { 165 {
175 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 166 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
176 _("Failed to not connect to `%s' service.\n"), 167 _("Failed to not connect to `%s' service.\n"), "fs");
177 "fs"); 168 GNUNET_SCHEDULER_add_continuation (cont,
178 GNUNET_SCHEDULER_add_continuation (cont, 169 cont_cls,
179 cont_cls, 170 GNUNET_SCHEDULER_REASON_TIMEOUT);
180 GNUNET_SCHEDULER_REASON_TIMEOUT); 171 return;
181 return; 172 }
182 }
183 173
184 gic = GNUNET_malloc (sizeof (struct GetIndexedContext)); 174 gic = GNUNET_malloc (sizeof (struct GetIndexedContext));
185 gic->h = h; 175 gic->h = h;
@@ -191,12 +181,12 @@ GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
191 msg.size = htons (sizeof (struct GNUNET_MessageHeader)); 181 msg.size = htons (sizeof (struct GNUNET_MessageHeader));
192 msg.type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET); 182 msg.type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET);
193 GNUNET_assert (GNUNET_OK == 183 GNUNET_assert (GNUNET_OK ==
194 GNUNET_CLIENT_transmit_and_get_response (client, 184 GNUNET_CLIENT_transmit_and_get_response (client,
195 &msg, 185 &msg,
196 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 186 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
197 GNUNET_YES, 187 GNUNET_YES,
198 &handle_index_info, 188 &handle_index_info,
199 gic)); 189 gic));
200} 190}
201 191
202/* end of fs_list_indexed.c */ 192/* end of fs_list_indexed.c */