prop.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* prop.h -- property request/response management routines
  2. *
  3. * Author: Chris Newman
  4. * Removal of implementation-specific details by: Rob Siemborski
  5. *
  6. * This is intended to be used to create a list of properties to request,
  7. * and _then_ request values for all properties. Any change to the request
  8. * list will discard any existing values. This assumption allows a very
  9. * efficient and simple memory model. This was designed for SASL API auxiliary
  10. * property support, but would be fine for other contexts where this property
  11. * model is appropriate.
  12. *
  13. * The "struct propctx" is allocated by prop_new and is a fixed size structure.
  14. * If a prop_init() call were added, it would be reasonable to embed a "struct
  15. * propctx" in another structure. prop_new also allocates a pool of memory
  16. * (in the vbase field) which will be used for an array of "struct propval"
  17. * to list all the requested properties.
  18. *
  19. * Properties may be multi-valued.
  20. */
  21. #ifndef PROP_H
  22. #define PROP_H 1
  23. /* The following ifdef block is the standard way of creating macros
  24. * which make exporting from a DLL simpler. All files within this DLL
  25. * are compiled with the LIBSASL_EXPORTS symbol defined on the command
  26. * line. this symbol should not be defined on any project that uses
  27. * this DLL. This way any other project whose source files include
  28. * this file see LIBSASL_API functions as being imported from a DLL,
  29. * wheras this DLL sees symbols defined with this macro as being
  30. * exported. */
  31. /* Under Unix, life is simpler: we just need to mark library functions
  32. * as extern. (Technically, we don't even have to do that.) */
  33. # define LIBSASL_API extern
  34. /* Same as above, but used during a variable declaration. */
  35. # define LIBSASL_VAR extern
  36. /* the resulting structure for property values
  37. */
  38. struct propval {
  39. const char *name; /* name of property; NULL = end of list */
  40. /* same pointer used in request will be used here */
  41. const char **values; /* list of strings, values == NULL if property not
  42. * found, *values == NULL if property found with
  43. * no values */
  44. unsigned nvalues; /* total number of value strings */
  45. unsigned valsize; /* total size in characters of all value strings */
  46. };
  47. /*
  48. * private internal structure
  49. */
  50. #define PROP_DEFAULT 4 /* default number of propvals to assume */
  51. struct propctx;
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55. /* create a property context
  56. * estimate -- an estimate of the storage needed for requests & responses
  57. * 0 will use module default
  58. * returns a new property context on success and NULL on any error
  59. */
  60. LIBSASL_API struct propctx *prop_new(unsigned estimate);
  61. /* create new propctx which duplicates the contents of an existing propctx
  62. * returns SASL_OK on success
  63. * possible other return values include: SASL_NOMEM, SASL_BADPARAM
  64. */
  65. LIBSASL_API int prop_dup(struct propctx *src_ctx, struct propctx **dst_ctx);
  66. /* Add property names to request
  67. * ctx -- context from prop_new()
  68. * names -- list of property names; must persist until context freed
  69. * or requests cleared (This extends to other contexts that
  70. * are dup'ed from this one, and their children, etc)
  71. *
  72. * NOTE: may clear values from context as side-effect
  73. * returns SASL_OK on success
  74. * possible other return values include: SASL_NOMEM, SASL_BADPARAM
  75. */
  76. LIBSASL_API int prop_request(struct propctx *ctx, const char **names);
  77. /* return array of struct propval from the context
  78. * return value persists until next call to
  79. * prop_request, prop_clear or prop_dispose on context
  80. *
  81. * returns NULL on error
  82. */
  83. LIBSASL_API const struct propval *prop_get(struct propctx *ctx);
  84. /* Fill in an array of struct propval based on a list of property names
  85. * return value persists until next call to
  86. * prop_request, prop_clear or prop_dispose on context
  87. * returns number of matching properties which were found (values != NULL)
  88. * if a name requested here was never requested by a prop_request, then
  89. * the name field of the associated vals entry will be set to NULL
  90. *
  91. * The vals array MUST be atleast as long as the names array.
  92. *
  93. * returns # of matching properties on success
  94. * possible other return values include: SASL_BADPARAM
  95. */
  96. LIBSASL_API int prop_getnames(struct propctx *ctx, const char **names,
  97. struct propval *vals);
  98. /* clear values and optionally requests from property context
  99. * ctx -- property context
  100. * requests -- 0 = don't clear requests, 1 = clear requests
  101. */
  102. LIBSASL_API void prop_clear(struct propctx *ctx, int requests);
  103. /* erase the value of a property
  104. */
  105. LIBSASL_API void prop_erase(struct propctx *ctx, const char *name);
  106. /* dispose of property context
  107. * ctx -- is disposed and set to NULL; noop if ctx or *ctx is NULL
  108. */
  109. LIBSASL_API void prop_dispose(struct propctx **ctx);
  110. /****fetcher interfaces****/
  111. /* format the requested property names into a string
  112. * ctx -- context from prop_new()/prop_request()
  113. * sep -- separator between property names (unused if none requested)
  114. * seplen -- length of separator, if < 0 then strlen(sep) will be used
  115. * outbuf -- output buffer
  116. * outmax -- maximum length of output buffer including NUL terminator
  117. * outlen -- set to length of output string excluding NUL terminator
  118. * returns SASL_OK on success
  119. * returns SASL_BADPARAM or amount of additional space needed on failure
  120. */
  121. LIBSASL_API int prop_format(struct propctx *ctx, const char *sep, int seplen,
  122. char *outbuf, unsigned outmax, unsigned *outlen);
  123. /* add a property value to the context
  124. * ctx -- context from prop_new()/prop_request()
  125. * name -- name of property to which value will be added
  126. * if NULL, add to the same name as previous prop_set/setvals call
  127. * value -- a value for the property; will be copied into context
  128. * if NULL, remove existing values
  129. * vallen -- length of value, if <= 0 then strlen(value) will be used
  130. * returns SASL_OK on success
  131. * possible error return values include: SASL_BADPARAM, SASL_NOMEM
  132. */
  133. LIBSASL_API int prop_set(struct propctx *ctx, const char *name,
  134. const char *value, int vallen);
  135. /* set the values for a property
  136. * ctx -- context from prop_new()/prop_request()
  137. * name -- name of property to which value will be added
  138. * if NULL, add to the same name as previous prop_set/setvals call
  139. * values -- array of values, ending in NULL. Each value is a NUL terminated
  140. * string
  141. * returns SASL_OK on success
  142. * possible error return values include: SASL_BADPARAM, SASL_NOMEM
  143. */
  144. LIBSASL_API int prop_setvals(struct propctx *ctx, const char *name,
  145. const char **values);
  146. #ifdef __cplusplus
  147. }
  148. #endif
  149. #endif /* PROP_H */