1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     ngc_ProfanityFilter.h
4 
5   Copyright (C)2009-2012 Nintendo Co., Ltd.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Rev: 47308 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NN_NGC_CTR_NGC_PROFANITY_FILTER_H_
17 #define NN_NGC_CTR_NGC_PROFANITY_FILTER_H_
18 
19 #include <nn/os.h>
20 
21 #if !defined( NN_NGC_CTR_NGC_PROFANITY_FILTER_PATTERN_LIST_H_ ) || !defined( NN_NGC_CTR_NGC_PROFANITY_FILTER_BASE_H_ )
22 #   error include error
23 #endif
24 
25 namespace nn
26 {
27 
28 namespace fs
29 {
30     class FileInputStream;
31 }   // namespace fs
32 
33 namespace ngc
34 {
35 namespace CTR
36 {
37 
38 /* Please see man pages for details
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56  */
57 #pragma push
58 #pragma diag_suppress 2530
59 class ProfanityFilter : public ProfanityFilterBase
60 {
61 public:
62 
63     /* Please see man pages for details
64 
65 
66 
67      */
68     explicit ProfanityFilter();
69 
70     /* Please see man pages for details
71 
72 
73 
74 
75      */
76     explicit ProfanityFilter( const nn::WithInitialize& );
77 
78 
79     /* Please see man pages for details
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90      */
ProfanityFilter(uptr pWorkMemory)91     explicit ProfanityFilter( uptr pWorkMemory ) { Initialize( pWorkMemory ); }
92 
93     /* Please see man pages for details
94 
95 
96 
97      */
~ProfanityFilter()98     virtual ~ProfanityFilter(){ Finalize(); }
99 
100     /* Please see man pages for details
101 
102 
103 
104 
105      */
106     nn::Result Initialize();
107 
108     /* Please see man pages for details
109 
110 
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 
121      */
122     nn::Result Initialize( uptr pWorkMemory );
123 
124     void SkipAtSignCheck( bool bSkipChecking );
125 
126     /* Please see man pages for details
127 
128 
129 
130 
131 
132      */
133     nn::Result Finalize();
134 
135     /* Please see man pages for details
136 
137 
138      */
139     virtual u32 GetContentVersion();
140 
141     /* Please see man pages for details
142 
143 
144 
145 
146 
147 
148 
149 
150 
151 
152 
153 
154 
155 
156 
157 
158 
159 
160 
161 
162 
163 
164 
165 
166 
167 
168 
169 
170      */
171     virtual nn::Result CheckProfanityWords( bit32* pCheckResults, const wchar_t** ppWords, size_t nWordCount );
172 
173     /* Please see man pages for details
174 
175 
176 
177 
178 
179 
180 
181 
182 
183 
184 
185 
186 
187 
188 
189 
190 
191 
192 
193 
194 
195 
196 
197 
198 
199 
200 
201 
202      */
203     virtual nn::Result CheckProfanityWords( bit32* pCheckResults, ProfanityFilterPatternList nPatternCode, const wchar_t** ppWords, size_t nWordCount );
204 
205     /* Please see man pages for details
206 
207 
208 
209 
210 
211 
212 
213 
214 
215 
216 
217 
218 
219 
220 
221 
222 
223 
224 
225 
226 
227 
228 
229 
230 
231 
232 
233 
234 
235 
236 
237      */
238     virtual nn::Result CheckProfanityWords( bit32* pCheckResults, bool bCommunicateWithOtherRegions, const wchar_t** ppWords, size_t nWordCount );
239 
240     /* Please see man pages for details
241 
242 
243 
244 
245 
246 
247 
248 
249 
250 
251 
252 
253 
254 
255 
256 
257 
258 
259      */
260     void SetMaskMode( bool bOverWrite );
261 
262     /* Please see man pages for details
263 
264 
265 
266 
267 
268 
269 
270 
271 
272 
273 
274 
275 
276 
277 
278 
279 
280 
281 
282 
283 
284 
285      */
286     virtual nn::Result MaskProfanityWordsInText( int* pProfanityWordCount, wchar_t* pText );
287 
288     /* Please see man pages for details
289 
290 
291 
292 
293 
294 
295 
296 
297 
298 
299 
300 
301 
302 
303 
304 
305 
306 
307 
308 
309 
310 
311 
312      */
313     virtual nn::Result MaskProfanityWordsInText( int* pProfanityWordCount, ProfanityFilterPatternList nPatternCode, wchar_t* pText );
314 
315     /* Please see man pages for details
316 
317 
318 
319 
320 
321 
322 
323 
324 
325 
326 
327 
328 
329 
330 
331 
332 
333 
334 
335 
336 
337      */
338     virtual nn::Result MaskProfanityWordsInText( int* pProfanityWordCount, bool bCommunicateWithOtherRegions, wchar_t* pText );
339 
340 public:
341     /* Please see man pages for details
342 
343      */
344     enum
345     {
346         //
347         WORKMEMORY_SIZE = 64 * 1024
348     };
349 
350 private:
351     void CleanUpVariables();
352     void SetupMemoryArea();
353     nn::Result MountSharedContents();
354 
355     nn::Result CheckArguments_Word( const bit32* pCheckResults, const wchar_t** ppWords, size_t nWordCount ) const;
356     nn::Result CheckProfanityWords_Impl( bit32* pCheckResults, nn::fs::FileInputStream* pFileStream, const wchar_t** ppWords, size_t nWordCount );
357     void CheckWords( bit32* pCheckResults, const wchar_t *pPattern, size_t nLength, wchar_t* const* ppConvertedWords, size_t nWordCount );
358 
359     nn::Result CheckArguments_Text( const wchar_t* pText ) const;
360     nn::Result MaskProfanityWordsInText_Impl( int* pProfanityWordCount, wchar_t* pUserInput, wchar_t* pConvertedUserInput, u8* pMapping, nn::fs::FileInputStream* pFileStream );
361     void MaskText( int* pProfanityWordCount, wchar_t* pUserInput, wchar_t* pConvertedUserInput, u8* pMapping, const wchar_t* pPattern, bool bIgnoreSpace );
362 
363 private:
364     //
365     nn::os::MemoryBlock m_MemoryBlock;
366 
367     //
368     bool m_bIsUsingMemoryBlock;
369 
370     //
371     bool m_bContentMounted;
372 
373     //
374     bool m_bSkipAtSignCheck;
375 
376     //
377     ProfanityFilterPatternList m_nPatternList;
378 
379     //
380     uptr m_pWorkingHead;
381 
382     //
383     uptr m_pTempPoolHead;
384 
385     //
386     uptr m_pPatternsHead;
387 
388     //
389     uptr m_pMountWorkingArea;
390 
391     //
392     uptr m_pUserArea;
393 
394     //
395     bool m_bMaskOverWrite;
396 };
397 #pragma diag_default 2530
398 #pragma pop
399 
400 }   // namespace CTR
401 }   // namespaec ngc
402 }   // namespace nn
403 
404 #endif // NN_NGC_CTR_NGC_PROFANITY_FILTER_H_
405