ecore_con: clean up, refactor and unpdate documentation.

Summary:
1. Have refactored code in ecore_con_local.c
2. Changed env variable from "TMP" to "TMPDIR".
3. Added check for negetive port number when type is ECORE_CON_LOCAL_USER.
4. Added check to check TMPDIR before assuming /tmp as temp directory.
5. Updated documentation in Ecore_Con.h explaining about local socket and port number.

Signed-off-by: Srivardhan Hebbar <sri.hebbar@samsung.com>

Reviewers: cedric

Reviewed By: cedric

Subscribers: cedric

Differential Revision: https://phab.enlightenment.org/D2194

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
This commit is contained in:
Srivardhan Hebbar 2015-03-23 19:44:03 +01:00 committed by Cedric BAIL
parent 1c3dbc3267
commit 9c03e3e728
2 changed files with 79 additions and 54 deletions

View File

@ -1123,9 +1123,16 @@ EAPI void ecore_con_socks_apply_always(Ecore_Con_Socks *ecs);
* The socket on which the server listens depends on the connection
* type:
* @li If @a type is @c ECORE_CON_LOCAL_USER, the server will listen on
* the Unix socket "~/.ecore/[name]/[port]".
* the Unix socket. The path to the socket is taken from XDG_RUNTIME_DIR,
* if that is not set, then from HOME, even if this is not set, then from
* TMPDIR. If none is set, then path would be /tmp. From this path socket
* would be created as "[path]/.ecore/[name]/[port]". If port is negetive,
* then "[path]/.ecore/[name]".
* @li If @a type is @c ECORE_CON_LOCAL_SYSTEM, the server will listen
* on Unix socket "/tmp/.ecore_service|[name]|[port]".
* on Unix socket "/tmp/.ecore_service|[name]|[port]". If port is negetive,
* then "/tmp/.ecore_service|[name]".
* @li If @a type is @c ECORE_CON_LOCAL_ABSTRACT, then port number is not
* considered while creating the socket.
* @li If @a type is @c ECORE_CON_REMOTE_TCP, the server will listen
* on TCP port @c port.
*
@ -1154,14 +1161,19 @@ EAPI Ecore_Con_Server *ecore_con_server_add(Ecore_Con_Type type,
* @return A new Ecore_Con_Server.
*
* The socket to which the connection is made depends on the connection type:
* @li If @a type is @c ECORE_CON_LOCAL_USER, the function will
* connect to the server at the Unix socket
* "~/.ecore/[name]/[port]".
* @li If @a type is @c ECORE_CON_LOCAL_SYSTEM, the function will
* connect to the server at the Unix socket
* "/tmp/.ecore_service|[name]|[port]".
* @li If @a type is @c ECORE_CON_REMOTE_TCP, the function will
* connect to the server at the TCP port "[name]:[port]".
* @li If @a type is @c ECORE_CON_LOCAL_USER, the server will conect to
* the Unix socket. The path to the socket is taken from XDG_RUNTIME_DIR,
* if that is not set, then from HOME, even if this is not set, then from
* TMPDIR. If none is set, then path would be /tmp. From this path the
* function would connect to socket at "[path]/.ecore/[name]/[port]". If
* port is negetive, then to socket at "[path]/.ecore/[name]".
* @li If @a type is @c ECORE_CON_LOCAL_SYSTEM, the server will connect to
* Unix socket at "/tmp/.ecore_service|[name]|[port]". If port is negetive,
* then to Unix socket at "/tmp/.ecore_service|[name]".
* @li If @a type is @c ECORE_CON_LOCAL_ABSTRACT, then port number is not
* considered while connecting to socket.
* @li If @a type is @c ECORE_CON_REMOTE_TCP, the server will listen
* on TCP port @c port.
*
* More information about the @p type can be found at @ref _Ecore_Con_Type.
*

View File

@ -37,6 +37,24 @@
static int _ecore_con_local_init_count = 0;
static inline const char *_ecore_con_get_tmpdir()
{
const char *tmpdir = "/tmp";
const char *dir = getenv("TMPDIR");
if (!dir) return tmpdir;
return dir;
}
static const char *_ecore_con_local_path_get()
{
const char *homedir = getenv("XDG_RUNTIME_DIR");
if (!homedir) homedir = getenv("HOME");
if (!homedir) homedir = _ecore_con_get_tmpdir();
return homedir;
}
int
ecore_con_local_init(void)
{
@ -77,33 +95,23 @@ ecore_con_local_connect(Ecore_Con_Server *obj,
#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
if (getuid() == geteuid())
#endif
{
homedir = getenv("XDG_RUNTIME_DIR");
if (!homedir)
{
homedir = getenv("HOME");
if (!homedir)
{
homedir = getenv("TMP");
if (!homedir) homedir = "/tmp";
}
}
snprintf(buf, sizeof(buf), "%s/.ecore/%s/%i", homedir, svr->name,
svr->port);
}
homedir = _ecore_con_local_path_get();
#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
else
{
struct passwd *pw = getpwent();
if ((!pw) || (!pw->pw_dir))
snprintf(buf, sizeof(buf), "/tmp/%s/%i", svr->name,
svr->port);
else
snprintf(buf, sizeof(buf), "%s/.ecore/%s/%i", pw->pw_dir, svr->name,
svr->port);
if ((!pw) || (!pw->pw_dir)) homedir = "/tmp";
else homedir = pw->pw_dir;
}
#endif
if (svr->port < 0)
snprintf(buf, sizeof(buf), "%s/.ecore/%s",
homedir, svr->name);
else
snprintf(buf, sizeof(buf), "%s/.ecore/%s/%i",
homedir, svr->name, svr->port);
}
else if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_SYSTEM)
{
@ -115,15 +123,22 @@ ecore_con_local_connect(Ecore_Con_Server *obj,
buf[sizeof(buf) - 1] = 0;
}
else
snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s", svr->name);
{
homedir = _ecore_con_get_tmpdir();
snprintf(buf, sizeof(buf), "%s/.ecore_service|%s",
homedir, svr->name);
}
}
else
{
if (svr->name[0] == '/')
snprintf(buf, sizeof(buf), "%s|%i", svr->name, svr->port);
else
snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s|%i",
svr->name, svr->port);
{
homedir = _ecore_con_get_tmpdir();
snprintf(buf, sizeof(buf), "%s/.ecore_service|%s|%i",
homedir, svr->name, svr->port);
}
}
}
else if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_ABSTRACT)
@ -225,18 +240,8 @@ ecore_con_local_listen(
#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
if (getuid() == geteuid())
#endif
{
homedir = getenv("XDG_RUNTIME_DIR");
if (!homedir)
{
homedir = getenv("HOME");
if (!homedir)
{
homedir = getenv("TMP");
if (!homedir) homedir = "/tmp";
}
}
}
homedir = _ecore_con_local_path_get();
#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
else
{
@ -259,12 +264,13 @@ ecore_con_local_listen(
if (mkdir(buf, mask) < 0) ERR("mkdir '%s' failed", buf);
}
snprintf(buf,
sizeof(buf),
"%s/.ecore/%s/%i",
homedir,
svr->name,
svr->port);
if (svr->port < 0)
snprintf(buf, sizeof(buf), "%s/.ecore/%s",
homedir, svr->name);
else
snprintf(buf, sizeof(buf), "%s/.ecore/%s/%i",
homedir, svr->name, svr->port);
mask = S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH;
}
else if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_SYSTEM)
@ -278,15 +284,22 @@ ecore_con_local_listen(
buf[sizeof(buf) - 1] = 0;
}
else
snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s", svr->name);
{
homedir = _ecore_con_get_tmpdir();
snprintf(buf, sizeof(buf), "%s/.ecore_service|%s",
homedir, svr->name);
}
}
else
{
if (svr->name[0] == '/')
snprintf(buf, sizeof(buf), "%s|%i", svr->name, svr->port);
else
snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s|%i",
svr->name, svr->port);
{
homedir = _ecore_con_get_tmpdir();
snprintf(buf, sizeof(buf), "%s/.ecore_service|%s|%i",
homedir, svr->name, svr->port);
}
}
}
else if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_ABSTRACT)