libgnunetchat

library for GNUnet Messenger
Log | Files | Refs | README | LICENSE

gnunet_chat_uri.h (2624B)


      1 /*
      2    This file is part of GNUnet.
      3    Copyright (C) 2022--2025 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 /*
     21  * @author Tobias Frisch
     22  * @file gnunet_chat_uri.h
     23  */
     24 
     25 #ifndef GNUNET_CHAT_URI_H_
     26 #define GNUNET_CHAT_URI_H_
     27 
     28 #include <gnunet/gnunet_fs_service.h>
     29 #include <gnunet/gnunet_util_lib.h>
     30 
     31 #include "gnunet_chat_util.h"
     32 
     33 struct GNUNET_CHAT_UriChat
     34 {
     35   struct GNUNET_CRYPTO_BlindablePublicKey zone;
     36   char *label;
     37 };
     38 
     39 struct GNUNET_CHAT_UriFile
     40 {
     41   struct GNUNET_FS_Uri *uri;
     42 };
     43 
     44 struct GNUNET_CHAT_Uri
     45 {
     46   enum GNUNET_CHAT_UriType type;
     47 
     48   union {
     49     struct GNUNET_CHAT_UriChat chat;
     50     struct GNUNET_CHAT_UriFile fs;
     51   };
     52 };
     53 
     54 /**
     55  * Creates a chat uri with a selected key as <i>zone</i>
     56  * and a <i>label</i> of type #GNUNET_CHAT_URI_TYPE_CHAT.
     57  *
     58  * @param[in] zone URI zone
     59  * @param[in] label URI label
     60  * @return New chat uri
     61  */
     62 struct GNUNET_CHAT_Uri*
     63 uri_create_chat (const struct GNUNET_CRYPTO_BlindablePublicKey *zone,
     64 	               const char *label);
     65 
     66 /**
     67  * Creates a chat uri from a selected FS <i>uri</i>
     68  * setting the type to #GNUNET_CHAT_URI_TYPE_FS.
     69  *
     70  * @param[in] uri FS URI
     71  * @return New chat uri
     72  */
     73 struct GNUNET_CHAT_Uri*
     74 uri_create_file (const struct GNUNET_FS_Uri *uri);
     75 
     76 /**
     77  * Destroys a chat <i>uri</i> and frees its memory.
     78  *
     79  * @param[in,out] uri Chat uri
     80  */
     81 void
     82 uri_destroy (struct GNUNET_CHAT_Uri *uri);
     83 
     84 /**
     85  * Parses an UTF-8 string to a chat URI which will 
     86  * be newly allocated.
     87  *
     88  * @param[in] string UTF-8 string to parse
     89  * @param[out] emsg Where to store the parser error message (if any)
     90  * @return URI on success, NULL on error
     91  */
     92 struct GNUNET_CHAT_Uri*
     93 uri_parse_from_string (const char *string,
     94                        char **emsg);
     95 
     96 /**
     97  * Returns an allocated UTF-8 string representing
     98  * a given chat <i>uri</i>.
     99  *
    100  * @param[in] uri Chat uri
    101  * @return The UTF-8 string representing the URI
    102  */
    103 char*
    104 uri_to_string (const struct GNUNET_CHAT_Uri *uri);
    105 
    106 #endif /* GNUNET_CHAT_URI_H_ */