social: watch modifiers
[oweals/gnunet.git] / src / include / gnunet_social_service.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2013 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      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      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20
21 /**
22  * @file include/gnunet_social_service.h
23  * @brief Social service; implements social interactions using the PSYC service.
24  * @author Gabor X Toth
25  * @author Christian Grothoff
26  */
27 #ifndef GNUNET_SOCIAL_SERVICE_H
28 #define GNUNET_SOCIAL_SERVICE_H
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #if 0                           /* keep Emacsens' auto-indent happy */
34 }
35 #endif
36 #endif
37
38 #include "gnunet_util_lib.h"
39 #include "gnunet_env_lib.h"
40 #include "gnunet_identity_service.h"
41 #include "gnunet_psyc_service.h"
42
43
44 /**
45  * Version number of GNUnet Social API.
46  */
47 #define GNUNET_SOCIAL_VERSION 0x00000000
48
49
50 /**
51  * Handle for a pseudonym of another user in the network.
52  */
53 struct GNUNET_SOCIAL_Nym;
54
55 /**
56  * Handle for a place where social interactions happen.
57  */
58 struct GNUNET_SOCIAL_Place;
59
60 /**
61  * Host handle for a place that we entered.
62  */
63 struct GNUNET_SOCIAL_Host;
64
65 /**
66  * Guest handle for place that we entered.
67  */
68 struct GNUNET_SOCIAL_Guest;
69
70 /**
71  * Handle to an implementation of try-and-slice.
72  */
73 struct GNUNET_SOCIAL_Slicer;
74
75
76 /**
77  * Function called upon receiving a message indicating a call to a @e method.
78  *
79  * This function is called one or more times for each message until all data
80  * fragments arrive from the network.
81  *
82  * @param cls
83  *        Closure.
84  * @param msg
85  *        Message part, as it arrived from the network.
86  * @param message_id
87  *        Message counter, monotonically increasing from 1.
88  * @param nym
89  *        The sender of the message.
90  *        Can be NULL if the message is not connected to a pseudonym.
91  * @param flags
92  *        OR'ed GNUNET_PSYC_MessageFlags
93  * @param method_name
94  *        Original method name from PSYC.
95  *        May be more specific than the registered method name due to
96  *        try-and-slice matching.
97  */
98 typedef void
99 (*GNUNET_SOCIAL_MethodCallback) (void *cls,
100                                  const struct GNUNET_PSYC_MessageMethod *msg,
101                                  uint64_t message_id,
102                                  uint32_t flags,
103                                  const struct GNUNET_SOCIAL_Nym *nym,
104                                  const char *method_name);
105
106
107 /**
108  * Function called upon receiving a modifier of a message.
109  *
110  * @param cls
111  *        Closure.
112  * @param message_id
113  *        Message ID this data fragment belongs to.
114  * @param msg
115  *        Message part, as it arrived from the network.
116  * @param oper
117  *        Operation to perform.
118  *        0 in case of a modifier continuation.
119  * @param name
120  *        Name of the modifier.
121  *        NULL in case of a modifier continuation.
122  * @param value
123  *        Value of the modifier.
124  * @param value_size
125  *        Size of @value.
126  */
127 typedef void
128 (*GNUNET_SOCIAL_ModifierCallback) (void *cls,
129                                    const struct GNUNET_MessageHeader *msg,
130                                    uint64_t message_id,
131                                    enum GNUNET_ENV_Operator oper,
132                                    const char *name,
133                                    const void *value,
134                                    uint16_t value_size,
135                                    uint16_t full_value_size);
136
137
138 /**
139  * Function called upon receiving a data fragment of a message.
140  *
141  * @param cls
142  *        Closure.
143  * @param message_id
144  *        Message ID this data fragment belongs to.
145  * @param msg
146  *        Message part, as it arrived from the network.
147  * @param data_offset
148  *        Byte offset of @a data in the overall data of the method.
149  * @param data_size
150  *        Number of bytes in @a data.
151  * @param data
152  *        Data stream given to the method.
153  * @param end
154  *        End of message?
155  *        #GNUNET_NO     if there are further fragments,
156  *        #GNUNET_YES    if this is the last fragment,
157  *        #GNUNET_SYSERR indicates the message was cancelled by the sender.
158  */
159 typedef void
160 (*GNUNET_SOCIAL_DataCallback) (void *cls,
161                                const struct GNUNET_MessageHeader *msg,
162                                uint64_t message_id,
163                                uint64_t data_offset,
164                                const void *data,
165                                uint16_t data_size);
166
167
168 /**
169  * End of message.
170  *
171  * @param cls
172  *        Closure.
173  * @param msg
174  *        Message part, as it arrived from the network.
175  * @param message_id
176  *        Message ID this data fragment belongs to.
177  * @param cancelled.
178  *        #GNUNET_YES if the message was cancelled,
179  *        #GNUNET_NO  if the message is complete.
180  */
181 typedef void
182 (*GNUNET_SOCIAL_EndOfMessageCallback) (void *cls,
183                                        const struct GNUNET_MessageHeader *msg,
184                                        uint64_t message_id,
185                                        uint8_t cancelled);
186
187
188 /**
189  * Create a try-and-slice instance.
190  *
191  * A slicer processes incoming messages and notifies callbacks about matching
192  * methods or modifiers encountered.
193  *
194  * @return A new try-and-slice construct.
195  */
196 struct GNUNET_SOCIAL_Slicer *
197 GNUNET_SOCIAL_slicer_create (void);
198
199
200 /**
201  * Add a method to the try-and-slice instance.
202  *
203  * The callbacks are called for messages with a matching @a method_name prefix.
204  *
205  * @param slicer
206  *        The try-and-slice instance to extend.
207  * @param method_name
208  *        Name of the given method, use empty string to match all.
209  * @param method_cb
210  *        Method handler invoked upon a matching message.
211  * @param modifier_cb
212  *        Modifier handler, invoked after @a method_cb
213  *        for each modifier in the message.
214  * @param data_cb
215  *        Data handler, invoked after @a modifier_cb for each data fragment.
216  * @param eom_cb
217  *        Invoked upon reaching the end of a matching message.
218  * @param cls
219  *        Closure for the callbacks.
220  */
221 void
222 GNUNET_SOCIAL_slicer_method_add (struct GNUNET_SOCIAL_Slicer *slicer,
223                                  const char *method_name,
224                                  GNUNET_SOCIAL_MethodCallback method_cb,
225                                  GNUNET_SOCIAL_ModifierCallback modifier_cb,
226                                  GNUNET_SOCIAL_DataCallback data_cb,
227                                  GNUNET_SOCIAL_EndOfMessageCallback eom_cb,
228                                  void *cls);
229
230 /**
231  * Remove a registered method from the try-and-slice instance.
232  *
233  * Removes one matching handler registered with the given
234  * @a method_name and callbacks.
235  *
236  * @param slicer
237  *        The try-and-slice instance.
238  * @param method_name
239  *        Name of the method to remove.
240  * @param method_cb
241  *        Method handler.
242  * @param modifier_cb
243  *        Modifier handler.
244  * @param data_cb
245  *        Data handler.
246  * @param eom_cb
247  *        End of message handler.
248  *
249  * @return #GNUNET_OK if a method handler was removed,
250  *         #GNUNET_NO if no handler matched the given method name and callbacks.
251  */
252 int
253 GNUNET_SOCIAL_slicer_method_remove (struct GNUNET_SOCIAL_Slicer *slicer,
254                                     const char *method_name,
255                                     GNUNET_SOCIAL_MethodCallback method_cb,
256                                     GNUNET_SOCIAL_ModifierCallback modifier_cb,
257                                     GNUNET_SOCIAL_DataCallback data_cb,
258                                     GNUNET_SOCIAL_EndOfMessageCallback eom_cb);
259
260
261 /**
262  * Watch a place for changed objects.
263  *
264  * @param slicer
265  *        The try-and-slice instance.
266  * @param object_filter
267  *        Object prefix to match.
268  * @param modifier_cb
269  *        Function to call when encountering a state modifier.
270  * @param cls
271  *        Closure for callback.
272  */
273 void
274 GNUNET_SOCIAL_slicer_modifier_add (struct GNUNET_SOCIAL_Slicer *slicer,
275                                    const char *object_filter,
276                                    GNUNET_SOCIAL_ModifierCallback modifier_cb,
277                                    void *cls);
278
279
280 /**
281  * Remove a registered modifier from the try-and-slice instance.
282  *
283  * Removes one matching handler registered with the given
284  * @a object_filter and callback.
285  *
286  * @param slicer
287  *        The try-and-slice instance.
288  * @param object_filter
289  *        Object prefix to match.
290  * @param modifier_cb
291  *        Function to call when encountering a state modifier changes.
292  */
293 int
294 GNUNET_SOCIAL_slicer_modifier_remove (struct GNUNET_SOCIAL_Slicer *slicer,
295                                       const char *object_filter,
296                                       GNUNET_SOCIAL_ModifierCallback modifier_cb);
297
298
299 /**
300  * Destroy a given try-and-slice instance.
301  *
302  * @param slicer
303  *        Slicer to destroy
304  */
305 void
306 GNUNET_SOCIAL_slicer_destroy (struct GNUNET_SOCIAL_Slicer *slicer);
307
308
309 /**
310  * Function called asking for nym to be admitted to the place.
311  *
312  * Should call either GNUNET_SOCIAL_host_admit() or
313  * GNUNET_SOCIAL_host_reject_entry() (possibly asynchronously).  If this host
314  * cannot decide, it is fine to call neither function, in which case hopefully
315  * some other host of the place exists that will make the decision.  The @a nym
316  * reference remains valid until the #GNUNET_SOCIAL_FarewellCallback is invoked
317  * for it.
318  *
319  * @param cls Closure.
320  * @param nym Handle for the user who wants to enter.
321  * @param method_name Method name in the entry request.
322  * @param variable_count Number of elements in the @a variables array.
323  * @param variables Variables present in the message.
324  * @param data_size Number of bytes in @a data.
325  * @param data Payload given on enter (e.g. a password).
326  */
327 typedef void
328 (*GNUNET_SOCIAL_AnswerDoorCallback) (void *cls,
329                                      struct GNUNET_SOCIAL_Nym *nym,
330                                      const char *method_name,
331                                      struct GNUNET_ENV_Environment *env,
332                                      size_t data_size,
333                                      const void *data);
334
335
336 /**
337  * Function called when a @a nym leaves the place.
338  *
339  * This is also called if the @a nym was never given permission to enter
340  * (i.e. the @a nym stopped asking to get in).
341  *
342  * @param cls   Closure.
343  * @param nym Handle for the user who left.
344  * @param variable_count Number of elements in the @a variables array.
345  * @param variables Variables present in the message.
346  */
347 typedef void
348 (*GNUNET_SOCIAL_FarewellCallback) (void *cls,
349                                    struct GNUNET_SOCIAL_Nym *nym,
350                                    struct GNUNET_ENV_Environment *env,
351                                    size_t variable_count,
352                                    struct GNUNET_ENV_Modifier *variables);
353
354
355 /**
356  * Function called after the host entered the place.
357  *
358  * @param cls
359  *        Closure.
360  * @param result
361  *        #GNUNET_OK on success, or
362  *        #GNUNET_SYSERR on error.
363  * @param max_message_id
364  *        Last message ID sent to the channel.
365  *        Or 0 if no messages have been sent to the place yet.
366  */
367 typedef void
368 (*GNUNET_SOCIAL_HostEnterCallback) (void *cls, int result,
369                                     uint64_t max_message_id);
370
371
372 /**
373  * Enter a place as host.
374  *
375  * A place is created upon first entering, and it is active until permanently
376  * left using GNUNET_SOCIAL_host_leave().
377  *
378  * @param cfg
379  *        Configuration to contact the social service.
380  * @param ego
381  *        Identity of the host.
382  * @param place_key
383  *        Private-public key pair of the place.
384  *        NULL for ephemeral places.
385  * @param policy
386  *        Policy specifying entry and history restrictions for the place.
387  * @param slicer
388  *        Slicer to handle incoming messages.
389  * @param answer_door_cb
390  *        Function to handle new nyms that want to enter.
391  * @param farewell_cb
392  *        Function to handle departing nyms.
393  * @param cls
394  *        Closure for the callbacks.
395  *
396  * @return Handle for the host.
397  */
398 struct GNUNET_SOCIAL_Host *
399 GNUNET_SOCIAL_host_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
400                           const struct GNUNET_IDENTITY_Ego *ego,
401                           const struct GNUNET_CRYPTO_EddsaPrivateKey *place_key,
402                           enum GNUNET_PSYC_Policy policy,
403                           struct GNUNET_SOCIAL_Slicer *slicer,
404                           GNUNET_SOCIAL_HostEnterCallback enter_cb,
405                           GNUNET_SOCIAL_AnswerDoorCallback answer_door_cb,
406                           GNUNET_SOCIAL_FarewellCallback farewell_cb,
407                           void *cls);
408
409
410 /**
411  * Decision whether to admit @a nym into the place or refuse entry.
412  *
413  * @param hst
414  *        Host of the place.
415  * @param nym
416  *        Handle for the entity that wanted to enter.
417  * @param is_admitted
418  *        #GNUNET_YES    if @a nym is admitted,
419  *        #GNUNET_NO     if @a nym is refused entry,
420  *        #GNUNET_SYSERR if we cannot answer the request.
421  * @param method_name
422  *        Method name for the rejection message.
423  * @param env
424  *        Environment containing variables for the message, or NULL.
425  * @param data
426  *        Data for the rejection message to send back.
427  * @param data_size
428  *        Number of bytes in @a data for method.
429  * @return #GNUNET_OK on success,
430  *         #GNUNET_SYSERR if the message is too large.
431  */
432 int
433 GNUNET_SOCIAL_host_entry_decision (struct GNUNET_SOCIAL_Host *hst,
434                                    struct GNUNET_SOCIAL_Nym *nym,
435                                    int is_admitted,
436                                    const struct GNUNET_PSYC_Message *entry_resp);
437
438
439 /**
440  * Throw @a nym out of the place.
441  *
442  * The @a nym reference will remain valid until the
443  * #GNUNET_SOCIAL_FarewellCallback is invoked,
444  * which should be very soon after this call.
445  *
446  * @param host  Host of the place.
447  * @param nym  Handle for the entity to be ejected.
448  */
449 void
450 GNUNET_SOCIAL_host_eject (struct GNUNET_SOCIAL_Host *host,
451                           struct GNUNET_SOCIAL_Nym *nym);
452
453
454 /**
455  * Get the public key of a @a nym.
456  *
457  * Suitable, for example, to be used with GNUNET_NAMESTORE_zone_to_name().
458  *
459  * @param nym
460  *        Pseudonym to map to a cryptographic identifier.
461  *
462  * @return Public key of nym;
463  */
464 struct GNUNET_CRYPTO_EcdsaPublicKey *
465 GNUNET_SOCIAL_nym_get_key (struct GNUNET_SOCIAL_Nym *nym);
466
467
468 /**
469  * Obtain the private-public key pair of the host.
470  *
471  * @param host  Host to get the key of.
472  * @param[out] host_key  Set to the private-public key pair of the host.  The
473  *                 public part is suitable for storing in GNS within a "PLACE"
474  *                 record, along with peer IDs to join at.
475  */
476 void
477 GNUNET_SOCIAL_host_get_key (struct GNUNET_SOCIAL_Host *host,
478                             struct GNUNET_CRYPTO_EddsaPrivateKey *host_key);
479
480
481 /**
482  * Advertise the place in the GNS zone of the @e ego of the @a host.
483  *
484  * @param host  Host of the place.
485  * @param name The name for the PLACE record to put in the zone.
486  * @param peer_count Number of elements in the @a peers array.
487  * @param peers List of peers in the PLACE record that can be used to send join
488  *        requests to.
489  * @param expiration_time Expiration time of the record, use 0 to remove the record.
490  * @param password Password used to encrypt the record.
491  */
492 void
493 GNUNET_SOCIAL_host_advertise (struct GNUNET_SOCIAL_Host *host,
494                               const char *name,
495                               size_t peer_count,
496                               const struct GNUNET_PeerIdentity *peers,
497                               struct GNUNET_TIME_Relative expiration_time,
498                               const char *password);
499
500
501 /**
502  * Flags for announcements by a host.
503  */
504 enum GNUNET_SOCIAL_AnnounceFlags
505 {
506   GNUNET_SOCIAL_ANNOUNCE_NONE = 0,
507
508   /**
509    * Whether this announcement removes all objects from the place.
510    *
511    * New objects can be still added to the now empty place using the @e env
512    * parameter of the same announcement.
513    */
514   GNUNET_SOCIAL_ANNOUNCE_CLEAR_OBJECTS = 1 << 0
515 };
516
517
518 /**
519  * Handle for an announcement request.
520  */
521 struct GNUNET_SOCIAL_Announcement;
522
523
524 /**
525  * Send a message to all nyms that are present in the place.
526  *
527  * This function is restricted to the host.  Nyms can only send requests
528  * to the host who can decide to relay it to everyone in the place.
529  *
530  * @param host
531  *        Host of the place.
532  * @param method_name
533  *        Method to use for the announcement.
534  * @param env
535  *        Environment containing variables for the message and operations
536  *        on objects of the place.
537  *        Has to remain available until the first call to @a notify_data.
538  *        Can be NULL.
539  * @param notify_data
540  *        Function to call to get the payload of the announcement.
541  * @param notify_data_cls
542  *        Closure for @a notify.
543  * @param flags
544  *        Flags for this announcement.
545  *
546  * @return NULL on error (another announcement already in progress?).
547  */
548 struct GNUNET_SOCIAL_Announcement *
549 GNUNET_SOCIAL_host_announce (struct GNUNET_SOCIAL_Host *host,
550                              const char *method_name,
551                              const struct GNUNET_ENV_Environment *env,
552                              GNUNET_PSYC_TransmitNotifyData notify_data,
553                              void *notify_data_cls,
554                              enum GNUNET_SOCIAL_AnnounceFlags flags);
555
556
557 /**
558  * Resume transmitting announcement.
559  *
560  * @param a
561  *        The announcement to resume.
562  */
563 void
564 GNUNET_SOCIAL_host_announce_resume (struct GNUNET_SOCIAL_Announcement *a);
565
566
567 /**
568  * Cancel announcement.
569  *
570  * @param a
571  *        The announcement to cancel.
572  */
573 void
574 GNUNET_SOCIAL_host_announce_cancel (struct GNUNET_SOCIAL_Announcement *a);
575
576
577 /**
578  * Obtain handle for a hosted place.
579  *
580  * The returned handle can be used to access the place API.
581  *
582  * @param host
583  *        Handle for the host.
584  *
585  * @return Handle for the hosted place, valid as long as @a host is valid.
586  */
587 struct GNUNET_SOCIAL_Place *
588 GNUNET_SOCIAL_host_get_place (struct GNUNET_SOCIAL_Host *host);
589
590
591 /**
592  * Stop hosting a place.
593  *
594  * Invalidates host handle.
595  *
596  * @param host
597  *        Host leaving the place.
598  * @param keep_active
599  *        Keep the place active after last host disconnected.
600  * @param leave_cb
601  *        Function called after the host left the place
602  *        and disconnected from the social service.
603  * @param leave_cls
604  *        Closure for @a leave_cb.
605  */
606 void
607 GNUNET_SOCIAL_host_leave (struct GNUNET_SOCIAL_Host *host,
608                           int keep_active,
609                           GNUNET_ContinuationCallback leave_cb,
610                           void *leave_cls);
611
612
613 /**
614  * Function called after the guest entered the local copy of the place.
615  *
616  * History and object query functions can be used after this call,
617  * but new messages can't be sent or received.
618  *
619  * @param cls
620  *        Closure.
621  * @param result
622  *        #GNUNET_OK on success, or
623  *        #GNUNET_SYSERR on error, e.g. could not connect to the service, or
624  *        could not resolve GNS name.
625  * @param max_message_id
626  *        Last message ID sent to the place.
627  *        Or 0 if no messages have been sent to the place yet.
628  */
629 typedef void
630 (*GNUNET_SOCIAL_GuestEnterCallback) (void *cls, int result,
631                                      uint64_t max_message_id);
632
633
634 /**
635  * Function called upon a guest receives a decision about entry to the place.
636  *
637  * @param is_admitted
638  *   Is the guest admitted to the place?
639  *   #GNUNET_YES    if admitted,
640  *   #GNUNET_NO     if refused entry
641  *   #GNUNET_SYSERR if the request could not be answered.
642  * @param method_name
643  *   Method for the message sent along with the decision.
644  *   NULL if no message was sent.
645  * @param env
646  *   Environment with variables for the message.
647  *   NULL if there are no variables.
648  *   It has to be freed using GNUNET_ENV_environment_destroy()
649  *   when it is not needed anymore.
650  * @param data_size
651  *   Size of @data.
652  * @param data
653  *   Payload of the message.
654  */
655 typedef void
656 (*GNUNET_SOCIAL_EntryDecisionCallback) (void *cls,
657                                         int is_admitted,
658                                         const struct GNUNET_PSYC_Message *entry_resp);
659
660
661 /**
662  * Request entry to a place as a guest.
663  *
664  * @param cfg Configuration to contact the social service.
665  * @param ego  Identity of the guest.
666  * @param crypto_address Public key of the place to enter.
667  * @param origin Peer identity of the origin of the underlying multicast group.
668  * @param relay_count Number of elements in the @a relays array.
669  * @param relays Relays for the underlying multicast group.
670  * @param method_name Method name for the message.
671  * @param env Environment containing variables for the message, or NULL.
672  * @param data Payload for the message to give to the enter callback.
673  * @param data_size Number of bytes in @a data.
674  * @param slicer Slicer to use for processing incoming requests from guests.
675  *
676  * @return NULL on errors, otherwise handle for the guest.
677  */
678 struct GNUNET_SOCIAL_Guest *
679 GNUNET_SOCIAL_guest_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
680                            const struct GNUNET_IDENTITY_Ego *ego,
681                            const struct GNUNET_CRYPTO_EddsaPublicKey *place_key,
682                            const struct GNUNET_PeerIdentity *origin,
683                            uint32_t relay_count,
684                            const struct GNUNET_PeerIdentity *relays,
685                            const struct GNUNET_PSYC_Message *entry_msg,
686                            struct GNUNET_SOCIAL_Slicer *slicer,
687                            GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
688                            GNUNET_SOCIAL_EntryDecisionCallback entry_decision_cb,
689                            void *cls);
690
691
692 /**
693  * Request entry to a place as a guest using a GNS name.
694  *
695  * @param cfg  Configuration to contact the social service.
696  * @param ego  Identity of the guest.
697  * @param address GNS name of the place to enter.  Either in the form of
698  *        'room.friend.gnu', or 'NYMPUBKEY.zkey'.  This latter case refers to
699  *        the 'PLACE' record of the empty label ("+") in the GNS zone with the
700  *        nym's public key 'NYMPUBKEY', and can be used to request entry to a
701  *        pseudonym's place directly.
702  * @param method_name Method name for the message.
703  * @param env Environment containing variables for the message, or NULL.
704  * @param data Payload for the message to give to the enter callback.
705  * @param data_size Number of bytes in @a data.
706  * @param slicer Slicer to use for processing incoming requests from guests.
707  *
708  * @return NULL on errors, otherwise handle for the guest.
709  */
710 struct GNUNET_SOCIAL_Guest *
711 GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_CONFIGURATION_Handle *cfg,
712                                    struct GNUNET_IDENTITY_Ego *ego,
713                                    char *gns_name,
714                                    const struct GNUNET_PSYC_Message *join_msg,
715                                    struct GNUNET_SOCIAL_Slicer *slicer,
716                                    GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
717                                    GNUNET_SOCIAL_EntryDecisionCallback entry_decision_cb,
718                                    void *cls);
719
720
721 /**
722  * Flags for talking to the host of a place.
723  */
724 enum GNUNET_SOCIAL_TalkFlags
725 {
726   GNUNET_SOCIAL_TALK_NONE = 0
727 };
728
729
730 /**
731  * A talk request.
732  */
733 struct GNUNET_SOCIAL_TalkRequest;
734
735
736 /**
737  * Talk to the host of the place.
738  *
739  * @param place
740  *        Place where we want to talk to the host.
741  * @param method_name
742  *        Method to invoke on the host.
743  * @param env
744  *        Environment containing variables for the message, or NULL.
745  * @param notify_data
746  *        Function to use to get the payload for the method.
747  * @param notify_data_cls
748  *        Closure for @a notify_data.
749  * @param flags
750  *        Flags for the message being sent.
751  *
752  * @return NULL if we are already trying to talk to the host,
753  *         otherwise handle to cancel the request.
754  */
755 struct GNUNET_SOCIAL_TalkRequest *
756 GNUNET_SOCIAL_guest_talk (struct GNUNET_SOCIAL_Guest *guest,
757                           const char *method_name,
758                           const struct GNUNET_ENV_Environment *env,
759                           GNUNET_PSYC_TransmitNotifyData notify_data,
760                           void *notify_data_cls,
761                           enum GNUNET_SOCIAL_TalkFlags flags);
762
763
764 /**
765  * Resume talking to the host of the place.
766  *
767  * @param tr
768  *        Talk request to resume.
769  */
770 void
771 GNUNET_SOCIAL_guest_talk_resume (struct GNUNET_SOCIAL_TalkRequest *tr);
772
773
774 /**
775  * Cancel talking to the host of the place.
776  *
777  * @param tr
778  *        Talk request to cancel.
779  */
780 void
781 GNUNET_SOCIAL_guest_talk_cancel (struct GNUNET_SOCIAL_TalkRequest *tr);
782
783
784 /**
785  * Leave a place permanently.
786  *
787  * Notifies the owner of the place about leaving, and destroys the place handle.
788  *
789  * @param place
790  *        Place to leave permanently.
791  * @param keep_active
792  *        Keep place active after last application disconnected.
793  * @param leave_cb
794  *        Function called after the guest left the place
795  *        and disconnected from the social service.
796  * @param leave_cls
797  *        Closure for @a leave_cb.
798  */
799 void
800 GNUNET_SOCIAL_guest_leave (struct GNUNET_SOCIAL_Guest *guest,
801                            int keep_active,
802                            GNUNET_ContinuationCallback leave_cb,
803                            void *leave_cls);
804
805
806 /**
807  * Obtain handle for a place entered as guest.
808  *
809  * The returned handle can be used to access the place API.
810  *
811  * @param guest  Handle for the guest.
812  *
813  * @return Handle for the place, valid as long as @a guest is valid.
814  */
815 struct GNUNET_SOCIAL_Place *
816 GNUNET_SOCIAL_guest_get_place (struct GNUNET_SOCIAL_Guest *guest);
817
818
819 /**
820  * A history request.
821  */
822 struct GNUNET_SOCIAL_HistoryRequest;
823
824
825 /**
826  * Learn about the history of a place.
827  *
828  * Messages are returned through the @a slicer function
829  * and have the #GNUNET_PSYC_MESSAGE_HISTORIC flag set.
830  *
831  * @param place
832  *        Place we want to learn more about.
833  * @param start_message_id
834  *        First historic message we are interested in.
835  * @param end_message_id
836  *        Last historic message we are interested in (inclusive).
837  * @param method_prefix
838  *        Only retrieve messages with this method prefix.
839  * @param flags
840  *        OR'ed GNUNET_PSYC_HistoryReplayFlags
841  * @param slicer
842  *        Slicer to use for retrieved messages.
843  *        Can be the same as the slicer of the place.
844  * @param result_cb
845  *        Function called after all messages retrieved.
846  *        NULL if not needed.
847  * @param cls Closure for @a result_cb.
848  */
849 struct GNUNET_SOCIAL_HistoryRequest *
850 GNUNET_SOCIAL_place_history_replay (struct GNUNET_SOCIAL_Place *plc,
851                                     uint64_t start_message_id,
852                                     uint64_t end_message_id,
853                                     const char *method_prefix,
854                                     uint32_t flags,
855                                     struct GNUNET_SOCIAL_Slicer *slicer,
856                                     GNUNET_ResultCallback result_cb,
857                                     void *cls);
858
859
860 /**
861  * Learn about the history of a place.
862  *
863  * Sends messages through the slicer function of the place where
864  * start_message_id <= message_id <= end_message_id.
865  * The messages will have the #GNUNET_PSYC_MESSAGE_HISTORIC flag set.
866  *
867  * To get the latest message, use 0 for both the start and end message ID.
868  *
869  * @param place
870  *        Place we want to learn more about.
871  * @param message_limit
872  *        Maximum number of historic messages we are interested in.
873  * @param result_cb
874  *        Function called after all messages retrieved.
875  *        NULL if not needed.
876  * @param cls Closure for @a result_cb.
877  */
878 struct GNUNET_SOCIAL_HistoryRequest *
879 GNUNET_SOCIAL_place_history_replay_latest (struct GNUNET_SOCIAL_Place *plc,
880                                            uint64_t message_limit,
881                                            const char *method_prefix,
882                                            uint32_t flags,
883                                            struct GNUNET_SOCIAL_Slicer *slicer,
884                                            GNUNET_ResultCallback result_cb,
885                                            void *cls);
886
887 /**
888  * Cancel learning about the history of a place.
889  *
890  * @param hist
891  *        History lesson to cancel.
892  */
893 void
894 GNUNET_SOCIAL_place_history_replay_cancel (struct GNUNET_SOCIAL_HistoryRequest *hist);
895
896
897 struct GNUNET_SOCIAL_LookHandle;
898
899
900 /**
901  * Look at a particular object in the place.
902  *
903  * The best matching object is returned (its name might be less specific than
904  * what was requested).
905  *
906  * @param place
907  *        The place to look the object at.
908  * @param full_name
909  *        Full name of the object.
910  * @param value_size
911  *        Set to the size of the returned value.
912  *
913  * @return NULL if there is no such object at this place.
914  */
915 struct GNUNET_SOCIAL_LookHandle *
916 GNUNET_SOCIAL_place_look_at (struct GNUNET_SOCIAL_Place *plc,
917                              const char *full_name,
918                              GNUNET_PSYC_StateVarCallback var_cb,
919                              GNUNET_ResultCallback result_cb,
920                              void *cls);
921
922 /**
923  * Look for objects in the place with a matching name prefix.
924  *
925  * @param place
926  *        The place to look its objects at.
927  * @param name_prefix
928  *        Look at objects with names beginning with this value.
929  * @param var_cb
930  *        Function to call for each object found.
931  * @param cls
932  *        Closure for callback function.
933  *
934  * @return Handle that can be used to stop looking at objects.
935  */
936 struct GNUNET_SOCIAL_LookHandle *
937 GNUNET_SOCIAL_place_look_for (struct GNUNET_SOCIAL_Place *plc,
938                               const char *name_prefix,
939                               GNUNET_PSYC_StateVarCallback var_cb,
940                               GNUNET_ResultCallback result_cb,
941                               void *cls);
942
943
944 /**
945  * Stop looking at objects.
946  *
947  * @param lh Look handle to stop.
948  */
949 void
950 GNUNET_SOCIAL_place_look_cancel (struct GNUNET_SOCIAL_LookHandle *lh);
951
952
953 #if 0                           /* keep Emacsens' auto-indent happy */
954 {
955 #endif
956 #ifdef __cplusplus
957 }
958 #endif
959
960 /* ifndef GNUNET_SOCIAL_SERVICE_H */
961 #endif
962 /* end of gnunet_social_service.h */