]> code.delx.au - pulseaudio/blob - src/daemon/dumpmodules.c
Merge remote-tracking branch 'mkbosmans/mingw32-build'
[pulseaudio] / src / daemon / dumpmodules.c
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, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA.
21 ***/
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <string.h>
28 #include <getopt.h>
29 #include <stdio.h>
30 #include <ltdl.h>
31
32 #include <pulse/util.h>
33 #include <pulse/i18n.h>
34
35 #include <pulsecore/modinfo.h>
36 #include <pulsecore/core-util.h>
37 #include <pulsecore/macro.h>
38
39 #include "dumpmodules.h"
40
41 #define PREFIX "module-"
42
43 static void short_info(const char *name, const char *path, pa_modinfo *i) {
44 pa_assert(name);
45 pa_assert(i);
46
47 printf("%-40s%s\n", name, i->description ? i->description : "n/a");
48 }
49
50 static void long_info(const char *name, const char *path, pa_modinfo *i) {
51 static int nl = 0;
52 pa_assert(name);
53 pa_assert(i);
54
55 if (nl)
56 printf("\n");
57
58 nl = 1;
59
60 printf(_("Name: %s\n"), name);
61
62 if (!i->description && !i->version && !i->author && !i->usage)
63 printf(_("No module information available\n"));
64 else {
65 if (i->version)
66 printf(_("Version: %s\n"), i->version);
67 if (i->description)
68 printf(_("Description: %s\n"), i->description);
69 if (i->author)
70 printf(_("Author: %s\n"), i->author);
71 if (i->usage)
72 printf(_("Usage: %s\n"), i->usage);
73 printf(_("Load Once: %s\n"), pa_yes_no(i->load_once));
74 if (i->deprecated)
75 printf(_("DEPRECATION WARNING: %s\n"), i->deprecated);
76 }
77
78 if (path)
79 printf(_("Path: %s\n"), path);
80 }
81
82 static void show_info(const char *name, const char *path, void (*info)(const char *name, const char *path, pa_modinfo*i)) {
83 pa_modinfo *i;
84
85 pa_assert(name);
86
87 if ((i = pa_modinfo_get_by_name(path ? path : name))) {
88 info(name, path, i);
89 pa_modinfo_free(i);
90 }
91 }
92
93 #ifndef OS_IS_WIN32
94 extern const lt_dlsymlist lt_preloaded_symbols[];
95 #endif
96
97 static int is_preloaded(const char *name) {
98 const lt_dlsymlist *l;
99
100 for (l = lt_preloaded_symbols; l->name; l++) {
101 char buf[64], *e;
102
103 if (l->address)
104 continue;
105
106 pa_snprintf(buf, sizeof(buf), "%s", l->name);
107 if ((e = strrchr(buf, '.')))
108 *e = 0;
109
110 if (!strcmp(name, buf))
111 return 1;
112 }
113
114 return 0;
115 }
116
117 static int callback(const char *path, lt_ptr data) {
118 const char *e;
119 pa_daemon_conf *c = (data);
120
121 e = pa_path_get_filename(path);
122
123 if (strlen(e) <= sizeof(PREFIX)-1 || strncmp(e, PREFIX, sizeof(PREFIX)-1))
124 return 0;
125
126 if (is_preloaded(e))
127 return 0;
128
129 show_info(e, path, c->log_level >= PA_LOG_INFO ? long_info : short_info);
130 return 0;
131 }
132
133 void pa_dump_modules(pa_daemon_conf *c, int argc, char * const argv[]) {
134 pa_assert(c);
135
136 if (argc > 0) {
137 int i;
138 for (i = 0; i < argc; i++)
139 show_info(argv[i], NULL, long_info);
140 } else {
141 const lt_dlsymlist *l;
142
143 for (l = lt_preloaded_symbols; l->name; l++) {
144 char buf[64], *e;
145
146 if (l->address)
147 continue;
148
149 if (strlen(l->name) <= sizeof(PREFIX)-1 || strncmp(l->name, PREFIX, sizeof(PREFIX)-1))
150 continue;
151
152 pa_snprintf(buf, sizeof(buf), "%s", l->name);
153 if ((e = strrchr(buf, '.')))
154 *e = 0;
155
156 show_info(buf, NULL, c->log_level >= PA_LOG_INFO ? long_info : short_info);
157 }
158
159 lt_dlforeachfile(NULL, callback, c);
160 }
161 }