Dillo v3.1.1-91-g6d5b3ee3
Loading...
Searching...
No Matches
dpi.c
Go to the documentation of this file.
1/*
2 Copyright (C) 2003 Ferdi Franceschini <ferdif@optusnet.com.au>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
24#include <errno.h>
25#include <stdlib.h> /* for exit */
26#include "dpid_common.h"
27#include "dpi.h"
28#include "misc_new.h"
29
35{
36 char *dpi_socket_dir, *dirfile_path = "/.dillo/dpi_socket_dir";
37
38 dpi_socket_dir = dStrconcat(dGethomedir(), dirfile_path, NULL);
39 return dpi_socket_dir;
40}
41
51char *a_Dpi_rd_dpi_socket_dir(char *dirname)
52{
53 FILE *dir;
54 char *sockdir = NULL, *rcpath;
55
56 rcpath = dStrconcat(dGethomedir(), "/.dillo", NULL);
57
58 /* If .dillo does not exist it is an unrecoverable error */
59 if (access(rcpath, F_OK) == -1) {
60 ERRMSG("a_Dpi_rd_dpi_socket_dir", "access", errno);
61 MSG_ERR(" - %s\n", rcpath);
62 exit(1);
63 }
64 dFree(rcpath);
65
66 if ((dir = fopen(dirname, "r")) != NULL) {
67 sockdir = dGetline(dir);
68 fclose(dir);
69 } else if (errno == ENOENT) {
70 ERRMSG("a_Dpi_rd_dpi_socket_dir", "fopen", errno);
71 MSG_ERR(" - %s\n", dirname);
72 } else if (errno != ENOENT) {
73 ERRMSG("a_Dpi_rd_dpi_socket_dir", "fopen", errno);
74 MSG_ERR(" - %s\n", dirname);
75 exit(1);
76 }
77
78 return sockdir;
79}
80
87char *a_Dpi_srs(void)
88{
89 char *dirfile_path, *sockdir, *srs_name;
90
91 dirfile_path = a_Dpi_sockdir_file();
92 sockdir = dStrstrip(a_Dpi_rd_dpi_socket_dir(dirfile_path));
93 srs_name = dStrconcat(sockdir, "/", "dpid.srs", NULL);
94 dFree(sockdir);
95 dFree(dirfile_path);
96 return (srs_name);
97}
char * dGetline(FILE *stream)
Get a line from a FILE stream.
Definition dlib.c:928
char * dStrconcat(const char *s1,...)
Concatenate a NULL-terminated list of strings.
Definition dlib.c:102
void dFree(void *mem)
Definition dlib.c:68
char * dStrstrip(char *s)
Remove leading and trailing whitespace.
Definition dlib.c:122
char * dGethomedir(void)
Return the home directory in a static string (don't free)
Definition dlib.c:906
char * a_Dpi_rd_dpi_socket_dir(char *dirname)
Definition dpi.c:51
char * a_Dpi_sockdir_file(void)
Definition dpi.c:34
char * a_Dpi_srs(void)
Definition dpi.c:87
char * srs_name
Definition main.c:44
#define MSG_ERR(...)
Definition dpid_common.h:23
#define ERRMSG(CALLER, CALLED, ERR)
Definition dpid_common.h:29