Drizzled Public API Documentation

conn_uds.cc
Go to the documentation of this file.
00001 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00002  *
00003  * Drizzle Client & Protocol Library
00004  *
00005  * Copyright (C) 2008 Eric Day (eday@oddments.org)
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are
00010  * met:
00011  *
00012  *     * Redistributions of source code must retain the above copyright
00013  * notice, this list of conditions and the following disclaimer.
00014  *
00015  *     * Redistributions in binary form must reproduce the above
00016  * copyright notice, this list of conditions and the following disclaimer
00017  * in the documentation and/or other materials provided with the
00018  * distribution.
00019  *
00020  *     * The names of its contributors may not be used to endorse or
00021  * promote products derived from this software without specific prior
00022  * written permission.
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00026  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00027  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00028  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00029  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00030  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00031  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00032  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00033  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00034  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  */
00037 
00043 #include <libdrizzle/common.h>
00044 
00045 const char *drizzle_con_uds(const drizzle_con_st *con)
00046 {
00047   if (con == NULL)
00048   {
00049     return NULL;
00050   }
00051 
00052   if (con->socket_type == DRIZZLE_CON_SOCKET_UDS)
00053   {
00054     if (con->socket.uds.sockaddr.sun_path[0] != 0)
00055       return con->socket.uds.sockaddr.sun_path;
00056 
00057     if (con->options & DRIZZLE_CON_MYSQL)
00058       return DRIZZLE_DEFAULT_UDS_MYSQL;
00059 
00060     return DRIZZLE_DEFAULT_UDS;
00061   }
00062 
00063   return NULL;
00064 }
00065 
00066 void drizzle_con_set_uds(drizzle_con_st *con, const char *uds)
00067 {
00068   if (con == NULL)
00069   {
00070     return;
00071   }
00072 
00073   drizzle_con_reset_addrinfo(con);
00074 
00075   con->socket_type= DRIZZLE_CON_SOCKET_UDS;
00076 
00077   if (uds == NULL)
00078   {
00079     uds= "";
00080   }
00081 
00082   con->socket.uds.sockaddr.sun_family= AF_UNIX;
00083   strncpy(con->socket.uds.sockaddr.sun_path, uds,
00084           sizeof(con->socket.uds.sockaddr.sun_path));
00085   con->socket.uds.sockaddr.sun_path[sizeof(con->socket.uds.sockaddr.sun_path) - 1]= 0;
00086 
00087   con->socket.uds.addrinfo.ai_family= AF_UNIX;
00088   con->socket.uds.addrinfo.ai_socktype= SOCK_STREAM;
00089   con->socket.uds.addrinfo.ai_protocol= 0;
00090   con->socket.uds.addrinfo.ai_addrlen= sizeof(struct sockaddr_un);
00091   con->socket.uds.addrinfo.ai_addr= (struct sockaddr *)&(con->socket.uds.sockaddr);
00092 }