GNUnet  0.10.x
fs_list_indexed.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2003, 2004, 2006, 2009 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19 */
20 
27 #include "platform.h"
28 #include "gnunet_constants.h"
29 #include "gnunet_fs_service.h"
30 #include "gnunet_protocols.h"
31 #include "fs_api.h"
32 
33 
38 {
39 
44 
49 
53  void *iterator_cls;
54 
59 
63  void *cont_cls;
64 };
65 
66 
74 static void
76  const struct GNUNET_MessageHeader *msg)
77 {
78  struct GNUNET_FS_GetIndexedContext *gic = cls;
79 
80  (void) gic->iterator (gic->iterator_cls,
81  NULL,
82  NULL);
84 }
85 
86 
94 static int
95 check_index_info (void *cls,
96  const struct IndexInfoMessage *iim)
97 {
98  uint16_t msize = ntohs (iim->header.size) - sizeof (*iim);
99  const char *filename;
100 
101  filename = (const char *) &iim[1];
102  if (filename[msize - 1] != '\0')
103  {
104  GNUNET_break (0);
105  return GNUNET_SYSERR;
106  }
107  return GNUNET_OK;
108 }
109 
110 
118 static void
119 handle_index_info (void *cls,
120  const struct IndexInfoMessage *iim)
121 {
122  struct GNUNET_FS_GetIndexedContext *gic = cls;
123  const char *filename;
124 
125  filename = (const char *) &iim[1];
126  if (GNUNET_OK !=
127  gic->iterator (gic->iterator_cls,
128  filename,
129  &iim->file_id))
130  {
132  return;
133  }
134 }
135 
136 
145 static void
146 mq_error_handler (void *cls,
147  enum GNUNET_MQ_Error error)
148 {
149  struct GNUNET_FS_GetIndexedContext *gic = cls;
150 
152  _("Failed to receive response from `%s' service.\n"),
153  "fs");
154  (void) gic->iterator (gic->iterator_cls, NULL, NULL);
156 }
157 
158 
170  void *iterator_cls)
171 {
172  struct GNUNET_FS_GetIndexedContext *gic
174  struct GNUNET_MQ_MessageHandler handlers[] = {
175  GNUNET_MQ_hd_fixed_size (index_info_end,
177  struct GNUNET_MessageHeader,
178  gic),
179  GNUNET_MQ_hd_var_size (index_info,
181  struct IndexInfoMessage,
182  gic),
184  };
185  struct GNUNET_MQ_Envelope *env;
186  struct GNUNET_MessageHeader *msg;
187 
188  gic->mq = GNUNET_CLIENT_connect (h->cfg,
189  "fs",
190  handlers,
192  h);
193  if (NULL == gic->mq)
194  {
196  _("Failed to not connect to `%s' service.\n"),
197  "fs");
198  GNUNET_free (gic);
199  return NULL;
200  }
201  gic->iterator = iterator;
202  gic->iterator_cls = iterator_cls;
203  env = GNUNET_MQ_msg (msg,
205  GNUNET_MQ_send (gic->mq,
206  env);
207  return gic;
208 }
209 
210 
216 void
218 {
219  GNUNET_MQ_destroy (gic->mq);
220  GNUNET_free (gic);
221 }
222 
223 
224 /* end of fs_list_indexed.c */
GNUNET_SCHEDULER_TaskCallback cont
Continuation to trigger at the end.
void * cont_cls
Closure for cont.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
void * iterator_cls
Closure for iterator.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:901
GNUNET_MQ_Error
Error codes for the queue.
Master context for most FS operations.
Definition: fs_api.h:1087
void GNUNET_FS_get_indexed_files_cancel(struct GNUNET_FS_GetIndexedContext *gic)
Cancel iteration over all indexed files.
#define GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET
Request from client for list of indexed files.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Message send by FS service in response to a request asking for a list of all indexed files...
Definition: fs.h:199
#define GNUNET_new(type)
Allocate a struct or union of the given type.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
struct GNUNET_HashCode file_id
Hash of the indexed file.
Definition: fs.h:215
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
#define GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY
Reply to client with an indexed file name.
int(* GNUNET_FS_IndexedFileProcessor)(void *cls, const char *filename, const struct GNUNET_HashCode *file_id)
Type of a function called by GNUNET_FS_get_indexed_files.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
struct GNUNET_FS_GetIndexedContext * GNUNET_FS_get_indexed_files(struct GNUNET_FS_Handle *h, GNUNET_FS_IndexedFileProcessor iterator, void *iterator_cls)
Iterate over all indexed files.
static char * filename
Message handler for a specific message type.
struct GNUNET_MQ_Handle * mq
Connection to the FS service.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static void handle_index_info_end(void *cls, const struct GNUNET_MessageHeader *msg)
Function called on each response from the FS service with information about indexed files...
struct GNUNET_MessageHeader header
Message type will be GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY.
Definition: fs.h:205
static int check_index_info(void *cls, const struct IndexInfoMessage *iim)
Check validity of response from the FS service with information about indexed files.
Handle to a message queue.
Definition: mq.c:85
#define GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END
Reply to client indicating end of list.
shared definitions for the FS library
static void handle_index_info(void *cls, const struct IndexInfoMessage *iim)
Function called on each response from the FS service with information about indexed files...
#define GNUNET_log(kind,...)
Context for GNUNET_FS_get_indexed_files().
Header for all communications.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:353
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
GNUNET_FS_IndexedFileProcessor iterator
Function to call for each indexed file.
#define GNUNET_free(ptr)
Wrapper around free.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: fs_api.h:1092