Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

220 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. coverpg.c
  5. Abstract:
  6. Functions for manipulating cover page structures
  7. Environment:
  8. Fax driver, user mode
  9. Revision History:
  10. 01/04/2000 -LiranL-
  11. Created it.
  12. mm/dd/yyyy -author-
  13. description
  14. --*/
  15. #include "faxlib.h"
  16. #include "faxutil.h"
  17. #include "covpg.h"
  18. VOID
  19. FreeCoverPageFields(
  20. PCOVERPAGEFIELDS pCPFields
  21. )
  22. /*++
  23. Routine Description:
  24. Free up memory used to hold the cover page information
  25. Arguments:
  26. pCPFields - Points to a COVERPAGEFIELDS structure
  27. Return Value:
  28. NONE
  29. --*/
  30. {
  31. if (pCPFields == NULL)
  32. return;
  33. //
  34. // NOTE: We don't need to free the following fields here because they're
  35. // allocated and freed elsewhere and we're only using a copy of the pointer:
  36. // RecName
  37. // RecFaxNumber
  38. // Note
  39. // Subject
  40. //
  41. MemFree(pCPFields->SdrName);
  42. MemFree(pCPFields->SdrFaxNumber);
  43. MemFree(pCPFields->SdrCompany);
  44. MemFree(pCPFields->SdrAddress);
  45. MemFree(pCPFields->SdrTitle);
  46. MemFree(pCPFields->SdrDepartment);
  47. MemFree(pCPFields->SdrOfficeLocation);
  48. MemFree(pCPFields->SdrHomePhone);
  49. MemFree(pCPFields->SdrOfficePhone);
  50. MemFree(pCPFields->SdrEmail);
  51. MemFree(pCPFields->NumberOfPages);
  52. MemFree(pCPFields->TimeSent);
  53. MemFree(pCPFields);
  54. }
  55. PCOVERPAGEFIELDS
  56. CollectCoverPageFields(
  57. PFAX_PERSONAL_PROFILE lpSenderInfo,
  58. DWORD pageCount
  59. )
  60. /*++
  61. Routine Description:
  62. Collect cover page information into the fields of a newly allocated COVERPAGEFIELDS structure.
  63. Fills sender information using the client registry. The following fields are filled:
  64. SdrName
  65. SdrCompany
  66. SdrAddress
  67. SdrTitle
  68. SdrDepartment
  69. SdrOfficeLocation
  70. SdrHomePhone
  71. SdrOfficePhone
  72. SdrFaxNumber
  73. SdrEmail
  74. NumberOfPages = pageCount
  75. TimeSent = formatted date/time string of the current time (calculated at this point)
  76. Arguments:
  77. pageCount - Total number of pages (including cover pages)
  78. Return Value:
  79. Pointer to a newly allocated COVERPAGEFIELDS structure, NULL if there is an error.
  80. It is up to the caller to free this structure using FreeCoverPageFields() which takes
  81. care of freeing the fields as well.
  82. --*/
  83. #define FillCoverPageField(DestField, SourceField) { \
  84. if (lpSenderInfo->SourceField && !(pCPFields->DestField = StringDup(lpSenderInfo->SourceField))) \
  85. { \
  86. Error(("Memory allocation failed\n")); \
  87. goto error; \
  88. } \
  89. }
  90. {
  91. PCOVERPAGEFIELDS pCPFields = NULL;
  92. INT dateTimeLen = 0;
  93. //
  94. // Allocate memory to hold the top level structure
  95. // and open the user info registry key for reading
  96. //
  97. if (! (pCPFields = MemAllocZ(sizeof(COVERPAGEFIELDS))))
  98. {
  99. return NULL;
  100. }
  101. ZeroMemory(pCPFields,sizeof(COVERPAGEFIELDS));
  102. //
  103. // Read sender information from the registry
  104. //
  105. pCPFields->ThisStructSize = sizeof(COVERPAGEFIELDS);
  106. FillCoverPageField(SdrName, lptstrName);
  107. FillCoverPageField(SdrCompany, lptstrCompany);
  108. FillCoverPageField(SdrTitle, lptstrTitle);
  109. FillCoverPageField(SdrDepartment, lptstrDepartment);
  110. FillCoverPageField(SdrOfficeLocation, lptstrOfficeLocation);
  111. FillCoverPageField(SdrHomePhone, lptstrHomePhone);
  112. FillCoverPageField(SdrOfficePhone, lptstrOfficePhone);
  113. FillCoverPageField(SdrFaxNumber, lptstrFaxNumber);
  114. FillCoverPageField(SdrAddress, lptstrStreetAddress);
  115. FillCoverPageField(SdrEmail, lptstrEmail);
  116. //
  117. // Number of pages and current local system time
  118. //
  119. if (pCPFields->NumberOfPages = MemAllocZ(sizeof(TCHAR) * 16))
  120. {
  121. wsprintf(pCPFields->NumberOfPages, TEXT("%d"), pageCount);
  122. }
  123. else
  124. {
  125. Error(("Memory allocation failed\n"));
  126. goto error;
  127. }
  128. //
  129. // When the fax was sent
  130. //
  131. dateTimeLen = 128;
  132. if (pCPFields->TimeSent = MemAllocZ(sizeof(TCHAR) * dateTimeLen))
  133. {
  134. LPTSTR p = pCPFields->TimeSent;
  135. INT cch;
  136. if (!GetY2KCompliantDate(LOCALE_USER_DEFAULT, 0, NULL, p, dateTimeLen))
  137. {
  138. Error(("GetY2KCompliantDate: failed. ec = 0X%x\n",GetLastError()));
  139. goto error;
  140. }
  141. cch = _tcslen(p);
  142. p += cch;
  143. if (++cch < dateTimeLen)
  144. {
  145. *p++ = (TCHAR)' ';
  146. dateTimeLen -= cch;
  147. FaxTimeFormat(LOCALE_USER_DEFAULT, 0, NULL, NULL, p, dateTimeLen);
  148. }
  149. }
  150. else
  151. {
  152. Error(("Memory allocation failed\n"));
  153. goto error;
  154. }
  155. return pCPFields;
  156. error:
  157. FreeCoverPageFields(pCPFields);
  158. return NULL;
  159. }