1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#![allow(unknown_lints)]
#![warn(rust_2018_idioms)]
// Let's allow these in the FFI code, since it's usually just a coincidence if
// the closure is small.
#![allow(clippy::redundant_closure)]
use ffi_support::{
    define_bytebuffer_destructor, define_handle_map_deleter, define_string_destructor, ByteBuffer,
    ConcurrentHandleMap, ExternError, FfiStr,
};
use fxa_client::{
    device::{Capability as DeviceCapability, CommandFetchReason, PushSubscription},
    ffi::{from_protobuf_ptr, AuthorizationParameters, MetricsParams},
    migrator::MigrationState,
    msg_types, FirefoxAccount,
};
use std::os::raw::c_char;
use url::Url;

lazy_static::lazy_static! {
    static ref ACCOUNTS: ConcurrentHandleMap<FirefoxAccount> = ConcurrentHandleMap::new();
}

/// Creates a [FirefoxAccount].
///
/// # Safety
///
/// A destructor [fxa_free] is provided for releasing the memory for this
/// pointer type.
#[no_mangle]
pub extern "C" fn fxa_new(
    content_url: FfiStr<'_>,
    client_id: FfiStr<'_>,
    redirect_uri: FfiStr<'_>,
    token_server_url_override: FfiStr<'_>,
    err: &mut ExternError,
) -> u64 {
    log::debug!("fxa_new");
    ACCOUNTS.insert_with_output(err, || {
        let content_url = content_url.as_str();
        let client_id = client_id.as_str();
        let redirect_uri = redirect_uri.as_str();
        let token_server_url_override = token_server_url_override.as_opt_str();
        FirefoxAccount::new(
            content_url,
            client_id,
            redirect_uri,
            token_server_url_override,
        )
    })
}

/// Restore a [FirefoxAccount] instance from an serialized state (created with [fxa_to_json]).
///
/// # Safety
///
/// A destructor [fxa_free] is provided for releasing the memory for this
/// pointer type.
#[no_mangle]
pub extern "C" fn fxa_from_json(json: FfiStr<'_>, err: &mut ExternError) -> u64 {
    log::debug!("fxa_from_json");
    ACCOUNTS.insert_with_result(err, || FirefoxAccount::from_json(json.as_str()))
}

/// Serializes the state of a [FirefoxAccount] instance. It can be restored later with [fxa_from_json].
///
/// It is the responsability of the caller to persist that serialized state regularly (after operations that mutate [FirefoxAccount])
/// in a **secure** location.
///
/// # Safety
///
/// A destructor [fxa_str_free] is provided for releasing the memory for this
/// pointer type.
#[no_mangle]
pub extern "C" fn fxa_to_json(handle: u64, error: &mut ExternError) -> *mut c_char {
    log::debug!("fxa_to_json");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| fxa.to_json())
}

/// Fetches the profile associated with a Firefox Account.
///
/// The profile might get cached in-memory and the caller might get served a cached version.
/// To bypass this, the `ignore_cache` parameter can be set to `true`.
///
/// # Safety
///
/// A destructor [fxa_bytebuffer_free] is provided for releasing the memory for this
/// pointer type.
#[no_mangle]
pub extern "C" fn fxa_profile(
    handle: u64,
    ignore_cache: u8,
    error: &mut ExternError,
) -> ByteBuffer {
    log::debug!("fxa_profile");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| fxa.get_profile(ignore_cache != 0))
}

/// Get the pairing URL to navigate to on the Auth side (typically a computer).
///
/// # Safety
///
/// A destructor [fxa_str_free] is provided for releasing the memory for this
/// pointer type.
#[no_mangle]
pub extern "C" fn fxa_get_pairing_authority_url(
    handle: u64,
    error: &mut ExternError,
) -> *mut c_char {
    log::debug!("fxa_get_pairing_authority_url");
    ACCOUNTS.call_with_result(error, handle, |fxa| {
        fxa.get_pairing_authority_url().map(Url::into_string)
    })
}

/// Get the Sync token server endpoint URL.
///
/// # Safety
///
/// A destructor [fxa_str_free] is provided for releasing the memory for this
/// pointer type.
#[no_mangle]
pub extern "C" fn fxa_get_token_server_endpoint_url(
    handle: u64,
    error: &mut ExternError,
) -> *mut c_char {
    log::debug!("fxa_get_token_server_endpoint_url");
    ACCOUNTS.call_with_result(error, handle, |fxa| {
        fxa.get_token_server_endpoint_url().map(Url::into_string)
    })
}

/// Get the url to redirect after there has been a successful connection to FxA.
///
/// # Safety
///
/// A destructor [fxa_str_free] is provided for releasing the memory for this
/// pointer type.
#[no_mangle]
pub extern "C" fn fxa_get_connection_success_url(
    handle: u64,
    error: &mut ExternError,
) -> *mut c_char {
    log::debug!("fxa_get_connection_success_url");
    ACCOUNTS.call_with_result(error, handle, |fxa| {
        fxa.get_connection_success_url().map(Url::into_string)
    })
}

/// Get the url to open the user's account-management page.
///
/// # Safety
///
/// A destructor [fxa_str_free] is provided for releasing the memory for this
/// pointer type.
#[no_mangle]
pub extern "C" fn fxa_get_manage_account_url(
    handle: u64,
    entrypoint: FfiStr<'_>,
    error: &mut ExternError,
) -> *mut c_char {
    log::debug!("fxa_get_manage_account_url");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| {
        fxa.get_manage_account_url(entrypoint.as_str())
            .map(Url::into_string)
    })
}

/// Get the url to open the user's devices-management page.
///
/// # Safety
///
/// A destructor [fxa_str_free] is provided for releasing the memory for this
/// pointer type.
#[no_mangle]
pub extern "C" fn fxa_get_manage_devices_url(
    handle: u64,
    entrypoint: FfiStr<'_>,
    error: &mut ExternError,
) -> *mut c_char {
    log::debug!("fxa_get_manage_devices_url");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| {
        fxa.get_manage_devices_url(entrypoint.as_str())
            .map(Url::into_string)
    })
}

/// Request a OAuth token by starting a new pairing flow, by calling the content server pairing endpoint.
///
/// This function returns a URL string that the caller should open in a webview.
///
/// Pairing assumes you want keys by default, so you must provide a key-bearing scope.
///
/// # Safety
///
/// A destructor [fxa_str_free] is provided for releasing the memory for this
/// pointer type.
#[no_mangle]
pub unsafe extern "C" fn fxa_begin_pairing_flow(
    handle: u64,
    pairing_url: FfiStr<'_>,
    scope: FfiStr<'_>,
    entrypoint: FfiStr<'_>,
    metrics_params: *const u8,
    metrics_params_len: i32,
    error: &mut ExternError,
) -> *mut c_char {
    log::debug!("fxa_begin_pairing_flow");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| {
        let pairing_url = pairing_url.as_str();
        let scope = scope.as_str();
        let scopes: Vec<&str> = scope.split(' ').collect();
        let metrics_params = from_protobuf_ptr::<MetricsParams, msg_types::MetricsParams>(
            metrics_params,
            metrics_params_len,
        )?;
        fxa.begin_pairing_flow(
            &pairing_url,
            &scopes,
            entrypoint.as_str(),
            Some(metrics_params),
        )
    })
}

/// Request a OAuth token by starting a new OAuth flow.
///
/// This function returns a URL string that the caller should open in a webview.
///
/// Once the user has confirmed the authorization grant, they will get redirected to `redirect_url`:
/// the caller must intercept that redirection, extract the `code` and `state` query parameters and call
/// [fxa_complete_oauth_flow] to complete the flow.
///
/// # Safety
///
/// A destructor [fxa_str_free] is provided for releasing the memory for this
/// pointer type.
#[no_mangle]
pub unsafe extern "C" fn fxa_begin_oauth_flow(
    handle: u64,
    scope: FfiStr<'_>,
    entrypoint: FfiStr<'_>,
    metrics_params: *const u8,
    metrics_params_len: i32,
    error: &mut ExternError,
) -> *mut c_char {
    log::debug!("fxa_begin_oauth_flow");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| {
        let scope = scope.as_str();
        let scopes: Vec<&str> = scope.split(' ').collect();
        let metrics_params = from_protobuf_ptr::<MetricsParams, msg_types::MetricsParams>(
            metrics_params,
            metrics_params_len,
        )?;
        fxa.begin_oauth_flow(&scopes, entrypoint.as_str(), Some(metrics_params))
    })
}

/// Finish an OAuth flow initiated by [fxa_begin_oauth_flow].
#[no_mangle]
pub extern "C" fn fxa_complete_oauth_flow(
    handle: u64,
    code: FfiStr<'_>,
    state: FfiStr<'_>,
    error: &mut ExternError,
) {
    log::debug!("fxa_complete_oauth_flow");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| {
        let code = code.as_str();
        let state = state.as_str();
        fxa.complete_oauth_flow(code, state)
    });
}

/// Migrate from a logged-in sessionToken Firefox Account.
#[no_mangle]
pub extern "C" fn fxa_migrate_from_session_token(
    handle: u64,
    session_token: FfiStr<'_>,
    k_sync: FfiStr<'_>,
    k_xcs: FfiStr<'_>,
    copy_session_token: u8,
    error: &mut ExternError,
) -> *mut c_char {
    log::debug!("fxa_migrate_from_session_token");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| -> fxa_client::Result<String> {
        let session_token = session_token.as_str();
        let k_sync = k_sync.as_str();
        let k_xcs = k_xcs.as_str();
        let migration_metrics =
            fxa.migrate_from_session_token(session_token, k_sync, k_xcs, copy_session_token != 0)?;
        let result = serde_json::to_string(&migration_metrics)?;
        Ok(result)
    })
}

/// Check if there is migration state.
#[no_mangle]
pub extern "C" fn fxa_is_in_migration_state(handle: u64, error: &mut ExternError) -> u8 {
    log::debug!("fxa_is_in_migration_state");
    ACCOUNTS.call_with_result(error, handle, |fxa| -> fxa_client::Result<MigrationState> {
        Ok(fxa.is_in_migration_state())
    })
}

/// Retry the migration attempt using the stored migration state.
#[no_mangle]
pub extern "C" fn fxa_retry_migrate_from_session_token(
    handle: u64,
    error: &mut ExternError,
) -> *mut c_char {
    log::debug!("fxa_retry_migrate_from_session_token");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| -> fxa_client::Result<String> {
        let migration_metrics = fxa.try_migration()?;
        let result = serde_json::to_string(&migration_metrics)?;
        Ok(result)
    })
}

/// Try to get an access token.
///
/// If the system can't find a suitable token but has a `refresh token` or a `session_token`,
/// it will generate a new one on the go.
///
/// If not, the caller must start an OAuth flow with [fxa_begin_oauth_flow].
///
/// Arguments:
///   * scope: space-separated list of scopes that the token should have
///   * ttl: the time in seconds for which the token should be valid
///          (or zero to use the server-controlled default ttl)
///
/// # Safety
///
/// A destructor [fxa_bytebuffer_free] is provided for releasing the memory for this
/// pointer type.
#[no_mangle]
pub extern "C" fn fxa_get_access_token(
    handle: u64,
    scope: FfiStr<'_>,
    ttl: u64,
    error: &mut ExternError,
) -> ByteBuffer {
    log::debug!("fxa_get_access_token");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| {
        let scope = scope.as_str();
        let time_left = if ttl > 0 { Some(ttl) } else { None };
        fxa.get_access_token(scope, time_left)
    })
}

/// Try to get a session token.
///
/// If the system can't find a suitable token it will return an error
///
/// # Safety
///
/// A destructor [fxa_bytebuffer_free] is provided for releasing the memory for this
/// pointer type.
#[no_mangle]
pub extern "C" fn fxa_get_session_token(handle: u64, error: &mut ExternError) -> *mut c_char {
    log::debug!("fxa_get_session_token");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| fxa.get_session_token())
}

/// Retrieve the refresh token authorization status.
#[no_mangle]
pub extern "C" fn fxa_check_authorization_status(
    handle: u64,
    error: &mut ExternError,
) -> ByteBuffer {
    log::debug!("fxa_check_authorization_status");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| fxa.check_authorization_status())
}

/// This method should be called when a request made with
/// an OAuth token failed with an authentication error.
/// It clears the internal cache of OAuth access tokens,
/// so the caller can try to call `fxa_get_access_token` or `fxa_profile`
/// again.
#[no_mangle]
pub extern "C" fn fxa_clear_access_token_cache(handle: u64, error: &mut ExternError) {
    log::debug!("fxa_clear_access_token_cache");
    ACCOUNTS.call_with_output_mut(error, handle, |fxa| fxa.clear_access_token_cache())
}

/// Try to get the current device id from state.
///
/// If the system can't find it then it will return an error
///
/// # Safety
///
/// A destructor [fxa_bytebuffer_free] is provided for releasing the memory for this
/// pointer type.
#[no_mangle]
pub extern "C" fn fxa_get_current_device_id(handle: u64, error: &mut ExternError) -> *mut c_char {
    log::debug!("fxa_get_current_device_id");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| fxa.get_current_device_id())
}

/// Update the Push subscription information for the current device.
#[no_mangle]
pub extern "C" fn fxa_set_push_subscription(
    handle: u64,
    endpoint: FfiStr<'_>,
    public_key: FfiStr<'_>,
    auth_key: FfiStr<'_>,
    error: &mut ExternError,
) {
    log::debug!("fxa_set_push_subscription");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| {
        let ps = PushSubscription {
            endpoint: endpoint.into_string(),
            public_key: public_key.into_string(),
            auth_key: auth_key.into_string(),
        };
        // We don't really care about passing back the resulting Device record.
        // We might in the future though.
        fxa.set_push_subscription(&ps).map(|_| ())
    })
}

/// Update the display name for the current device.
#[no_mangle]
pub extern "C" fn fxa_set_device_name(
    handle: u64,
    display_name: FfiStr<'_>,
    error: &mut ExternError,
) {
    log::debug!("fxa_set_device_name");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| {
        // We don't really care about passing back the resulting Device record.
        // We might in the future though.
        fxa.set_device_name(display_name.as_str()).map(|_| ())
    })
}

/// Fetch the devices (including the current one) in the current account.
///
/// Devices might get cached in-memory and the caller might get served a cached version.
/// To bypass this, the `ignore_cache` parameter can be set to `true`.
///
/// # Safety
///
/// A destructor [fxa_bytebuffer_free] is provided for releasing the memory for this
/// pointer type.
#[no_mangle]
pub extern "C" fn fxa_get_devices(
    handle: u64,
    ignore_cache: u8,
    error: &mut ExternError,
) -> ByteBuffer {
    log::debug!("fxa_get_devices");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| {
        fxa.get_devices(ignore_cache != 0).map(|d| {
            let devices = d.into_iter().map(|device| device.into()).collect();
            fxa_client::msg_types::Devices { devices }
        })
    })
}

/// Try to get an OAuth code using a session token.
///
/// The system will use the stored `session_token` to provision a new code and return it.
///
/// # Safety
///
/// A destructor [fxa_bytebuffer_free] is provided for releasing the memory for this
/// pointer type.
#[no_mangle]
pub unsafe extern "C" fn fxa_authorize_auth_code(
    handle: u64,
    auth_params: *const u8,
    auth_params_len: i32,
    error: &mut ExternError,
) -> *mut c_char {
    log::debug!("fxa_authorize_auth_code");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| {
        let auth_params = from_protobuf_ptr::<
            AuthorizationParameters,
            msg_types::AuthorizationParams,
        >(auth_params, auth_params_len)?;
        fxa.authorize_code_using_session_token(auth_params)
    })
}

/// Typically called during a password change flow.
/// Invalidate all tokens and get a new refresh token.
#[no_mangle]
pub extern "C" fn fxa_handle_session_token_change(
    handle: u64,
    new_session_token: FfiStr<'_>,
    error: &mut ExternError,
) {
    log::debug!("fxa_handle_session_token_change");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| {
        let new_session_token = new_session_token.as_str();
        fxa.handle_session_token_change(new_session_token)
    })
}

/// Poll and parse available remote commands targeted to our own device.
///
/// # Safety
///
/// A destructor [fxa_bytebuffer_free] is provided for releasing the memory for this
/// pointer type.
#[no_mangle]
pub extern "C" fn fxa_poll_device_commands(handle: u64, error: &mut ExternError) -> ByteBuffer {
    log::debug!("fxa_poll_device_commands");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| {
        fxa.poll_device_commands(CommandFetchReason::Poll)
            .map(|cmds| {
                let commands = cmds.into_iter().map(|e| e.into()).collect();
                fxa_client::msg_types::IncomingDeviceCommands { commands }
            })
    })
}

/// Disconnect from the account and optionaly destroy our device record.
#[no_mangle]
pub extern "C" fn fxa_disconnect(handle: u64, error: &mut ExternError) {
    log::debug!("fxa_disconnect");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| -> fxa_client::Result<()> {
        fxa.disconnect();
        Ok(())
    })
}

/// Handle a push payload coming from the Firefox Account servers.
///
/// # Safety
///
/// A destructor [fxa_bytebuffer_free] is provided for releasing the memory for this
/// pointer type.
#[no_mangle]
pub extern "C" fn fxa_handle_push_message(
    handle: u64,
    json_payload: FfiStr<'_>,
    error: &mut ExternError,
) -> ByteBuffer {
    log::debug!("fxa_handle_push_message");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| {
        fxa.handle_push_message(json_payload.as_str()).map(|evs| {
            let events = evs.into_iter().map(|e| e.into()).collect();
            fxa_client::msg_types::AccountEvents { events }
        })
    })
}

/// Initalizes our own device, most of the time this will be called right after
/// logging-in for the first time.
///
/// # Safety
/// This function is unsafe because it will dereference `capabilities_data` and
/// read `capabilities_len` bytes from it.
#[no_mangle]
pub unsafe extern "C" fn fxa_initialize_device(
    handle: u64,
    name: FfiStr<'_>,
    device_type: i32,
    capabilities_data: *const u8,
    capabilities_len: i32,
    error: &mut ExternError,
) {
    log::debug!("fxa_initialize_device");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| {
        let capabilities =
            DeviceCapability::from_protobuf_array_ptr(capabilities_data, capabilities_len)?;
        // This should not fail as device_type i32 representation is derived from our .proto schema.
        let device_type =
            msg_types::device::Type::from_i32(device_type).expect("Unknown device type code");
        fxa.initialize_device(name.as_str(), device_type.into(), &capabilities)
    })
}

/// Ensure that the device capabilities are registered with the server.
///
/// # Safety
/// This function is unsafe because it will dereference `capabilities_data` and
/// read `capabilities_len` bytes from it.
#[no_mangle]
pub unsafe extern "C" fn fxa_ensure_capabilities(
    handle: u64,
    capabilities_data: *const u8,
    capabilities_len: i32,
    error: &mut ExternError,
) {
    log::debug!("fxa_ensure_capabilities");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| {
        let capabilities =
            DeviceCapability::from_protobuf_array_ptr(capabilities_data, capabilities_len)?;
        fxa.ensure_capabilities(&capabilities)
    })
}

/// Send a tab to another device identified by its Device ID.
#[no_mangle]
pub extern "C" fn fxa_send_tab(
    handle: u64,
    target_device_id: FfiStr<'_>,
    title: FfiStr<'_>,
    url: FfiStr<'_>,
    error: &mut ExternError,
) {
    log::debug!("fxa_send_tab");
    let target = target_device_id.as_str();
    let title = title.as_str();
    let url = url.as_str();
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| fxa.send_tab(target, title, url))
}

#[no_mangle]
pub extern "C" fn fxa_get_ecosystem_anon_id(handle: u64, error: &mut ExternError) -> *mut c_char {
    log::debug!("fxa_get_ecosystem_anon_id");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| fxa.get_ecosystem_anon_id())
}

define_handle_map_deleter!(ACCOUNTS, fxa_free);
define_string_destructor!(fxa_str_free);
define_bytebuffer_destructor!(fxa_bytebuffer_free);

/// Gather telemetry collected by FxA.
#[no_mangle]
pub extern "C" fn fxa_gather_telemetry(handle: u64, error: &mut ExternError) -> *mut c_char {
    log::debug!("fxa_gather_telemetry");
    ACCOUNTS.call_with_result_mut(error, handle, |fxa| fxa.gather_telemetry())
}