Source code of Windows XP (NT5)
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.

336 lines
8.5 KiB

  1. /*
  2. * REVISIONS:
  3. * jod30NOV92 Changes made due to GCIP stuff
  4. * ane16DEC92 Added cdefine.h
  5. * pcy02Feb93: AddEvent must return a value. Changed to return ErrNO_ERROR
  6. * cad29Oct93: added get next attr
  7. * cad08Dec93: added extended get/set types
  8. * mwh05May94: #include file madness , part 2
  9. * mwh07Jun94: port for NCR
  10. * jbc07Nov96: added check to only allow one transaction per code
  11. * mds10Jul97: modified Transaction Item Equal() function
  12. * mds10Jul97: changed GetFirstAttribute() to const to work with Equal()
  13. * mds14Jul97: StrIntCmpI was renamed to ApcStrIntCmpI
  14. */
  15. #define INCL_BASE
  16. #define INCL_NOPM
  17. #include "cdefine.h"
  18. #include "_defs.h"
  19. extern "C" {
  20. #include <stdlib.h>
  21. #include <string.h>
  22. }
  23. #include "trans.h"
  24. #include "apc.h"
  25. #include "err.h"
  26. #include "event.h"
  27. #include "list.h"
  28. #include "message.h"
  29. #include "utils.h"
  30. #if (C_OS & C_NCR)
  31. # include "incfix.h"
  32. #endif
  33. TransactionObject::TransactionObject(Type type, INT anId)
  34. : theType(type),
  35. theId(anId),
  36. theProtocolMessageList((List*)NULL),
  37. thePMIterator((ListIterator*)NULL)
  38. {
  39. theProtocolMessageList = new List();
  40. if (theProtocolMessageList)
  41. thePMIterator = &(RListIterator)(theProtocolMessageList->InitIterator());
  42. else
  43. SetObjectStatus(ErrMEMORY);
  44. }
  45. TransactionObject:: ~TransactionObject()
  46. {
  47. if (theProtocolMessageList)
  48. theProtocolMessageList->FlushAll();
  49. delete theProtocolMessageList;
  50. theProtocolMessageList = (List*)NULL;
  51. delete thePMIterator;
  52. thePMIterator = NULL;
  53. }
  54. VOID TransactionObject::AddMessage(PMessage aMessage)
  55. {
  56. theProtocolMessageList->Append(aMessage);
  57. }
  58. INT TransactionItem::transactionItemCount = 0;
  59. TransactionItem::TransactionItem(Type aType, INT aCode, CHAR* aValue)
  60. : TransactionObject(aType, transactionItemCount++),
  61. theCode(aCode),
  62. theErrorCode(0),
  63. theValue((CHAR*)NULL),
  64. theAttributeList((List*)NULL),
  65. theAttribIterator((ListIterator*)NULL)
  66. {
  67. SetValue(aValue);
  68. theAttributeList = new List();
  69. if (theAttributeList)
  70. theAttribIterator = &(RListIterator)(theAttributeList->InitIterator());
  71. }
  72. TransactionItem::~TransactionItem()
  73. {
  74. if (theValue)
  75. free(theValue);
  76. theValue = (CHAR*)NULL;
  77. if (theAttributeList)
  78. theAttributeList->FlushAll();
  79. delete theAttributeList;
  80. theAttributeList = (List*)NULL;
  81. delete theAttribIterator;
  82. theAttribIterator = (ListIterator*)NULL;
  83. }
  84. VOID TransactionItem::SetValue(CHAR* aValue)
  85. {
  86. if (theValue != (CHAR*)NULL)
  87. {
  88. free(theValue);
  89. theValue = (CHAR*)NULL;
  90. }
  91. if (aValue != (CHAR*)NULL)
  92. theValue = _strdup(aValue);
  93. }
  94. VOID TransactionItem::AddAttribute(PAttribute anAttribute)
  95. {
  96. theAttributeList->Append(anAttribute);
  97. }
  98. VOID TransactionItem::AddAttribute(INT aCode, CHAR* aValue)
  99. {
  100. PAttribute attribute = new Attribute(aCode, aValue);
  101. AddAttribute(attribute);
  102. }
  103. PAttribute TransactionItem:: GetFirstAttribute() const
  104. {
  105. theAttribIterator->Reset();
  106. return (Attribute*)theAttributeList->GetHead();
  107. }
  108. PAttribute TransactionItem:: GetNextAttribute()
  109. {
  110. PAttribute ret = (PAttribute)(theAttribIterator->Next());
  111. return ret;
  112. }
  113. INT TransactionItem:: Equal(RObj obj) const
  114. {
  115. INT ret_value = FALSE;
  116. RTransactionItem trans_item = (RTransactionItem) obj;
  117. if (trans_item.GetCode() == GetCode()){
  118. ret_value = TRUE;
  119. // if the code values are the same, this does not
  120. // necessarily mean that the transaction items are equal
  121. // A transaction item contains a list of attributes, and
  122. // if the first attributes of each transaction item are
  123. // not equal, then the transaction items are not equal.
  124. // get first attributes from the attribute list
  125. PAttribute attrib1 = trans_item.GetFirstAttribute();
  126. PAttribute attrib2 = GetFirstAttribute();
  127. // if both attributes are present
  128. if(attrib1 && attrib2){
  129. // get actual attribute values
  130. PCHAR attrib_str1 = attrib1->GetValue();
  131. PCHAR attrib_str2 = attrib2->GetValue();
  132. // check to make sure that attribute values are not NULL
  133. if(attrib_str1 != NULL && attrib_str2 != NULL){
  134. if(attrib_str1[0] != NULL && attrib_str2[0] != NULL){
  135. // if both of the attribute strings are not equal to
  136. // one another, then return false
  137. if(ApcStrIntCmpI(attrib_str1,attrib_str2) != EQUAL){
  138. ret_value = FALSE;
  139. }
  140. }
  141. }
  142. }
  143. }
  144. return ret_value;
  145. }
  146. INT TransactionGroup::transactionGroupCount = 0;
  147. TransactionGroup::TransactionGroup(Type aType) :
  148. TransactionObject(aType, transactionGroupCount++),
  149. theAuthenticationString((CHAR*)NULL),
  150. theResponse((CHAR*)NULL),
  151. theEventList((List*)NULL),
  152. theEventIterator((ListIterator*)NULL),
  153. theTransactionList((List*)NULL),
  154. theTransactionIterator((ListIterator*)NULL),
  155. InitialSetResponseRepeated(0),
  156. InitialSetResponse((CHAR*)NULL),
  157. theErrorCode(0),
  158. theErrorIndex(0)
  159. {
  160. theEventList = new List();
  161. theEventIterator = &(RListIterator)(theEventList->InitIterator());
  162. theTransactionList = new List();
  163. theTransactionIterator = &(RListIterator)(theTransactionList->InitIterator());
  164. }
  165. TransactionGroup:: ~TransactionGroup()
  166. {
  167. if (theAuthenticationString)
  168. free (theAuthenticationString);
  169. theAuthenticationString =(CHAR*)NULL;
  170. if (theResponse)
  171. free( theResponse);
  172. theResponse =(CHAR*)NULL;
  173. if (InitialSetResponse)
  174. free(InitialSetResponse);
  175. InitialSetResponse = (CHAR*)NULL;
  176. theEventList->FlushAll();
  177. delete theEventList;
  178. theEventList = (List*)NULL;
  179. delete theEventIterator;
  180. theEventIterator = NULL;
  181. theTransactionList->FlushAll();
  182. delete theTransactionList;
  183. theTransactionList = (List*)NULL;
  184. delete theTransactionIterator;
  185. theTransactionIterator = NULL;
  186. }
  187. INT TransactionGroup:: Equal(RObj obj) const
  188. {
  189. // if (strcmp(obj.IsA(), IsA()))
  190. // return FALSE;
  191. RTransactionGroup tg = (RTransactionGroup)obj;
  192. if (tg.GetId() == GetId())
  193. return TRUE;
  194. return FALSE;
  195. }
  196. VOID TransactionGroup::SetAuthentication(CHAR* aString)
  197. {
  198. if (theAuthenticationString != (CHAR*)NULL)
  199. {
  200. free(theAuthenticationString);
  201. theAuthenticationString = (CHAR*)NULL;
  202. }
  203. if (aString != (CHAR*)NULL)
  204. theAuthenticationString = _strdup(aString);
  205. }
  206. VOID TransactionGroup::SetResponse(CHAR* aString)
  207. {
  208. if (theResponse != (CHAR*)NULL)
  209. {
  210. free(theResponse);
  211. theResponse = (CHAR*)NULL;
  212. }
  213. if (aString != (CHAR*)NULL)
  214. theResponse = _strdup(aString);
  215. }
  216. VOID TransactionGroup:: SetInitialSetResponseRepeated(INT repeat)
  217. {
  218. InitialSetResponseRepeated = repeat;
  219. }
  220. VOID TransactionGroup:: SetErrorIndex(INT index)
  221. {
  222. theErrorIndex = index;
  223. }
  224. VOID TransactionGroup:: SetInitialSetResponse(CHAR* initialResponse)
  225. {
  226. InitialSetResponse = _strdup(initialResponse);
  227. }
  228. INT TransactionGroup::AddTransactionItem(PTransactionItem aTransactionItem)
  229. {
  230. int err = ErrNO_ERROR;
  231. Type addType = aTransactionItem->GetType();
  232. // simple transactions types can be added to complex groups, but
  233. // not vice-versa. This is a completely arbitrary exclusion,
  234. // and could be changed if needed. For now it save a couple
  235. // of lines of code.
  236. //
  237. if ((addType == theType) ||
  238. ((theType == EXTENDED_GET) && (addType == GET)) ||
  239. ((theType == EXTENDED_SET) && (addType == SET)))
  240. {
  241. // Check to see if transaction already exists.
  242. PTransactionItem trans_item = (PTransactionItem)NULL;
  243. trans_item = (PTransactionItem)theTransactionList->Find(aTransactionItem);
  244. // If the transaction was not found, then add it to theTransactionList
  245. if (trans_item==NULL)
  246. {
  247. theTransactionList->Append(aTransactionItem);
  248. }
  249. if (theTransactionIterator == (ListIterator*)NULL) {
  250. theTransactionIterator =
  251. &(RListIterator)(theTransactionList->InitIterator());
  252. }
  253. }
  254. else
  255. {
  256. aTransactionItem->SetErrorCode(ErrTYPE_COMBINATION);
  257. err = ErrTYPE_COMBINATION;
  258. }
  259. return err;
  260. }
  261. INT TransactionGroup::AddEvent(PEvent aEvent)
  262. {
  263. // theEventList->Add(*aEvent);
  264. return ErrNO_ERROR;
  265. }
  266. PTransactionItem TransactionGroup::GetCurrentTransaction()
  267. {
  268. return (PTransactionItem)(& (theTransactionIterator->Current()));
  269. }
  270. PTransactionItem TransactionGroup::GetFirstTransactionItem()
  271. {
  272. theTransactionIterator->Reset();
  273. return (PTransactionItem) theTransactionList->GetHead();
  274. }
  275. PTransactionItem TransactionGroup::GetNextTransactionItem()
  276. {
  277. return (PTransactionItem) theTransactionIterator->Next();
  278. }