1 /* This file is part of GNU Pies.
2    Copyright (C) 2009-2020 Sergey Poznyakoff
3 
4    GNU Pies 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, or (at your option)
7    any later version.
8 
9    GNU Pies 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 GNU Pies.  If not, see <http://www.gnu.org/licenses/>. */
16 
17 #include <sys/types.h>
18 #include <unistd.h>
19 #include <stdlib.h>
20 #include <gettext.h>
21 #include <netinet/in.h>
22 #include <sys/un.h>
23 #include <sys/socket.h>
24 #include <grecs.h>
25 
26 #if defined HAVE_SYSCONF && defined _SC_OPEN_MAX
27 # define getmaxfd() sysconf(_SC_OPEN_MAX)
28 #elif defined (HAVE_GETDTABLESIZE)
29 # define getmaxfd() getdtablesize()
30 #else
31 # define getmaxfd() 256
32 #endif
33 
34 void pies_close_fds (int minfd);
35 
36 void mf_proctitle_init (int argc, char *argv[], char *env[]);
37 void mf_proctitle_format (const char *fmt, ...);
38 
39 size_t longtostr (long i, char *buf, size_t size);
40 size_t ulongtostr (unsigned long i, char *buf, size_t size);
41 
42 struct tokendef
43 {
44   char *name;
45   int tok;
46 };
47 
48 int strtotok_len (struct tokendef *tab, const char *str, size_t len,
49 		  int *pres);
50 int strtotok_len_ci (struct tokendef *tab, const char *str, size_t len,
51 		     int *pres);
52 int strtotok (struct tokendef *tab, const char *str, int *pres);
53 int strtotok_ci (struct tokendef *tab, const char *str, int *pres);
54 int toktostr (struct tokendef *tab, int tok, const char **pres);
55 
56 int is_array_member (char * const * ar, char const *str);
57 int array_index (char * const *ar, char const *str);
58 int strsplit3 (const char *input, char *result[3], int flag);
59 int safe_strcmp (char const *a, char const *b);
60 
61 /* url.c */
62 struct pies_url
63 {
64   char *string;
65   char *scheme;
66   char *host;
67   char *port_s;
68   int port;
69   char *proto_s;
70   int proto;
71   char *path;
72   char *user;
73   char *passwd;
74   int argc;
75   char **argv;
76 };
77 
78 int pies_basic_url_create (struct pies_url **purl, const char *str);
79 int pies_url_create (struct pies_url **purl, const char *str);
80 void pies_url_destroy (struct pies_url **purl);
81 const char *pies_url_get_arg (struct pies_url *url, const char *argname);
82 int pies_url_copy (struct pies_url **purl, struct pies_url *src);
83 void pies_url_free_user (struct pies_url *url);
84 void pies_url_free_passwd (struct pies_url *url);
85 
86 void netrc_scan (struct pies_url *url);
87 
88 
89 /* pp.c */
90 void pp_add_option (const char *opt, const char *arg);
91 char *pp_command_line (void);
92 
93 char *mkfilename (const char *dir, const char *name, const char *suf);
94 
95 union pies_sockaddr_storage
96 {
97   struct sockaddr s;
98   struct sockaddr_in s_in;
99   struct sockaddr_un s_un;
100 };
101 
102 /* addrfmt.c */
103 void sockaddr_to_str (const struct sockaddr *sa, int salen,
104 		      char *bufptr, size_t buflen,
105 		      size_t *plen);
106 char *sockaddr_to_astr (const struct sockaddr *sa, int salen);
107 
108 /* urlconn.c */
109 int url_connect (struct pies_url *url, struct grecs_sockaddr *source_addr);
110 
111 
112 
113