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_Capabilities::ACE_Capabilities ()
21 ACE_Capabilities::~ACE_Capabilities ()
27 ACE_Capabilities::parse (const ACE_TCHAR
*buf
, ACE_TString
&cap
)
29 while (*buf
!= ACE_TEXT ('\0') && *buf
!= ACE_TEXT (','))
31 if (*buf
== ACE_TEXT ('\\'))
34 if (*buf
== ACE_TEXT ('E') || *buf
== ACE_TEXT ('e'))
40 else if (*buf
== ACE_TEXT ('r'))
42 cap
+= ACE_TEXT ('\r');
46 else if (*buf
== ACE_TEXT ('n'))
48 cap
+= ACE_TEXT ('\n');
52 else if (*buf
== ACE_TEXT ('t'))
54 cap
+= ACE_TEXT ('\t');
58 else if (*buf
== ACE_TEXT ('\\'))
63 if (ACE_OS::ace_isdigit(*buf
))
65 // @@ UNICODE Does this work with unicode?
68 i
< 3 && *buf
&& ACE_OS::ace_isdigit (*buf
);
70 oc
= oc
* 8 + (*buf
++ - ACE_TEXT ('0'));
72 cap
+= (ACE_TCHAR
) oc
;
82 ACE_Capabilities::parse (const ACE_TCHAR
*buf
, int &cap
)
86 while (*buf
&& ACE_OS::ace_isdigit (*buf
))
87 n
= n
* 10 + (*buf
++ - ACE_TEXT ('0'));
95 ACE_Capabilities::resetcaps ()
97 for (CAPABILITIES_MAP::ITERATOR
iter (this->caps_
);
101 CAPABILITIES_MAP::ENTRY
*entry
= 0;
103 delete entry
->int_id_
;
106 this->caps_
.close ();
111 ACE_Capabilities::fillent (const ACE_TCHAR
*buf
)
122 while (*buf
&& ACE_OS::ace_isspace(*buf
)) buf
++;
123 // If we get end of line return
125 if (*buf
== ACE_TEXT ('\0'))
128 if (*buf
== ACE_TEXT ('#'))
130 while (*buf
&& *buf
!= ACE_TEXT ('\n'))
132 if (*buf
== ACE_TEXT ('\n'))
136 while(*buf
&& *buf
!= ACE_TEXT ('=')
137 && *buf
!= ACE_TEXT ('#')
138 && *buf
!= ACE_TEXT (','))
146 buf
= this->parse (buf
+ 1, s
);
148 ACE_StringCapEntry (s
),
150 if (this->caps_
.bind (name
, ce
) == -1)
158 buf
= this->parse (buf
+ 1, n
);
162 if (this->caps_
.bind (name
, ce
) == -1)
171 ACE_BoolCapEntry (1),
173 if (this->caps_
.bind (name
, ce
) == -1)
183 if (*buf
++ != ACE_TEXT (','))
191 ACE_Capabilities::is_entry (const ACE_TCHAR
*name
, const ACE_TCHAR
*line
)
195 // Skip blanks or irrelevant characters
196 while (*line
&& ACE_OS::ace_isspace(*line
))
199 // End of line reached
200 if (*line
== ACE_TEXT ('\0'))
203 // Build the entry name
204 ACE_TString nextname
;
205 while (*line
&& *line
!= ACE_TEXT ('|') && *line
!= ACE_TEXT (','))
208 // We have found the required entry?
209 if (ACE_OS::strcmp (nextname
.c_str (), name
) == 0)
212 // Skip puntuaction char if neccesary.
213 if (*line
== ACE_TEXT ('|') || *line
== ACE_TEXT (','))
217 ACELIB_DEBUG ((LM_DEBUG
,
218 ACE_TEXT ("Invalid entry\n")));
226 ACE_Capabilities::getline (FILE *fp
, ACE_TString
&line
)
232 while ((ch
= ACE_OS::fgetc (fp
)) != EOF
&& ch
!= ACE_TEXT ('\n'))
233 line
+= (ACE_TCHAR
) ch
;
235 if (ch
== EOF
&& line
.length () == 0)
242 ACE_Capabilities::getval (const ACE_TCHAR
*keyname
, ACE_TString
&val
)
244 ACE_CapEntry
* cap
= 0;
245 if (this->caps_
.find (keyname
, cap
) == -1)
248 ACE_StringCapEntry
*scap
=
249 dynamic_cast<ACE_StringCapEntry
*> (cap
);
253 val
= scap
->getval ();
258 ACE_Capabilities::getval (const ACE_TCHAR
*keyname
, int &val
)
260 ACE_CapEntry
*cap
= 0;
261 if (this->caps_
.find (keyname
, cap
) == -1)
264 ACE_IntCapEntry
*icap
=
265 dynamic_cast<ACE_IntCapEntry
*> (cap
);
268 val
= icap
->getval ();
272 ACE_BoolCapEntry
*bcap
=
273 dynamic_cast<ACE_BoolCapEntry
*> (cap
);
278 val
= bcap
->getval ();
283 is_empty (const ACE_TCHAR
*line
)
285 while (*line
&& ACE_OS::ace_isspace (*line
))
288 return *line
== ACE_TEXT ('\0') || *line
== ACE_TEXT ('#');
292 is_line (const ACE_TCHAR
*line
)
294 while (*line
&& ACE_OS::ace_isspace (*line
))
297 return *line
!= ACE_TEXT ('\0');
301 ACE_Capabilities::getent (const ACE_TCHAR
*fname
, const ACE_TCHAR
*name
)
303 FILE *fp
= ACE_OS::fopen (fname
, ACE_TEXT ("r"));
306 ACELIB_ERROR_RETURN ((LM_ERROR
,
307 ACE_TEXT ("Can't open %s file\n"),
314 while (0 == (done
= (this->getline (fp
, line
) == -1))
315 && is_empty (line
.c_str ()))
321 ACE_TString description
;
323 while (0 == (done
= (this->getline (fp
, newline
) == -1)))
324 if (is_line (newline
.c_str ()))
325 description
+= newline
;
329 if (this->is_entry (name
, line
.c_str()))
332 return this->fillent (description
.c_str ());
336 while (!done
&& is_empty (line
.c_str ()))
337 done
= this->getline (fp
, line
) == -1;
344 ACE_ALLOC_HOOK_DEFINE(ACE_StringCapEntry
)
345 ACE_ALLOC_HOOK_DEFINE(ACE_IntCapEntry
)
346 ACE_ALLOC_HOOK_DEFINE(ACE_BoolCapEntry
)
348 ACE_END_VERSIONED_NAMESPACE_DECL