libgnunetchat

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

gnunet_chat_file.h (6656B)


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