2015-06-30 18:06:36 +02:00
|
|
|
/* Pinos
|
2015-04-16 19:45:26 +02:00
|
|
|
* Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <stdio.h>
|
2016-12-21 17:19:06 +01:00
|
|
|
#include <sys/prctl.h>
|
|
|
|
|
#include <pwd.h>
|
2015-04-16 19:45:26 +02:00
|
|
|
|
2016-02-01 15:40:48 +01:00
|
|
|
#include "pinos/client/pinos.h"
|
2015-04-16 19:45:26 +02:00
|
|
|
|
2015-04-21 16:57:09 +02:00
|
|
|
/**
|
2015-07-07 16:46:23 +02:00
|
|
|
* pinos_init:
|
2015-04-21 16:57:09 +02:00
|
|
|
* @argc: pointer to argc
|
|
|
|
|
* @argv: pointer to argv
|
|
|
|
|
*
|
2015-06-30 18:06:36 +02:00
|
|
|
* initialize the pinos system, parse and modify any parameters given
|
2015-04-21 16:57:09 +02:00
|
|
|
* by @argc and @argv.
|
|
|
|
|
*/
|
2015-04-16 19:45:26 +02:00
|
|
|
void
|
2015-07-07 16:46:23 +02:00
|
|
|
pinos_init (int *argc, char **argv[])
|
2015-04-16 19:45:26 +02:00
|
|
|
{
|
|
|
|
|
}
|
2015-07-28 17:05:03 +02:00
|
|
|
|
2016-12-21 17:19:06 +01:00
|
|
|
const char *
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_get_application_name (void)
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-21 17:19:06 +01:00
|
|
|
const char *
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_get_prgname (void)
|
|
|
|
|
{
|
2016-12-21 17:19:06 +01:00
|
|
|
static char tcomm[16+1];
|
|
|
|
|
spa_zero(tcomm);
|
|
|
|
|
|
|
|
|
|
if (prctl (PR_GET_NAME, (unsigned long) tcomm, 0, 0, 0) == 0)
|
|
|
|
|
return tcomm;
|
|
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-21 17:19:06 +01:00
|
|
|
const char *
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_get_user_name (void)
|
|
|
|
|
{
|
2016-12-21 17:19:06 +01:00
|
|
|
struct passwd *pw;
|
|
|
|
|
|
|
|
|
|
if ((pw = getpwuid (getuid ())))
|
|
|
|
|
return pw->pw_name;
|
|
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-21 17:19:06 +01:00
|
|
|
const char *
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_get_host_name (void)
|
|
|
|
|
{
|
2016-12-21 17:19:06 +01:00
|
|
|
static char hname[256];
|
|
|
|
|
|
|
|
|
|
if (gethostname (hname, 256) < 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
hname[255] = 0;
|
|
|
|
|
return hname;
|
2016-11-24 17:00:42 +01:00
|
|
|
}
|
|
|
|
|
|
2015-07-28 17:05:03 +02:00
|
|
|
/**
|
|
|
|
|
* pinos_client_name:
|
|
|
|
|
*
|
|
|
|
|
* Make a new pinos client name that can be used to construct a context.
|
|
|
|
|
*/
|
2016-11-24 17:00:42 +01:00
|
|
|
char *
|
2015-07-28 17:05:03 +02:00
|
|
|
pinos_client_name (void)
|
|
|
|
|
{
|
2016-11-24 17:00:42 +01:00
|
|
|
char *c;
|
2016-12-21 17:19:06 +01:00
|
|
|
const char *cc;
|
2016-11-24 17:00:42 +01:00
|
|
|
|
2016-12-21 17:19:06 +01:00
|
|
|
if ((cc = pinos_get_application_name ()))
|
|
|
|
|
return strdup (cc);
|
|
|
|
|
else if ((cc = pinos_get_prgname ()))
|
|
|
|
|
return strdup (cc);
|
2016-11-24 17:00:42 +01:00
|
|
|
else {
|
|
|
|
|
asprintf (&c, "pinos-pid-%zd", (size_t) getpid ());
|
|
|
|
|
return c;
|
|
|
|
|
}
|
2015-07-28 17:05:03 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-12 08:55:20 +02:00
|
|
|
/**
|
|
|
|
|
* pinos_fill_context_properties:
|
|
|
|
|
* @properties: a #PinosProperties
|
|
|
|
|
*
|
|
|
|
|
* Fill @properties with a set of default context properties.
|
|
|
|
|
*/
|
2015-07-28 17:05:03 +02:00
|
|
|
void
|
|
|
|
|
pinos_fill_context_properties (PinosProperties *properties)
|
|
|
|
|
{
|
|
|
|
|
if (!pinos_properties_get (properties, "application.name"))
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_properties_set (properties, "application.name", pinos_get_application_name ());
|
2015-07-28 17:05:03 +02:00
|
|
|
|
|
|
|
|
if (!pinos_properties_get (properties, "application.prgname"))
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_properties_set (properties, "application.prgname", pinos_get_prgname ());
|
2015-07-28 17:05:03 +02:00
|
|
|
|
|
|
|
|
if (!pinos_properties_get (properties, "application.language")) {
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_properties_set (properties, "application.language", getenv ("LANG"));
|
2015-07-28 17:05:03 +02:00
|
|
|
}
|
|
|
|
|
if (!pinos_properties_get (properties, "application.process.id")) {
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_properties_setf (properties, "application.process.id", "%zd", (size_t) getpid ());
|
2015-07-28 17:05:03 +02:00
|
|
|
}
|
|
|
|
|
if (!pinos_properties_get (properties, "application.process.user"))
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_properties_set (properties, "application.process.user", pinos_get_user_name ());
|
2015-07-28 17:05:03 +02:00
|
|
|
|
|
|
|
|
if (!pinos_properties_get (properties, "application.process.host"))
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_properties_set (properties, "application.process.host", pinos_get_host_name ());
|
2015-07-28 17:05:03 +02:00
|
|
|
|
|
|
|
|
if (!pinos_properties_get (properties, "application.process.session_id")) {
|
2016-11-24 17:00:42 +01:00
|
|
|
pinos_properties_set (properties, "application.process.session_id", getenv ("XDG_SESSION_ID"));
|
2015-07-28 17:05:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-12 08:55:20 +02:00
|
|
|
/**
|
|
|
|
|
* pinos_fill_stream_properties
|
|
|
|
|
* @properties: a #PinosProperties
|
|
|
|
|
*
|
|
|
|
|
* Fill @properties with a set of default stream properties.
|
|
|
|
|
*/
|
2015-07-28 17:05:03 +02:00
|
|
|
void
|
|
|
|
|
pinos_fill_stream_properties (PinosProperties *properties)
|
|
|
|
|
{
|
|
|
|
|
}
|
2016-05-17 09:38:30 +02:00
|
|
|
|
|
|
|
|
PinosDirection
|
|
|
|
|
pinos_direction_reverse (PinosDirection direction)
|
|
|
|
|
{
|
|
|
|
|
if (direction == PINOS_DIRECTION_INPUT)
|
|
|
|
|
return PINOS_DIRECTION_OUTPUT;
|
|
|
|
|
else if (direction == PINOS_DIRECTION_OUTPUT)
|
|
|
|
|
return PINOS_DIRECTION_INPUT;
|
|
|
|
|
return direction;
|
|
|
|
|
}
|