1 #include "ace/Capabilities.h"
2 #include "ace/OS_NS_ctype.h"
3 #include "ace/OS_Memory.h"
4 #include "ace/OS_NS_string.h"
6 #if !defined (__ACE_INLINE__)
7 #include "ace/Capabilities.inl"
8 #endif /* !__ACE_INLINE__ */
10 #include "ace/OS_NS_stdio.h"
12 #define ACE_ESC ((ACE_TCHAR)0x1b)
14 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
16 ACE_CapEntry::~ACE_CapEntry (void)
20 ACE_Capabilities::ACE_Capabilities (void)
25 ACE_Capabilities::~ACE_Capabilities (void)
31 ACE_Capabilities::parse (const ACE_TCHAR
*buf
, ACE_TString
&cap
)
33 while (*buf
!= ACE_TEXT ('\0') && *buf
!= ACE_TEXT (','))
35 if (*buf
== ACE_TEXT ('\\'))
38 if (*buf
== ACE_TEXT ('E') || *buf
== ACE_TEXT ('e'))
44 else if (*buf
== ACE_TEXT ('r'))
46 cap
+= ACE_TEXT ('\r');
50 else if (*buf
== ACE_TEXT ('n'))
52 cap
+= ACE_TEXT ('\n');
56 else if (*buf
== ACE_TEXT ('t'))
58 cap
+= ACE_TEXT ('\t');
62 else if (*buf
== ACE_TEXT ('\\'))
67 if (ACE_OS::ace_isdigit(*buf
))
69 // @@ UNICODE Does this work with unicode?
72 i
< 3 && *buf
&& ACE_OS::ace_isdigit (*buf
);
74 oc
= oc
* 8 + (*buf
++ - ACE_TEXT ('0'));
76 cap
+= (ACE_TCHAR
) oc
;
86 ACE_Capabilities::parse (const ACE_TCHAR
*buf
, int &cap
)
90 while (*buf
&& ACE_OS::ace_isdigit (*buf
))
91 n
= n
* 10 + (*buf
++ - ACE_TEXT ('0'));
99 ACE_Capabilities::resetcaps (void)
101 for (CAPABILITIES_MAP::ITERATOR
iter (this->caps_
);
105 CAPABILITIES_MAP::ENTRY
*entry
= 0;
107 delete entry
->int_id_
;
110 this->caps_
.close ();
115 ACE_Capabilities::fillent (const ACE_TCHAR
*buf
)
126 while (*buf
&& ACE_OS::ace_isspace(*buf
)) buf
++;
127 // If we get end of line return
129 if (*buf
== ACE_TEXT ('\0'))
132 if (*buf
== ACE_TEXT ('#'))
134 while (*buf
&& *buf
!= ACE_TEXT ('\n'))
136 if (*buf
== ACE_TEXT ('\n'))
140 while(*buf
&& *buf
!= ACE_TEXT ('=')
141 && *buf
!= ACE_TEXT ('#')
142 && *buf
!= ACE_TEXT (','))
150 buf
= this->parse (buf
+ 1, s
);
152 ACE_StringCapEntry (s
),
154 if (this->caps_
.bind (name
, ce
) == -1)
162 buf
= this->parse (buf
+ 1, n
);
166 if (this->caps_
.bind (name
, ce
) == -1)
175 ACE_BoolCapEntry (1),
177 if (this->caps_
.bind (name
, ce
) == -1)
187 if (*buf
++ != ACE_TEXT (','))
195 ACE_Capabilities::is_entry (const ACE_TCHAR
*name
, const ACE_TCHAR
*line
)
199 // Skip blanks or irrelevant characters
200 while (*line
&& ACE_OS::ace_isspace(*line
))
203 // End of line reached
204 if (*line
== ACE_TEXT ('\0'))
207 // Build the entry name
208 ACE_TString nextname
;
209 while (*line
&& *line
!= ACE_TEXT ('|') && *line
!= ACE_TEXT (','))
212 // We have found the required entry?
213 if (ACE_OS::strcmp (nextname
.c_str (), name
) == 0)
216 // Skip puntuaction char if neccesary.
217 if (*line
== ACE_TEXT ('|') || *line
== ACE_TEXT (','))
221 ACELIB_DEBUG ((LM_DEBUG
,
222 ACE_TEXT ("Invalid entry\n")));
230 ACE_Capabilities::getline (FILE *fp
, ACE_TString
&line
)
236 while ((ch
= ACE_OS::fgetc (fp
)) != EOF
&& ch
!= ACE_TEXT ('\n'))
237 line
+= (ACE_TCHAR
) ch
;
239 if (ch
== EOF
&& line
.length () == 0)
246 ACE_Capabilities::getval (const ACE_TCHAR
*keyname
, ACE_TString
&val
)
248 ACE_CapEntry
* cap
= 0;
249 if (this->caps_
.find (keyname
, cap
) == -1)
252 ACE_StringCapEntry
*scap
=
253 dynamic_cast<ACE_StringCapEntry
*> (cap
);
257 val
= scap
->getval ();
262 ACE_Capabilities::getval (const ACE_TCHAR
*keyname
, int &val
)
264 ACE_CapEntry
*cap
= 0;
265 if (this->caps_
.find (keyname
, cap
) == -1)
268 ACE_IntCapEntry
*icap
=
269 dynamic_cast<ACE_IntCapEntry
*> (cap
);
272 val
= icap
->getval ();
276 ACE_BoolCapEntry
*bcap
=
277 dynamic_cast<ACE_BoolCapEntry
*> (cap
);
282 val
= bcap
->getval ();
287 is_empty (const ACE_TCHAR
*line
)
289 while (*line
&& ACE_OS::ace_isspace (*line
))
292 return *line
== ACE_TEXT ('\0') || *line
== ACE_TEXT ('#');
296 is_line (const ACE_TCHAR
*line
)
298 while (*line
&& ACE_OS::ace_isspace (*line
))
301 return *line
!= ACE_TEXT ('\0');
305 ACE_Capabilities::getent (const ACE_TCHAR
*fname
, const ACE_TCHAR
*name
)
307 FILE *fp
= ACE_OS::fopen (fname
, ACE_TEXT ("r"));
310 ACELIB_ERROR_RETURN ((LM_ERROR
,
311 ACE_TEXT ("Can't open %s file\n"),
318 while (0 == (done
= (this->getline (fp
, line
) == -1))
319 && is_empty (line
.c_str ()))
325 ACE_TString description
;
327 while (0 == (done
= (this->getline (fp
, newline
) == -1)))
328 if (is_line (newline
.c_str ()))
329 description
+= newline
;
333 if (this->is_entry (name
, line
.c_str()))
336 return this->fillent (description
.c_str ());
340 while (!done
&& is_empty (line
.c_str ()))
341 done
= this->getline (fp
, line
) == -1;
348 ACE_ALLOC_HOOK_DEFINE(ACE_StringCapEntry
)
349 ACE_ALLOC_HOOK_DEFINE(ACE_IntCapEntry
)
350 ACE_ALLOC_HOOK_DEFINE(ACE_BoolCapEntry
)
352 ACE_END_VERSIONED_NAMESPACE_DECL