Mixe for Privacy and Anonymity in the Internet
CAStatusManager.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) The JAP-Team, JonDos GmbH
3 
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright notice,
10  this list of conditions and the following disclaimer in the documentation and/or
11  other materials provided with the distribution.
12  * Neither the name of the University of Technology Dresden, Germany, nor the name of
13  the JonDos GmbH, nor the names of their contributors may be used to endorse or
14  promote products derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
20 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 #include "StdAfx.h"
29 #include "CAStatusManager.hpp"
30 
31 #ifdef SERVER_MONITORING
32 
33 #include "CAMsg.hpp"
34 #include "CAMutex.hpp"
35 #include "CAUtil.hpp"
36 #include "xml/DOM_Output.hpp"
37 #include "CALibProxytest.hpp"
38 #include "monitoringDefs.h"
39 
46 CAStatusManager *CAStatusManager::ms_pStatusManager = NULL;
47 state_t ***CAStatusManager::ms_pAllStates = NULL;
48 event_t ***CAStatusManager::ms_pAllEvents = NULL;
49 
51 {
52  if(ms_pAllEvents == NULL)
53  {
54  initEvents();
55  }
56  if(ms_pAllStates == NULL)
57  {
58  initStates();
59  }
60  if(ms_pStatusManager == NULL)
61  {
62  ms_pStatusManager = new CAStatusManager();
63  }
64 }
65 
67 {
68 #ifdef DEBUG
69  CAMsg::printMsg(LOG_DEBUG,
70  "CAStatusManager: doing cleanup\n");
71 #endif
72  /*if(ms_pStatusManager->m_pStatusSocket != NULL)
73  {
74  if(!(ms_pStatusManager->m_pStatusSocket->isClosed()))
75  {
76  ms_pStatusManager->m_pStatusSocket->close();
77  }
78  }*/
79 
80  if(ms_pStatusManager != NULL)
81  {
82  delete ms_pStatusManager;
83  ms_pStatusManager = NULL;
84  }
85  if(ms_pAllStates != NULL)
86  {
87  deleteStates();
88  }
89  if(ms_pAllEvents != NULL)
90  {
91  deleteEvents();
92  }
93 }
94 
95 SINT32 CAStatusManager::fireEvent(event_type_t e_type, enum status_type s_type)
96 {
97  if(ms_pStatusManager != NULL)
98  {
99  return ms_pStatusManager->transition(e_type, s_type);
100  }
101  else
102  {
103  CAMsg::printMsg(LOG_CRIT,
104  "StatusManager: cannot handle event %d/%d "
105  "because there is no StatusManager deployed\n",
106  s_type, e_type);
107  return E_UNKNOWN;
108  }
109 }
110 
111 CAStatusManager::CAStatusManager()
112 {
113  int i = 0, ret = 0;
114  m_pCurrentStates = NULL;
115  m_pCurrentStatesInfo = NULL;
116  m_pStatusLock = NULL;
117  m_pStatusSocket = NULL;
118  m_pListenAddr = NULL;
119  m_pMonitoringThread = NULL;
120  m_pPreparedStatusMessage = NULL;
121  m_bTryListen = false;
122 
123  m_pCurrentStates = new state_t*[NR_STATUS_TYPES];
124 
125  for(i = FIRST_STATUS; i < NR_STATUS_TYPES; i++)
126  {
127  m_pCurrentStates[i] =
128  ms_pAllStates[i][ENTRY_STATE];
129 #ifdef DEBUG
130  CAMsg::printMsg(LOG_DEBUG, "Init state: %s - %s\n", STATUS_NAMES[i],
131  m_pCurrentStates[i]->st_description);
132 #endif
133  }
134 
135  m_pStatusLock = new CAMutex();
136  m_pStatusSocket = new CASocket();
137  ret = initSocket();
138  if( (ret == E_SUCCESS))
139  {
140  m_pMonitoringThread = new CAThread((UINT8*)"Monitoring Thread");
141  m_pMonitoringThread->setMainLoop(serveMonitoringRequests);
142  m_pMonitoringThread->start(this);
143  }
144  else
145  {
146  CAMsg::printMsg(LOG_ERR,
147  "StatusManager: an error occured while initializing the"
148  " server monitoring socket\n");
149  }
150  initStatusMessage();
151  /* pass entry state staus information to the DOM structure */
152  for(i = FIRST_STATUS; i < NR_STATUS_TYPES; i++)
153  {
155  (m_pCurrentStatesInfo[i]).dsi_stateType,
156  (UINT32)(m_pCurrentStates[i])->st_type);
158  (m_pCurrentStatesInfo[i]).dsi_stateDesc,
159  (UINT8*)(m_pCurrentStates[i])->st_description);
161  (m_pCurrentStatesInfo[i]).dsi_stateLevel,
162  (UINT8*)(STATUS_LEVEL_NAMES[(m_pCurrentStates[i])->st_stateLevel]));
163  }
164 }
165 
166 CAStatusManager::~CAStatusManager()
167 {
168  int i = 0;
169  if(m_pMonitoringThread != NULL)
170  {
171  if(m_pStatusSocket != NULL)
172  {
173  if( !(m_pStatusSocket->isClosed()) )
174  {
175  m_pStatusSocket->close();
176  }
177  }
178 
179  delete m_pMonitoringThread;
180 #ifdef DEBUG
181  CAMsg::printMsg(LOG_DEBUG,
182  "CAStatusManager: The monitoring thread is no more.\n");
183 #endif
184  m_pMonitoringThread = NULL;
185  }
186  if(m_pStatusLock != NULL)
187  {
188  delete m_pStatusLock;
189  m_pStatusLock = NULL;
190  }
191  if(m_pCurrentStates != NULL)
192  {
193  for(i = FIRST_STATUS; i < NR_STATUS_TYPES; i++)
194  {
195  m_pCurrentStates[i] = NULL;
196  }
197  delete[] m_pCurrentStates;
198  m_pCurrentStates = NULL;
199  }
200  if(m_pStatusSocket != NULL)
201  {
202  delete m_pStatusSocket;
203  m_pStatusSocket = NULL;
204  }
205  if(m_pListenAddr != NULL)
206  {
207  delete m_pListenAddr;
208  m_pListenAddr = NULL;
209  }
210  if(m_pPreparedStatusMessage != NULL)
211  {
212  m_pPreparedStatusMessage->release();
213  m_pPreparedStatusMessage = NULL;
214  }
215 }
216 SINT32 CAStatusManager::initSocket()
217 {
218  SINT32 ret = E_UNKNOWN;
219  int errnum = 0;
220 
221  if(m_pStatusSocket == NULL)
222  {
223  m_pStatusSocket = new CASocket();
224  }
225 
226  if( !(m_pStatusSocket->isClosed()) )
227  {
228  CAMsg::printMsg(LOG_ERR,
229  "StatusManager: server monitoring socket already connected.\n");
230  return E_UNKNOWN;
231  }
232 
233  ret = m_pStatusSocket->create();
234  if(ret != E_SUCCESS)
235  {
236  CAMsg::printMsg(LOG_ERR,
237  "StatusManager: could not create server monitoring socket.\n");
238  return ret;
239  }
240  m_pStatusSocket->setReuseAddr(true);
241  /* listen to default server address, if nothing is specified:
242  * localhost:8080
243  */
244  char *hostname = "localhost";
246  bool userdefined = false;
247 
248  if(CALibProxytest::getOptions()->getMonitoringListenerHost()!= NULL)
249  {
250  hostname = CALibProxytest::getOptions()->getMonitoringListenerHost();
251  userdefined = true;
252  }
253  if(CALibProxytest::getOptions()->getMonitoringListenerPort()!= 0xFFFF)
254  {
255  port = CALibProxytest::getOptions()->getMonitoringListenerPort();
256  userdefined = true;
257  }
258 
259  m_pListenAddr = new CASocketAddrINet();
260  ret = m_pListenAddr->setAddr((UINT8 *) hostname, port);
261  if(ret != E_SUCCESS)
262  {
263  if(ret == E_UNKNOWN_HOST)
264  {
265  CAMsg::printMsg(LOG_ERR,
266  "StatusManager: could not initialize specified listener interface:"
267  " invalid host %s\n", hostname);
268  if(userdefined)
269  {
270  hostname = "localhost";
271  CAMsg::printMsg(LOG_ERR,
272  "StatusManager: trying %s.\n", hostname);
273 
274  ret = m_pListenAddr->setAddr((UINT8 *) hostname, port);
275  if(ret != E_SUCCESS)
276  {
277  CAMsg::printMsg(LOG_ERR,
278  "StatusManager: setting up listener interface %s:%d for "
279  "server monitoring failed\n",
280  hostname, port);
281  return ret;
282  }
283  }
284  }
285  else
286  {
287  CAMsg::printMsg(LOG_ERR,
288  "StatusManager: setting up listener interface %s:%d for "
289  "server monitoring failed\n",
290  hostname, port);
291  return ret;
292  }
293  }
294  ret = m_pStatusSocket->listen(*m_pListenAddr);
295 
296  if(ret != E_SUCCESS)
297  {
298  if(ret != E_UNKNOWN)
299  {
300  errnum = GET_NET_ERROR;
301  CAMsg::printMsg(LOG_ERR,
302  "StatusManager: not able to init server socket %s:%d "
303  "for server monitoring. %s failed because: %s\n",
304  hostname, port,
305  ((ret == E_SOCKET_BIND) ? "Bind" : "Listen"),
306  GET_NET_ERROR_STR(errnum));
307  }
308  return ret;
309  }
310 #ifdef DEBUG
311  CAMsg::printMsg(LOG_DEBUG,
312  "StatusManager: listen to monitoring socket on %s:%d\n",
313  hostname, port);
314 #endif
315  return E_SUCCESS;
316 }
317 
318 SINT32 CAStatusManager::transition(event_type_t e_type, status_type_t s_type)
319 {
320  transition_t transitionToNextState = st_ignore;
321  state_t *prev = NULL;
322 
323  if( (m_pStatusLock == NULL) ||
324  (m_pCurrentStates == NULL) )
325  {
326  CAMsg::printMsg(LOG_CRIT,
327  "StatusManager: fatal error\n");
328  return E_UNKNOWN;
329  }
330  if((s_type >= NR_STATUS_TYPES) || (s_type < FIRST_STATUS))
331  {
332  CAMsg::printMsg(LOG_ERR,
333  "StatusManager: received event for an invalid status type: %d\n", s_type);
334  return E_INVALID;
335  }
336  if((e_type >= EVENT_COUNT[s_type]) || (e_type < FIRST_EVENT))
337  {
338  CAMsg::printMsg(LOG_ERR,
339  "StatusManager: received an invalid event: %d\n", e_type);
340  return E_INVALID;
341  }
342 
343  /* We process incoming events synchronously, so the calling thread
344  * should perform state transition very quickly to avoid long blocking
345  * of other calling threads
346  */
347  m_pStatusLock->lock();
348  if(m_pCurrentStates[s_type]->st_transitions == NULL)
349  {
350  m_pStatusLock->unlock();
351  CAMsg::printMsg(LOG_CRIT,
352  "StatusManager: current state is corrupt\n");
353  return E_UNKNOWN;
354  }
355  transitionToNextState = m_pCurrentStates[s_type]->st_transitions[e_type];
356  if(transitionToNextState >= STATE_COUNT[s_type])
357  {
358  m_pStatusLock->unlock();
359  CAMsg::printMsg(LOG_ERR,
360  "StatusManager: transition to invalid state %d\n", transitionToNextState);
361  return E_INVALID;
362  }
363  if(transitionToNextState != st_ignore)
364  {
365  prev = m_pCurrentStates[s_type];
366  m_pCurrentStates[s_type] = ms_pAllStates[s_type][transitionToNextState];
367  m_pCurrentStates[s_type]->st_prev = prev;
368  m_pCurrentStates[s_type]->st_cause = ms_pAllEvents[s_type][e_type];
369 
370  /* setting the xml elements of the info message won't be too expensive */
372  (m_pCurrentStatesInfo[s_type]).dsi_stateType,
373  (UINT32)(m_pCurrentStates[s_type])->st_type);
375  (m_pCurrentStatesInfo[s_type]).dsi_stateDesc,
376  (UINT8*)(m_pCurrentStates[s_type])->st_description);
378  (m_pCurrentStatesInfo[s_type]).dsi_stateLevel,
379  (UINT8*)(STATUS_LEVEL_NAMES[(m_pCurrentStates[s_type])->st_stateLevel]));
380 #ifdef DEBUG
381  CAMsg::printMsg(LOG_DEBUG,
382  "StatusManager: status %s: "
383  "transition from state %d (%s) "
384  "to state %d (%s) caused by event %d (%s)\n",
385  STATUS_NAMES[s_type],
386  prev->st_type, prev->st_description,
387  m_pCurrentStates[s_type]->st_type, m_pCurrentStates[s_type]->st_description,
388  e_type, (ms_pAllEvents[s_type][e_type])->ev_description);
389 #endif
390  }
391  m_pStatusLock->unlock();
392  return E_SUCCESS;
393 }
394 
395 /* prepares (once) a DOM template for all status messages */
396 SINT32 CAStatusManager::initStatusMessage()
397 {
398  int i = 0;
399  m_pPreparedStatusMessage = createDOMDocument();
400  m_pCurrentStatesInfo = new dom_state_info[NR_STATUS_TYPES];
401  DOMElement *elemRoot = createDOMElement(m_pPreparedStatusMessage, DOM_ELEMENT_STATUS_MESSAGE_NAME);
402  DOMElement *status_dom_element = NULL;
403 
404  for(i = FIRST_STATUS; i < NR_STATUS_TYPES; i++)
405  {
406  status_dom_element =
407  createDOMElement(m_pPreparedStatusMessage, STATUS_NAMES[i]);
408  (m_pCurrentStatesInfo[i]).dsi_stateType =
409  createDOMElement(m_pPreparedStatusMessage, DOM_ELEMENT_STATE_NAME);
410 #ifdef DEBUG
411  setDOMElementValue((m_pCurrentStatesInfo[i]).dsi_stateType, (UINT8*)"Statenumber");
412 #endif
413  (m_pCurrentStatesInfo[i]).dsi_stateLevel =
414  createDOMElement(m_pPreparedStatusMessage, DOM_ELEMENT_STATE_LEVEL_NAME);
415 #ifdef DEBUG
416  setDOMElementValue((m_pCurrentStatesInfo[i]).dsi_stateLevel, (UINT8*)"OK or Critcal or something");
417 #endif
418  (m_pCurrentStatesInfo[i]).dsi_stateDesc =
419  createDOMElement(m_pPreparedStatusMessage, DOM_ELEMENT_STATE_DESCRIPTION_NAME);
420 #ifdef DEBUG
421  setDOMElementValue((m_pCurrentStatesInfo[i]).dsi_stateDesc, (UINT8*)"Description of the state");
422 #endif
423  status_dom_element->appendChild((m_pCurrentStatesInfo[i]).dsi_stateType);
424  status_dom_element->appendChild((m_pCurrentStatesInfo[i]).dsi_stateLevel);
425  status_dom_element->appendChild((m_pCurrentStatesInfo[i]).dsi_stateDesc);
426  elemRoot->appendChild(status_dom_element);
427  }
428  m_pPreparedStatusMessage->appendChild(elemRoot);
429 #ifdef DEBUG
430  UINT32 debuglen = XML_STATUS_MESSAGE_MAX_SIZE - 1;
432  memset(debugout, 0, (sizeof(UINT8)*XML_STATUS_MESSAGE_MAX_SIZE));
433  DOM_Output::dumpToMem(m_pPreparedStatusMessage,debugout,&debuglen);
434  CAMsg::printMsg(LOG_DEBUG, "the status message template looks like this: %s \n",debugout);
435 #endif
436  return E_SUCCESS;
437 }
438 
439 THREAD_RETURN serveMonitoringRequests(void* param)
440 {
441  CASocket monitoringRequestSocket;
442  int ret = 0;
443  CAStatusManager *statusManager = (CAStatusManager*) param;
444 
445  if(statusManager == NULL)
446  {
447  CAMsg::printMsg(LOG_CRIT,
448  "Monitoring Thread: fatal error, exiting.\n");
450  }
451 
452  for(;EVER;)
453  {
454 
455  if(statusManager->m_pStatusSocket != NULL)
456  {
457  if(statusManager->m_pStatusSocket->isClosed())
458  {
459  CAMsg::printMsg(LOG_INFO,
460  "Monitoring Thread: server socket closed, leaving loop.\n");
462  }
463  }
464  else
465  {
466  CAMsg::printMsg(LOG_ERR,
467  "Monitoring Thread: server socket disposed, leaving loop.\n");
469  }
470 
471  if(statusManager->m_pStatusSocket->accept(monitoringRequestSocket) == E_SUCCESS)
472  {
473  UINT32 xmlStatusMessageLength = XML_STATUS_MESSAGE_MAX_SIZE - 1;
474  char xmlStatusMessage[XML_STATUS_MESSAGE_MAX_SIZE];
475  memset(xmlStatusMessage, 0, (sizeof(char)*XML_STATUS_MESSAGE_MAX_SIZE));
476  statusManager->m_pStatusLock->lock();
478  statusManager->m_pPreparedStatusMessage,
479  (UINT8*)xmlStatusMessage,
480  &xmlStatusMessageLength);
481  statusManager->m_pStatusLock->unlock();
482 
483  char http_prefix[HTTP_ANSWER_PREFIX_MAX_LENGTH];
484  memset(http_prefix, 0, (sizeof(char)*HTTP_ANSWER_PREFIX_MAX_LENGTH));
485  snprintf(http_prefix, HTTP_ANSWER_PREFIX_MAX_LENGTH,
486  HTTP_ANSWER_PREFIX_FORMAT, xmlStatusMessageLength);
487  size_t http_prefix_length = strlen(http_prefix);
488 
489  char statusMessageResponse[http_prefix_length+xmlStatusMessageLength+1];
490  strncpy(statusMessageResponse, http_prefix, http_prefix_length);
491  strncpy((statusMessageResponse+http_prefix_length), xmlStatusMessage, xmlStatusMessageLength);
492  statusMessageResponse[xmlStatusMessageLength+http_prefix_length]=0;
493 
494 #ifdef DEBUG
495  CAMsg::printMsg(LOG_DEBUG, "the status message looks like this: %s \n",statusMessageResponse);
496 #endif
497 
498  if(monitoringRequestSocket.send((UINT8*)statusMessageResponse,
499  (http_prefix_length+xmlStatusMessageLength)) < 0)
500  {
501  CAMsg::printMsg(LOG_ERR,
502  "StatusManager: error: could not send status message.\n");
503  }
504  monitoringRequestSocket.close();
505  }
506  else
507  {
508  SINT32 errnum = GET_NET_ERROR;
509  CAMsg::printMsg(LOG_ERR,
510  "StatusManager: error: could not process monitoring request: %s\n", GET_NET_ERROR_STR(errnum));
511  switch (errnum)
512  {
513  //case ECONNABORTED:
514  case EBADF:
515  case EINVAL:
517  }
518  }
519  }
520 }
521 
522 void CAStatusManager::initStates()
523 {
524  int i = 0, j = 0;
525  ms_pAllStates = new state_t**[NR_STATUS_TYPES];
526 
527  for(i = FIRST_STATUS; i < NR_STATUS_TYPES; i++)
528  {
529  ms_pAllStates[i] =
530  new state_t*[STATE_COUNT[i]];
531 
532  for(j = ENTRY_STATE; j < STATE_COUNT[i]; j++)
533  {
534  ms_pAllStates[i][j] = new state_t;
535  /* only state identifier are set, transitions and state description
536  * must be set via macro
537  **/
538  ms_pAllStates[i][j]->st_type = (state_type_t) j;
539  ms_pAllStates[i][j]->st_statusType = (status_type_t) i;
540  }
541  }
542  FINISH_STATE_DEFINITIONS(ms_pAllStates);
543 
544 }
545 
546 void CAStatusManager::deleteStates()
547 {
548  int i = 0, j = 0;
549 
550  for(i = FIRST_STATUS; i < NR_STATUS_TYPES; i++)
551  {
552  for(j = ENTRY_STATE; j < STATE_COUNT[i]; j++)
553  {
554  if(ms_pAllStates[i][j] != NULL)
555  {
556  if(ms_pAllStates[i][j]->st_transitions != NULL)
557  {
558  delete[] ms_pAllStates[i][j]->st_transitions;
559  ms_pAllStates[i][j]->st_transitions = NULL;
560  }
561  delete ms_pAllStates[i][j];
562  ms_pAllStates[i][j] = NULL;
563  }
564  }
565  delete[] ms_pAllStates[i];
566  ms_pAllStates[i] = NULL;
567  }
568  delete[] ms_pAllStates;
569  ms_pAllStates = NULL;
570 }
571 
572 void CAStatusManager::initEvents()
573 {
574  int i = 0, j = 0;
575  ms_pAllEvents = new event_t**[NR_STATUS_TYPES];
576 
577  for(i = FIRST_STATUS; i < NR_STATUS_TYPES; i++)
578  {
579  ms_pAllEvents[i] = new event_t*[EVENT_COUNT[i]];
580  for(j = FIRST_EVENT; j < EVENT_COUNT[i]; j++)
581  {
582  ms_pAllEvents[i][j] = new event_t;
583  ms_pAllEvents[i][j]->ev_type = (event_type_t) j;
584  ms_pAllEvents[i][j]->ev_statusType = (status_type_t) i;
585  }
586  }
587  FINISH_EVENT_DEFINITIONS(ms_pAllEvents);
588 }
589 
590 void CAStatusManager::deleteEvents()
591 {
592  int i = 0, j = 0;
593 
594  for(i = FIRST_STATUS; i < NR_STATUS_TYPES; i++)
595  {
596  for(j = FIRST_EVENT; j < EVENT_COUNT[i]; j++)
597  {
598  delete ms_pAllEvents[i][j];
599  ms_pAllEvents[i][j] = NULL;
600  }
601  delete[] ms_pAllEvents[i];
602  ms_pAllEvents[i] = NULL;
603  }
604  delete[] ms_pAllEvents;
605  ms_pAllEvents = NULL;
606 }
607 
608 transition_t *defineTransitions(status_type_t s_type, SINT32 transitionCount, ...)
609 {
610  int i = 0;
611  va_list ap;
612  transition_t *transitions = NULL;
613  event_type_t specifiedEventTypes[transitionCount];
614  transition_t specifiedTransitions[transitionCount];
615 
616  /* read in the specified events with the corresponding transitions */
617  va_start(ap, transitionCount);
618  for(i = 0; i < transitionCount; i++)
619  {
620  specifiedEventTypes[i] = (event_type_t) va_arg(ap, int);
621  specifiedTransitions[i] = (transition_t) va_arg(ap, int);
622  }
623  va_end(ap);
624 
625  if((s_type >= NR_STATUS_TYPES) || (s_type < FIRST_STATUS))
626  {
627  /* invalid status type specified */
628  return NULL;
629  }
630  if(transitionCount > (EVENT_COUNT[s_type]))
631  {
632  /* more transitions specified than events defined*/
633  return NULL;
634  }
635 
636  transitions = new transition_t[(EVENT_COUNT[s_type])];
637  memset(transitions, st_ignore, (sizeof(transition_t)*(EVENT_COUNT[s_type])));
638  for(i = 0; i < transitionCount; i++)
639  {
640  if((specifiedEventTypes[i] >= EVENT_COUNT[s_type]) ||
641  (specifiedEventTypes[i] < 0))
642  {
643  /* specified event is invalid */
644  CAMsg::printMsg(LOG_WARNING,
645  "StatusManager: definition of an invalid state transition (invalid event %d).\n",
646  specifiedEventTypes[i]);
647  continue;
648  }
649  if((specifiedTransitions[i] >= STATE_COUNT[s_type]) ||
650  (specifiedTransitions[i] < st_ignore))
651  {
652  /* corresponding transition to event is not valid */
653  CAMsg::printMsg(LOG_WARNING,
654  "StatusManager: definition of an invalid state transition (invalid state %d).\n",
655  specifiedTransitions[i]);
656  continue;
657  }
658  transitions[specifiedEventTypes[i]] = specifiedTransitions[i];
659  }
660 
661  return transitions;
662 
663 }
664 #endif
SINT32 setDOMElementValue(DOMElement *pElem, SINT32 value)
Definition: CAUtil.cpp:939
XERCES_CPP_NAMESPACE::DOMDocument * createDOMDocument()
Parses a timestamp in JDBC timestamp escape format (as it comes from the BI) and outputs the value in...
Definition: CAUtil.cpp:1568
DOMElement * createDOMElement(XERCES_CPP_NAMESPACE::DOMDocument *pOwnerDoc, const char *const name)
Creates a new DOMElement with the given name which belongs to the DOMDocument owernDoc.
Definition: CAUtil.cpp:814
#define GET_NET_ERROR
Definition: StdAfx.h:469
#define GET_NET_ERROR_STR(x)
Definition: StdAfx.h:471
#define THREAD_RETURN_ERROR
Definition: StdAfx.h:541
#define THREAD_RETURN
Definition: StdAfx.h:540
#define THREAD_RETURN_SUCCESS
Definition: StdAfx.h:542
unsigned short UINT16
Definition: basetypedefs.h:133
signed int SINT32
Definition: basetypedefs.h:132
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
static CACmdLnOptions * getOptions()
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
Definition: CAMsg.cpp:251
This class represents a socket address for Internet (IP) connections.
virtual SINT32 send(const UINT8 *buff, UINT32 len)
Sends some data over the network.
Definition: CASocket.cpp:400
virtual SINT32 close()
Definition: CASocket.cpp:351
static SINT32 dumpToMem(const DOMNode *node, UINT8 *buff, UINT32 *size)
Dumps the node and all childs into buff.
Definition: DOM_Output.hpp:161
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
#define E_UNKNOWN_HOST
Definition: errorcodes.hpp:18
#define E_INVALID
Definition: errorcodes.hpp:25
#define E_SOCKET_BIND
Definition: errorcodes.hpp:15
#define E_UNKNOWN
Definition: errorcodes.hpp:3
#define HTTP_ANSWER_PREFIX_MAX_LENGTH
transition_t * defineTransitions(status_type_t s_type, int transitionCount,...)
a convenience function for easily defining state transitions
#define EVER
#define MONITORING_SERVER_PORT
#define ENTRY_STATE
#define XML_STATUS_MESSAGE_MAX_SIZE
enum state_type transition_t
@ st_ignore
#define DOM_ELEMENT_STATUS_MESSAGE_NAME
#define FINISH_STATE_DEFINITIONS(state_array)
helper macros for defining states and events:
struct state state_t
#define FIRST_STATUS
#define HTTP_ANSWER_PREFIX_FORMAT
enum state_type state_type_t
#define FIRST_EVENT
#define DOM_ELEMENT_STATE_LEVEL_NAME
enum event_type event_type_t
#define FINISH_EVENT_DEFINITIONS(event_array)
#define DOM_ELEMENT_STATE_DESCRIPTION_NAME
#define NR_STATUS_TYPES
enum status_type status_type_t
struct event event_t
#define DOM_ELEMENT_STATE_NAME
status_type
void init()
do necessary initialisations of libraries etc.
Definition: proxytest.cpp:145
void cleanup()
do necessary cleanups of libraries etc.
Definition: proxytest.cpp:151
event_type_t ev_type
struct state * st_prev
state_type_t st_type
struct event * st_cause
char * st_description