Mixe for Privacy and Anonymity in the Internet
TermsAndConditions.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 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_FIRST_MIX
30 
31 #include "TermsAndConditions.hpp"
32 #include "CAMsg.hpp"
33 #include "CACmdLnOptions.hpp"
34 #include "CAUtil.hpp"
35 
45 {
46  if( (answer != NULL) )
47  {
48  if((answer->xmlAnswer != NULL))
49  {
50  answer->xmlAnswer->release();
51  answer->xmlAnswer = NULL;
52  }
53  answer->result = TC_UNFINISHED;
54  }
55 }
56 
58 {
59  if(tnCTranslation != NULL)
60  {
61  tnCTranslation->tnc_id = NULL;
62  tnCTranslation->tnc_template = NULL;
63  if(tnCTranslation->tnc_customized != NULL)
64  {
65  tnCTranslation->tnc_customized->release();
66  }
67  tnCTranslation->tnc_customized = NULL;
68  delete [] tnCTranslation->tnc_locale;
69  tnCTranslation->tnc_locale = NULL;
70  }
71 }
72 
77 {
79  /* The id of the Terms & Conditions is the operator ski. */
80  if(id != NULL)
81  {
82  size_t idlen = strlen((char *) id);
83  tnc_id = new UINT8[idlen+1];
84  memset(tnc_id, 0, (idlen+1));
85  memcpy(tnc_id, id, idlen);
86  }
87  else
88  {
89  tnc_id = NULL;
90  }
91 
92  translations = (nrOfTranslations == 0) ? 1 : nrOfTranslations;
95  for (UINT32 i = 0; i < translations; i++)
96  {
97  allTranslations[i] = NULL;
98  }
99  synchLock = new CAMutex();
100 }
101 
103 {
104  delete synchLock;
105  synchLock = NULL;
106  for (UINT32 i = 0; i < translations; i++)
107  {
108  if(allTranslations[i] != NULL)
109  {
111  delete allTranslations[i];
112  allTranslations[i] = NULL;
113  }
114  }
115  delete [] allTranslations;
116  allTranslations = NULL;
117  delete [] tnc_id;
118  tnc_id = NULL;
119  translations = 0;
121  customizedSectionsOwner->release();
123 }
124 
131 {
132  if(locale == NULL)
133  {
134  return NULL;
135  }
136  const termsAndConditionsTranslation_t *foundEntry = NULL;
137  for (UINT32 i = 0; i < translations; i++)
138  {
139  if(allTranslations[i] != NULL)
140  {
141  if( strncasecmp((const char *) locale, (char *) allTranslations[i]->tnc_locale, 2) == 0 )
142  {
143  foundEntry = allTranslations[i];
144  break;
145  }
146  }
147  }
148  return (const termsAndConditionsTranslation_t *) foundEntry;
149 }
150 
156 {
157  const termsAndConditionsTranslation_t *foundEntry = getTranslation(locale);
158  if(foundEntry != NULL)
159  {
160  return foundEntry->tnc_template;
161  }
162  return NULL;
163 }
164 
170 {
171  const termsAndConditionsTranslation_t *foundEntry = getTranslation(locale);
172  if(foundEntry != NULL)
173  {
174  return (const DOMNode *) foundEntry->tnc_customized;
175  }
176  return NULL;
177 }
178 
183 void TermsAndConditions::addTranslation(const UINT8* locale, DOMNode *tnc_customized, DOMNode *tnc_template)
184 {
185  if(locale == NULL)
186  {
187  return;
188  }
190  if(newEntry == NULL)
191  {
192  newEntry = new termsAndConditionsTranslation_t;
193  //import the customized sections to the internal T & C document to ensure it is not
194  //released by it's former owner document.
195  newEntry->tnc_customized = customizedSectionsOwner->importNode(tnc_customized, true);
196  newEntry->tnc_template = tnc_template;
197  newEntry->tnc_id = tnc_id;
198  newEntry->tnc_locale = new UINT8[TMP_LOCALE_SIZE];
199  memset(newEntry->tnc_locale, 0, TMP_LOCALE_SIZE);
200  memcpy(newEntry->tnc_locale, locale, TMP_LOCALE_SIZE);
201 
203  {
204  //allocate new storage space.
206  memset(newAllocatedSpace, 0, (sizeof(termsAndConditionsTranslation_t *)*(translations+RESIZE_STORE)) );
207  memcpy(newAllocatedSpace, allTranslations,
209  delete [] allTranslations;
210  allTranslations = newAllocatedSpace;
212  }
214  CAMsg::printMsg(LOG_DEBUG,"Adding translation [%s] for t&c %s to index %u\n", newEntry->tnc_locale, newEntry->tnc_id, currentTranslationIndex);
216  }
217  else
218  {
219  newEntry->tnc_customized->release();
220  //same as above: avoid release by the former owner document of this node.
221  newEntry->tnc_customized = customizedSectionsOwner->importNode(tnc_customized, true);
222  newEntry->tnc_template = tnc_template;
223  }
224 }
225 
231 {
232  for (UINT32 i = 0; i < translations; i++)
233  {
234  if(allTranslations[i] != NULL)
235  {
236  if( strncasecmp((const char *) locale, (char *) allTranslations[i]->tnc_locale, 2) == 0 )
237  {
239  delete allTranslations[i];
240  allTranslations[i] = NULL;
241  break;
242  }
243  }
244  }
246 }
247 
249 {
250  return (const UINT8 *) tnc_id;
251 }
252 
253 
255 {
256  for (UINT32 i = 0; i < translations; i++)
257  {
258  if(allTranslations[i] == NULL)
259  {
261  return;
262  }
263  }
264  /* Nothing is free */
266 }
267 #endif //ONLY_LOCAL_PROXY
268 
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
#define TMP_LOCALE_SIZE
Definition: CAUtil.hpp:39
void cleanupTnCTranslation(termsAndConditionsTranslation_t *tnCTranslation)
void cleanupTnCMixAnswer(termsAndConditionMixAnswer_t *answer)
IMPORTANT NOTE: all methods does NOT incorporate locking over the translation store and thus are NOT ...
@ TC_UNFINISHED
#define RESIZE_STORE
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
Definition: CAMsg.cpp:251
const DOMNode * getTranslationCustomizedSections(const UINT8 *locale)
returns only the customized sections of the translation specified by the language code or NULL if no ...
void removeTranslation(const UINT8 *locale)
removes the specific Terms & Conditions translation for the the language with the specified language ...
TermsAndConditions(UINT8 *id, UINT32 nrOfTranslations)
Constructor with the id (Operator SKI), the number of translations and those elements to be imported ...
const termsAndConditionsTranslation_t * getTranslation(const UINT8 *locale)
returns the specific TermsAndconditions translation for the the language with the specified language ...
XERCES_CPP_NAMESPACE::DOMDocument * customizedSectionsOwner
const DOMNode * getTranslationTemplate(const UINT8 *locale)
returns only the template of the translation specified by the language code or NULL if no such transl...
termsAndConditionsTranslation_t ** allTranslations
void addTranslation(const UINT8 *locale, DOMNode *tnc_customized, DOMNode *tnc_template)
add a language specific terms and Conditions document, which can be retrieved by *getTermsAndConditio...
XERCES_CPP_NAMESPACE::DOMDocument * xmlAnswer