Gearman Developer Documentation

libgearman/gearman.c
Go to the documentation of this file.
00001 /* Gearman server and library
00002  * Copyright (C) 2008 Brian Aker, Eric Day
00003  * All rights reserved.
00004  *
00005  * Use and distribution licensed under the BSD license.  See
00006  * the COPYING file in the parent directory for full text.
00007  */
00008 
00014 #include "common.h"
00015 
00025 static const char *_verbose_name[GEARMAN_VERBOSE_MAX]=
00026 {
00027   "NEVER",
00028   "FATAL",
00029   "ERROR",
00030   "INFO",
00031   "DEBUG",
00032   "CRAZY"
00033 };
00034 
00037 /*
00038  * Public Definitions
00039  */
00040 
00041 const char *gearman_version(void)
00042 {
00043     return PACKAGE_VERSION;
00044 }
00045 
00046 const char *gearman_bugreport(void)
00047 {
00048     return PACKAGE_BUGREPORT;
00049 }
00050 
00051 const char *gearman_verbose_name(gearman_verbose_t verbose)
00052 {
00053   if (verbose >= GEARMAN_VERBOSE_MAX)
00054     return "UNKNOWN";
00055 
00056   return _verbose_name[verbose];
00057 }
00058 
00059 gearman_return_t gearman_parse_servers(const char *servers,
00060                                        gearman_parse_server_fn *function,
00061                                        void *context)
00062 {
00063   const char *ptr= servers;
00064   size_t x;
00065   char host[NI_MAXHOST];
00066   char port[NI_MAXSERV];
00067   gearman_return_t ret;
00068 
00069   if (ptr == NULL)
00070     return (*function)(NULL, 0, (void *)context);
00071 
00072   while (1)
00073   {
00074     x= 0;
00075 
00076     while (*ptr != 0 && *ptr != ',' && *ptr != ':')
00077     {
00078       if (x < (NI_MAXHOST - 1))
00079         host[x++]= *ptr;
00080 
00081       ptr++;
00082     }
00083 
00084     host[x]= 0;
00085 
00086     if (*ptr == ':')
00087     {
00088       ptr++;
00089       x= 0;
00090 
00091       while (*ptr != 0 && *ptr != ',')
00092       {
00093         if (x < (NI_MAXSERV - 1))
00094           port[x++]= *ptr;
00095 
00096         ptr++;
00097       }
00098 
00099       port[x]= 0;
00100     }
00101     else
00102       port[0]= 0;
00103 
00104     ret= (*function)(host, (in_port_t)atoi(port), (void *)context);
00105     if (ret != GEARMAN_SUCCESS)
00106       return ret;
00107 
00108     if (*ptr == 0)
00109       break;
00110 
00111     ptr++;
00112   }
00113 
00114   return GEARMAN_SUCCESS;
00115 }