1 /***
2 This file is part of PulseAudio.
3
4 Copyright 2004-2006 Lennart Poettering
5 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
6
7 PulseAudio is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published
9 by the Free Software Foundation; either version 2.1 of the License,
10 or (at your option) any later version.
11
12 PulseAudio is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
19 ***/
20
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24
25 #include <string.h>
26 #include <stdio.h>
27 #include <ltdl.h>
28
29 #include <pulse/util.h>
30
31 #include <pulsecore/core-util.h>
32 #include <pulsecore/i18n.h>
33 #include <pulsecore/macro.h>
34 #include <pulsecore/modinfo.h>
35
36 #include "dumpmodules.h"
37
38 #define PREFIX "module-"
39
short_info(const char * name,const char * path,pa_modinfo * i)40 static void short_info(const char *name, const char *path, pa_modinfo *i) {
41 pa_assert(name);
42 pa_assert(i);
43
44 printf("%-40s%s\n", name, i->description ? i->description : "n/a");
45 }
46
long_info(const char * name,const char * path,pa_modinfo * i)47 static void long_info(const char *name, const char *path, pa_modinfo *i) {
48 static int nl = 0;
49 pa_assert(name);
50 pa_assert(i);
51
52 if (nl)
53 printf("\n");
54
55 nl = 1;
56
57 printf(_("Name: %s\n"), name);
58
59 if (!i->description && !i->version && !i->author && !i->usage)
60 printf(_("No module information available\n"));
61 else {
62 if (i->version)
63 printf(_("Version: %s\n"), i->version);
64 if (i->description)
65 printf(_("Description: %s\n"), i->description);
66 if (i->author)
67 printf(_("Author: %s\n"), i->author);
68 if (i->usage)
69 printf(_("Usage: %s\n"), i->usage);
70 printf(_("Load Once: %s\n"), pa_yes_no(i->load_once));
71 if (i->deprecated)
72 printf(_("DEPRECATION WARNING: %s\n"), i->deprecated);
73 }
74
75 if (path)
76 printf(_("Path: %s\n"), path);
77 }
78
show_info(const char * name,const char * path,void (* info)(const char * name,const char * path,pa_modinfo * i))79 static void show_info(const char *name, const char *path, void (*info)(const char *name, const char *path, pa_modinfo*i)) {
80 pa_modinfo *i;
81
82 pa_assert(name);
83
84 if ((i = pa_modinfo_get_by_name(path ? path : name))) {
85 info(name, path, i);
86 pa_modinfo_free(i);
87 }
88 }
89
is_preloaded(const char * name)90 static int is_preloaded(const char *name) {
91 const lt_dlsymlist *l;
92
93 for (l = lt_preloaded_symbols; l->name; l++) {
94 char buf[64], *e;
95
96 if (l->address)
97 continue;
98
99 pa_snprintf(buf, sizeof(buf), "%s", l->name);
100 if ((e = strrchr(buf, '.')))
101 *e = 0;
102
103 if (pa_streq(name, buf))
104 return 1;
105 }
106
107 return 0;
108 }
109
callback(const char * path,lt_ptr data)110 static int callback(const char *path, lt_ptr data) {
111 const char *e;
112 pa_daemon_conf *c = (data);
113
114 e = pa_path_get_filename(path);
115
116 if (strlen(e) <= sizeof(PREFIX)-1 || strncmp(e, PREFIX, sizeof(PREFIX)-1))
117 return 0;
118
119 if (is_preloaded(e))
120 return 0;
121
122 show_info(e, path, c->log_level >= PA_LOG_INFO ? long_info : short_info);
123 return 0;
124 }
125
pa_dump_modules(pa_daemon_conf * c,int argc,char * const argv[])126 void pa_dump_modules(pa_daemon_conf *c, int argc, char * const argv[]) {
127 pa_assert(c);
128
129 if (argc > 0) {
130 int i;
131 for (i = 0; i < argc; i++)
132 show_info(argv[i], NULL, long_info);
133 } else {
134 const lt_dlsymlist *l;
135
136 for (l = lt_preloaded_symbols; l->name; l++) {
137 char buf[64], *e;
138
139 if (l->address)
140 continue;
141
142 if (strlen(l->name) <= sizeof(PREFIX)-1 || strncmp(l->name, PREFIX, sizeof(PREFIX)-1))
143 continue;
144
145 pa_snprintf(buf, sizeof(buf), "%s", l->name);
146 if ((e = strrchr(buf, '.')))
147 *e = 0;
148
149 show_info(buf, NULL, c->log_level >= PA_LOG_INFO ? long_info : short_info);
150 }
151
152 lt_dlforeachfile(NULL, callback, c);
153 }
154 }
155