2121#include <stumpless/facility.h>
2222#include "private/facility.h"
2323#include "private/strhelper.h"
24+ #include "private/error.h"
2425
2526static char * facility_enum_to_string [] = {
2627 STUMPLESS_FOREACH_FACILITY ( GENERATE_STRING )
@@ -29,44 +30,58 @@ static char *facility_enum_to_string[] = {
2930const char *
3031stumpless_get_facility_string ( enum stumpless_facility facility ) {
3132 if ( !facility_is_invalid ( facility ) ) {
33+ clear_error ();
3234 return facility_enum_to_string [facility >> 3 ];
3335 }
34- return "NO_SUCH_FACILITY" ;
35- }
3636
37- enum stumpless_facility
38- stumpless_get_facility_enum ( const char * facility_string ) {
39- return stumpless_get_facility_enum_from_buffer (facility_string , strlen (facility_string ));
37+ raise_error ( STUMPLESS_INVALID_FACILITY , "invalid facility enum" , 0 , NULL );
38+ return "NO_SUCH_FACILITY" ;
4039}
4140
4241enum stumpless_facility
43- stumpless_get_facility_enum_from_buffer (const char * facility_buffer , size_t facility_buffer_length ) {
44- size_t facility_bound ;
45- size_t i ;
46- const int str_offset = 19 ; // to ommit "STUMPLESS_FACILITY_"
42+ stumpless_get_facility_enum_from_buffer ( const char * facility_buffer , size_t facility_buffer_length ) {
43+ size_t facility_bound ;
44+ size_t i ;
45+ const int str_offset = 19 ; // to ommit "STUMPLESS_FACILITY_"
4746
48- facility_bound = sizeof ( facility_enum_to_string ) /
49- sizeof ( facility_enum_to_string [0 ] );
47+ facility_bound = sizeof ( facility_enum_to_string ) /
48+ sizeof ( facility_enum_to_string [0 ] );
5049
51- for ( i = 0 ; i < facility_bound ; i ++ ) {
52- if ( strncasecmp_custom ( facility_buffer , facility_enum_to_string [i ] + str_offset , facility_buffer_length ) == 0 ) {
53- return i << 3 ;
50+ for ( i = 0 ; i < facility_bound ; i ++ ) {
51+ if ( strncasecmp_custom ( facility_buffer , facility_enum_to_string [i ] + str_offset , facility_buffer_length ) == 0 ) {
52+ clear_error ();
53+ return i << 3 ;
54+ }
5455 }
55- }
5656
57- // exeption, for 'security' return 'auth' enum value
5857 if ( strncasecmp_custom ( facility_buffer , "SECURITY" , facility_buffer_length ) == 0 ) {
59- return STUMPLESS_FACILITY_AUTH_VALUE ;
60- }
58+ clear_error ();
59+ return STUMPLESS_FACILITY_AUTH_VALUE ;
60+ }
6161
62- // exeption, for 'authpriv' not presented in enum list
6362 if ( strncasecmp_custom ( facility_buffer , "AUTHPRIV" , facility_buffer_length ) == 0 ) {
64- return STUMPLESS_FACILITY_AUTH2_VALUE ;
65- }
63+ clear_error ();
64+ return STUMPLESS_FACILITY_AUTH2_VALUE ;
65+ }
66+
67+ raise_error ( STUMPLESS_INVALID_FACILITY , "invalid facility string" , 0 , NULL );
68+ return -1 ;
69+ }
70+
71+ enum stumpless_facility
72+ stumpless_get_facility_enum ( const char * facility_string ) {
73+ enum stumpless_facility result = stumpless_get_facility_enum_from_buffer (
74+ facility_string , strlen ( facility_string ) );
6675
67- return -1 ;
76+ if ( result != -1 ) {
77+ clear_error ();
78+ }
79+
80+ return result ;
6881}
6982
83+
84+
7085/* private functions */
7186
7287int
0 commit comments