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 /* Includes that are used frequently. This file may also be used to create predefined headers. */
9 #include <stdlib.h>
10 #include <string.h>
11 #include <pthread.h>
12 #include <libetpan/libetpan.h>
13 #include "deltachat.h"
14 #include "dc_sqlite3.h"
15 #include "dc_tools.h"
16 #include "dc_strbuilder.h"
17 #include "dc_strencode.h"
18 #include "dc_param.h"
19 #include "dc_stock.h"
20 #include "dc_array.h"
21 #include "dc_chat.h"
22 #include "dc_chatlist.h"
23 #include "dc_lot.h"
24 #include "dc_msg.h"
25 #include "dc_contact.h"
26 #include "dc_jobthread.h"
27 #include "dc_imap.h"
28 #include "dc_smtp.h"
29 #include "dc_job.h"
30 #include "dc_mimeparser.h"
31 #include "dc_hash.h"
32 
33 
35 struct _dc_context
36 {
38  #define DC_CONTEXT_MAGIC 0x11a11807
39  uint32_t magic;
41  void* userdata;
43  char* dbfile;
44  char* blobdir;
46  dc_sqlite3_t* sql;
48  dc_imap_t* inbox;
49  pthread_mutex_t inboxidle_condmutex;
50  int perform_inbox_jobs_needed;
51  int probe_imap_network;
53  dc_jobthread_t sentbox_thread;
54  dc_jobthread_t mvbox_thread;
55 
56  dc_smtp_t* smtp;
57  pthread_cond_t smtpidle_cond;
58  pthread_mutex_t smtpidle_condmutex;
59  int smtpidle_condflag;
60  int smtp_suspended;
61  int smtp_doing_jobs;
62  #define DC_JOBS_NEEDED_AT_ONCE 1
63  #define DC_JOBS_NEEDED_AVOID_DOS 2
64  int perform_smtp_jobs_needed;
65  int probe_smtp_network;
67  dc_callback_t cb;
69  char* os_name;
71  uint32_t cmdline_sel_chat_id;
73  // QR code scanning (view from Bob, the joiner)
74  #define DC_VC_AUTH_REQUIRED 2
75  #define DC_VC_CONTACT_CONFIRM 6
76  int bob_expects;
77  #define DC_BOB_ERROR 0
78  #define DC_BOB_SUCCESS 1
79  int bobs_status;
80  dc_lot_t* bobs_qr_scan;
81  pthread_mutex_t bobs_qr_critical;
82 
83  // time smearing - to keep messages in order, we may modify the time by some seconds
84  time_t last_smeared_timestamp;
85  pthread_mutex_t smear_critical;
86 
87  // handling ongoing processes initiated by the user
88  int ongoing_running;
89  int shall_stop_ongoing;
90 };
91 
92 void dc_log_event (dc_context_t*, int event_code, int data1, const char* msg, ...);
93 void dc_log_event_seq (dc_context_t*, int event_code, int* sequence_start, const char* msg, ...);
94 void dc_log_error (dc_context_t*, int data1, const char* msg, ...);
95 void dc_log_warning (dc_context_t*, int data1, const char* msg, ...);
96 void dc_log_info (dc_context_t*, int data1, const char* msg, ...);
97 
98 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);
99 
100 #define DC_NOT_CONNECTED 0
101 #define DC_ALREADY_CONNECTED 1
102 #define DC_JUST_CONNECTED 2
103 int dc_connect_to_configured_imap (dc_context_t*, dc_imap_t*);
104 
105 #define DC_CREATE_MVBOX 0x01
106 #define DC_FOLDERS_CONFIGURED_VERSION 3
107 void dc_configure_folders (dc_context_t*, dc_imap_t*, int flags);
108 
109 
110 void dc_do_heuristics_moves(dc_context_t*, const char* folder, uint32_t msg_id);
111 
112 
113 int dc_is_inbox (dc_context_t*, const char* folder);
114 int dc_is_sentbox (dc_context_t*, const char* folder);
115 int dc_is_mvbox (dc_context_t*, const char* folder);
116 
117 #define DC_BAK_PREFIX "delta-chat"
118 #define DC_BAK_SUFFIX "bak"
119 
120 
121 // attachments of 25 mb brutto should work on the majority of providers
122 // (brutto examples: web.de=50, 1&1=40, t-online.de=32, gmail=25, posteo=50, yahoo=25, all-inkl=100).
123 // as an upper limit, we double the size; the core won't send messages larger than this
124 // to get the netto sizes, we substract 1 mb header-overhead and the base64-overhead.
125 #define DC_MSGSIZE_MAX_RECOMMENDED ((24*1024*1024)/4*3)
126 #define DC_MSGSIZE_UPPER_LIMIT ((49*1024*1024)/4*3)
127 
128 
129 // some defaults
130 #define DC_E2EE_DEFAULT_ENABLED 1
131 #define DC_MDNS_DEFAULT_ENABLED 1
132 #define DC_INBOX_WATCH_DEFAULT 1
133 #define DC_SENTBOX_WATCH_DEFAULT 1
134 #define DC_MVBOX_WATCH_DEFAULT 1
135 #define DC_MVBOX_MOVE_DEFAULT 1
136 
137 
138 typedef struct _dc_e2ee_helper dc_e2ee_helper_t;
139 
140 
141 /* library private: end-to-end-encryption */
142 struct _dc_e2ee_helper {
143  // encryption
144  int encryption_successfull;
145  void* cdata_to_free;
146 
147  // decryption
148  int encrypted; // encrypted without problems
149  dc_hash_t* signatures; // fingerprints of valid signatures
150  dc_hash_t* gossipped_addr;
151 
152 };
153 
154 void dc_e2ee_encrypt (dc_context_t*, const clist* recipients_addr, int force_plaintext, int e2ee_guaranteed, int min_verified, struct mailmime* in_out_message, dc_e2ee_helper_t*);
155 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 */
156 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! */
157 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 */
158 char* dc_create_setup_code (dc_context_t*);
159 char* dc_normalize_setup_code(dc_context_t*, const char* passphrase);
160 char* dc_render_setup_file (dc_context_t*, const char* passphrase);
161 char* dc_decrypt_setup_file(dc_context_t*, const char* passphrase, const char* filecontent);
162 
163 extern int dc_shall_stop_ongoing;
164 int dc_has_ongoing (dc_context_t*);
165 int dc_alloc_ongoing (dc_context_t*);
166 void dc_free_ongoing (dc_context_t*);
167 
168 /* library private: secure-join */
169 #define DC_HANDSHAKE_CONTINUE_NORMAL_PROCESSING 0x01
170 #define DC_HANDSHAKE_STOP_NORMAL_PROCESSING 0x02
171 #define DC_HANDSHAKE_ADD_DELETE_JOB 0x04
172 int dc_handle_securejoin_handshake(dc_context_t*, dc_mimeparser_t*, uint32_t contact_id);
173 void dc_handle_degrade_event (dc_context_t*, dc_apeerstate_t*);
174 
175 
176 #define DC_OPENPGP4FPR_SCHEME "OPENPGP4FPR:" /* yes: uppercase */
177 
178 
179 /* library private: key-history */
180 void dc_add_to_keyhistory(dc_context_t*, const char* rfc724_mid, time_t, const char* addr, const char* fingerprint);
181 
182 
183 #ifdef __cplusplus
184 } /* /extern "C" */
185 #endif
186 #endif /* __DC_CONTEXT_H__ */
An object representing a single account.
An object containing a set of values.