annotate dpid/dpi.c @ 2048:5060d415a85a

clickable menu items (even those introducing submenus) MUST have callbacks I clicked on the "Panel size" item itself instead of any of the options in its submenu, and: Segfault!
author corvid <corvid@lavabit.com>
date Thu, 26 May 2011 02:51:18 +0000
parents a09dbf132be6
children
rev   line source
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
2 Copyright (C) 2003 Ferdi Franceschini <ferdif@optusnet.com.au>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
3
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
7 (at your option) any later version.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
8
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
12 GNU General Public License for more details.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
13
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
972
d7dbd3dcfa38 Updated the GPL copyright note in the source files
Detlef Riekenberg <wine.dev@web.de>
parents: 0
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
16 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
17
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
18 /*! \file
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
19 * Access functions for ~/.dillo/dpi_socket_dir.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
20 * The most useful function for dillo is a_Dpi_srs, it returns
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
21 * the full path to the dpid service request socket.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
22 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
23
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
24 #include <errno.h>
1223
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 972
diff changeset
25 #include <stdlib.h> /* for exit */
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
26 #include "dpid_common.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
27 #include "dpi.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
28 #include "misc_new.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
29
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
30 /*! \Return
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
31 * Returns path to the dpi_socket_dir file
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
32 * Use dFree to free memory
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
33 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
34 char *a_Dpi_sockdir_file(void)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
35 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
36 char *dpi_socket_dir, *dirfile_path = "/.dillo/dpi_socket_dir";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
37
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
38 dpi_socket_dir = dStrconcat(dGethomedir(), dirfile_path, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
39 return dpi_socket_dir;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
40 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
41
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
42 /*! Read socket directory path from ~/.dillo/dpi_socket_dir
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
43 * \Return
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
44 * socket directory path or NULL if the dpi_socket_dir file does not exist.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
45 * \Note
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
46 * This function exits if ~/.dillo does not exist or
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
47 * if the dpi_socket_dir file cannot be opened for a
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
48 * reason other than it does not exist.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
49 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
50
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
51 char *a_Dpi_rd_dpi_socket_dir(char *dirname)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
52 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
53 FILE *dir;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
54 char *sockdir = NULL, *rcpath;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
55
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
56 rcpath = dStrconcat(dGethomedir(), "/.dillo", NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
57
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
58 /* If .dillo does not exist it is an unrecoverable error */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
59 if (access(rcpath, F_OK) == -1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
60 ERRMSG("a_Dpi_rd_dpi_socket_dir", "access", errno);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
61 MSG_ERR(" - %s\n", rcpath);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
62 exit(1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
63 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
64 dFree(rcpath);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
65
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
66 if ((dir = fopen(dirname, "r")) != NULL) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
67 sockdir = dGetline(dir);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
68 fclose(dir);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
69 } else if (errno == ENOENT) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
70 ERRMSG("a_Dpi_rd_dpi_socket_dir", "fopen", errno);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
71 MSG_ERR(" - %s\n", dirname);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
72 } else if (errno != ENOENT) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
73 ERRMSG("a_Dpi_rd_dpi_socket_dir", "fopen", errno);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
74 MSG_ERR(" - %s\n", dirname);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
75 exit(1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
76 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
77
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
78 return sockdir;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
79 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
80
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
81 /*!
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
82 * \Modifies
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
83 * srs_name
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
84 * \Return
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
85 * The service request socket name with its complete path.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
86 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
87 char *a_Dpi_srs(void)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
88 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
89 char *dirfile_path, *sockdir, *srs_name;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
90
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
91 dirfile_path = a_Dpi_sockdir_file();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
92 sockdir = dStrstrip(a_Dpi_rd_dpi_socket_dir(dirfile_path));
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
93 srs_name = dStrconcat(sockdir, "/", "dpid.srs", NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
94 dFree(sockdir);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
95 dFree(dirfile_path);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
96 return (srs_name);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
97 }