62f6ab7c7ab48a2d18579eeb5f29e3cecee53d9f
[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
343  *        Closure.
344  * @param nym
345  *        Handle for the user who left.
346  */
347 typedef void
348 (*GNUNET_SOCIAL_FarewellCallback) (void *cls,
349                                    const struct GNUNET_SOCIAL_Nym *nym,
350                                    struct GNUNET_ENV_Environment *env);
351
352
353 /**
354  * Function called after the host entered the place.
355  *
356  * @param cls
357  *        Closure.
358  * @param result
359  *        #GNUNET_OK on success, or
360  *        #GNUNET_SYSERR on error.
361  * @param max_message_id
362  *        Last message ID sent to the channel.
363  *        Or 0 if no messages have been sent to the place yet.
364  */
365 typedef void
366 (*GNUNET_SOCIAL_HostEnterCallback) (void *cls, int result,
367                                     uint64_t max_message_id);
368
369
370 /**
371  * Enter a place as host.
372  *
373  * A place is created upon first entering, and it is active until permanently
374  * left using GNUNET_SOCIAL_host_leave().
375  *
376  * @param cfg
377  *        Configuration to contact the social service.
378  * @param ego
379  *        Identity of the host.
380  * @param place_key
381  *        Private-public key pair of the place.
382  *        NULL for ephemeral places.
383  * @param policy
384  *        Policy specifying entry and history restrictions for the place.
385  * @param slicer
386  *        Slicer to handle incoming messages.
387  * @param answer_door_cb
388  *        Function to handle new nyms that want to enter.
389  * @param farewell_cb
390  *        Function to handle departing nyms.
391  * @param cls
392  *        Closure for the callbacks.
393  *
394  * @return Handle for the host.
395  */
396 struct GNUNET_SOCIAL_Host *
397 GNUNET_SOCIAL_host_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
398                           const struct GNUNET_IDENTITY_Ego *ego,
399                           const struct GNUNET_CRYPTO_EddsaPrivateKey *place_key,
400                           enum GNUNET_PSYC_Policy policy,
401                           struct GNUNET_SOCIAL_Slicer *slicer,
402                           GNUNET_SOCIAL_HostEnterCallback enter_cb,
403                           GNUNET_SOCIAL_AnswerDoorCallback answer_door_cb,
404                           GNUNET_SOCIAL_FarewellCallback farewell_cb,
405                           void *cls);
406
407
408 /**
409  * Decision whether to admit @a nym into the place or refuse entry.
410  *
411  * @param hst
412  *        Host of the place.
413  * @param nym
414  *        Handle for the entity that wanted to enter.
415  * @param is_admitted
416  *        #GNUNET_YES    if @a nym is admitted,
417  *        #GNUNET_NO     if @a nym is refused entry,
418  *        #GNUNET_SYSERR if we cannot answer the request.
419  * @param method_name
420  *        Method name for the rejection message.
421  * @param env
422  *        Environment containing variables for the message, or NULL.
423  * @param data
424  *        Data for the rejection message to send back.
425  * @param data_size
426  *        Number of bytes in @a data for method.
427  * @return #GNUNET_OK on success,
428  *         #GNUNET_SYSERR if the message is too large.
429  */
430 int
431 GNUNET_SOCIAL_host_entry_decision (struct GNUNET_SOCIAL_Host *hst,
432                                    struct GNUNET_SOCIAL_Nym *nym,
433                                    int is_admitted,
434                                    const struct GNUNET_PSYC_Message *entry_resp);
435
436
437 /**
438  * Throw @a nym out of the place.
439  *
440  * The @a nym reference will remain valid until the
441  * #GNUNET_SOCIAL_FarewellCallback is invoked,
442  * which should be very soon after this call.
443  *
444  * @param host
445  *        Host of the place.
446  * @param nym
447  *        Handle for the entity to be ejected.
448  */
449 void
450 GNUNET_SOCIAL_host_eject (struct GNUNET_SOCIAL_Host *host,
451                           const 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 const struct GNUNET_CRYPTO_EcdsaPublicKey *
465 GNUNET_SOCIAL_nym_get_key (const struct GNUNET_SOCIAL_Nym *nym);
466
467
468 /**
469  * Advertise the place in the GNS zone of the @e ego of the @a host.
470  *
471  * @param host  Host of the place.
472  * @param name The name for the PLACE record to put in the zone.
473  * @param peer_count Number of elements in the @a peers array.
474  * @param peers List of peers in the PLACE record that can be used to send join
475  *        requests to.
476  * @param expiration_time Expiration time of the record, use 0 to remove the record.
477  * @param password Password used to encrypt the record.
478  */
479 void
480 GNUNET_SOCIAL_host_advertise (struct GNUNET_SOCIAL_Host *host,
481                               const char *name,
482                               size_t peer_count,
483                               const struct GNUNET_PeerIdentity *peers,
484                               struct GNUNET_TIME_Relative expiration_time,
485                               const char *password);
486
487
488 /**
489  * Flags for announcements by a host.
490  */
491 enum GNUNET_SOCIAL_AnnounceFlags
492 {
493   GNUNET_SOCIAL_ANNOUNCE_NONE = 0,
494
495   /**
496    * Whether this announcement removes all objects from the place.
497    *
498    * New objects can be still added to the now empty place using the @e env
499    * parameter of the same announcement.
500    */
501   GNUNET_SOCIAL_ANNOUNCE_CLEAR_OBJECTS = 1 << 0
502 };
503
504
505 /**
506  * Handle for an announcement request.
507  */
508 struct GNUNET_SOCIAL_Announcement;
509
510
511 /**
512  * Send a message to all nyms that are present in the place.
513  *
514  * This function is restricted to the host.  Nyms can only send requests
515  * to the host who can decide to relay it to everyone in the place.
516  *
517  * @param host
518  *        Host of the place.
519  * @param method_name
520  *        Method to use for the announcement.
521  * @param env
522  *        Environment containing variables for the message and operations
523  *        on objects of the place.
524  *        Has to remain available until the first call to @a notify_data.
525  *        Can be NULL.
526  * @param notify_data
527  *        Function to call to get the payload of the announcement.
528  * @param notify_data_cls
529  *        Closure for @a notify.
530  * @param flags
531  *        Flags for this announcement.
532  *
533  * @return NULL on error (another announcement already in progress?).
534  */
535 struct GNUNET_SOCIAL_Announcement *
536 GNUNET_SOCIAL_host_announce (struct GNUNET_SOCIAL_Host *host,
537                              const char *method_name,
538                              const struct GNUNET_ENV_Environment *env,
539                              GNUNET_PSYC_TransmitNotifyData notify_data,
540                              void *notify_data_cls,
541                              enum GNUNET_SOCIAL_AnnounceFlags flags);
542
543
544 /**
545  * Resume transmitting announcement.
546  *
547  * @param a
548  *        The announcement to resume.
549  */
550 void
551 GNUNET_SOCIAL_host_announce_resume (struct GNUNET_SOCIAL_Announcement *a);
552
553
554 /**
555  * Cancel announcement.
556  *
557  * @param a
558  *        The announcement to cancel.
559  */
560 void
561 GNUNET_SOCIAL_host_announce_cancel (struct GNUNET_SOCIAL_Announcement *a);
562
563
564 /**
565  * Obtain handle for a hosted place.
566  *
567  * The returned handle can be used to access the place API.
568  *
569  * @param host
570  *        Handle for the host.
571  *
572  * @return Handle for the hosted place, valid as long as @a host is valid.
573  */
574 struct GNUNET_SOCIAL_Place *
575 GNUNET_SOCIAL_host_get_place (struct GNUNET_SOCIAL_Host *host);
576
577
578 /**
579  * Stop hosting a place.
580  *
581  * Invalidates host handle.
582  *
583  * @param host
584  *        Host leaving the place.
585  * @param keep_active
586  *        Keep the place active after last host disconnected.
587  * @param leave_cb
588  *        Function called after the host left the place
589  *        and disconnected from the social service.
590  * @param leave_cls
591  *        Closure for @a leave_cb.
592  */
593 void
594 GNUNET_SOCIAL_host_leave (struct GNUNET_SOCIAL_Host *host,
595                           int keep_active,
596                           GNUNET_ContinuationCallback leave_cb,
597                           void *leave_cls);
598
599
600 /**
601  * Function called after the guest entered the local copy of the place.
602  *
603  * History and object query functions can be used after this call,
604  * but new messages can't be sent or received.
605  *
606  * @param cls
607  *        Closure.
608  * @param result
609  *        #GNUNET_OK on success, or
610  *        #GNUNET_SYSERR on error, e.g. could not connect to the service, or
611  *        could not resolve GNS name.
612  * @param max_message_id
613  *        Last message ID sent to the place.
614  *        Or 0 if no messages have been sent to the place yet.
615  */
616 typedef void
617 (*GNUNET_SOCIAL_GuestEnterCallback) (void *cls, int result,
618                                      uint64_t max_message_id);
619
620
621 /**
622  * Function called upon a guest receives a decision about entry to the place.
623  *
624  * @param is_admitted
625  *   Is the guest admitted to the place?
626  *   #GNUNET_YES    if admitted,
627  *   #GNUNET_NO     if refused entry
628  *   #GNUNET_SYSERR if the request could not be answered.
629  * @param method_name
630  *   Method for the message sent along with the decision.
631  *   NULL if no message was sent.
632  * @param env
633  *   Environment with variables for the message.
634  *   NULL if there are no variables.
635  *   It has to be freed using GNUNET_ENV_environment_destroy()
636  *   when it is not needed anymore.
637  * @param data_size
638  *   Size of @data.
639  * @param data
640  *   Payload of the message.
641  */
642 typedef void
643 (*GNUNET_SOCIAL_EntryDecisionCallback) (void *cls,
644                                         int is_admitted,
645                                         const struct GNUNET_PSYC_Message *entry_resp);
646
647
648 /**
649  * Request entry to a place as a guest.
650  *
651  * @param cfg Configuration to contact the social service.
652  * @param ego  Identity of the guest.
653  * @param crypto_address Public key of the place to enter.
654  * @param origin Peer identity of the origin of the underlying multicast group.
655  * @param relay_count Number of elements in the @a relays array.
656  * @param relays Relays for the underlying multicast group.
657  * @param method_name Method name for the message.
658  * @param env Environment containing variables for the message, or NULL.
659  * @param data Payload for the message to give to the enter callback.
660  * @param data_size Number of bytes in @a data.
661  * @param slicer Slicer to use for processing incoming requests from guests.
662  *
663  * @return NULL on errors, otherwise handle for the guest.
664  */
665 struct GNUNET_SOCIAL_Guest *
666 GNUNET_SOCIAL_guest_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
667                            const struct GNUNET_IDENTITY_Ego *ego,
668                            const struct GNUNET_CRYPTO_EddsaPublicKey *place_key,
669                            const struct GNUNET_PeerIdentity *origin,
670                            uint32_t relay_count,
671                            const struct GNUNET_PeerIdentity *relays,
672                            const struct GNUNET_PSYC_Message *entry_msg,
673                            struct GNUNET_SOCIAL_Slicer *slicer,
674                            GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
675                            GNUNET_SOCIAL_EntryDecisionCallback entry_decision_cb,
676                            void *cls);
677
678
679 /**
680  * Request entry to a place as a guest using a GNS name.
681  *
682  * @param cfg  Configuration to contact the social service.
683  * @param ego  Identity of the guest.
684  * @param address GNS name of the place to enter.  Either in the form of
685  *        'room.friend.gnu', or 'NYMPUBKEY.zkey'.  This latter case refers to
686  *        the 'PLACE' record of the empty label ("+") in the GNS zone with the
687  *        nym's public key 'NYMPUBKEY', and can be used to request entry to a
688  *        pseudonym's place directly.
689  * @param method_name Method name for the message.
690  * @param env Environment containing variables for the message, or NULL.
691  * @param data Payload for the message to give to the enter callback.
692  * @param data_size Number of bytes in @a data.
693  * @param slicer Slicer to use for processing incoming requests from guests.
694  *
695  * @return NULL on errors, otherwise handle for the guest.
696  */
697 struct GNUNET_SOCIAL_Guest *
698 GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_CONFIGURATION_Handle *cfg,
699                                    struct GNUNET_IDENTITY_Ego *ego,
700                                    char *gns_name,
701                                    const struct GNUNET_PSYC_Message *join_msg,
702                                    struct GNUNET_SOCIAL_Slicer *slicer,
703                                    GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
704                                    GNUNET_SOCIAL_EntryDecisionCallback entry_decision_cb,
705                                    void *cls);
706
707
708 /**
709  * Flags for talking to the host of a place.
710  */
711 enum GNUNET_SOCIAL_TalkFlags
712 {
713   GNUNET_SOCIAL_TALK_NONE = 0
714 };
715
716
717 /**
718  * A talk request.
719  */
720 struct GNUNET_SOCIAL_TalkRequest;
721
722
723 /**
724  * Talk to the host of the place.
725  *
726  * @param place
727  *        Place where we want to talk to the host.
728  * @param method_name
729  *        Method to invoke on the host.
730  * @param env
731  *        Environment containing variables for the message, or NULL.
732  * @param notify_data
733  *        Function to use to get the payload for the method.
734  * @param notify_data_cls
735  *        Closure for @a notify_data.
736  * @param flags
737  *        Flags for the message being sent.
738  *
739  * @return NULL if we are already trying to talk to the host,
740  *         otherwise handle to cancel the request.
741  */
742 struct GNUNET_SOCIAL_TalkRequest *
743 GNUNET_SOCIAL_guest_talk (struct GNUNET_SOCIAL_Guest *guest,
744                           const char *method_name,
745                           const struct GNUNET_ENV_Environment *env,
746                           GNUNET_PSYC_TransmitNotifyData notify_data,
747                           void *notify_data_cls,
748                           enum GNUNET_SOCIAL_TalkFlags flags);
749
750
751 /**
752  * Resume talking to the host of the place.
753  *
754  * @param tr
755  *        Talk request to resume.
756  */
757 void
758 GNUNET_SOCIAL_guest_talk_resume (struct GNUNET_SOCIAL_TalkRequest *tr);
759
760
761 /**
762  * Cancel talking to the host of the place.
763  *
764  * @param tr
765  *        Talk request to cancel.
766  */
767 void
768 GNUNET_SOCIAL_guest_talk_cancel (struct GNUNET_SOCIAL_TalkRequest *tr);
769
770
771 /**
772  * Leave a place temporarily or permanently.
773  *
774  * Notifies the owner of the place about leaving, and destroys the place handle.
775  *
776  * @param place
777  *        Place to leave.
778  * @param keep_active
779  *        Keep place active after last application disconnected.
780  *        #GNUNET_YES or #GNUNET_NO
781  * @param env
782  *        Optional environment for the leave message if @a keep_active
783  *        is #GNUNET_NO.  NULL if not needed.
784  * @param leave_cb
785  *        Called upon disconnecting from the social service.
786  */
787 void
788 GNUNET_SOCIAL_guest_leave (struct GNUNET_SOCIAL_Guest *gst,
789                            int keep_active,
790                            struct GNUNET_ENV_Environment *env,
791                            GNUNET_ContinuationCallback leave_cb,
792                            void *leave_cls);
793
794
795 /**
796  * Obtain handle for a place entered as guest.
797  *
798  * The returned handle can be used to access the place API.
799  *
800  * @param guest  Handle for the guest.
801  *
802  * @return Handle for the place, valid as long as @a guest is valid.
803  */
804 struct GNUNET_SOCIAL_Place *
805 GNUNET_SOCIAL_guest_get_place (struct GNUNET_SOCIAL_Guest *guest);
806
807
808 /**
809  * A history request.
810  */
811 struct GNUNET_SOCIAL_HistoryRequest;
812
813
814 /**
815  * Learn about the history of a place.
816  *
817  * Messages are returned through the @a slicer function
818  * and have the #GNUNET_PSYC_MESSAGE_HISTORIC flag set.
819  *
820  * @param place
821  *        Place we want to learn more about.
822  * @param start_message_id
823  *        First historic message we are interested in.
824  * @param end_message_id
825  *        Last historic message we are interested in (inclusive).
826  * @param method_prefix
827  *        Only retrieve messages with this method prefix.
828  * @param flags
829  *        OR'ed GNUNET_PSYC_HistoryReplayFlags
830  * @param slicer
831  *        Slicer to use for retrieved messages.
832  *        Can be the same as the slicer of the place.
833  * @param result_cb
834  *        Function called after all messages retrieved.
835  *        NULL if not needed.
836  * @param cls Closure for @a result_cb.
837  */
838 struct GNUNET_SOCIAL_HistoryRequest *
839 GNUNET_SOCIAL_place_history_replay (struct GNUNET_SOCIAL_Place *plc,
840                                     uint64_t start_message_id,
841                                     uint64_t end_message_id,
842                                     const char *method_prefix,
843                                     uint32_t flags,
844                                     struct GNUNET_SOCIAL_Slicer *slicer,
845                                     GNUNET_ResultCallback result_cb,
846                                     void *cls);
847
848
849 /**
850  * Learn about the history of a place.
851  *
852  * Sends messages through the slicer function of the place where
853  * start_message_id <= message_id <= end_message_id.
854  * The messages will have the #GNUNET_PSYC_MESSAGE_HISTORIC flag set.
855  *
856  * To get the latest message, use 0 for both the start and end message ID.
857  *
858  * @param place
859  *        Place we want to learn more about.
860  * @param message_limit
861  *        Maximum number of historic messages we are interested in.
862  * @param result_cb
863  *        Function called after all messages retrieved.
864  *        NULL if not needed.
865  * @param cls Closure for @a result_cb.
866  */
867 struct GNUNET_SOCIAL_HistoryRequest *
868 GNUNET_SOCIAL_place_history_replay_latest (struct GNUNET_SOCIAL_Place *plc,
869                                            uint64_t message_limit,
870                                            const char *method_prefix,
871                                            uint32_t flags,
872                                            struct GNUNET_SOCIAL_Slicer *slicer,
873                                            GNUNET_ResultCallback result_cb,
874                                            void *cls);
875
876 /**
877  * Cancel learning about the history of a place.
878  *
879  * @param hist
880  *        History lesson to cancel.
881  */
882 void
883 GNUNET_SOCIAL_place_history_replay_cancel (struct GNUNET_SOCIAL_HistoryRequest *hist);
884
885
886 struct GNUNET_SOCIAL_LookHandle;
887
888
889 /**
890  * Look at a particular object in the place.
891  *
892  * The best matching object is returned (its name might be less specific than
893  * what was requested).
894  *
895  * @param place
896  *        The place to look the object at.
897  * @param full_name
898  *        Full name of the object.
899  * @param value_size
900  *        Set to the size of the returned value.
901  *
902  * @return NULL if there is no such object at this place.
903  */
904 struct GNUNET_SOCIAL_LookHandle *
905 GNUNET_SOCIAL_place_look_at (struct GNUNET_SOCIAL_Place *plc,
906                              const char *full_name,
907                              GNUNET_PSYC_StateVarCallback var_cb,
908                              GNUNET_ResultCallback result_cb,
909                              void *cls);
910
911 /**
912  * Look for objects in the place with a matching name prefix.
913  *
914  * @param place
915  *        The place to look its objects at.
916  * @param name_prefix
917  *        Look at objects with names beginning with this value.
918  * @param var_cb
919  *        Function to call for each object found.
920  * @param cls
921  *        Closure for callback function.
922  *
923  * @return Handle that can be used to stop looking at objects.
924  */
925 struct GNUNET_SOCIAL_LookHandle *
926 GNUNET_SOCIAL_place_look_for (struct GNUNET_SOCIAL_Place *plc,
927                               const char *name_prefix,
928                               GNUNET_PSYC_StateVarCallback var_cb,
929                               GNUNET_ResultCallback result_cb,
930                               void *cls);
931
932
933 /**
934  * Stop looking at objects.
935  *
936  * @param lh Look handle to stop.
937  */
938 void
939 GNUNET_SOCIAL_place_look_cancel (struct GNUNET_SOCIAL_LookHandle *lh);
940
941
942 #if 0                           /* keep Emacsens' auto-indent happy */
943 {
944 #endif
945 #ifdef __cplusplus
946 }
947 #endif
948
949 /* ifndef GNUNET_SOCIAL_SERVICE_H */
950 #endif
951 /* end of gnunet_social_service.h */