libgnunetchat

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

gnunet_chat_file.h (6811B)


      1 /*
      2    This file is part of GNUnet.
      3    Copyright (C) 2021--2024 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_file.h
     23  */
     24 
     25 #ifndef GNUNET_CHAT_FILE_H_
     26 #define GNUNET_CHAT_FILE_H_
     27 
     28 #include <gnunet/gnunet_fs_service.h>
     29 #include <gnunet/gnunet_messenger_service.h>
     30 #include <gnunet/gnunet_util_lib.h>
     31 
     32 #include "gnunet_chat_lib.h"
     33 
     34 struct GNUNET_CHAT_FileUpload
     35 {
     36   struct GNUNET_CHAT_FileUpload *prev;
     37   struct GNUNET_CHAT_FileUpload *next;
     38 
     39   struct GNUNET_CHAT_Context *context;
     40   GNUNET_CHAT_FileUploadCallback callback;
     41 
     42   void *cls;
     43 };
     44 
     45 struct GNUNET_CHAT_FileDownload
     46 {
     47   struct GNUNET_CHAT_FileDownload *prev;
     48   struct GNUNET_CHAT_FileDownload *next;
     49 
     50   GNUNET_CHAT_FileDownloadCallback callback;
     51 
     52   void *cls;
     53 };
     54 
     55 struct GNUNET_CHAT_FileUnindex
     56 {
     57   struct GNUNET_CHAT_FileUnindex *prev;
     58   struct GNUNET_CHAT_FileUnindex *next;
     59 
     60   GNUNET_CHAT_FileUnindexCallback callback;
     61 
     62   void *cls;
     63 };
     64 
     65 struct GNUNET_CHAT_Handle;
     66 
     67 #define GNUNET_CHAT_FILE_STATUS_DOWNLOAD 0x1
     68 #define GNUNET_CHAT_FILE_STATUS_PUBLISH  0x2
     69 #define GNUNET_CHAT_FILE_STATUS_UNINDEX  0x4
     70 #define GNUNET_CHAT_FILE_STATUS_MASK     0x7
     71 
     72 struct GNUNET_CHAT_File
     73 {
     74   struct GNUNET_CHAT_Handle *handle;
     75 
     76   char *name;
     77 
     78   struct GNUNET_HashCode hash;
     79   struct GNUNET_CRYPTO_SymmetricSessionKey *key;
     80   struct GNUNET_FS_MetaData *meta;
     81   struct GNUNET_FS_Uri *uri;
     82 
     83   struct GNUNET_FS_DownloadContext *download;
     84   struct GNUNET_FS_PublishContext *publish;
     85   struct GNUNET_FS_UnindexContext *unindex;
     86 
     87   struct GNUNET_CHAT_FileUpload *upload_head;
     88   struct GNUNET_CHAT_FileUpload *upload_tail;
     89 
     90   struct GNUNET_CHAT_FileDownload *download_head;
     91   struct GNUNET_CHAT_FileDownload *download_tail;
     92 
     93   struct GNUNET_CHAT_FileUnindex *unindex_head;
     94   struct GNUNET_CHAT_FileUnindex *unindex_tail;
     95 
     96   int status;
     97   char *preview;
     98 
     99   void *user_pointer;
    100 };
    101 
    102 /**
    103  * Creates a chat file handle from a file body in a
    104  * <i>message</i> with a selected chat <i>handle</i>.
    105  *
    106  * @param[in,out] handle Chat handle
    107  * @param[in] message File message body
    108  * @return New chat file handle
    109  */
    110 struct GNUNET_CHAT_File*
    111 file_create_from_message (struct GNUNET_CHAT_Handle *handle,
    112 			                    const struct GNUNET_MESSENGER_MessageFile *message);
    113 
    114 /**
    115  * Creates a chat file handle from a FS CHK URI and
    116  * with a selected chat <i>handle</i>.
    117  *
    118  * @param[in,out] handle Chat handle
    119  * @param[in] uri FS CHK URI
    120  * @return New chat file handle
    121  */
    122 struct GNUNET_CHAT_File*
    123 file_create_from_chk_uri (struct GNUNET_CHAT_Handle *handle,
    124                           const struct GNUNET_FS_Uri *uri);
    125 
    126 /**
    127  * Creates a chat file handle from a local file on disk
    128  * under a given <i>name</i> using a <i>hash</i> and a
    129  * selected symmetric <i>key</i> with a selected chat
    130  * <i>handle</i>.
    131  *
    132  * @param[in,out] handle Chat handle
    133  * @param[in] name File name
    134  * @param[in] hash File hash
    135  * @param[in] key Symmetric key
    136  * @return New chat file handle
    137  */
    138 struct GNUNET_CHAT_File*
    139 file_create_from_disk (struct GNUNET_CHAT_Handle *handle,
    140                        const char *name,
    141                        const struct GNUNET_HashCode *hash,
    142                        const struct GNUNET_CRYPTO_SymmetricSessionKey *key);
    143 
    144 /**
    145  * Destroys a chat <i>file</i> handle and frees its memory.
    146  *
    147  * @param[in,out] file Chat file handle
    148  */
    149 void
    150 file_destroy (struct GNUNET_CHAT_File *file);
    151 
    152 /**
    153  * Binds a chat <i>context</i>, a callback and a closure
    154  * to a given chat <i>file</i> handle to be called on any
    155  * progress uploading the regarding file.
    156  *
    157  * @param[in,out] file Chat file handle
    158  * @param[in,out] context Chat context
    159  * @param[in] cb Callback for upload progress
    160  * @param[in,out] cls Closure
    161  */
    162 void
    163 file_bind_upload (struct GNUNET_CHAT_File *file,
    164                   struct GNUNET_CHAT_Context *context,
    165                   GNUNET_CHAT_FileUploadCallback cb,
    166                   void *cls);
    167 
    168 /**
    169  * Binds a callback and a closure to a given chat <i>file</i>
    170  * handle to be called on any progress downloading the
    171  * regarding file.
    172  *
    173  * @param[in,out] file Chat file handle
    174  * @param[in] cb Callback for download progress
    175  * @param[in,out] cls Closure
    176  */
    177 void
    178 file_bind_downlaod (struct GNUNET_CHAT_File *file,
    179                     GNUNET_CHAT_FileDownloadCallback cb,
    180                     void *cls);
    181 
    182 /**
    183  * Binds a callback and a closure to a given chat <i>file</i>
    184  * handle to be called on any progress unindexing the
    185  * regarding file.
    186  *
    187  * @param[in,out] file Chat file handle
    188  * @param[in] cb Callback for unindex progress
    189  * @param[in,out] cls Closure
    190  */
    191 void
    192 file_bind_unindex (struct GNUNET_CHAT_File *file,
    193                    GNUNET_CHAT_FileUnindexCallback cb,
    194                    void *cls);
    195 
    196 /**
    197  * Calls the regarding events and bound callback of a given
    198  * chat <i>file</i> handle to a file upload progress using
    199  * the provided state of <i>completed</i> bytes and its file
    200  * <i>size</i>.
    201  *
    202  * @param[in,out] file Chat file handle
    203  * @param[in] completed Amount of uploaded bytes
    204  * @param[in] size Full file size
    205  */
    206 void
    207 file_update_upload (struct GNUNET_CHAT_File *file,
    208                     uint64_t completed,
    209                     uint64_t size);
    210 
    211 /**
    212  * Calls the regarding events and bound callback of a given
    213  * chat <i>file</i> handle to a file download progress using
    214  * the provided state of <i>completed</i> bytes and its file
    215  * <i>size</i>.
    216  *
    217  * @param[in,out] file Chat file handle
    218  * @param[in] completed Amount of downloaded bytes
    219  * @param[in] size Full file size
    220  */
    221 void
    222 file_update_download (struct GNUNET_CHAT_File *file,
    223                       uint64_t completed,
    224                       uint64_t size);
    225 
    226 /**
    227  * Calls the regarding events and bound callback of a given
    228  * chat <i>file</i> handle to a file unindex progress using
    229  * the provided state of <i>completed</i> bytes and its file
    230  * <i>size</i>.
    231  *
    232  * @param[in,out] file Chat file handle
    233  * @param[in] completed Amount of unindexed bytes
    234  * @param[in] size Full file size
    235  */
    236 void
    237 file_update_unindex (struct GNUNET_CHAT_File *file,
    238                      uint64_t completed,
    239                      uint64_t size);
    240 
    241 #endif /* GNUNET_CHAT_FILE_H_ */