Delta Chat Core C-API
dc_context.h
1 #ifndef __DC_CONTEXT_H__
2 #define __DC_CONTEXT_H__
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6 
7 
8 /* define DC_USE_RPGP to enable use of rPGP instead of netpgp where available;
9 preferrably, this should be done in the project configuration currently */
10 //#define DC_USE_RPGP 1
11 
12 
13 /* Includes that are used frequently. This file may also be used to create predefined headers. */
14 #include <stdlib.h>
15 #include <string.h>
16 #include <pthread.h>
17 #include <libetpan/libetpan.h>
18 #include "deltachat.h"
19 #include "dc_sqlite3.h"
20 #include "dc_tools.h"
21 #include "dc_strbuilder.h"
22 #include "dc_strencode.h"
23 #include "dc_param.h"
24 #include "dc_stock.h"
25 #include "dc_array.h"
26 #include "dc_chat.h"
27 #include "dc_chatlist.h"
28 #include "dc_lot.h"
29 #include "dc_msg.h"
30 #include "dc_contact.h"
31 #include "dc_jobthread.h"
32 #include "dc_imap.h"
33 #include "dc_smtp.h"
34 #include "dc_job.h"
35 #include "dc_mimeparser.h"
36 #include "dc_hash.h"
37 
38 
40 struct _dc_context
41 {
43  #define DC_CONTEXT_MAGIC 0x11a11807
44  uint32_t magic;
46  void* userdata;
48  char* dbfile;
49  char* blobdir;
51  dc_sqlite3_t* sql;
53  dc_imap_t* inbox;
54  pthread_mutex_t inboxidle_condmutex;
55  int perform_inbox_jobs_needed;
56  int probe_imap_network;
58  dc_jobthread_t sentbox_thread;
59  dc_jobthread_t mvbox_thread;
60 
61  dc_smtp_t* smtp;
62  pthread_cond_t smtpidle_cond;
63  pthread_mutex_t smtpidle_condmutex;
64  int smtpidle_condflag;
65  int smtp_suspended;
66  int smtp_doing_jobs;
67  #define DC_JOBS_NEEDED_AT_ONCE 1
68  #define DC_JOBS_NEEDED_AVOID_DOS 2
69  int perform_smtp_jobs_needed;
70  int probe_smtp_network;
72  pthread_mutex_t oauth2_critical;
73 
74  dc_callback_t cb;
76  char* os_name;
78  uint32_t cmdline_sel_chat_id;
80  // QR code scanning (view from Bob, the joiner)
81  #define DC_VC_AUTH_REQUIRED 2
82  #define DC_VC_CONTACT_CONFIRM 6
83  int bob_expects;
84  #define DC_BOB_ERROR 0
85  #define DC_BOB_SUCCESS 1
86  int bobs_status;
87  dc_lot_t* bobs_qr_scan;
88  pthread_mutex_t bobs_qr_critical;
89 
90  // time smearing - to keep messages in order, we may modify the time by some seconds
91  time_t last_smeared_timestamp;
92  pthread_mutex_t smear_critical;
93 
94  // handling ongoing processes initiated by the user
95  int ongoing_running;
96  int shall_stop_ongoing;
97 };
98 
99 void dc_log_event (dc_context_t*, int event_code, int data1, const char* msg, ...);
100 void dc_log_event_seq (dc_context_t*, int event_code, int* sequence_start, const char* msg, ...);
101 void dc_log_error (dc_context_t*, int data1, const char* msg, ...);
102 void dc_log_warning (dc_context_t*, int data1, const char* msg, ...);
103 void dc_log_info (dc_context_t*, int data1, const char* msg, ...);
104 
105 void dc_receive_imf (dc_context_t*, const char* imf_raw_not_terminated, size_t imf_raw_bytes, const char* server_folder, uint32_t server_uid, uint32_t flags);
106 
107 #define DC_NOT_CONNECTED 0
108 #define DC_ALREADY_CONNECTED 1
109 #define DC_JUST_CONNECTED 2
110 int dc_connect_to_configured_imap (dc_context_t*, dc_imap_t*);
111 
112 #define DC_CREATE_MVBOX 0x01
113 #define DC_FOLDERS_CONFIGURED_VERSION 3
114 void dc_configure_folders (dc_context_t*, dc_imap_t*, int flags);
115 
116 
117 void dc_do_heuristics_moves(dc_context_t*, const char* folder, uint32_t msg_id);
118 
119 
120 int dc_is_inbox (dc_context_t*, const char* folder);
121 int dc_is_sentbox (dc_context_t*, const char* folder);
122 int dc_is_mvbox (dc_context_t*, const char* folder);
123 
124 
125 // location handling
126 typedef struct _dc_location
127 {
128  #define DC_ARRAY_LOCATIONS 1
129  uint32_t location_id;
130  double latitude;
131  double longitude;
132  double accuracy;
133  time_t timestamp;
134  uint32_t contact_id;
135  uint32_t msg_id;
136  uint32_t chat_id;
137  char* marker;
138  int independent;
139 } dc_location_t;
140 
141 typedef struct _dc_kml
142 {
143  char* addr;
144  dc_array_t* locations;
145  int tag;
146  dc_location_t curr;
147 } dc_kml_t;
148 
149 char* dc_get_location_kml (dc_context_t*, uint32_t chat_id, uint32_t* last_added_location_id);
150 char* dc_get_message_kml (dc_context_t*, time_t timestamp, double latitude, double longitude);
151 void dc_set_kml_sent_timestamp (dc_context_t*, uint32_t chat_id, time_t);
152 void dc_set_msg_location_id (dc_context_t*, uint32_t msg_id, uint32_t location_id);
153 uint32_t dc_save_locations (dc_context_t*, uint32_t chat_id, uint32_t contact_id, const dc_array_t*, int independent);
154 dc_kml_t* dc_kml_parse (dc_context_t*, const char* content, size_t content_bytes);
155 void dc_kml_unref (dc_kml_t*);
156 void dc_job_do_DC_JOB_MAYBE_SEND_LOCATIONS (dc_context_t*, dc_job_t*);
157 void dc_job_do_DC_JOB_MAYBE_SEND_LOC_ENDED (dc_context_t*, dc_job_t*);
158 
159 
160 // backups
161 #define DC_BAK_PREFIX "delta-chat"
162 #define DC_BAK_SUFFIX "bak"
163 
164 
165 // attachments of 25 mb brutto should work on the majority of providers
166 // (brutto examples: web.de=50, 1&1=40, t-online.de=32, gmail=25, posteo=50, yahoo=25, all-inkl=100).
167 // as an upper limit, we double the size; the core won't send messages larger than this
168 // to get the netto sizes, we substract 1 mb header-overhead and the base64-overhead.
169 #define DC_MSGSIZE_MAX_RECOMMENDED ((24*1024*1024)/4*3)
170 #define DC_MSGSIZE_UPPER_LIMIT ((49*1024*1024)/4*3)
171 
172 
173 // some defaults
174 #define DC_E2EE_DEFAULT_ENABLED 1
175 #define DC_MDNS_DEFAULT_ENABLED 1
176 #define DC_INBOX_WATCH_DEFAULT 1
177 #define DC_SENTBOX_WATCH_DEFAULT 1
178 #define DC_MVBOX_WATCH_DEFAULT 1
179 #define DC_MVBOX_MOVE_DEFAULT 1
180 #define DC_SHOW_EMAILS_DEFAULT DC_SHOW_EMAILS_OFF
181 
182 
183 typedef struct _dc_e2ee_helper dc_e2ee_helper_t;
184 
185 
186 /* library private: end-to-end-encryption */
187 struct _dc_e2ee_helper {
188  // encryption
189  int encryption_successfull;
190  void* cdata_to_free;
191 
192  // decryption
193  int encrypted; // encrypted without problems
194  dc_hash_t* signatures; // fingerprints of valid signatures
195  dc_hash_t* gossipped_addr;
196 
197 };
198 
199 void dc_e2ee_encrypt (dc_context_t*, const clist* recipients_addr,
200  int force_plaintext, int e2ee_guaranteed, int min_verified,
201  int do_gossip, struct mailmime* in_out_message, dc_e2ee_helper_t*);
202 void dc_e2ee_decrypt (dc_context_t*, struct mailmime* in_out_message, dc_e2ee_helper_t*); /* returns 1 if sth. was decrypted, 0 in other cases */
203 void dc_e2ee_thanks (dc_e2ee_helper_t*); /* frees data referenced by "mailmime" but not freed by mailmime_free(). After calling this function, in_out_message cannot be used any longer! */
204 int dc_ensure_secret_key_exists (dc_context_t*); /* makes sure, the private key exists, needed only for exporting keys and the case no message was sent before */
205 char* dc_create_setup_code (dc_context_t*);
206 char* dc_normalize_setup_code(dc_context_t*, const char* passphrase);
207 char* dc_render_setup_file (dc_context_t*, const char* passphrase);
208 char* dc_decrypt_setup_file(dc_context_t*, const char* passphrase, const char* filecontent);
209 
210 extern int dc_shall_stop_ongoing;
211 int dc_has_ongoing (dc_context_t*);
212 int dc_alloc_ongoing (dc_context_t*);
213 void dc_free_ongoing (dc_context_t*);
214 
215 /* library private: secure-join */
216 #define DC_HANDSHAKE_CONTINUE_NORMAL_PROCESSING 0x01
217 #define DC_HANDSHAKE_STOP_NORMAL_PROCESSING 0x02
218 #define DC_HANDSHAKE_ADD_DELETE_JOB 0x04
219 int dc_handle_securejoin_handshake(dc_context_t*, dc_mimeparser_t*, uint32_t contact_id);
220 void dc_handle_degrade_event (dc_context_t*, dc_apeerstate_t*);
221 
222 
223 #define DC_OPENPGP4FPR_SCHEME "OPENPGP4FPR:" /* yes: uppercase */
224 
225 
226 /* library private: key-history */
227 void dc_add_to_keyhistory(dc_context_t*, const char* rfc724_mid, time_t, const char* addr, const char* fingerprint);
228 
229 
230 #ifdef __cplusplus
231 } /* /extern "C" */
232 #endif
233 #endif /* __DC_CONTEXT_H__ */
dc_lot_t
dc_array_t
dc_context_t