attr.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: attr.c /main/1 1996/04/21 19:21:41 drk $ */
  24. /*
  25. * (c) Copyright 1993, 1994 Hewlett-Packard Company
  26. * (c) Copyright 1993, 1994 International Business Machines Corp.
  27. * (c) Copyright 1993, 1994 Novell, Inc.
  28. * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  29. */
  30. #include <EUSCompat.h>
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #include <sys/types.h>
  35. #include <unistd.h>
  36. #include "attr.h"
  37. #include "cmsdata.h"
  38. #include "nametbl.h"
  39. #include "free.h"
  40. #include "misc.h"
  41. #include "iso8601.h"
  42. #include "lutil.h"
  43. /*
  44. * calendar attributes defined by the library
  45. * Note: index zero is not used
  46. */
  47. char *_CSA_calendar_attribute_names[] = {
  48. NULL,
  49. "-//XAPIA/CSA/CALATTR//NONSGML Access List//EN",
  50. "-//XAPIA/CSA/CALATTR//NONSGML Calendar Name//EN",
  51. "-//XAPIA/CSA/CALATTR//NONSGML Calendar Owner//EN",
  52. "-//XAPIA/CSA/CALATTR//NONSGML Calendar Size//EN",
  53. "-//XAPIA/CSA/CALATTR//NONSGML Character Set//EN",
  54. "-//XAPIA/CSA/CALATTR//NONSGML Country//EN",
  55. "-//XAPIA/CSA/CALATTR//NONSGML Date Created//EN",
  56. "-//XAPIA/CSA/CALATTR//NONSGML Language//EN",
  57. "-//XAPIA/CSA/CALATTR//NONSGML Number Entries//EN",
  58. "-//XAPIA/CSA/CALATTR//NONSGML Product Identifier//EN",
  59. "-//XAPIA/CSA/CALATTR//NONSGML Time Zone//EN",
  60. "-//XAPIA/CSA/CALATTR//NONSGML Version//EN",
  61. "-//XAPIA/CSA/CALATTR//NONSGML Work Schedule//EN",
  62. "-//CDE_XAPIA_PRIVATE/CSA/CALATTR//NONSGML Server Version//EN",
  63. "-//CDE_XAPIA_PRIVATE/CSA/CALATTR//NONSGML Data Version//EN",
  64. "-//CDE_XAPIA_PRIVATE/CSA/CALATTR//NONSGML Calendar Delimiter//EN"
  65. };
  66. /*
  67. * entry attributes defined by the library
  68. * Note: index zero is not used
  69. */
  70. char *_CSA_entry_attribute_names[] = {
  71. NULL,
  72. "-//XAPIA/CSA/ENTRYATTR//NONSGML Attendee List//EN",
  73. "-//XAPIA/CSA/ENTRYATTR//NONSGML Audio Reminder//EN",
  74. "-//XAPIA/CSA/ENTRYATTR//NONSGML Classification//EN",
  75. "-//XAPIA/CSA/ENTRYATTR//NONSGML Date Completed//EN",
  76. "-//XAPIA/CSA/ENTRYATTR//NONSGML Date Created//EN",
  77. "-//XAPIA/CSA/ENTRYATTR//NONSGML Description//EN",
  78. "-//XAPIA/CSA/ENTRYATTR//NONSGML Due Date//EN",
  79. "-//XAPIA/CSA/ENTRYATTR//NONSGML End Date//EN",
  80. "-//XAPIA/CSA/ENTRYATTR//NONSGML Exception Dates//EN",
  81. "-//XAPIA/CSA/ENTRYATTR//NONSGML Exception Rule//EN",
  82. "-//XAPIA/CSA/ENTRYATTR//NONSGML Flashing Reminder//EN",
  83. "-//XAPIA/CSA/ENTRYATTR//NONSGML Last Update//EN",
  84. "-//XAPIA/CSA/ENTRYATTR//NONSGML Mail Reminder//EN",
  85. "-//XAPIA/CSA/ENTRYATTR//NONSGML Number Recurrences//EN",
  86. "-//XAPIA/CSA/ENTRYATTR//NONSGML Organizer//EN",
  87. "-//XAPIA/CSA/ENTRYATTR//NONSGML Popup Reminder//EN",
  88. "-//XAPIA/CSA/ENTRYATTR//NONSGML Priority//EN",
  89. "-//XAPIA/CSA/ENTRYATTR//NONSGML Recurrence Rule//EN",
  90. "-//XAPIA/CSA/ENTRYATTR//NONSGML Recurring Dates//EN",
  91. "-//XAPIA/CSA/ENTRYATTR//NONSGML Reference Identifier//EN",
  92. "-//XAPIA/CSA/ENTRYATTR//NONSGML Sequence Number//EN",
  93. "-//XAPIA/CSA/ENTRYATTR//NONSGML Sponsor//EN",
  94. "-//XAPIA/CSA/ENTRYATTR//NONSGML Start Date//EN",
  95. "-//XAPIA/CSA/ENTRYATTR//NONSGML Status//EN",
  96. "-//XAPIA/CSA/ENTRYATTR//NONSGML Subtype//EN",
  97. "-//XAPIA/CSA/ENTRYATTR//NONSGML Summary//EN",
  98. "-//XAPIA/CSA/ENTRYATTR//NONSGML Time Transparency//EN",
  99. "-//XAPIA/CSA/ENTRYATTR//NONSGML Type//EN",
  100. "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Show Time//EN",
  101. "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Type//EN",
  102. "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Times//EN",
  103. "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Interval//EN",
  104. "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Occurrence Number//EN",
  105. "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Sequence End Date//EN",
  106. "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Entry Delimiter//EN"
  107. };
  108. /*
  109. * Values for entry attribute CSA_ENTRY_ATTR_SUBTYPE
  110. */
  111. char *_CSA_entry_subtype_values[] = {
  112. "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Appointment//EN",
  113. "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Class//EN",
  114. "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Holiday//EN",
  115. "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Meeting//EN",
  116. "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Miscellaneous//EN",
  117. "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Phone Call//EN",
  118. "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Sick Day//EN",
  119. "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Special Occasion//EN",
  120. "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Travel//EN",
  121. "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Vacation//EN",
  122. };
  123. /* list of calendar attributes and value type */
  124. _DtCmAttrInfo _CSA_cal_attr_info[] =
  125. {
  126. /* first element is not used */
  127. { 0, -1, 0, _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
  128. { CSA_CAL_ATTR_ACCESS_LIST_I, CSA_VALUE_ACCESS_LIST, 1,
  129. _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
  130. { CSA_CAL_ATTR_CALENDAR_NAME_I, CSA_VALUE_STRING, 1,
  131. _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
  132. { CSA_CAL_ATTR_CALENDAR_OWNER_I, CSA_VALUE_CALENDAR_USER, 1,
  133. _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
  134. { CSA_CAL_ATTR_CALENDAR_SIZE_I, CSA_VALUE_UINT32, 4,
  135. _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
  136. { CSA_CAL_ATTR_CHARACTER_SET_I, CSA_VALUE_STRING, 4,
  137. _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
  138. { CSA_CAL_ATTR_COUNTRY_I, CSA_VALUE_STRING, 0,
  139. _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
  140. { CSA_CAL_ATTR_DATE_CREATED_I, CSA_VALUE_DATE_TIME, 4,
  141. _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
  142. { CSA_CAL_ATTR_LANGUAGE_I, CSA_VALUE_STRING, 0,
  143. _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
  144. { CSA_CAL_ATTR_NUMBER_ENTRIES_I, CSA_VALUE_UINT32, 1,
  145. _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
  146. { CSA_CAL_ATTR_PRODUCT_IDENTIFIER_I, CSA_VALUE_STRING, 1,
  147. _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
  148. { CSA_CAL_ATTR_TIME_ZONE_I, CSA_VALUE_STRING, 4,
  149. _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
  150. { CSA_CAL_ATTR_VERSION_I, CSA_VALUE_STRING, 1,
  151. _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
  152. { CSA_CAL_ATTR_WORK_SCHEDULE_I, CSA_VALUE_OPAQUE_DATA, 0,
  153. _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
  154. { CSA_X_DT_CAL_ATTR_SERVER_VERSION_I, CSA_VALUE_UINT32, 1,
  155. _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
  156. { CSA_X_DT_CAL_ATTR_DATA_VERSION_I, CSA_VALUE_UINT32, 1,
  157. _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
  158. { CSA_X_DT_CAL_ATTR_CAL_DELIMITER_I, CSA_VALUE_STRING, -1,
  159. _DtCm_old_attr_unknown, B_TRUE, B_TRUE }
  160. };
  161. /* list of entry attributes and value type */
  162. _DtCmAttrInfo _CSA_entry_attr_info[] =
  163. {
  164. /* first element is not used */
  165. { 0, -1, 0, _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
  166. { CSA_ENTRY_ATTR_ATTENDEE_LIST_I, CSA_VALUE_ATTENDEE_LIST,
  167. 0, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
  168. { CSA_ENTRY_ATTR_AUDIO_REMINDER_I, CSA_VALUE_REMINDER,
  169. 1, _DtCm_old_attr_beep_reminder, B_FALSE, B_FALSE },
  170. { CSA_ENTRY_ATTR_CLASSIFICATION_I, CSA_VALUE_UINT32,
  171. 2, _DtCm_old_attr_privacy, B_FALSE, B_FALSE },
  172. { CSA_ENTRY_ATTR_DATE_COMPLETED_I, CSA_VALUE_DATE_TIME,
  173. 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
  174. { CSA_ENTRY_ATTR_DATE_CREATED_I, CSA_VALUE_DATE_TIME,
  175. 4, _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
  176. { CSA_ENTRY_ATTR_DESCRIPTION_I, CSA_VALUE_STRING,
  177. 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
  178. { CSA_ENTRY_ATTR_DUE_DATE_I, CSA_VALUE_DATE_TIME,
  179. 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
  180. { CSA_ENTRY_ATTR_END_DATE_I, CSA_VALUE_DATE_TIME,
  181. 1, _DtCm_old_attr_duration, B_FALSE, B_FALSE },
  182. { CSA_ENTRY_ATTR_EXCEPTION_DATES_I, CSA_VALUE_DATE_TIME_LIST,
  183. 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
  184. { CSA_ENTRY_ATTR_EXCEPTION_RULE_I, CSA_VALUE_STRING,
  185. 0, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
  186. { CSA_ENTRY_ATTR_FLASHING_REMINDER_I, CSA_VALUE_REMINDER,
  187. 1, _DtCm_old_attr_flash_reminder, B_FALSE, B_FALSE },
  188. { CSA_ENTRY_ATTR_LAST_UPDATE_I, CSA_VALUE_DATE_TIME,
  189. 4, _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
  190. { CSA_ENTRY_ATTR_MAIL_REMINDER_I, CSA_VALUE_REMINDER,
  191. 1, _DtCm_old_attr_mail_reminder, B_FALSE, B_FALSE },
  192. { CSA_ENTRY_ATTR_NUMBER_RECURRENCES_I, CSA_VALUE_UINT32,
  193. 4, _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
  194. { CSA_ENTRY_ATTR_ORGANIZER_I, CSA_VALUE_CALENDAR_USER,
  195. 1, _DtCm_old_attr_author, B_TRUE, B_TRUE },
  196. { CSA_ENTRY_ATTR_POPUP_REMINDER_I, CSA_VALUE_REMINDER,
  197. 1, _DtCm_old_attr_popup_reminder, B_FALSE, B_FALSE },
  198. { CSA_ENTRY_ATTR_PRIORITY_I, CSA_VALUE_UINT32,
  199. 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
  200. { CSA_ENTRY_ATTR_RECURRENCE_RULE_I, CSA_VALUE_STRING,
  201. 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
  202. { CSA_ENTRY_ATTR_RECURRING_DATES_I, CSA_VALUE_DATE_TIME_LIST,
  203. 0, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
  204. { CSA_ENTRY_ATTR_REFERENCE_IDENTIFIER_I, CSA_VALUE_OPAQUE_DATA,
  205. 1, _DtCm_old_attr_id, B_TRUE, B_TRUE },
  206. { CSA_ENTRY_ATTR_SEQUENCE_NUMBER_I, CSA_VALUE_UINT32,
  207. 0, _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
  208. { CSA_ENTRY_ATTR_SPONSOR_I, CSA_VALUE_CALENDAR_USER,
  209. 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
  210. { CSA_ENTRY_ATTR_START_DATE_I, CSA_VALUE_DATE_TIME,
  211. 1, _DtCm_old_attr_time, B_FALSE, B_FALSE },
  212. { CSA_ENTRY_ATTR_STATUS_I, CSA_VALUE_UINT32,
  213. 2, _DtCm_old_attr_status, B_FALSE, B_FALSE },
  214. { CSA_ENTRY_ATTR_SUBTYPE_I, CSA_VALUE_STRING,
  215. 1, _DtCm_old_attr_type2, B_FALSE, B_FALSE },
  216. { CSA_ENTRY_ATTR_SUMMARY_I, CSA_VALUE_STRING,
  217. 1, _DtCm_old_attr_what, B_FALSE, B_FALSE },
  218. { CSA_ENTRY_ATTR_TIME_TRANSPARENCY_I, CSA_VALUE_SINT32,
  219. 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
  220. { CSA_ENTRY_ATTR_TYPE_I, CSA_VALUE_UINT32,
  221. 1, _DtCm_old_attr_type, B_FALSE, B_FALSE },
  222. { CSA_X_DT_ENTRY_ATTR_SHOWTIME_I, CSA_VALUE_SINT32,
  223. 2, _DtCm_old_attr_showtime, B_FALSE, B_FALSE },
  224. { CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE_I, CSA_VALUE_SINT32,
  225. 1, _DtCm_old_attr_repeat_type, B_FALSE, B_TRUE },
  226. { CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES_I, CSA_VALUE_UINT32,
  227. 1, _DtCm_old_attr_repeat_times, B_FALSE, B_TRUE },
  228. { CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL_I, CSA_VALUE_UINT32,
  229. 3, _DtCm_old_attr_repeat_nth_interval, B_FALSE, B_TRUE },
  230. { CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM_I, CSA_VALUE_SINT32,
  231. 3, _DtCm_old_attr_repeat_nth_weeknum, B_FALSE, B_TRUE },
  232. { CSA_X_DT_ENTRY_ATTR_SEQUENCE_END_DATE_I, CSA_VALUE_DATE_TIME,
  233. 3, _DtCm_old_attr_end_date, B_FALSE, B_TRUE },
  234. { CSA_X_DT_ENTRY_ATTR_ENTRY_DELIMITER_I, CSA_VALUE_STRING,
  235. -1, _DtCm_old_attr_unknown, B_TRUE, B_TRUE }
  236. };
  237. /*****************************************************************************
  238. * forward declaration of static functions used within the file
  239. *****************************************************************************/
  240. static CSA_return_code check_predefined_attrs(
  241. int fversion,
  242. uint num_attrs,
  243. cms_attribute *attrs,
  244. boolean_t checkreadonly,
  245. _DtCmNameTable *tbl,
  246. uint num_defined,
  247. _DtCmAttrInfo *our_attrs);
  248. static CSA_return_code convert_cms_user_to_csa_user(char *from,
  249. CSA_calendar_user **to);
  250. static CSA_return_code hash_entry_attrs(uint num_attrs, CSA_attribute *csaattrs,
  251. cms_attribute *cmsattrs, uint *hnum, cms_attribute **hattrs, uint *num);
  252. static CSA_return_code hash_cal_attrs(uint num_attrs, CSA_attribute *csaattrs,
  253. cms_attribute *cmsattrs, uint *hnum, cms_attribute **hattrs, uint *num);
  254. static CSA_return_code _DtCm_check_hashed_entry_attributes(
  255. int fvers,
  256. uint num_attrs,
  257. cms_attribute *attrs,
  258. CSA_flags utype);
  259. static CSA_return_code _DtCm_check_hashed_cal_attributes(
  260. int fvers,
  261. uint num_attrs,
  262. cms_attribute *attrs,
  263. char *owner,
  264. char *cname,
  265. boolean_t checkreadonly,
  266. boolean_t firsttime,
  267. boolean_t csatype);
  268. static CSA_return_code _CheckNameAtHost(char *owner, char *value);
  269. static CSA_return_code _CheckCalendarOwner(char *owner, int type, char *name);
  270. static CSA_return_code _CheckCalendarName(char *owner, char *cname,
  271. cms_attribute_value *val);
  272. /*****************************************************************************
  273. * extern functions used in the library
  274. *****************************************************************************/
  275. /*
  276. * For each calendar attribute, if it is a predefined attribute,
  277. * check that the data type is correct.
  278. * If checkreadonly is B_TRUE, also check that it's not readonly.
  279. */
  280. extern CSA_return_code
  281. _DtCm_check_cal_csa_attributes(
  282. int fvers,
  283. uint num_attrs,
  284. CSA_attribute *attrs,
  285. char *cname,
  286. boolean_t checkreadonly,
  287. boolean_t firsttime,
  288. boolean_t checkattrnum)
  289. {
  290. CSA_return_code stat;
  291. uint hnum;
  292. cms_attribute *hattrs;
  293. uint realnum;
  294. if ((stat = hash_cal_attrs(num_attrs, attrs, NULL, &hnum, &hattrs,
  295. &realnum)) != CSA_SUCCESS)
  296. return (stat);
  297. if (checkattrnum == B_TRUE && realnum == 0) {
  298. free(hattrs);
  299. return (CSA_E_INVALID_PARAMETER);
  300. }
  301. stat = _DtCm_check_hashed_cal_attributes(fvers, hnum, hattrs,
  302. NULL, cname, checkreadonly, firsttime, B_TRUE);
  303. free(hattrs);
  304. return (stat);
  305. }
  306. extern CSA_return_code
  307. _DtCm_check_cal_cms_attributes(
  308. int fvers,
  309. uint num_attrs,
  310. cms_attribute *attrs,
  311. char *owner,
  312. char *cname,
  313. boolean_t checkreadonly,
  314. boolean_t firsttime,
  315. boolean_t checkattrnum)
  316. {
  317. CSA_return_code stat;
  318. uint hnum;
  319. cms_attribute *hattrs;
  320. uint realnum;
  321. if ((stat = hash_cal_attrs(num_attrs, NULL, attrs, &hnum, &hattrs,
  322. &realnum)) != CSA_SUCCESS)
  323. return (stat);
  324. if (checkattrnum == B_TRUE && realnum == 0) {
  325. free(hattrs);
  326. return (CSA_E_INVALID_PARAMETER);
  327. }
  328. stat = _DtCm_check_hashed_cal_attributes(fvers, hnum, hattrs,
  329. owner, cname, checkreadonly, firsttime, B_FALSE);
  330. free(hattrs);
  331. return (stat);
  332. }
  333. extern CSA_return_code
  334. _DtCm_check_entry_attributes(
  335. int fvers,
  336. uint num_attrs,
  337. CSA_attribute *attrs,
  338. CSA_flags utype,
  339. boolean_t checkattrnum)
  340. {
  341. CSA_return_code stat;
  342. uint hnum;
  343. cms_attribute *hattrs;
  344. uint realnum;
  345. if ((stat = hash_entry_attrs(num_attrs, attrs, NULL, &hnum, &hattrs,
  346. &realnum)) != CSA_SUCCESS)
  347. return (stat);
  348. if (checkattrnum == B_TRUE && realnum == 0) {
  349. free(hattrs);
  350. return (CSA_E_INVALID_PARAMETER);
  351. }
  352. stat = _DtCm_check_hashed_entry_attributes(fvers, hnum, hattrs,
  353. utype);
  354. free(hattrs);
  355. return (stat);
  356. }
  357. extern CSA_return_code
  358. _DtCm_check_entry_cms_attributes(
  359. int fvers,
  360. uint num_attrs,
  361. cms_attribute *attrs,
  362. CSA_flags utype,
  363. boolean_t checkattrnum)
  364. {
  365. CSA_return_code stat;
  366. uint hnum;
  367. cms_attribute *hattrs;
  368. uint realnum;
  369. if ((stat = hash_entry_attrs(num_attrs, NULL, attrs, &hnum, &hattrs,
  370. &realnum)) != CSA_SUCCESS)
  371. return (stat);
  372. if (checkattrnum == B_TRUE && realnum == 0) {
  373. free(hattrs);
  374. return (CSA_E_INVALID_PARAMETER);
  375. }
  376. stat = _DtCm_check_hashed_entry_attributes(fvers, hnum, hattrs,
  377. utype);
  378. free(hattrs);
  379. return (stat);
  380. }
  381. /*
  382. * copy attributes
  383. * attributes with a name but NULL value is allowed
  384. * attributes with null names are ignored
  385. * validity of attributes should be checked before calling this routine
  386. *
  387. * Note: the first entry is not used
  388. */
  389. extern CSA_return_code
  390. _DtCm_copy_cms_attributes(
  391. uint srcsize,
  392. cms_attribute *srcattrs,
  393. uint *dstsize,
  394. cms_attribute **dstattrs)
  395. {
  396. int i, j;
  397. CSA_return_code stat = CSA_SUCCESS;
  398. cms_attribute *attrs;
  399. if (dstsize == NULL || dstattrs == NULL)
  400. return (CSA_E_INVALID_PARAMETER);
  401. *dstsize = 0;
  402. *dstattrs = NULL;
  403. if (srcsize == 0)
  404. return (CSA_SUCCESS);
  405. if ((attrs = calloc(1, sizeof(cms_attribute) * (srcsize + 1))) == NULL)
  406. return (CSA_E_INSUFFICIENT_MEMORY);
  407. /* firstr element is not used */
  408. for (i = 1, j = 1; i <= srcsize; i++) {
  409. if (srcattrs[i].name.name != NULL) {
  410. if ((stat = _DtCm_copy_cms_attribute(&attrs[j],
  411. &srcattrs[i], B_TRUE)) != CSA_SUCCESS)
  412. break;
  413. else
  414. j++;
  415. }
  416. }
  417. if (stat != CSA_SUCCESS && j > 1) {
  418. _DtCm_free_cms_attributes(j, attrs);
  419. free(attrs);
  420. } else {
  421. *dstsize = j - 1;
  422. *dstattrs = attrs;
  423. }
  424. return(stat);
  425. }
  426. /*
  427. * Frees the name and value field of the array, but not
  428. * array itself.
  429. * note: element 0 is not used
  430. */
  431. extern void
  432. _DtCm_free_cms_attributes(uint size, cms_attribute *attrs)
  433. {
  434. int i;
  435. for (i = 0; i < size; i++) {
  436. if (attrs[i].name.name) {
  437. free(attrs[i].name.name);
  438. attrs[i].name.name = NULL;
  439. if (attrs[i].value) {
  440. _DtCm_free_cms_attribute_value(attrs[i].value);
  441. attrs[i].value = NULL;
  442. }
  443. }
  444. }
  445. }
  446. /*
  447. * Frees the name and value field of the array, but not
  448. * array itself.
  449. */
  450. extern void
  451. _DtCm_free_attributes(uint size, CSA_attribute * attrs)
  452. {
  453. int i;
  454. for (i = 0; i < size; i++) {
  455. if (attrs[i].name) {
  456. free(attrs[i].name);
  457. attrs[i].name = NULL;
  458. if (attrs[i].value) {
  459. _DtCm_free_attribute_value(attrs[i].value);
  460. attrs[i].value = NULL;
  461. }
  462. }
  463. }
  464. }
  465. /*
  466. * Free the value part of the cms_attribute structure.
  467. * note: element 0 is not used
  468. */
  469. extern void
  470. _DtCm_free_cms_attribute_values(uint size, cms_attribute *attrs)
  471. {
  472. int i;
  473. for (i = 1; i <= size; i++) {
  474. if (attrs[i].value) {
  475. _DtCm_free_cms_attribute_value(attrs[i].value);
  476. attrs[i].value = NULL;
  477. }
  478. }
  479. }
  480. /*
  481. * Free the value part of the the attribute structure.
  482. */
  483. extern void
  484. _DtCm_free_attribute_values(uint size, CSA_attribute * attrs)
  485. {
  486. int i;
  487. for (i = 0; i < size; i++) {
  488. if (attrs[i].value) {
  489. _DtCm_free_attribute_value(attrs[i].value);
  490. attrs[i].value = NULL;
  491. }
  492. }
  493. }
  494. extern char *
  495. _DtCm_old_reminder_name_to_name(char *oldname)
  496. {
  497. if (strcmp(oldname, _DtCM_OLD_ATTR_BEEP_REMINDER) == 0)
  498. return (CSA_ENTRY_ATTR_AUDIO_REMINDER);
  499. else if (strcmp(oldname, _DtCM_OLD_ATTR_FLASH_REMINDER) == 0)
  500. return (CSA_ENTRY_ATTR_FLASHING_REMINDER);
  501. else if (strcmp(oldname, _DtCM_OLD_ATTR_MAIL_REMINDER) == 0)
  502. return (CSA_ENTRY_ATTR_MAIL_REMINDER);
  503. else if (strcmp(oldname, _DtCM_OLD_ATTR_POPUP_REMINDER) == 0)
  504. return (CSA_ENTRY_ATTR_POPUP_REMINDER);
  505. else
  506. return (oldname);
  507. }
  508. extern int
  509. _DtCm_old_reminder_name_to_index(char *oldname)
  510. {
  511. char *name;
  512. name = _DtCm_old_reminder_name_to_name(oldname);
  513. return (_DtCm_get_index_from_table(_DtCm_entry_name_tbl, name));
  514. }
  515. /*
  516. * Given an attribute name, return the corresponding
  517. * attribute number that's supported by old backends (v4 and before).
  518. */
  519. extern CSA_return_code
  520. _DtCm_get_old_attr_by_name(char *name, _DtCm_old_attrs *attr)
  521. {
  522. int index;
  523. index = _DtCm_get_index_from_table(_DtCm_entry_name_tbl, name);
  524. if (index > 0 && index <= _DtCM_DEFINED_ENTRY_ATTR_SIZE) {
  525. if (_CSA_entry_attr_info[index].oldattr
  526. != _DtCm_old_attr_unknown) {
  527. *attr = _CSA_entry_attr_info[index].oldattr;
  528. return (CSA_SUCCESS);
  529. } else
  530. return (CSA_E_UNSUPPORTED_ATTRIBUTE);
  531. } else
  532. return (CSA_E_INVALID_ATTRIBUTE);
  533. }
  534. /*
  535. * Given an attribute index, return the corresponding
  536. * attribute number that's supported by old backends (v4 and before).
  537. */
  538. extern CSA_return_code
  539. _DtCm_get_old_attr_by_index(int index, _DtCm_old_attrs *attr)
  540. {
  541. if (index <= _DtCM_DEFINED_ENTRY_ATTR_SIZE) {
  542. if (_CSA_entry_attr_info[index].oldattr
  543. != _DtCm_old_attr_unknown) {
  544. *attr = _CSA_entry_attr_info[index].oldattr;
  545. return (CSA_SUCCESS);
  546. } else
  547. return (CSA_E_UNSUPPORTED_ATTRIBUTE);
  548. } else
  549. return (CSA_E_INVALID_ATTRIBUTE);
  550. }
  551. /*
  552. * copy attribute
  553. * the attribute structure should contain valid value
  554. * a NULL attribute value is valid
  555. */
  556. extern CSA_return_code
  557. _DtCm_copy_cms_attribute(
  558. cms_attribute *to,
  559. cms_attribute *from,
  560. boolean_t copyname)
  561. {
  562. CSA_return_code stat = CSA_SUCCESS;
  563. char *name;
  564. if (to == NULL)
  565. return (CSA_E_INVALID_PARAMETER);
  566. /* copy the attribute name */
  567. if (copyname) {
  568. if ((name = strdup(from->name.name)) == NULL)
  569. return(CSA_E_INSUFFICIENT_MEMORY);
  570. }
  571. if ((stat = _DtCm_copy_cms_attr_val(from->value, &to->value))
  572. == CSA_SUCCESS) {
  573. if (copyname) {
  574. to->name.name = name;
  575. to->name.num = from->name.num;
  576. }
  577. } else if (copyname)
  578. free (name);
  579. return(stat);
  580. }
  581. extern CSA_return_code
  582. _DtCm_copy_cms_attr_val(cms_attribute_value *from, cms_attribute_value **to)
  583. {
  584. CSA_return_code stat = CSA_SUCCESS;
  585. cms_attribute_value *val;
  586. if (to == NULL)
  587. return (CSA_E_INVALID_PARAMETER);
  588. /* copy the attribute value */
  589. if (from == NULL)
  590. val = NULL;
  591. else {
  592. if ((val = (cms_attribute_value *)calloc(1,
  593. sizeof(cms_attribute_value))) == NULL)
  594. return (CSA_E_INSUFFICIENT_MEMORY);
  595. switch (from->type) {
  596. case CSA_VALUE_BOOLEAN:
  597. case CSA_VALUE_ENUMERATED:
  598. case CSA_VALUE_FLAGS:
  599. case CSA_VALUE_UINT32:
  600. case CSA_VALUE_SINT32:
  601. val->item.uint32_value = from->item.uint32_value;
  602. break;
  603. case CSA_VALUE_STRING:
  604. case CSA_VALUE_DATE_TIME:
  605. case CSA_VALUE_DATE_TIME_RANGE:
  606. case CSA_VALUE_TIME_DURATION:
  607. case CSA_VALUE_CALENDAR_USER:
  608. if (from->item.string_value)
  609. val->item.string_value =
  610. strdup(from->item.string_value);
  611. else
  612. val->item.string_value = calloc(1, 1);
  613. if (val->item.string_value == NULL)
  614. stat = CSA_E_INSUFFICIENT_MEMORY;
  615. break;
  616. case CSA_VALUE_REMINDER:
  617. if (from->item.reminder_value == NULL)
  618. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  619. else
  620. stat = _DtCm_copy_reminder(
  621. from->item.reminder_value,
  622. &val->item.reminder_value);
  623. break;
  624. case CSA_VALUE_ATTENDEE_LIST:
  625. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  626. break;
  627. case CSA_VALUE_ACCESS_LIST:
  628. if (from->item.access_list_value &&
  629. (val->item.access_list_value =
  630. _DtCm_copy_cms_access_list(
  631. from->item.access_list_value)) == NULL) {
  632. stat = CSA_E_INSUFFICIENT_MEMORY;
  633. }
  634. break;
  635. case CSA_VALUE_DATE_TIME_LIST:
  636. if (from->item.date_time_list_value &&
  637. (val->item.date_time_list_value =
  638. _DtCm_copy_date_time_list(
  639. from->item.date_time_list_value)) == NULL) {
  640. stat = CSA_E_INSUFFICIENT_MEMORY;
  641. }
  642. break;
  643. case CSA_VALUE_OPAQUE_DATA:
  644. if (from->item.opaque_data_value) {
  645. stat = _DtCm_copy_opaque_data(
  646. from->item.opaque_data_value,
  647. &val->item.opaque_data_value);
  648. }
  649. break;
  650. default:
  651. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  652. break;
  653. }
  654. if (stat != CSA_SUCCESS)
  655. free(val);
  656. else
  657. val->type = from->type;
  658. }
  659. if (stat == CSA_SUCCESS) {
  660. *to = val;
  661. }
  662. return(stat);
  663. }
  664. /*
  665. * copy the attribute name, and convert the attribute value
  666. */
  667. extern CSA_return_code
  668. _DtCm_cms2csa_attribute(cms_attribute from, CSA_attribute *to)
  669. {
  670. CSA_return_code stat;
  671. char *name;
  672. CSA_attribute_value *val;
  673. if ((name = strdup(from.name.name)) == NULL)
  674. return (CSA_E_INSUFFICIENT_MEMORY);
  675. if ((stat = _DtCm_cms2csa_attrval(from.value, &val)) == CSA_SUCCESS) {
  676. to->name = name;
  677. to->value = val;
  678. } else
  679. free(name);
  680. return (stat);
  681. }
  682. extern CSA_return_code
  683. _DtCm_cms2csa_attrval(cms_attribute_value *from, CSA_attribute_value **to)
  684. {
  685. CSA_return_code stat = CSA_SUCCESS;
  686. CSA_attribute_value *val;
  687. if (to == NULL)
  688. return (CSA_E_INVALID_PARAMETER);
  689. /* copy the attribute value */
  690. if (from == NULL)
  691. val = NULL;
  692. else {
  693. if ((val = (CSA_attribute_value *)calloc(1,
  694. sizeof(CSA_attribute_value))) == NULL)
  695. return (CSA_E_INSUFFICIENT_MEMORY);
  696. switch (from->type) {
  697. case CSA_VALUE_BOOLEAN:
  698. case CSA_VALUE_ENUMERATED:
  699. case CSA_VALUE_FLAGS:
  700. case CSA_VALUE_UINT32:
  701. case CSA_VALUE_SINT32:
  702. val->item.uint32_value = from->item.uint32_value;
  703. break;
  704. case CSA_VALUE_STRING:
  705. case CSA_VALUE_DATE_TIME:
  706. case CSA_VALUE_DATE_TIME_RANGE:
  707. case CSA_VALUE_TIME_DURATION:
  708. if (from->item.string_value)
  709. val->item.string_value =
  710. strdup(from->item.string_value);
  711. else
  712. val->item.string_value = calloc(1, 1);
  713. if (val->item.string_value == NULL)
  714. stat = CSA_E_INSUFFICIENT_MEMORY;
  715. break;
  716. case CSA_VALUE_REMINDER:
  717. if (from->item.reminder_value == NULL)
  718. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  719. else
  720. stat = _DtCm_copy_reminder(
  721. from->item.reminder_value,
  722. &val->item.reminder_value);
  723. break;
  724. case CSA_VALUE_CALENDAR_USER:
  725. if (from->item.calendar_user_value == NULL)
  726. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  727. else
  728. stat = convert_cms_user_to_csa_user(
  729. from->item.calendar_user_value,
  730. &val->item.calendar_user_value);
  731. break;
  732. case CSA_VALUE_ACCESS_LIST:
  733. stat = _DtCm_cms2csa_access_list(
  734. from->item.access_list_value,
  735. &val->item.access_list_value);
  736. break;
  737. case CSA_VALUE_ATTENDEE_LIST:
  738. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  739. break;
  740. case CSA_VALUE_DATE_TIME_LIST:
  741. if (from->item.date_time_list_value &&
  742. (val->item.date_time_list_value =
  743. _DtCm_copy_date_time_list(
  744. from->item.date_time_list_value)) == NULL) {
  745. stat = CSA_E_INSUFFICIENT_MEMORY;
  746. }
  747. break;
  748. case CSA_VALUE_OPAQUE_DATA:
  749. if (from->item.opaque_data_value) {
  750. stat = _DtCm_copy_opaque_data(
  751. from->item.opaque_data_value,
  752. &val->item.opaque_data_value);
  753. } else
  754. val->item.opaque_data_value = NULL;
  755. break;
  756. default:
  757. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  758. break;
  759. }
  760. if (stat != CSA_SUCCESS)
  761. free(val);
  762. else
  763. val->type = from->type;
  764. }
  765. if (stat == CSA_SUCCESS) {
  766. *to = val;
  767. }
  768. return(stat);
  769. }
  770. extern void
  771. _DtCm_free_cms_attribute_value(cms_attribute_value *val)
  772. {
  773. if (val == NULL)
  774. return;
  775. switch (val->type) {
  776. case CSA_VALUE_STRING:
  777. case CSA_VALUE_DATE_TIME:
  778. case CSA_VALUE_DATE_TIME_RANGE:
  779. case CSA_VALUE_TIME_DURATION:
  780. case CSA_VALUE_CALENDAR_USER:
  781. if (val->item.string_value)
  782. free(val->item.string_value);
  783. break;
  784. case CSA_VALUE_REMINDER:
  785. if (val->item.reminder_value)
  786. _DtCm_free_reminder(val->item.reminder_value);
  787. break;
  788. case CSA_VALUE_ACCESS_LIST:
  789. if (val->item.access_list_value)
  790. _DtCm_free_cms_access_entry(val->item.access_list_value);
  791. break;
  792. case CSA_VALUE_DATE_TIME_LIST:
  793. if (val->item.date_time_list_value)
  794. _DtCm_free_date_time_list(
  795. val->item.date_time_list_value);
  796. break;
  797. case CSA_VALUE_OPAQUE_DATA:
  798. if (val->item.opaque_data_value) {
  799. _DtCm_free_opaque_data(val->item.opaque_data_value);
  800. }
  801. break;
  802. }
  803. free(val);
  804. }
  805. extern void
  806. _DtCm_free_attribute_value(CSA_attribute_value *val)
  807. {
  808. if (val == NULL)
  809. return;
  810. switch (val->type) {
  811. case CSA_VALUE_STRING:
  812. case CSA_VALUE_DATE_TIME:
  813. case CSA_VALUE_DATE_TIME_RANGE:
  814. case CSA_VALUE_TIME_DURATION:
  815. if (val->item.string_value)
  816. free(val->item.string_value);
  817. break;
  818. case CSA_VALUE_REMINDER:
  819. if (val->item.reminder_value)
  820. _DtCm_free_reminder(val->item.reminder_value);
  821. break;
  822. case CSA_VALUE_ACCESS_LIST:
  823. if (val->item.access_list_value)
  824. _DtCm_free_csa_access_list(val->item.access_list_value);
  825. break;
  826. case CSA_VALUE_CALENDAR_USER:
  827. if (val->item.calendar_user_value) {
  828. if (val->item.calendar_user_value->user_name)
  829. free(val->item.calendar_user_value->user_name);
  830. if (val->item.calendar_user_value->calendar_address)
  831. free(val->item.calendar_user_value->user_name);
  832. free(val->item.calendar_user_value);
  833. }
  834. break;
  835. case CSA_VALUE_DATE_TIME_LIST:
  836. if (val->item.date_time_list_value)
  837. _DtCm_free_date_time_list(
  838. val->item.date_time_list_value);
  839. break;
  840. case CSA_VALUE_OPAQUE_DATA:
  841. if (val->item.opaque_data_value) {
  842. _DtCm_free_opaque_data(val->item.opaque_data_value);
  843. }
  844. break;
  845. }
  846. free(val);
  847. }
  848. extern CSA_return_code
  849. _DtCm_set_uint32_attrval(uint numval, cms_attribute_value **attrval)
  850. {
  851. cms_attribute_value *val;
  852. if ((val = (cms_attribute_value *)malloc(sizeof(cms_attribute_value)))
  853. == NULL) {
  854. return (CSA_E_INSUFFICIENT_MEMORY);
  855. }
  856. val->type = CSA_VALUE_UINT32;
  857. val->item.uint32_value = numval;
  858. *attrval = val;
  859. return (CSA_SUCCESS);
  860. }
  861. extern CSA_return_code
  862. _DtCm_set_sint32_attrval(int numval, cms_attribute_value **attrval)
  863. {
  864. cms_attribute_value *val;
  865. if ((val = (cms_attribute_value *)malloc(sizeof(cms_attribute_value)))
  866. == NULL) {
  867. return (CSA_E_INSUFFICIENT_MEMORY);
  868. }
  869. val->type = CSA_VALUE_SINT32;
  870. val->item.sint32_value = numval;
  871. *attrval = val;
  872. return (CSA_SUCCESS);
  873. }
  874. extern CSA_return_code
  875. _DtCm_set_string_attrval(
  876. char *strval,
  877. cms_attribute_value **attrval,
  878. CSA_enum type)
  879. {
  880. cms_attribute_value *val;
  881. if (type != CSA_VALUE_STRING && type != CSA_VALUE_DATE_TIME &&
  882. type != CSA_VALUE_DATE_TIME_RANGE &&
  883. type != CSA_VALUE_TIME_DURATION && type != CSA_VALUE_CALENDAR_USER)
  884. return (CSA_E_INVALID_PARAMETER);
  885. if ((val = (cms_attribute_value *)malloc(sizeof(cms_attribute_value)))
  886. == NULL) {
  887. return (CSA_E_INSUFFICIENT_MEMORY);
  888. }
  889. val->type = type;
  890. if (strval == NULL) {
  891. val->item.string_value = NULL;
  892. } else if ((val->item.string_value = strdup(strval)) == NULL) {
  893. free(val);
  894. return (CSA_E_INSUFFICIENT_MEMORY);
  895. }
  896. *attrval = val;
  897. return (CSA_SUCCESS);
  898. }
  899. extern CSA_return_code
  900. _DtCm_set_user_attrval(
  901. char *user,
  902. cms_attribute_value **attrval)
  903. {
  904. cms_attribute_value *val;
  905. if (user == NULL) {
  906. *attrval = NULL;
  907. return (CSA_SUCCESS);
  908. }
  909. if ((val = (cms_attribute_value *)malloc(sizeof(cms_attribute_value)))
  910. == NULL) {
  911. return (CSA_E_INSUFFICIENT_MEMORY);
  912. }
  913. val->type = CSA_VALUE_CALENDAR_USER;
  914. if ((val->item.calendar_user_value = strdup(user)) == NULL) {
  915. free(val);
  916. return (CSA_E_INSUFFICIENT_MEMORY);
  917. }
  918. *attrval = val;
  919. return (CSA_SUCCESS);
  920. }
  921. extern CSA_return_code
  922. _DtCm_set_reminder_attrval(CSA_reminder *remval, cms_attribute_value **attrval)
  923. {
  924. cms_attribute_value *val;
  925. CSA_return_code stat;
  926. if (remval == NULL)
  927. return (CSA_E_INVALID_ATTRIBUTE_VALUE);
  928. if ((val = (cms_attribute_value *)malloc(sizeof(cms_attribute_value)))
  929. == NULL) {
  930. return (CSA_E_INSUFFICIENT_MEMORY);
  931. }
  932. val->type = CSA_VALUE_REMINDER;
  933. if ((stat = _DtCm_copy_reminder(remval, &val->item.reminder_value))
  934. != CSA_SUCCESS) {
  935. free(val);
  936. return (stat);
  937. } else {
  938. *attrval = val;
  939. return (CSA_SUCCESS);
  940. }
  941. }
  942. extern CSA_return_code
  943. _DtCm_set_csa_access_attrval(
  944. cms_access_entry *aval,
  945. CSA_attribute_value **attrval)
  946. {
  947. CSA_attribute_value *val;
  948. CSA_return_code stat = CSA_SUCCESS;
  949. if ((val = (CSA_attribute_value *)malloc(sizeof(CSA_attribute_value)))
  950. == NULL) {
  951. return (CSA_E_INSUFFICIENT_MEMORY);
  952. }
  953. val->type = CSA_VALUE_ACCESS_LIST;
  954. if (aval == NULL) {
  955. val->item.access_list_value = NULL;
  956. } else {
  957. stat = _DtCm_cms2csa_access_list(aval,
  958. &val->item.access_list_value);
  959. }
  960. if (stat == CSA_SUCCESS)
  961. *attrval = val;
  962. else
  963. free(val);
  964. return (stat);
  965. }
  966. extern CSA_return_code
  967. _DtCm_set_opaque_attrval(CSA_opaque_data *data, cms_attribute_value **attrval)
  968. {
  969. CSA_return_code stat;
  970. cms_attribute_value *val;
  971. if (data == NULL)
  972. return (CSA_E_INVALID_ATTRIBUTE_VALUE);
  973. if ((val = (cms_attribute_value *)malloc(sizeof(cms_attribute_value)))
  974. == NULL) {
  975. return (CSA_E_INSUFFICIENT_MEMORY);
  976. }
  977. val->type = CSA_VALUE_OPAQUE_DATA;
  978. if ((stat = _DtCm_copy_opaque_data(data, &val->item.opaque_data_value))
  979. != CSA_SUCCESS) {
  980. free(val);
  981. return (stat);
  982. } else {
  983. *attrval = val;
  984. return (CSA_SUCCESS);
  985. }
  986. }
  987. extern CSA_return_code
  988. _DtCm_set_csa_uint32_attrval(uint numval, CSA_attribute_value **attrval)
  989. {
  990. CSA_attribute_value *val;
  991. if ((val = (CSA_attribute_value *)malloc(sizeof(CSA_attribute_value)))
  992. == NULL) {
  993. return (CSA_E_INSUFFICIENT_MEMORY);
  994. }
  995. val->type = CSA_VALUE_UINT32;
  996. val->item.uint32_value = numval;
  997. *attrval = val;
  998. return (CSA_SUCCESS);
  999. }
  1000. extern CSA_return_code
  1001. _DtCm_set_csa_string_attrval(
  1002. char *strval,
  1003. CSA_attribute_value **attrval,
  1004. CSA_enum type)
  1005. {
  1006. CSA_attribute_value *val;
  1007. if (type != CSA_VALUE_STRING && type != CSA_VALUE_DATE_TIME &&
  1008. type != CSA_VALUE_DATE_TIME_RANGE &&
  1009. type != CSA_VALUE_TIME_DURATION && type != CSA_VALUE_CALENDAR_USER)
  1010. return (CSA_E_INVALID_PARAMETER);
  1011. if ((val = (CSA_attribute_value *)malloc(sizeof(CSA_attribute_value)))
  1012. == NULL) {
  1013. return (CSA_E_INSUFFICIENT_MEMORY);
  1014. }
  1015. val->type = type;
  1016. if (strval == NULL) {
  1017. val->item.string_value = NULL;
  1018. } else if ((val->item.string_value = strdup(strval)) == NULL) {
  1019. free(val);
  1020. return (CSA_E_INSUFFICIENT_MEMORY);
  1021. }
  1022. *attrval = val;
  1023. return (CSA_SUCCESS);
  1024. }
  1025. extern void
  1026. _DtCm_free_csa_access_list(CSA_access_list alist)
  1027. {
  1028. CSA_access_list nptr;
  1029. while (alist != NULL) {
  1030. nptr = alist->next;
  1031. if (alist->user) {
  1032. if (alist->user->user_name) {
  1033. free(alist->user->user_name);
  1034. }
  1035. if (alist->user->calendar_address) {
  1036. free(alist->user->calendar_address);
  1037. }
  1038. free(alist->user);
  1039. }
  1040. free(alist);
  1041. alist = nptr;
  1042. }
  1043. }
  1044. extern void
  1045. _DtCm_free_date_time_list(CSA_date_time_list list)
  1046. {
  1047. CSA_date_time_entry *nptr;
  1048. while (list != NULL) {
  1049. nptr = list->next;
  1050. if (list->date_time) {
  1051. free(list->date_time);
  1052. }
  1053. free(list);
  1054. list = nptr;
  1055. }
  1056. }
  1057. extern void
  1058. _DtCm_free_cms_access_entry(cms_access_entry *list)
  1059. {
  1060. cms_access_entry *nptr;
  1061. while (list != NULL) {
  1062. nptr = list->next;
  1063. if (list->user) {
  1064. free(list->user);
  1065. }
  1066. free(list);
  1067. list = nptr;
  1068. }
  1069. }
  1070. extern cms_access_entry *
  1071. _DtCm_copy_cms_access_list(cms_access_entry *alist)
  1072. {
  1073. cms_access_entry *l, *head, *prev;
  1074. boolean_t cleanup = B_FALSE;
  1075. prev = head = NULL;
  1076. while (alist != NULL) {
  1077. if ((l = (cms_access_entry *)calloc(1, sizeof(cms_access_entry)))
  1078. == NULL) {
  1079. cleanup = B_TRUE;
  1080. break;
  1081. }
  1082. if ((l->user = strdup(alist->user)) == NULL) {
  1083. free(l);
  1084. cleanup = B_TRUE;
  1085. break;
  1086. }
  1087. l->rights = alist->rights;
  1088. l->next = NULL;
  1089. if (head == NULL)
  1090. head = l;
  1091. else
  1092. prev->next = l;
  1093. prev = l;
  1094. alist = alist->next;
  1095. }
  1096. if (cleanup == B_TRUE) {
  1097. _DtCm_free_cms_access_entry(head);
  1098. head = NULL;
  1099. }
  1100. return(head);
  1101. }
  1102. extern CSA_return_code
  1103. _DtCm_cms2csa_access_list(
  1104. cms_access_entry *cmslist,
  1105. CSA_access_rights **csalist)
  1106. {
  1107. CSA_return_code stat = CSA_SUCCESS;
  1108. CSA_access_rights *to, *head, *prev;
  1109. head = prev = NULL;
  1110. while (cmslist != NULL) {
  1111. if ((to = (CSA_access_rights *)calloc(1,
  1112. sizeof(CSA_access_rights))) == NULL) {
  1113. stat = CSA_E_INSUFFICIENT_MEMORY;
  1114. break;
  1115. }
  1116. if ((to->user = (CSA_calendar_user *)calloc(1,
  1117. sizeof(CSA_calendar_user))) == NULL) {
  1118. free(to);
  1119. stat = CSA_E_INSUFFICIENT_MEMORY;
  1120. break;
  1121. }
  1122. if ((to->user->user_name = strdup(cmslist->user)) == NULL) {
  1123. free(to->user);
  1124. free(to);
  1125. stat = CSA_E_INSUFFICIENT_MEMORY;
  1126. break;
  1127. }
  1128. to->rights = cmslist->rights;
  1129. to->next = NULL;
  1130. if (head == NULL)
  1131. head = to;
  1132. else
  1133. prev->next = to;
  1134. prev = to;
  1135. cmslist = cmslist->next;
  1136. }
  1137. if (stat != CSA_SUCCESS) {
  1138. _DtCm_free_csa_access_list(head);
  1139. head = NULL;
  1140. }
  1141. *csalist = head;
  1142. return (stat);
  1143. }
  1144. extern CSA_return_code
  1145. _DtCm_csa2cms_access_list(
  1146. CSA_access_rights *csalist,
  1147. cms_access_entry **cmslist)
  1148. {
  1149. CSA_return_code stat = CSA_SUCCESS;
  1150. cms_access_entry *to, *head, *prev;
  1151. head = prev = NULL;
  1152. while (csalist != NULL) {
  1153. if ((to = (cms_access_entry *)calloc(1,
  1154. sizeof(cms_access_entry))) == NULL) {
  1155. stat = CSA_E_INSUFFICIENT_MEMORY;
  1156. break;
  1157. }
  1158. if (csalist->user->user_name) {
  1159. if ((to->user = strdup(csalist->user->user_name))
  1160. == NULL) {
  1161. stat = CSA_E_INSUFFICIENT_MEMORY;
  1162. free(to);
  1163. break;
  1164. }
  1165. } else {
  1166. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  1167. free(to);
  1168. break;
  1169. }
  1170. to->rights = csalist->rights;
  1171. to->next = NULL;
  1172. if (head == NULL)
  1173. head = to;
  1174. else
  1175. prev->next = to;
  1176. prev = to;
  1177. csalist = csalist->next;
  1178. }
  1179. if (stat != CSA_SUCCESS) {
  1180. _DtCm_free_cms_access_entry(head);
  1181. head = NULL;
  1182. }
  1183. *cmslist = head;
  1184. return (stat);
  1185. }
  1186. extern CSA_date_time_list
  1187. _DtCm_copy_date_time_list(CSA_date_time_list dlist)
  1188. {
  1189. CSA_date_time_entry *l, *head, *prev;
  1190. boolean_t cleanup = B_FALSE;
  1191. prev = head = NULL;
  1192. while (dlist != NULL) {
  1193. if ((l = (CSA_date_time_entry *)calloc(1,
  1194. sizeof(CSA_date_time_entry))) == NULL) {
  1195. cleanup = B_TRUE;
  1196. break;
  1197. }
  1198. if ((l->date_time = strdup(dlist->date_time)) == NULL) {
  1199. free(l);
  1200. cleanup = B_TRUE;
  1201. break;
  1202. }
  1203. l->next = NULL;
  1204. if (head == NULL)
  1205. head = l;
  1206. else
  1207. prev->next = l;
  1208. prev = l;
  1209. dlist = dlist->next;
  1210. }
  1211. if (cleanup == B_TRUE) {
  1212. _DtCm_free_date_time_list(head);
  1213. head = NULL;
  1214. }
  1215. return(head);
  1216. }
  1217. extern CSA_return_code
  1218. _DtCm_copy_reminder(CSA_reminder *from, CSA_reminder **to)
  1219. {
  1220. CSA_reminder *newval;
  1221. if ((newval = (CSA_reminder *)calloc(1, sizeof(CSA_reminder))) == NULL)
  1222. return (CSA_E_INSUFFICIENT_MEMORY);
  1223. if (from->lead_time) {
  1224. if ((newval->lead_time = strdup(from->lead_time)) == NULL) {
  1225. free(newval);
  1226. return (CSA_E_INSUFFICIENT_MEMORY);
  1227. }
  1228. } else {
  1229. free(newval);
  1230. return (CSA_E_INVALID_ATTRIBUTE_VALUE);
  1231. }
  1232. if (from->snooze_time)
  1233. newval->snooze_time = strdup(from->snooze_time);
  1234. else
  1235. newval->snooze_time = calloc(1, 1);
  1236. if (newval->snooze_time == NULL) {
  1237. _DtCm_free_reminder(newval);
  1238. return (CSA_E_INSUFFICIENT_MEMORY);
  1239. }
  1240. newval->repeat_count = from->repeat_count;
  1241. if (from->reminder_data.size > 0) {
  1242. newval->reminder_data.size = from->reminder_data.size;
  1243. if ((newval->reminder_data.data = malloc(
  1244. newval->reminder_data.size)) == NULL) {
  1245. _DtCm_free_reminder(newval);
  1246. return (CSA_E_INSUFFICIENT_MEMORY);
  1247. }
  1248. memcpy(newval->reminder_data.data, from->reminder_data.data,
  1249. from->reminder_data.size);
  1250. }
  1251. *to = newval;
  1252. return (CSA_SUCCESS);
  1253. }
  1254. extern void
  1255. _DtCm_free_reminder(CSA_reminder *val)
  1256. {
  1257. if (val == NULL) return;
  1258. if (val->lead_time)
  1259. free(val->lead_time);
  1260. if (val->snooze_time)
  1261. free(val->snooze_time);
  1262. if (val->reminder_data.size > 0)
  1263. free(val->reminder_data.data);
  1264. free(val);
  1265. }
  1266. extern CSA_return_code
  1267. _DtCm_copy_opaque_data(CSA_opaque_data *from, CSA_opaque_data **to)
  1268. {
  1269. CSA_opaque_data *val;
  1270. if ((val = (CSA_opaque_data *)calloc(1, sizeof(CSA_opaque_data)))
  1271. == NULL) {
  1272. return (CSA_E_INSUFFICIENT_MEMORY);
  1273. }
  1274. if (from->size > 0) {
  1275. val->size = from->size;
  1276. if ((val->data = malloc(from->size)) == NULL) {
  1277. free(val);
  1278. return (CSA_E_INSUFFICIENT_MEMORY);
  1279. }
  1280. memcpy(val->data, from->data, from->size);
  1281. } else {
  1282. val->size = 0;
  1283. val->data = NULL;
  1284. }
  1285. *to = val;
  1286. return (CSA_SUCCESS);
  1287. }
  1288. extern void
  1289. _DtCm_free_opaque_data(CSA_opaque_data *val)
  1290. {
  1291. if (val == NULL) return;
  1292. if (val->data)
  1293. free(val->data);
  1294. free(val);
  1295. }
  1296. extern void
  1297. _DtCm_get_attribute_types(uint size, int *types)
  1298. {
  1299. int i;
  1300. for (i = 1; i <= size; i++) {
  1301. types[i] = _CSA_entry_attr_info[i].type;
  1302. }
  1303. }
  1304. /******************************************************************************
  1305. * static functions used within the file
  1306. ******************************************************************************/
  1307. /*
  1308. * The passed in attributes are hashed.
  1309. * For each attribute, check
  1310. * 1. type is valid and supported
  1311. * 2. if it's a date time value type, check validity of date time.
  1312. * 3. if it's a reminder value type, check validity of lead time.
  1313. * 4. if it is a defined attribute, check that the data type is correct.
  1314. * 5. if it is a defined attribute and checkreadonly is set, check
  1315. * that it's not readonly.
  1316. */
  1317. static CSA_return_code
  1318. check_predefined_attrs(
  1319. int fver,
  1320. uint num_attrs,
  1321. cms_attribute *attrs,
  1322. boolean_t checkreadonly,
  1323. _DtCmNameTable *tbl,
  1324. uint num_defined,
  1325. _DtCmAttrInfo *our_attrs)
  1326. {
  1327. int i, index, cl;
  1328. CSA_reminder *rptr;
  1329. time_t tick;
  1330. for (i = 0; i < num_attrs; i++) {
  1331. if (attrs[i].name.name == NULL)
  1332. continue;
  1333. if (tbl == NULL)
  1334. index = i;
  1335. else
  1336. index = _DtCm_get_index_from_table(tbl,
  1337. attrs[i].name.name);
  1338. if (index > 0 && index <= num_defined) {
  1339. /* check whether the attribute is supported
  1340. * in this version
  1341. */
  1342. if (our_attrs[index].fst_vers == 0 ||
  1343. (fver < _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
  1344. fver < our_attrs[index].fst_vers))
  1345. return (CSA_E_UNSUPPORTED_ATTRIBUTE);
  1346. else if (our_attrs[index].fst_vers == -1)
  1347. return (CSA_E_INVALID_ATTRIBUTE);
  1348. /* check whether the attribute is readonly */
  1349. if (checkreadonly &&
  1350. ((fver < _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
  1351. our_attrs[index].nex_ro) ||
  1352. (fver >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
  1353. our_attrs[index].ex_ro)))
  1354. return (CSA_E_READONLY);
  1355. /* check data type */
  1356. if (attrs[i].value &&
  1357. attrs[i].value->type != our_attrs[index].type)
  1358. return (CSA_E_INVALID_ATTRIBUTE_VALUE);
  1359. if (index == CSA_ENTRY_ATTR_CLASSIFICATION_I) {
  1360. cl = attrs[i].value->item.uint32_value;
  1361. if (cl < CSA_CLASS_PUBLIC ||
  1362. cl > CSA_CLASS_CONFIDENTIAL)
  1363. return (CSA_E_INVALID_ATTRIBUTE_VALUE);
  1364. }
  1365. if (index == CSA_ENTRY_ATTR_TYPE_I) {
  1366. cl = attrs[i].value->item.uint32_value;
  1367. if (cl < CSA_TYPE_EVENT ||
  1368. cl > CSA_X_DT_TYPE_OTHER)
  1369. return (CSA_E_INVALID_ATTRIBUTE_VALUE);
  1370. }
  1371. } else if (fver < _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
  1372. return (CSA_E_INVALID_ATTRIBUTE);
  1373. }
  1374. /* check validity of value type */
  1375. if (attrs[i].value) {
  1376. if (attrs[i].value->type < CSA_VALUE_BOOLEAN ||
  1377. attrs[i].value->type > CSA_VALUE_OPAQUE_DATA)
  1378. return (CSA_E_INVALID_ATTRIBUTE_VALUE);
  1379. /* cast the sint32_value element to the desired
  1380. * type to be safe since the value part could
  1381. * actually be a pointer to a CSA_attribute_value
  1382. */
  1383. switch (attrs[i].value->type) {
  1384. case CSA_VALUE_DATE_TIME:
  1385. if (attrs[i].value->item.sint32_value == 0
  1386. || _csa_iso8601_to_tick(
  1387. (char *)attrs[i].value->item.sint32_value,
  1388. &tick))
  1389. return (CSA_E_INVALID_DATE_TIME);
  1390. break;
  1391. case CSA_VALUE_REMINDER:
  1392. rptr = (CSA_reminder *)
  1393. attrs[i].value->item.sint32_value;
  1394. if (rptr == NULL || rptr->lead_time == NULL ||
  1395. _csa_iso8601_to_duration(rptr->lead_time,
  1396. &tick))
  1397. return (CSA_E_INVALID_ATTRIBUTE_VALUE);
  1398. break;
  1399. case CSA_VALUE_ATTENDEE_LIST:
  1400. return (CSA_E_INVALID_ATTRIBUTE_VALUE);
  1401. }
  1402. }
  1403. }
  1404. return (CSA_SUCCESS);
  1405. }
  1406. static CSA_return_code
  1407. convert_cms_user_to_csa_user(char *from, CSA_calendar_user **to)
  1408. {
  1409. CSA_calendar_user *newval;
  1410. if ((newval = (CSA_calendar_user *)calloc(1,
  1411. sizeof(CSA_calendar_user))) == NULL)
  1412. return (CSA_E_INSUFFICIENT_MEMORY);
  1413. if (from) {
  1414. if ((newval->user_name = strdup(from)) == NULL) {
  1415. free(newval);
  1416. return (CSA_E_INSUFFICIENT_MEMORY);
  1417. }
  1418. }
  1419. *to = newval;
  1420. return (CSA_SUCCESS);
  1421. }
  1422. static CSA_return_code
  1423. hash_entry_attrs(
  1424. uint num_attrs,
  1425. CSA_attribute *csaattrs,
  1426. cms_attribute *cmsattrs,
  1427. uint *hnum,
  1428. cms_attribute **hattrs,
  1429. uint *num)
  1430. {
  1431. int i, j, index, count = 0;
  1432. cms_attribute *nattrs;
  1433. char *name;
  1434. cms_attribute_value *val;
  1435. if ((nattrs = (cms_attribute *)calloc(1,
  1436. sizeof(cms_attribute)*(num_attrs+_DtCM_DEFINED_ENTRY_ATTR_SIZE+1)))
  1437. == NULL)
  1438. return (CSA_E_INSUFFICIENT_MEMORY);
  1439. for (i = 0, j = _DtCM_DEFINED_ENTRY_ATTR_SIZE + 1; i < num_attrs; i++) {
  1440. name = (csaattrs ? csaattrs[i].name : cmsattrs[i].name.name);
  1441. if (name == NULL)
  1442. continue;
  1443. else {
  1444. count++;
  1445. val = (csaattrs ?
  1446. ((cms_attribute_value *)csaattrs[i].value) :
  1447. cmsattrs[i].value);
  1448. }
  1449. index = _DtCm_get_index_from_table(_DtCm_entry_name_tbl, name);
  1450. if (index > 0) {
  1451. if (cmsattrs) cmsattrs[i].name.num = index;
  1452. nattrs[index].name.name = name;
  1453. nattrs[index].value = val;
  1454. } else {
  1455. nattrs[j].name.name = name;
  1456. nattrs[j++].value = val;
  1457. }
  1458. }
  1459. if (num) *num = count;
  1460. *hnum = j - 1;
  1461. *hattrs = nattrs;
  1462. return (CSA_SUCCESS);
  1463. }
  1464. static CSA_return_code
  1465. hash_cal_attrs(
  1466. uint num_attrs,
  1467. CSA_attribute *csaattrs,
  1468. cms_attribute *cmsattrs,
  1469. uint *hnum,
  1470. cms_attribute **hattrs,
  1471. uint *num)
  1472. {
  1473. int i, j, index, count = 0;
  1474. cms_attribute *nattrs;
  1475. char *name;
  1476. cms_attribute_value *val;
  1477. if ((nattrs = (cms_attribute *)calloc(1,
  1478. sizeof(cms_attribute)*(num_attrs+_DtCM_DEFINED_CAL_ATTR_SIZE+1)))
  1479. == NULL)
  1480. return (CSA_E_INSUFFICIENT_MEMORY);
  1481. for (i = 0, j = _DtCM_DEFINED_CAL_ATTR_SIZE + 1; i < num_attrs; i++) {
  1482. name = (csaattrs ? csaattrs[i].name : cmsattrs[i].name.name);
  1483. if (name == NULL)
  1484. continue;
  1485. else {
  1486. count++;
  1487. val = (csaattrs ?
  1488. ((cms_attribute_value *)csaattrs[i].value) :
  1489. cmsattrs[i].value);
  1490. }
  1491. index = _DtCm_get_index_from_table(_DtCm_cal_name_tbl, name);
  1492. if (index > 0) {
  1493. if (cmsattrs) cmsattrs[i].name.num = index;
  1494. nattrs[index].name.name = name;
  1495. nattrs[index].value = val;
  1496. } else {
  1497. nattrs[j].name.name = name;
  1498. nattrs[j++].value = val;
  1499. }
  1500. }
  1501. if (num) *num = count;
  1502. *hnum = j - 1;
  1503. *hattrs = nattrs;
  1504. return (CSA_SUCCESS);
  1505. }
  1506. static CSA_return_code
  1507. _DtCm_check_hashed_cal_attributes(
  1508. int fvers,
  1509. uint num_attrs,
  1510. cms_attribute *attrs,
  1511. char *owner,
  1512. char *cname,
  1513. boolean_t checkreadonly,
  1514. boolean_t firsttime,
  1515. boolean_t csatype)
  1516. {
  1517. CSA_return_code stat;
  1518. CSA_attribute_value *csaval;
  1519. cms_attribute_value *cmsval;
  1520. char *nattr = NULL; /* calendar name */
  1521. char *oattr = NULL; /* calendar owner */
  1522. char *cattr = NULL; /* character set */
  1523. char *tattr = NULL; /* time zone */
  1524. if (firsttime) {
  1525. if (attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].name.name) {
  1526. if (attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].value == NULL
  1527. || attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].value->\
  1528. item.calendar_user_value == NULL)
  1529. return (CSA_E_INVALID_ATTRIBUTE_VALUE);
  1530. if (csatype) {
  1531. csaval = (CSA_attribute_value *)attrs[\
  1532. CSA_CAL_ATTR_CALENDAR_OWNER_I].value;
  1533. stat = _CheckCalendarOwner(owner, csaval->type,
  1534. (csaval && csaval->item.calendar_user_value?
  1535. csaval->item.calendar_user_value->user_name:
  1536. NULL));
  1537. } else {
  1538. cmsval = attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].\
  1539. value;
  1540. stat = _CheckCalendarOwner(owner, cmsval->type,
  1541. cmsval ?
  1542. cmsval->item.calendar_user_value:NULL);
  1543. }
  1544. if (stat != CSA_SUCCESS)
  1545. return (stat);
  1546. oattr = attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].name.name;
  1547. attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].name.name = NULL;
  1548. }
  1549. if (attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].name.name) {
  1550. if (attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].value == NULL ||
  1551. attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].value->\
  1552. item.string_value == NULL) {
  1553. if (oattr)
  1554. attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].\
  1555. name.name = oattr;
  1556. return (CSA_E_INVALID_ATTRIBUTE_VALUE);
  1557. }
  1558. if ((stat = _CheckCalendarName(owner, cname,
  1559. attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].value))
  1560. != CSA_SUCCESS) {
  1561. if (oattr)
  1562. attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].\
  1563. name.name = oattr;
  1564. return (stat);
  1565. }
  1566. nattr = attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].name.name;
  1567. attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].name.name = NULL;
  1568. }
  1569. if (attrs[CSA_CAL_ATTR_CHARACTER_SET_I].name.name) {
  1570. cattr = attrs[CSA_CAL_ATTR_CHARACTER_SET_I].name.name;
  1571. attrs[CSA_CAL_ATTR_CHARACTER_SET_I].name.name = NULL;
  1572. }
  1573. if (attrs[CSA_CAL_ATTR_TIME_ZONE_I].name.name) {
  1574. tattr = attrs[CSA_CAL_ATTR_TIME_ZONE_I].name.name;
  1575. attrs[CSA_CAL_ATTR_TIME_ZONE_I].name.name = NULL;
  1576. }
  1577. }
  1578. stat = check_predefined_attrs(fvers, num_attrs+1, attrs,
  1579. checkreadonly, NULL, _DtCM_DEFINED_CAL_ATTR_SIZE,
  1580. _CSA_cal_attr_info);
  1581. if (oattr)
  1582. attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].name.name = oattr;
  1583. if (nattr)
  1584. attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].name.name = nattr;
  1585. if (cattr)
  1586. attrs[CSA_CAL_ATTR_CHARACTER_SET_I].name.name = oattr;
  1587. if (tattr)
  1588. attrs[CSA_CAL_ATTR_TIME_ZONE_I].name.name = nattr;
  1589. return (stat);
  1590. }
  1591. static CSA_return_code
  1592. _DtCm_check_hashed_entry_attributes(
  1593. int fvers,
  1594. uint num_attrs,
  1595. cms_attribute *attrs,
  1596. CSA_flags utype)
  1597. {
  1598. CSA_return_code stat;
  1599. if ((stat = check_predefined_attrs(fvers, num_attrs+1, attrs,
  1600. (utype == 0 ? B_FALSE : B_TRUE), NULL,
  1601. _DtCM_DEFINED_ENTRY_ATTR_SIZE, _CSA_entry_attr_info))
  1602. != CSA_SUCCESS) {
  1603. return (stat);
  1604. }
  1605. if (utype == CSA_CB_ENTRY_ADDED) {
  1606. /* make sure the minimum set of attribute is specified */
  1607. if (attrs[CSA_ENTRY_ATTR_START_DATE_I].value == NULL ||
  1608. attrs[CSA_ENTRY_ATTR_TYPE_I].value == NULL)
  1609. return (CSA_E_INVALID_PARAMETER);
  1610. } else if (utype == CSA_CB_ENTRY_UPDATED) {
  1611. /* type can only be set at insertion time */
  1612. if (attrs[CSA_ENTRY_ATTR_TYPE_I].name.name)
  1613. return (CSA_E_READONLY);
  1614. }
  1615. return (CSA_SUCCESS);
  1616. }
  1617. static CSA_return_code
  1618. _CheckNameAtHost(char *owner, char *value)
  1619. {
  1620. char *ptr, *optr;
  1621. int res;
  1622. /* check name part first */
  1623. if (owner == NULL) {
  1624. /* get user name of user running the application */
  1625. if ((owner = _DtCmGetUserName()) == NULL)
  1626. return (CSA_E_FAILURE);
  1627. }
  1628. if (optr = strchr(owner, '@')) *optr = '\0';
  1629. if (ptr = strchr(value, '@')) *ptr = '\0';
  1630. res = strcmp(value, owner);
  1631. if (optr) *optr = '@';
  1632. if (ptr) *ptr = '@';
  1633. if (res != 0)
  1634. return (CSA_E_INVALID_ATTRIBUTE_VALUE);
  1635. /* check host too if it's specified */
  1636. if (ptr == NULL)
  1637. return (CSA_SUCCESS);
  1638. ptr++;
  1639. if (strcmp(ptr, (optr ? ++optr : _DtCmGetLocalHost())) == 0)
  1640. return (CSA_SUCCESS);
  1641. else
  1642. return (CSA_E_INVALID_ATTRIBUTE_VALUE);
  1643. }
  1644. /*
  1645. * check the data type and validity of calendar owner attribute
  1646. */
  1647. static CSA_return_code
  1648. _CheckCalendarOwner(char *owner, int type, char *user)
  1649. {
  1650. if (type != CSA_VALUE_CALENDAR_USER || user == NULL)
  1651. return (CSA_E_INVALID_ATTRIBUTE_VALUE);
  1652. /* make sure user is the same as the one running the application */
  1653. return (_CheckNameAtHost(owner, user));
  1654. }
  1655. /*
  1656. * check the data type and validity of calendar name attribute
  1657. */
  1658. static CSA_return_code
  1659. _CheckCalendarName(char *owner, char *cname, cms_attribute_value *val)
  1660. {
  1661. CSA_return_code stat;
  1662. char *ptr, *optr;
  1663. char user[BUFSIZ];
  1664. boolean_t isuser;
  1665. if (val->type != CSA_VALUE_STRING)
  1666. return (CSA_E_INVALID_ATTRIBUTE_VALUE);
  1667. /* check that the attribute value is the same as the given
  1668. * calendar name
  1669. */
  1670. if ((stat = _CheckNameAtHost(cname, val->item.string_value))
  1671. != CSA_SUCCESS)
  1672. return (stat);
  1673. /* now make sure if cal name is a user name, it's
  1674. * the same as that of the calling user
  1675. */
  1676. if (ptr = strchr(val->item.string_value, '@')) *ptr = '\0';
  1677. isuser = _DtCmIsUserName(val->item.string_value);
  1678. if (ptr) *ptr = '@';
  1679. /* make sure it's the same as the user running the application */
  1680. if (isuser == B_TRUE) {
  1681. sprintf(user, "%s%s", val->item.string_value, (ptr ? ptr : ""));
  1682. return (_CheckNameAtHost(owner, user));
  1683. }
  1684. /* check the host part */
  1685. if (ptr == NULL)
  1686. return (CSA_SUCCESS);
  1687. else
  1688. ptr++;
  1689. if (owner && (optr = strchr(owner, '@')))
  1690. optr++;
  1691. else
  1692. optr = _DtCmGetLocalHost();
  1693. if (strcmp(ptr, optr) == 0)
  1694. return (CSA_SUCCESS);
  1695. else
  1696. return (CSA_E_INVALID_ATTRIBUTE_VALUE);
  1697. }