The Linphone account creator allows to create accounts, check if an account exist, etc... Liblinphone provides a default account creator service to handle accounts on sip.linphone.org but also allows developers to implement their own account creator service.

Linphone Android, Linphone IOS, and Linphone desktop use a Linphone implementation of account creator based on XML-RPC requests.

How does it work

The Linphone account creator follows a common pattern for available actions. Each action like create, exist and so on can be implemented using function of type:

LinphoneAccountCreatorStatus (*LinphoneAccountCreatorRequestFunc)(LinphoneAccountCreator *creator);

Implementation must synchronously and asynchronously return a value of type LinphoneAccountCreatorStatus as a provisional status.

A final result must taken as a result of a remote action must be notified and forward to response callback corresponding by the implementor using corresponding functions as listed in the callbacks section.

Callbacks

The following functions can be implemented:

  • Account creator constructor

    • Set with this function:
    void linphone_account_creator_service_set_constructor_cb(LinphoneAccountCreatorService *service, LinphoneAccountCreatorRequestFunc cb);
    • Invoked when an account creator is created with this function:
    LinphoneAccountCreator * linphone_account_creator_new(LinphoneCore *core, const char *xmlrpc_url);
  • Account creator destructor

    • Set with this function:
    void linphone_account_creator_service_set_destructor_cb(LinphoneAccountCreatorService *service, LinphoneAccountCreatorRequestFunc cb);
    • Invoked when an account creator is destroyed with this function:
    void linphone_account_creator_unref(LinphoneAccountCreator *creator);
  • Is account exist

    • Set with this function:
    void linphone_account_creator_service_set_is_account_exist_cb(LinphoneAccountCreatorService *service, LinphoneAccountCreatorRequestFunc cb);
    • Invoked when you call:
    LinphoneAccountCreatorStatus linphone_account_creator_is_account_exist(LinphoneAccountCreator *creator);
    • Associated response callback:
    LinphoneAccountCreatorCbsStatusCb linphone_account_creator_cbs_get_is_account_exist(const LinphoneAccountCreatorCbs *cbs);
  • Create account

    • Set with this function:
    void linphone_account_creator_service_set_create_account_cb(LinphoneAccountCreatorService *service, LinphoneAccountCreatorRequestFunc cb);
    • Invoked when you call:
    LinphoneAccountCreatorStatus linphone_account_creator_create_account(LinphoneAccountCreator *creator);
    • Associated response callback:
    LinphoneAccountCreatorCbsStatusCb linphone_account_creator_cbs_get_create_account(const LinphoneAccountCreatorCbs *cbs);
  • Activate account

    • Set with this function:
    void linphone_account_creator_service_set_activate_account_cb(LinphoneAccountCreatorService *service, LinphoneAccountCreatorRequestFunc cb);
    • Invoked when you call:
    LinphoneAccountCreatorStatus linphone_account_creator_activate_account(LinphoneAccountCreator *creator);
    • Associated response callback:
    LinphoneAccountCreatorCbsStatusCb linphone_account_creator_cbs_get_activate_account(const LinphoneAccountCreatorCbs *cbs);
  • Is account activated

    • Set with this function:
    void linphone_account_creator_service_set_is_account_activated_cb(LinphoneAccountCreatorService *service, LinphoneAccountCreatorRequestFunc cb);
    • Invoked when you call:
    LinphoneAccountCreatorStatus linphone_account_creator_is_account_activated(LinphoneAccountCreator *creator);
    • Associated response callback:
    LinphoneAccountCreatorCbsStatusCb linphone_account_creator_cbs_get_is_account_activated(const LinphoneAccountCreatorCbs *cbs);
  • Is alias used

    • Set with this function:
    void linphone_account_creator_service_set_is_alias_used_cb(LinphoneAccountCreatorService *service, LinphoneAccountCreatorRequestFunc cb);
    • Invoked when you call:
    LinphoneAccountCreatorStatus linphone_account_creator_is_alias_used(LinphoneAccountCreator *creator);
    • Associated response callback:
    LinphoneAccountCreatorCbsStatusCb linphone_account_creator_cbs_get_is_alias_used(const LinphoneAccountCreatorCbs *cbs);
  • Link account

    • Set with this function:
    void linphone_account_creator_service_set_link_account_cb(LinphoneAccountCreatorService *service, LinphoneAccountCreatorRequestFunc cb);
    • Invoked when you call:
    LinphoneAccountCreatorStatus linphone_account_creator_link_account(LinphoneAccountCreator *creator);
    • Associated response callback:
    LinphoneAccountCreatorCbsStatusCb linphone_account_creator_cbs_get_link_account(const LinphoneAccountCreatorCbs *cbs);
  • Activate alias

    • Set with this function:
    void linphone_account_creator_service_set_activate_alias_cb(LinphoneAccountCreatorService *service, LinphoneAccountCreatorRequestFunc cb);
    • Invoked when you call:
    LinphoneAccountCreatorStatus linphone_account_creator_activate_alias(LinphoneAccountCreator *creator);
    • Associated response callback:
    LinphoneAccountCreatorCbsStatusCb linphone_account_creator_cbs_get_activate_alias(const LinphoneAccountCreatorCbs *cbs);
  • Recover account

    • Set with this function:
    void linphone_account_creator_service_set_recover_account_cb(LinphoneAccountCreatorService *service, LinphoneAccountCreatorRequestFunc cb);
    • Invoked when you call:
    LinphoneAccountCreatorStatus linphone_account_creator_recover_account(LinphoneAccountCreator *creator);
    • Associated response callback:
    LinphoneAccountCreatorCbsStatusCb linphone_account_creator_cbs_get_recover_account(const LinphoneAccountCreatorCbs *cbs);
  • Is account linked

    • Set with this function:
    void linphone_account_creator_service_set_is_account_linked_cb(LinphoneAccountCreatorService *service, LinphoneAccountCreatorRequestFunc cb);
    • Invoked when you call:
    LinphoneAccountCreatorStatus linphone_account_creator_is_account_linked(LinphoneAccountCreator *creator);
    • Associated response callback:
    LinphoneAccountCreatorCbsStatusCb linphone_account_creator_cbs_get_is_account_linked(const LinphoneAccountCreatorCbs *cbs);
  • Update account

    • Set with this function:
    void linphone_account_creator_service_set_update_account_cb(LinphoneAccountCreatorService *service, LinphoneAccountCreatorRequestFunc cb);
    • Invoked when you called:
    LinphoneAccountCreatorStatus linphone_account_creator_update_account(LinphoneAccountCreator *creator);
    • Associated response callback:
    LinphoneAccountCreatorCbsStatusCb linphone_account_creator_cbs_get_update_account(const LinphoneAccountCreatorCbs *cbs);

How to use it

Create your own implemenation and set it by default to LinphoneCore.

// Create a new service
LinphoneAccountCreatorService *service = linphone_account_creator_service_new();

// Set your callbacks
linphone_account_creator_service_set_constructor_cb(service, linphone_account_creator_constructor_custom);
linphone_account_creator_service_set_destructor_cb(service, linphone_account_creator_destructor_custom);
...
linphone_account_creator_service_set_update_account_cb(service, linphone_account_creator_update_account_custom);

// Do not forget to set your implementation to LinphoneCore
linphone_core_set_account_creator_service(lc, service);

Sample code

This is an example of custom request to know if an account exist.

static LinphoneAccountCreatorStatus my_account_creator_request_is_account_exist(LinphoneAccountCreator *creator) {
 // If no username is set we can't know if this account exist
 if (!creator->username) {
   // We notify the response callback to notify it
   linphone_account_creator_cbs_get_is_account_exist(linphone_account_creator_get_callbacks(creator))
      (creator, LinphoneRequestMissingArguments, "Missing required parameters");

   // The request failed
   return LinphoneRequestMissingArguments;
  }

 if (str_cmp("user_exist", creator->username) != 0) {
   // Account exists so we call the callback to notify it
   linphone_account_creator_cbs_get_is_account_exist(linphone_account_creator_get_callbacks(creator))
      (creator, LinphoneRequestAccountExist, "Account exist");
  } else {
    // Account does not exist so we call the callback to notify it
    linphone_account_creator_cbs_get_is_account_exist(linphone_account_creator_get_callbacks(creator))
      (creator, LinphoneRequestAccountNotExist, "Account does not exist");
  }

 // The request passed
 return LinphoneRequestOk;
}

void main(void) {
  LinphoneCoreVTable vtable = {0};
  LinphoneCore *lc = linphone_core_new(&vtable, NULL, NULL, NULL);

 // Create a new service
 LinphoneAccountCreatorService *service = linphone_account_creator_service_new();

 // Set your callback
 linphone_account_creator_service_set_is_account_exist_cb(service, my_account_creator_request_is_account_exist);

 // Do not forget to set your implementation to LinphoneCore
 linphone_core_set_account_creator_service(lc, service);

 // Create a new account creator that has your implementation of is_account_exist callback
 LinphoneAccountCreator *creator = linphone_account_creator_new(lc, "url://serveur.com");
  linphone_account_creator_set_username(creator, "user_exist");

 // Send request
 if (linphone_account_creator_is_account_exist(creator) != LinphoneRequestOk) {
    ms_message("Error with the request is_account_exist");
  }

  linphone_account_creator_unref(creator);
  linphone_core_destroy(lc);
}
Created by Erwan Croze on 2017/04/03 14:30