1 /*
2  *   LASH
3  *
4  *   Copyright (C) 2003 Robert Ham <rah@bash.sh>
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation; either version 2 of the License, or
9  *   (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with this program; if not, write to the Free Software
18  *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #include <lash/lash.h>
22 #include <lash/internal_headers.h>
23 
24 #include "client.h"
25 
26 client_t *
client_new()27 client_new()
28 {
29 	client_t *client;
30 
31 	client = lash_malloc0(sizeof(client_t));
32 	uuid_clear(client->id);
33 	return client;
34 }
35 
36 void
client_destroy(client_t * client)37 client_destroy(client_t * client)
38 {
39 	client_set_name(client, NULL);
40 	client_set_jack_client_name(client, NULL);
41 	free(client);
42 }
43 
44 void
client_set_name(client_t * client,const char * name)45 client_set_name(client_t * client, const char *name)
46 {
47 	set_string_property(client->name, name);
48 }
49 
50 void
client_set_jack_client_name(client_t * client,const char * name)51 client_set_jack_client_name(client_t * client, const char *name)
52 {
53 	set_string_property(client->jack_client_name, name);
54 }
55 
56 const char *
client_get_identity(client_t * client)57 client_get_identity(client_t * client)
58 {
59 	static char *identity = NULL;
60 	static size_t identity_size = sizeof(char[37]);
61 
62 	if (!identity)
63 		identity = lash_malloc(identity_size);
64 
65 	if (client->name) {
66 		size_t name_size;
67 
68 		name_size = strlen(client->name) + 1;
69 		if (name_size > identity_size) {
70 			identity_size = name_size;
71 			identity = lash_realloc(identity, identity_size);
72 		}
73 
74 		strcpy(identity, client->name);
75 	} else
76 		uuid_unparse(client->id, identity);
77 
78 	return identity;
79 }
80 
81 /* EOF */
82