"Fossies" - the Fresh Open Source Software Archive

Member "amavisd-milter-1.7.2/amavisd-milter/log.c" (27 Jan 2019, 2937 Bytes) of package /linux/privat/amavisd-milter-1.7.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "log.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (c) 2005, Petr Rehor <rx@rx.cz>. All rights reserved.
    3  *
    4  * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions
    6  * are met:
    7  * 1. Redistributions of source code must retain the above copyright
    8  *    notice, this list of conditions and the following disclaimer.
    9  * 2. Redistributions in binary form must reproduce the above copyright
   10  *    notice, this list of conditions and the following disclaimer in the
   11  *    documentation and/or other materials provided with the distribution.
   12  * 3. Neither the name of the copyright holders nor the names of its
   13  *    contributors may be used to endorse or promote products derived from
   14  *    this software without specific prior written permission.
   15  *
   16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
   20  * OWNERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
   22  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
   23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
   24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   27  */
   28 
   29 #include "amavisd-milter.h"
   30 
   31 #include <stdarg.h>
   32 
   33 
   34 /*
   35 ** LOGMSG - Print log message
   36 */
   37 void
   38 logmsg(int priority, const char *fmt, ...)
   39 {
   40     char        buf[MAXLOGBUF];
   41     va_list     ap;
   42 
   43     if (priority <= debug_level || priority <= LOG_WARNING) {
   44 
   45         /* Format message */
   46         va_start(ap, fmt);
   47         (void) vsnprintf(buf, sizeof(buf), fmt, ap);
   48         va_end(ap);
   49 
   50         /* Write message to syslog */
   51         syslog(priority, "%s", buf);
   52 
   53         /* Print message to terminal */
   54         if (!daemonized) {
   55             (void) fprintf(stdout, "%s\n", buf);
   56         }
   57     }
   58 }
   59 
   60 
   61 /*
   62 ** LOGQIDMSG - Log message with mail queue id
   63 */
   64 void
   65 logqidmsg(struct mlfiCtx *mlfi, int priority, const char *fmt, ...)
   66 {
   67     char        buf[MAXLOGBUF];
   68     const char *p;
   69     va_list     ap;
   70 
   71     /* Format message */
   72     va_start(ap, fmt);
   73     (void) vsnprintf(buf, sizeof(buf), fmt, ap);
   74     va_end(ap);
   75 
   76     /* Print log message */
   77     if (mlfi != NULL) {
   78         if (mlfi->mlfi_qid != NULL) {
   79             p = mlfi->mlfi_qid;
   80         } else if (mlfi->mlfi_prev_qid != NULL) {
   81             p = mlfi->mlfi_prev_qid;
   82         } else if (mlfi->mlfi_client_host != NULL) {
   83             p = mlfi->mlfi_client_host;
   84         } else {
   85             p = "UNKNOWN";
   86         }
   87     } else {
   88         p = "NOQUEUE";
   89     }
   90     logmsg(priority, "%s: %s", p, buf);
   91 }