phonebook.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. *
  4. * OBEX Server
  5. *
  6. * Copyright (C) 2007-2010 Marcel Holtmann <marcel@holtmann.org>
  7. *
  8. *
  9. */
  10. #define EOL "\r\n"
  11. #define VCARD_LISTING_BEGIN \
  12. "<?xml version=\"1.0\"?>" EOL\
  13. "<!DOCTYPE vcard-listing SYSTEM \"vcard-listing.dtd\">" EOL\
  14. "<vCard-listing version=\"1.0\">" EOL
  15. #define VCARD_LISTING_ELEMENT "<card handle = \"%d.vcf\" name = \"%s\"/>" EOL
  16. #define VCARD_LISTING_END "</vCard-listing>"
  17. #define PB_TELECOM_FOLDER "/telecom"
  18. #define PB_CONTACTS_FOLDER "/telecom/pb"
  19. #define PB_CALENDAR_FOLDER "/telecom/cal"
  20. #define PB_NOTES_FOLDER "/telecom/nt"
  21. #define PB_CALLS_COMBINED_FOLDER "/telecom/cch"
  22. #define PB_CALLS_INCOMING_FOLDER "/telecom/ich"
  23. #define PB_CALLS_MISSED_FOLDER "/telecom/mch"
  24. #define PB_CALLS_OUTGOING_FOLDER "/telecom/och"
  25. #define PB_CALLS_SPEEDDIAL_FOLDER "/telecom/spd"
  26. #define PB_CALLS_FAVORITE_FOLDER "/telecom/fav"
  27. #define PB_LUID_FOLDER "/telecom/pb/luid"
  28. #define PB_CONTACTS "/telecom/pb.vcf"
  29. #define PB_CALLS_COMBINED "/telecom/cch.vcf"
  30. #define PB_CALLS_INCOMING "/telecom/ich.vcf"
  31. #define PB_CALLS_MISSED "/telecom/mch.vcf"
  32. #define PB_CALLS_OUTGOING "/telecom/och.vcf"
  33. #define PB_CALLS_SPEEDDIAL "/telecom/spd.vcf"
  34. #define PB_CALLS_FAVORITE "/telecom/fav.vcf"
  35. #define PB_DEVINFO "/telecom/devinfo.txt"
  36. #define PB_INFO_LOG "/telecom/pb/info.log"
  37. #define PB_CC_LOG "/telecom/pb/luid/cc.log"
  38. struct apparam_field {
  39. /* list and pull attributes */
  40. uint16_t maxlistcount;
  41. uint16_t liststartoffset;
  42. /* pull and vcard attributes */
  43. uint64_t filter;
  44. uint8_t format;
  45. /* list attributes only */
  46. uint8_t order;
  47. uint8_t searchattrib;
  48. char *searchval;
  49. };
  50. /*
  51. * Interface between the PBAP core and backends to retrieve
  52. * all contacts that match the application parameters rules.
  53. * Contacts will be returned in the vcard format.
  54. */
  55. typedef void (*phonebook_cb) (const char *buffer, size_t bufsize,
  56. int vcards, int missed, gboolean lastpart, void *user_data);
  57. /*
  58. * Interface between the PBAP core and backends to
  59. * append a new entry in the PBAP folder cache.
  60. */
  61. #define PHONEBOOK_INVALID_HANDLE 0xffffffff
  62. typedef void (*phonebook_entry_cb) (const char *id, uint32_t handle,
  63. const char *name, const char *sound,
  64. const char *tel, void *user_data);
  65. /*
  66. * After notify all entries to PBAP core, the backend
  67. * needs to notify that the operation has finished.
  68. */
  69. typedef void (*phonebook_cache_ready_cb) (void *user_data);
  70. int phonebook_init(void);
  71. void phonebook_exit(void);
  72. /*
  73. * Changes the current folder in the phonebook back-end. The PBAP core
  74. * doesn't validate or restrict the possible values for the folders,
  75. * allowing non-standard backends implementation which doesn't follow
  76. * the PBAP virtual folder architecture. Validate the folder's name
  77. * is responsibility of the back-ends.
  78. */
  79. char *phonebook_set_folder(const char *current_folder,
  80. const char *new_folder, uint8_t flags, int *err);
  81. /*
  82. * phonebook_pull should be used only to prepare pull request - prepared
  83. * request data is returned by this function. Start of fetching data from
  84. * back-end will be done only after calling phonebook_pull_read with this
  85. * returned request given as a parameter.
  86. *
  87. * phonebook_req_finalize MUST always be used to free associated resources.
  88. */
  89. void *phonebook_pull(const char *name, const struct apparam_field *params,
  90. phonebook_cb cb, void *user_data, int *err);
  91. /*
  92. * phonebook_pull_read should be used to start getting results from back-end.
  93. * The back-end can return data as one response or can return it many parts.
  94. * After obtaining one part, PBAP core need to call phonebook_pull_read with
  95. * the same request again to get more results from back-end.
  96. * The back-end MUST return only the content based on the application
  97. * parameters requested by the client.
  98. *
  99. * Returns error code or 0 in case of success
  100. */
  101. int phonebook_pull_read(void *request);
  102. /*
  103. * Function used to retrieve a contact from the backend. Only contacts
  104. * found in the cache are requested to the back-ends. The back-end MUST
  105. * return only the content based on the application parameters requested
  106. * by the client.
  107. *
  108. * Return value is a pointer to asynchronous request to phonebook back-end.
  109. * phonebook_req_finalize MUST always be used to free associated resources.
  110. */
  111. void *phonebook_get_entry(const char *folder, const char *id,
  112. const struct apparam_field *params,
  113. phonebook_cb cb, void *user_data, int *err);
  114. /*
  115. * PBAP core will keep the contacts cache per folder. SetPhoneBook or
  116. * PullvCardListing can invalidate the cache if the current folder changes.
  117. * Cache will store only the necessary information required to reply to
  118. * PullvCardListing request and verify if a given contact belongs to the
  119. * source.
  120. *
  121. * Return value is a pointer to asynchronous request to phonebook back-end.
  122. * phonebook_req_finalize MUST always be used to free associated resources.
  123. */
  124. void *phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
  125. phonebook_cache_ready_cb ready_cb, void *user_data, int *err);
  126. /*
  127. * Finalizes request to phonebook back-end and deallocates associated
  128. * resources. Operation is canceled if not completed. This function MUST
  129. * always be used after any of phonebook_pull, phonebook_get_entry, and
  130. * phonebook_create_cache invoked.
  131. *
  132. * request is a pointer to asynchronous operation returned by phonebook_pull,
  133. * phonebook_get_entry, and phonebook_create_cache.
  134. */
  135. void phonebook_req_finalize(void *request);