@@ -31,6 +31,7 @@ use deltachat::ephemeral::Timer as EphemeralTimer;
31
31
use deltachat:: imex:: BackupProvider ;
32
32
use deltachat:: key:: DcKey ;
33
33
use deltachat:: message:: MsgId ;
34
+ use deltachat:: net:: read_url_blob;
34
35
use deltachat:: qr_code_generator:: { generate_backup_qr, get_securejoin_qr_svg} ;
35
36
use deltachat:: reaction:: { get_msg_reactions, send_reaction, Reactions } ;
36
37
use deltachat:: stock_str:: StockMessage ;
@@ -4572,6 +4573,93 @@ pub unsafe extern "C" fn dc_provider_unref(provider: *mut dc_provider_t) {
4572
4573
// this may change once we start localizing string.
4573
4574
}
4574
4575
4576
+ // dc_http_response_t
4577
+
4578
+ pub type dc_http_response_t = net:: HttpResponse ;
4579
+
4580
+ #[ no_mangle]
4581
+ pub unsafe extern "C" fn dc_get_http_response (
4582
+ context : * const dc_context_t ,
4583
+ url : * const libc:: c_char ,
4584
+ ) -> * mut dc_http_response_t {
4585
+ if context. is_null ( ) || url. is_null ( ) {
4586
+ eprintln ! ( "ignoring careless call to dc_get_http_response()" ) ;
4587
+ return ptr:: null_mut ( ) ;
4588
+ }
4589
+
4590
+ let context = & * context;
4591
+ let url = to_string_lossy ( url) ;
4592
+ if let Ok ( response) = block_on ( read_url_blob ( context, & url) ) . log_err ( context, "read_url_blob" ) {
4593
+ Box :: into_raw ( Box :: new ( response) )
4594
+ } else {
4595
+ ptr:: null_mut ( )
4596
+ }
4597
+ }
4598
+
4599
+ #[ no_mangle]
4600
+ pub unsafe extern "C" fn dc_http_response_get_mimetype (
4601
+ response : * const dc_http_response_t ,
4602
+ ) -> * mut libc:: c_char {
4603
+ if response. is_null ( ) {
4604
+ eprintln ! ( "ignoring careless call to dc_http_response_get_mimetype()" ) ;
4605
+ return ptr:: null_mut ( ) ;
4606
+ }
4607
+
4608
+ let response = & * response;
4609
+ response. mimetype . strdup ( )
4610
+ }
4611
+
4612
+ #[ no_mangle]
4613
+ pub unsafe extern "C" fn dc_http_response_get_encoding (
4614
+ response : * const dc_http_response_t ,
4615
+ ) -> * mut libc:: c_char {
4616
+ if response. is_null ( ) {
4617
+ eprintln ! ( "ignoring careless call to dc_http_response_get_encoding()" ) ;
4618
+ return ptr:: null_mut ( ) ;
4619
+ }
4620
+
4621
+ let response = & * response;
4622
+ response. encoding . strdup ( )
4623
+ }
4624
+
4625
+ #[ no_mangle]
4626
+ pub unsafe extern "C" fn dc_http_response_get_blob (
4627
+ response : * const dc_http_response_t ,
4628
+ ) -> * mut libc:: c_char {
4629
+ if response. is_null ( ) {
4630
+ eprintln ! ( "ignoring careless call to dc_http_response_get_blob()" ) ;
4631
+ return ptr:: null_mut ( ) ;
4632
+ }
4633
+
4634
+ let response = & * response;
4635
+ let blob_len = response. blob . len ( ) ;
4636
+ let ptr = libc:: malloc ( blob_len) ;
4637
+ libc:: memcpy ( ptr, response. blob . as_ptr ( ) as * mut libc:: c_void , blob_len) ;
4638
+ ptr as * mut libc:: c_char
4639
+ }
4640
+
4641
+ #[ no_mangle]
4642
+ pub unsafe extern "C" fn dc_http_response_get_size (
4643
+ response : * const dc_http_response_t ,
4644
+ ) -> libc:: size_t {
4645
+ if response. is_null ( ) {
4646
+ eprintln ! ( "ignoring careless call to dc_http_response_get_size()" ) ;
4647
+ return 0 ;
4648
+ }
4649
+
4650
+ let response = & * response;
4651
+ response. blob . len ( )
4652
+ }
4653
+
4654
+ #[ no_mangle]
4655
+ pub unsafe extern "C" fn dc_http_response_unref ( response : * mut dc_http_response_t ) {
4656
+ if response. is_null ( ) {
4657
+ eprintln ! ( "ignoring careless call to dc_http_response_unref()" ) ;
4658
+ return ;
4659
+ }
4660
+ drop ( Box :: from_raw ( response) ) ;
4661
+ }
4662
+
4575
4663
// -- Accounts
4576
4664
4577
4665
/// Reader-writer lock wrapper for accounts manager to guarantee thread safety when using
0 commit comments