DtMailValuesBuiltin.C 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. /*
  24. *+SNOTICE
  25. *
  26. *
  27. * $TOG: DtMailValuesBuiltin.C /main/6 1999/01/29 14:44:21 mgreess $
  28. *
  29. * RESTRICTED CONFIDENTIAL INFORMATION:
  30. *
  31. * The information in this document is subject to special
  32. * restrictions in a confidential disclosure agreement bertween
  33. * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
  34. * document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
  35. * Sun's specific written approval. This documment and all copies
  36. * and derivative works thereof must be returned or destroyed at
  37. * Sun's request.
  38. *
  39. * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
  40. *
  41. *+ENOTICE
  42. */
  43. #include <unistd.h>
  44. #include <stdlib.h>
  45. #include <string.h>
  46. #include <DtMail/DtMailValues.hh>
  47. #include <DtMail/IO.hh>
  48. #include <DtMail/DtMailError.hh>
  49. DtMailValueSeq::DtMailValueSeq(int size) : DtVirtArray<DtMailValue *>(size)
  50. {
  51. }
  52. DtMailValueSeq::~DtMailValueSeq(void)
  53. {
  54. for (int ent = 0; ent < this->length(); ent++) {
  55. delete (*this)[ent];
  56. }
  57. }
  58. void
  59. DtMailValueSeq::clear(void)
  60. {
  61. while(this->length()) {
  62. delete (*this)[0];
  63. this->remove(0);
  64. }
  65. }
  66. DtMailValue::DtMailValue(const char * str)
  67. {
  68. _value = NULL;
  69. if (str) {
  70. _value = strdup(str);
  71. }
  72. }
  73. DtMailValue::~DtMailValue(void)
  74. {
  75. if (_value) {
  76. free(_value);
  77. }
  78. }
  79. DtMailValue::operator const char *(void)
  80. {
  81. return(_value);
  82. }
  83. const char *
  84. DtMailValue::operator= (const char * str)
  85. {
  86. if (_value) {
  87. free(_value);
  88. }
  89. _value = strdup(str);
  90. return(_value);
  91. }
  92. DtMailValueDate
  93. DtMailValue::toDate(void)
  94. {
  95. DtMailValueDate date;
  96. memset(&date, 0, sizeof(DtMailValueDate));
  97. return(date);
  98. }
  99. #ifdef DEAD_WOOD
  100. void
  101. DtMailValue::fromDate(const DtMailValueDate & date)
  102. {
  103. if (_value) {
  104. free(_value);
  105. }
  106. _value = (char *)malloc(64);
  107. tm result;
  108. SafeLocaltime(&date.dtm_date, result);
  109. /* NL_COMMENT
  110. * The %C is the time and date format, please refer to strftime man page for
  111. * explanation of each format.
  112. */
  113. SafeStrftime(_value, 64, DtMailError::getMessageText(2, 1, "%C"), &result);
  114. }
  115. #endif /* DEAD_WOOD */
  116. DtMailAddressSeq *
  117. DtMailValue::toAddress(void)
  118. {
  119. return(NULL);
  120. }
  121. #ifdef DEAD_WOOD
  122. void
  123. DtMailValue::fromAddress(const DtMailAddressSeq &)
  124. {
  125. }
  126. #endif /* DEAD_WOOD */
  127. const char *
  128. DtMailValue::raw(void)
  129. {
  130. return(_value);
  131. }
  132. DtMailValueAddress::DtMailValueAddress(void)
  133. {
  134. dtm_address = NULL;
  135. dtm_person = NULL;
  136. dtm_namespace = NULL;
  137. }
  138. DtMailValueAddress::DtMailValueAddress(const DtMailValueAddress & other)
  139. {
  140. dtm_address = NULL;
  141. dtm_person = NULL;
  142. dtm_namespace = NULL;
  143. if (other.dtm_address) {
  144. dtm_address = strdup(other.dtm_address);
  145. }
  146. if (other.dtm_person) {
  147. dtm_person = strdup(other.dtm_person);
  148. }
  149. if (other.dtm_namespace) {
  150. dtm_namespace = strdup(other.dtm_namespace);
  151. }
  152. }
  153. DtMailValueAddress::DtMailValueAddress(const char * address,
  154. const char * person,
  155. const char * nameSpace)
  156. {
  157. dtm_address = NULL;
  158. dtm_person = NULL;
  159. dtm_namespace = NULL;
  160. if (address) {
  161. dtm_address = strdup(address);
  162. }
  163. if (person) {
  164. dtm_person = strdup(person);
  165. }
  166. if (nameSpace) {
  167. dtm_namespace = strdup(nameSpace);
  168. }
  169. }
  170. DtMailValueAddress::DtMailValueAddress(const char * address, const int addr_len,
  171. const char * person, const int per_len,
  172. const char * nameSpace)
  173. {
  174. dtm_address = NULL;
  175. dtm_person = NULL;
  176. dtm_namespace = NULL;
  177. if (address) {
  178. dtm_address = (char *)malloc(addr_len + 1);
  179. memcpy(dtm_address, address, addr_len);
  180. dtm_address[addr_len] = 0;
  181. }
  182. if (person) {
  183. dtm_person = (char *)malloc(per_len + 1);
  184. memcpy(dtm_person, person, per_len);
  185. dtm_person[per_len] = 0;
  186. }
  187. if (nameSpace) {
  188. dtm_namespace = strdup(nameSpace);
  189. }
  190. }
  191. DtMailValueAddress::~DtMailValueAddress(void)
  192. {
  193. if (dtm_address) {
  194. free(dtm_address);
  195. }
  196. if (dtm_person) {
  197. free(dtm_person);
  198. }
  199. if (dtm_namespace) {
  200. free(dtm_namespace);
  201. }
  202. }
  203. DtMailAddressSeq::DtMailAddressSeq(int size) : DtVirtArray<DtMailValueAddress *>(size)
  204. {
  205. }
  206. DtMailAddressSeq::~DtMailAddressSeq(void)
  207. {
  208. while(this->length()) {
  209. delete (*this)[0];
  210. this->remove(0);
  211. }
  212. }