nanohttp-error.c

Go to the documentation of this file.
00001 /******************************************************************
00002 *  $Id: nanohttp-error.c,v 1.1 2006/12/09 09:36:57 m0gg Exp $
00003 *
00004 * CSOAP Project:  A http client/server library in C
00005 * Copyright (C) 2003  Ferhat Ayaz
00006 *
00007 * This library is free software; you can redistribute it and/or
00008 * modify it under the terms of the GNU Library General Public
00009 * License as published by the Free Software Foundation; either
00010 * version 2 of the License, or (at your option) any later version.
00011 *
00012 * This library is distributed in the hope that it will be useful,
00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 * Library General Public License for more details.
00016 *
00017 * You should have received a copy of the GNU Library General Public
00018 * License along with this library; if not, write to the
00019 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00020 * Boston, MA  02111-1307, USA.
00021 *
00022 * Email: ayaz@jprogrammer.net
00023 ******************************************************************/
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027 
00028 #ifdef HAVE_STDLIB_H
00029 #include <stdlib.h>
00030 #endif
00031 
00032 #ifdef HAVE_STDIO_H
00033 #include <stdio.h>
00034 #endif
00035 
00036 #ifdef HAVE_STDARG_H
00037 #include <stdarg.h>
00038 #endif
00039 
00040 #ifdef HAVE_STRING_H
00041 #include <string.h>
00042 #endif
00043 
00044 #ifdef HAVE_ERRNO_H
00045 #include <errno.h>
00046 #endif
00047 
00048 #include "nanohttp-logging.h"
00049 #include "nanohttp-error.h"
00050 
00051 typedef struct _herror_impl_t
00052 {
00053   int errcode;
00054   char message[250];
00055   char *func;
00056 } herror_impl_t;
00057 
00058 herror_t
00059 herror_new(const char *func, int errcode, const char *format, ...)
00060 {
00061   va_list ap;
00062   herror_impl_t *impl;
00063  
00064   if (!(impl = (herror_impl_t *) malloc(sizeof(herror_impl_t))))
00065   {
00066     log_error2("malloc failed (%s)", strerror(errno));
00067     return NULL;
00068   }
00069 
00070   impl->errcode = errcode;
00071 
00072   if (func)
00073     impl->func = strdup(func);
00074   else
00075     func = NULL;
00076 
00077   va_start(ap, format);
00078   vsprintf(impl->message, format, ap);
00079   va_end(ap);
00080 
00081   return (herror_t) impl;
00082 }
00083 
00084 int
00085 herror_code(herror_t err)
00086 {
00087   herror_impl_t *impl = (herror_impl_t *) err;
00088 
00089   if (!err)
00090     return H_OK;
00091 
00092   return impl->errcode;
00093 }
00094 
00095 const char *
00096 herror_func(herror_t err)
00097 {
00098   herror_impl_t *impl = (herror_impl_t *) err;
00099 
00100   if (!err)
00101     return "";
00102 
00103   return impl->func;
00104 }
00105 
00106 const char *
00107 herror_message(herror_t err)
00108 {
00109   herror_impl_t *impl = (herror_impl_t *) err;
00110 
00111   if (!err)
00112     return "";
00113 
00114   return impl->message;
00115 }
00116 
00117 void
00118 herror_release(herror_t err)
00119 {
00120   herror_impl_t *impl = (herror_impl_t *) err;
00121 
00122   if (!err)
00123     return;
00124 
00125   if (impl->func)
00126     free(impl->func);
00127 
00128   free(impl);
00129 
00130   return;
00131 }

Generated on Thu Jan 25 23:36:02 2007 for csoap by  doxygen 1.4.6