• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

ink_syslog.cc

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 /***************************************/
00025 /****************************************************************************
00026  *
00027  *  ink_syslog.cc
00028  *
00029  *
00030  ****************************************************************************/
00031 #include "libts.h"
00032 
00033 struct syslog_fac
00034 {
00035   char *long_str;
00036   char *short_str;
00037   int fac_int;
00038 };
00039 
00040 static const syslog_fac convert_table[] = {
00041   {(char *) "LOG_KERN", (char *) "KERN", LOG_KERN},
00042   {(char *) "LOG_USER", (char *) "USER", LOG_USER},
00043   {(char *) "LOG_MAIL", (char *) "MAIL", LOG_MAIL},
00044   {(char *) "LOG_DAEMON", (char *) "DAEMON", LOG_DAEMON},
00045   {(char *) "LOG_AUTH", (char *) "AUTH", LOG_AUTH},
00046   {(char *) "LOG_LPR", (char *) "LPR", LOG_LPR},
00047   {(char *) "LOG_NEWS", (char *) "NEWS", LOG_NEWS},
00048   {(char *) "LOG_UUCP", (char *) "UUCP", LOG_UUCP},
00049   {(char *) "LOG_CRON", (char *) "CRON", LOG_CRON},
00050   {(char *) "LOG_LOCAL0", (char *) "LOCAL0", LOG_LOCAL0},
00051   {(char *) "LOG_LOCAL1", (char *) "LOCAL1", LOG_LOCAL1},
00052   {(char *) "LOG_LOCAL2", (char *) "LOCAL2", LOG_LOCAL2},
00053   {(char *) "LOG_LOCAL3", (char *) "LOCAL3", LOG_LOCAL3},
00054   {(char *) "LOG_LOCAL4", (char *) "LOCAL4", LOG_LOCAL4},
00055   {(char *) "LOG_LOCAL5", (char *) "LOCAL5", LOG_LOCAL5},
00056   {(char *) "LOG_LOCAL6", (char *) "LOCAL6", LOG_LOCAL6},
00057   {(char *) "LOG_LOCAL7", (char *) "LOCAL7", LOG_LOCAL7},
00058   {(char *) "INVALID_LOG_FAC", (char *) "INVALID", -1}
00059 };
00060 static const int convert_table_size = sizeof(convert_table) / sizeof(syslog_fac) - 1;
00061 
00062 // int facility_string_to_int(const char* str)
00063 //   Converts a string for a syslog to an int for that
00064 //    facility, suitable for passing to openlog()
00065 //
00066 //   If the string can not be converted, returns
00067 //    a negative value
00068 //
00069 int
00070 facility_string_to_int(const char *str)
00071 {
00072 
00073   if (str == NULL) {
00074     return -1;
00075   }
00076   // Loop Through to see if the string has a valid conversion
00077   for (int i = 0; i < convert_table_size; i++) {
00078     if (strcasecmp(convert_table[i].long_str, str) == 0 || strcasecmp(convert_table[i].short_str, str) == 0) {
00079       return convert_table[i].fac_int;
00080     }
00081 
00082   }
00083   return -1;
00084 }

Generated by  doxygen 1.7.1