Commit a94d1cca a94d1cca434bfddec216710a4863aecdbb2522e3 by Alain Magloire

_cpystr.c attribute.c attribute.h attribute0.h auth.c auth.h

 	cpystr.h locker.c locker.h message.c message.h message0.h
 	registrar.c registrar.h registrar0.h rfc822.c url.c url.h
 	url0.h url_imap.c url_mail.c url_mbox.c url_mdir.c url_mh.c
 	url_mmdf.c url_pop.c url_unix.c
still young in the implementation.
1 parent bd507cf1
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <cpystr.h>
19 #include <string.h>
20
21 size_t
22 _cpystr (char *dst, const char *src, size_t size)
23 {
24 size_t len = src ? strlen (src) : 0 ;
25 if (dst == NULL || size == 0)
26 return len;
27 if (len >= size)
28 len = size - 1;
29 memcpy (dst, src, len);
30 dst[len] = '\0';
31 return len;
32 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <attribute0.h>
19
20 #include <sys/types.h>
21 #include <stdlib.h>
22 #include <errno.h>
23
24 int
25 attribute_init (attribute_t *pattr)
26 {
27 attribute_t attr;
28 if (pattr == NULL)
29 return EINVAL;
30 attr = calloc (1, sizeof(*attr));
31 if (attr == NULL)
32 return ENOMEM;
33 *pattr = attr;
34 return 0;
35 }
36
37 void
38 attribute_destroy (attribute_t *pattr)
39 {
40 if (pattr && *pattr)
41 {
42 attribute_t attr = *pattr;
43 /* no owner we can free */
44 if (! attr->message)
45 free (*pattr);
46 }
47 return;
48 }
49
50 int
51 attribute_set_seen (attribute_t attr)
52 {
53 if (attr == NULL)
54 return EINVAL;
55 attr->flag |= MU_ATTRIBUTE_SEEN;
56 return 0;
57 }
58
59 int
60 attribute_set_answered (attribute_t attr)
61 {
62 if (attr == NULL)
63 return EINVAL;
64 attr->flag|= MU_ATTRIBUTE_ANSWERED;
65 attr->flag |= MU_ATTRIBUTE_SEEN;
66 return 0;
67 }
68
69 int
70 attribute_set_flagged (attribute_t attr)
71 {
72 if (attr == NULL)
73 return EINVAL;
74 attr->flag |= MU_ATTRIBUTE_FLAGGED;
75 attr->flag |= MU_ATTRIBUTE_SEEN;
76 return 0;
77 }
78
79 int
80 attribute_set_read (attribute_t attr)
81 {
82 if (attr == NULL)
83 return EINVAL;
84 attr->flag |= MU_ATTRIBUTE_READ;
85 attr->flag |= MU_ATTRIBUTE_SEEN;
86 return 0;
87 }
88
89 int
90 attribute_set_deleted (attribute_t attr)
91 {
92 if (attr == NULL)
93 return EINVAL;
94 attr->flag |= MU_ATTRIBUTE_DELETED;
95 return 0;
96 }
97
98 int
99 attribute_set_draft (attribute_t attr)
100 {
101 if (attr == NULL)
102 return EINVAL;
103 attr->flag |= MU_ATTRIBUTE_DRAFT;
104 return 0;
105 }
106
107 int
108 attribute_set_recent (attribute_t attr)
109 {
110 if (attr == NULL)
111 return EINVAL;
112 attr->flag |= MU_ATTRIBUTE_RECENT;
113 return 0;
114 }
115
116 int
117 attribute_is_seen (attribute_t attr)
118 {
119 if (attr == NULL)
120 return 0;
121 return attr->flag & MU_ATTRIBUTE_SEEN;
122 }
123
124 int
125 attribute_is_answered (attribute_t attr)
126 {
127 if (attr == NULL)
128 return 0;
129 return attr->flag & MU_ATTRIBUTE_ANSWERED;
130 }
131
132 int
133 attribute_is_flagged (attribute_t attr)
134 {
135 if (attr == NULL)
136 return 0;
137 return attr->flag & MU_ATTRIBUTE_FLAGGED;
138 }
139
140 int
141 attribute_is_read (attribute_t attr)
142 {
143 if (attr == NULL)
144 return 0;
145 return attr->flag & MU_ATTRIBUTE_READ;
146 }
147
148 int
149 attribute_is_deleted (attribute_t attr)
150 {
151 if (attr == NULL)
152 return 0;
153 return attr->flag & MU_ATTRIBUTE_DELETED;
154 }
155
156 int
157 attribute_is_draft (attribute_t attr)
158 {
159 if (attr == NULL)
160 return 0;
161 return attr->flag & MU_ATTRIBUTE_DRAFT;
162 }
163
164 int
165 attribute_is_recent (attribute_t attr)
166 {
167 if (attr == NULL)
168 return 0;
169 return attr->flag & MU_ATTRIBUTE_RECENT;
170 }
171
172 int
173 attribute_unset_seen (attribute_t attr)
174 {
175 if (attr == NULL)
176 return 0;
177 attr->flag ^= MU_ATTRIBUTE_SEEN;
178 attr->flag ^= MU_ATTRIBUTE_ANSWERED;
179 attr->flag ^= MU_ATTRIBUTE_FLAGGED;
180 attr->flag ^= MU_ATTRIBUTE_READ;
181 return 0;
182 }
183
184 int
185 attribute_unset_answered (attribute_t attr)
186 {
187 if (attr == NULL)
188 return 0;
189 attr->flag ^= MU_ATTRIBUTE_ANSWERED;
190 return 0;
191 }
192
193 int
194 attribute_unset_flagged (attribute_t attr)
195 {
196 if (attr == NULL)
197 return 0;
198 attr->flag ^= MU_ATTRIBUTE_FLAGGED;
199 return 0;
200 }
201
202 int
203 attribute_unset_read (attribute_t attr)
204 {
205 if (attr == NULL)
206 return 0;
207 attr->flag ^= MU_ATTRIBUTE_READ;
208 return 0;
209 }
210
211 int
212 attribute_unset_deleted (attribute_t attr)
213 {
214 if (attr == NULL)
215 return 0;
216 attr->flag ^= MU_ATTRIBUTE_DELETED;
217 return 0;
218 }
219
220 int
221 attribute_unset_draft (attribute_t attr)
222 {
223 if (attr == NULL)
224 return 0;
225 attr->flag ^= MU_ATTRIBUTE_DRAFT;
226 return 0;
227 }
228
229 int
230 attribute_unset_recent (attribute_t attr)
231 {
232 if (attr == NULL)
233 return 0;
234 attr->flag ^= MU_ATTRIBUTE_RECENT;
235 return 0;
236 }
237
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #ifndef _ATTRIBUTE_H
19 #define _ATTRIBUTE_H
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 #ifndef __P
26 # ifdef __STDC__
27 # define __P(args) args
28 # else
29 # define __P(args) ()
30 # endif
31 #endif /*__P */
32
33 struct _attribute;
34 typedef struct _attribute * attribute_t;
35
36 extern int attribute_init __P ((attribute_t *));
37 extern void attribute_destroy __P ((attribute_t *));
38
39 extern int attribute_is_seen __P ((attribute_t));
40 extern int attribute_is_answered __P ((attribute_t));
41 extern int attribute_is_flagged __P ((attribute_t));
42 extern int attribute_is_deleted __P ((attribute_t));
43 extern int attribute_is_draft __P ((attribute_t));
44 extern int attribute_is_recent __P ((attribute_t));
45 extern int attribute_is_read __P ((attribute_t));
46
47 extern int attribute_set_seen __P ((attribute_t));
48 extern int attribute_set_answered __P ((attribute_t));
49 extern int attribute_set_flagged __P ((attribute_t));
50 extern int attribute_set_deleted __P ((attribute_t));
51 extern int attribute_set_draft __P ((attribute_t));
52 extern int attribute_set_recent __P ((attribute_t));
53 extern int attribute_set_read __P ((attribute_t));
54
55 extern int attribute_unset_seen __P ((attribute_t));
56 extern int attribute_unset_answered __P ((attribute_t));
57 extern int attribute_unset_flagged __P ((attribute_t));
58 extern int attribute_unset_deleted __P ((attribute_t));
59 extern int attribute_unset_draft __P ((attribute_t));
60 extern int attribute_unset_recent __P ((attribute_t));
61 extern int attribute_unset_read __P ((attribute_t));
62
63 #ifdef __cplusplus
64 }
65 #endif
66
67 #endif /* _ATTRIBUTE_H */
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #ifndef _ATTRIBUTE0_H
19 #define _ATTRIBUTE0_H
20
21 #include <attribute.h>
22
23 #include <sys/types.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #ifndef __P
30 # ifdef __STDC__
31 # define __P(args) args
32 # else
33 # define __P(args) ()
34 # endif
35 #endif /*__P */
36
37 #define MU_ATTRIBUTE_SEEN ((int)1)
38 #define MU_ATTRIBUTE_ANSWERED (MU_ATTRIBUTE_SEEN << 1)
39 #define MU_ATTRIBUTE_FLAGGED (MU_ATTRIBUTE_ANSWERED << 1)
40 #define MU_ATTRIBUTE_DELETED (MU_ATTRIBUTE_FLAGGED << 1)
41 #define MU_ATTRIBUTE_DRAFT (MU_ATTRIBUTE_DELETED << 1)
42 #define MU_ATTRIBUTE_RECENT (MU_ATTRIBUTE_DRAFT << 1)
43 #define MU_ATTRIBUTE_READ (MU_ATTRIBUTE_RECENT << 1)
44
45 struct _attribute
46 {
47 size_t flag;
48 void *message;
49 };
50
51 #ifdef __cplusplus
52 }
53 #endif
54
55 #endif /* _ATTRIBUTE0_H */
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <auth.h>
19 #include <cpystr.h>
20
21 #include <errno.h>
22 #include <sys/types.h>
23 #include <string.h>
24 #include <stdlib.h>
25
26 struct _auth
27 {
28 char *login;
29 char *passwd;
30 uid_t owner;
31 gid_t group;
32 mode_t mode;
33 };
34
35 int
36 auth_init (auth_t *pauth)
37 {
38 auth_t auth;
39 if (pauth == NULL)
40 return EINVAL;
41 auth = calloc (1, sizeof (*auth));
42 if (auth == NULL)
43 return ENOMEM;
44 auth->owner = auth->group = -1;
45 auth->mode = 0600;
46 *pauth = auth;
47 return 0;
48 }
49
50 void
51 auth_destroy (auth_t *pauth)
52 {
53 if (pauth && *pauth)
54 {
55 auth_t auth = *pauth;
56 free (auth->login);
57 free (auth->passwd);
58 free (auth);
59 *pauth = NULL;
60 }
61 }
62
63 /* login/passwd */
64 int
65 auth_get_login (auth_t auth, char *login, size_t len, size_t *n)
66 {
67 size_t nwrite = 0;
68 if (auth == NULL)
69 return EINVAL;
70 nwrite = _cpystr (login, auth->login, len);
71 if (n)
72 *n = nwrite;
73 return 0;
74 }
75
76 int
77 auth_set_login (auth_t auth, const char *login, size_t len)
78 {
79 char *log = NULL;
80 if (auth == NULL)
81 return EINVAL;
82 if (login != NULL)
83 {
84 log = calloc (len + 1, sizeof (char));
85 if (log == NULL)
86 return ENOMEM;
87 memcpy (log, login, len);
88 }
89 free (auth->login);
90 auth->login = log;
91 return 0;
92 }
93
94 int
95 auth_get_passwd (auth_t auth, char *passwd, size_t len, size_t *n)
96 {
97 size_t nwrite = 0;
98 if (auth == NULL)
99 return EINVAL;
100 nwrite = _cpystr (passwd, auth->passwd, len);
101 if (n)
102 *n = nwrite;
103 return 0;
104 }
105
106 int
107 auth_set_passwd (auth_t auth, const char *passwd, size_t len)
108 {
109 char *pass = NULL;
110 if (auth == NULL)
111 return EINVAL;
112 if (passwd != NULL)
113 {
114 char *pass = calloc (len + 1, sizeof (char));
115 if (pass == NULL)
116 return ENOMEM;
117 memcpy (pass, passwd, len);
118 }
119 free (auth->passwd);
120 auth->passwd = pass;
121 return 0;
122 }
123
124 /* owner and group */
125 int
126 auth_get_owner (auth_t auth, uid_t *powner)
127 {
128 if (auth == NULL)
129 return EINVAL;
130 if (powner)
131 *powner = auth->owner;
132 return 0;
133 }
134
135 int
136 auth_set_owner (auth_t auth, uid_t owner)
137 {
138 if (auth == NULL)
139 return 0;
140 auth->owner = owner;
141 return 0;
142 }
143
144 int
145 auth_get_group (auth_t auth, gid_t *pgroup)
146 {
147 if (auth == NULL)
148 return EINVAL;
149 if (pgroup)
150 *pgroup = auth->group;
151 return 0;
152 }
153
154 int
155 auth_set_group (auth_t auth, gid_t group)
156 {
157 if (auth == NULL)
158 return EINVAL;
159 auth->group = group;
160 return 0;
161 }
162
163 int
164 auth_get_mode (auth_t auth, mode_t *pmode)
165 {
166 if (auth == NULL)
167 return EINVAL;
168 if (pmode)
169 *pmode = auth->mode;
170 return 0;
171 }
172
173 int
174 auth_set_mode (auth_t auth, mode_t mode)
175 {
176 if (auth == NULL)
177 return EINVAL;
178 auth->mode = mode;
179 return 0;
180 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #ifndef _AUTH_H
19 #define _AUTH_H
20
21 #include <sys/types.h>
22
23 #ifndef __P
24 #ifdef __STDC__
25 #define __P(args) args
26 #else
27 #define __P(args) ()
28 #endif
29 #endif /*__P */
30
31 #ifdef _cpluscplus
32 extern "C" {
33 #endif
34
35 /* forward declaration */
36 struct _auth;
37 typedef struct _auth *auth_t;
38
39 extern int auth_init __P ((auth_t *));
40 extern void auth_destroy __P ((auth_t *));
41
42 /* login/passwd */
43 extern int auth_get_login __P ((auth_t, char *login,
44 size_t len, size_t *n));
45 extern int auth_set_login __P ((auth_t, const char *login, size_t len));
46
47 extern int auth_get_passwd __P ((auth_t, char *passwd,
48 size_t len, size_t *n));
49 extern int auth_set_passwd __P ((auth_t, const char *passwd, size_t len));
50
51 /* owner group mode*/
52 extern int auth_get_owner __P ((auth_t, uid_t *uid));
53 extern int auth_set_owner __P ((auth_t, uid_t uid));
54 extern int auth_get_group __P ((auth_t, gid_t *gid));
55 extern int auth_set_group __P ((auth_t, gid_t gid));
56 extern int auth_get_mode __P ((auth_t, mode_t *mode));
57 extern int auth_set_mode __P ((auth_t, mode_t mode));
58
59 #ifdef _cpluscplus
60 }
61 #endif
62
63 #endif /* _AUTH_H */
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #ifndef _CPYSTR_H
19 #define _CPYSTR_H
20
21 #include <sys/types.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 #ifndef __P
28 # if __STDC__
29 # define __P(x) x
30 # else
31 # define __P(x)
32 # endif
33 #endif
34 extern size_t _cpystr __P ((char *dst, const char *src, size_t size));
35
36 #ifdef __cplusplus
37 }
38 #endif
39
40 #endif
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <locker.h>
19 #include <errno.h>
20 #include <sys/types.h>
21 #include <stdlib.h>
22 #include <string.h>
23
24 /*
25 * Waiting for Brian E. to implement this.
26 */
27
28 struct _locker
29 {
30 char *filename;
31 size_t filename_len;
32 int lock;
33 };
34
35 int
36 locker_init (locker_t *plocker, char *filename, size_t len)
37 {
38 locker_t l;
39 if (plocker == NULL)
40 return EINVAL;
41 if (filename == NULL || len == 0)
42 return EINVAL;
43 l = malloc (sizeof(*l));
44 if (l == NULL)
45 return ENOMEM;
46 l->filename = calloc (len + 1, sizeof(char));
47 if (l->filename == NULL)
48 {
49 free (l);
50 return ENOMEM;
51 }
52 memcpy (l->filename, filename, len);
53 l->lock = 0;
54 l->filename_len = len;
55 *plocker = l;
56 return 0;
57 }
58
59 void
60 locker_destroy (locker_t *plocker)
61 {
62 if (plocker && *plocker)
63 {
64 free ((*plocker)->filename);
65 free (*plocker);
66 *plocker = NULL;
67 }
68 }
69
70 int
71 locker_lock (locker_t locker, int flags)
72 {
73 (void)flags;
74 if (locker == NULL)
75 return EINVAL;
76 locker->lock++;
77 return 0;
78 }
79
80 int
81 locker_touchlock (locker_t locker)
82 {
83 if (locker == NULL)
84 return EINVAL;
85 return 0;
86 }
87
88 int
89 locker_unlock (locker_t locker)
90 {
91 if (locker == NULL)
92 return EINVAL;
93 locker->lock--;
94 return 0;
95 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #ifndef _LOCKER_H
19 #define _LOCKER_H
20
21 #include <sys/types.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 #ifndef __P
28 # ifdef __STDC__
29 # define __P(args) args
30 # else
31 # define __P(args) ()
32 # endif
33 #endif /*__P */
34
35 struct _locker;
36 typedef struct _locker *locker_t;
37
38 extern int locker_init __P ((locker_t *, char *filename, size_t len));
39 extern void locker_destroy __P ((locker_t *));
40
41 #define MU_LOCKER_RDLOCK 0
42 #define MU_LOCKER_WRLOCK 1
43 extern int locker_lock __P ((locker_t, int flag));
44 extern int locker_touchlock __P ((locker_t));
45 extern int locker_unlock __P ((locker_t));
46
47 #ifdef __cplusplus
48 }
49 #endif
50
51 #endif /* _MAILBOX_H */
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18
19 #include <header0.h>
20 #include <attribute0.h>
21 #include <message0.h>
22 #include <mailbox0.h>
23
24 #include <errno.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27
28 int
29 message_init (message_t *pmsg)
30 {
31 message_t msg;
32
33 if (pmsg == NULL)
34 return EINVAL;
35 msg = calloc (1, sizeof (*msg));
36 if (msg == NULL)
37 return ENOMEM;
38 *pmsg = msg;
39 return 0;
40 }
41
42 void
43 message_destroy (message_t *pmsg)
44 {
45 if (pmsg && *pmsg)
46 {
47 message_t msg = *pmsg;
48 /*
49 * The message has an mailbox owner
50 * let the mailbox destroy when it finishes
51 */
52 if (msg->mailbox)
53 {
54 *pmsg = NULL;
55 return;
56 }
57 /* is the header own by us ? */
58 if (msg->header->message == msg)
59 msg->header->message = NULL;
60 header_destroy (&(msg->header));
61 /* is the attribute own by us ? */
62 if (msg->attribute->message == msg)
63 msg->attribute->message = NULL;
64 attribute_destroy (&(msg->attribute));
65 if (msg->body)
66 {
67 body_t body = msg->body;
68 if (body->file)
69 fclose (body->file);
70 free (body->content);
71 }
72 free (msg->body);
73 if (msg->part_num > 0)
74 {
75 size_t i;
76 for (i = 0; i < msg->part_num; i++)
77 message_destroy (&(msg->parts[i]));
78 }
79 free (msg->parts);
80 free (msg);
81 *pmsg = NULL;
82 }
83 }
84
85 int
86 message_get_header (message_t msg, header_t *phdr)
87 {
88 int err = 0;
89 int nread, n = 0;
90 char *pbuf = NULL, *tbuf = NULL;
91 char buf [BUFSIZ];
92 int off = 0;
93
94 if (phdr == NULL || msg == NULL)
95 return EINVAL;
96
97 if (msg->header != NULL)
98 {
99 *phdr = msg->header;
100 return 0;
101 }
102
103 if (msg->mailbox == NULL)
104 return EINVAL;
105
106 do
107 {
108 nread = mailbox_get_header (msg->mailbox, msg->num, buf, sizeof(buf),
109 off, &err);
110 if (err == EAGAIN || err == EINPROGRESS)
111 continue;
112 else if (err != 0)
113 {
114 free (pbuf);
115 return err;
116 }
117 off += nread;
118 tbuf = realloc (pbuf, off);
119 if (tbuf == NULL)
120 {
121 free (pbuf);
122 return ENOMEM;
123 }
124 else
125 pbuf = tbuf;
126 memcpy (pbuf + n, buf, nread);
127 n = nread;
128 } while (nread > 0);
129
130 err = header_init (&(msg->header), pbuf, off, MU_HEADER_RFC822);
131 if (err == 0)
132 {
133 /* we own it */
134 msg->header->message = msg;
135 *phdr = msg->header;
136 }
137 free (pbuf);
138 return err;
139 }
140
141 int
142 message_set_header (message_t msg, header_t hdr)
143 {
144 if (msg == NULL || msg->mailbox == NULL)
145 return EINVAL;
146 if (msg->header)
147 {
148 if (msg->header->message == msg)
149 msg->header->message = NULL;
150 header_destroy (&(msg->header));
151 }
152 msg->header = hdr;
153 return 0;
154 }
155
156 ssize_t
157 message_get_content (message_t msg, char *buf, size_t buflen,
158 off_t off, int *err)
159 {
160 if (msg == NULL || msg->mailbox == NULL)
161 {
162 if (err)
163 *err = EINVAL;
164 return -1;
165 }
166 return mailbox_get_body (msg->mailbox, msg->num, buf, buflen, off, err);
167 }
168
169 int
170 message_set_content (message_t msg, char *buf, size_t buflen)
171 {
172 (void)msg;(void)buf; (void)buflen;
173 return ENOSYS;
174 }
175
176 int
177 message_size (message_t msg, size_t *size)
178 {
179 if (msg == NULL || size == NULL)
180 return EINVAL;
181 if (msg->mailbox)
182 {
183 size_t hs, bs;
184 int status;
185 status = mailbox_get_size (msg->mailbox, msg->num, &hs, &bs);
186 if (status == 0)
187 {
188 if (size)
189 *size = hs + bs;
190 }
191 return status;
192 }
193 return ENOSYS;
194 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #ifndef _MESSAGE_H
19 #define _MESSAGE_H
20
21 #include <header.h>
22 #include <attribute.h>
23
24 #include <sys/types.h>
25
26 #ifndef __P
27 # ifdef __STDC__
28 # define __P(args) args
29 # else
30 # define __P(args) ()
31 # endif
32 #endif /* __P */
33
34 #ifdef _cpluscplus
35 extern "C" {
36 #endif
37
38 /* forward declaration */
39 struct _message;
40 typedef struct _message *message_t;
41
42 extern int message_init __P ((message_t *));
43 extern void message_destroy __P ((message_t *));
44
45 extern int message_get_header __P ((message_t, header_t *));
46 extern int message_set_header __P ((message_t, header_t));
47
48 extern ssize_t message_get_content __P ((message_t, char *,
49 size_t, off_t, int *));
50 extern int message_set_content __P ((message_t, char *, size_t));
51
52 extern int message_is_multipart __P ((message_t));
53 extern int message_get_part_count __P ((message_t, size_t *));
54 extern int message_get_part __P ((message_t, size_t, message_t *));
55 extern int message_add_part __P ((message_t, message_t));
56
57 extern int message_get_size __P ((message_t, size_t *));
58
59 extern int message_get_attribute __P ((message_t, attribute_t *));
60 extern int message_set_attribute __P ((message_t, attribute_t));
61
62 #ifdef _cpluscplus
63 }
64 #endif
65
66 #endif /* _MESSAGE_H */
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #ifndef _MESSAGE0_H
19 #define _MESSAGE0_H
20
21 #include <attribute.h>
22 #include <header.h>
23 #include <message.h>
24 #include <mailbox.h>
25
26 #include <sys/types.h>
27 #include <stdio.h>
28
29 #ifdef _cpluscplus
30 extern "C" {
31 #endif
32
33 struct _body
34 {
35 FILE *file;
36 char *content;
37 size_t content_len;
38 };
39
40 typedef struct _body * body_t;
41
42 /* forward declaration */
43 struct _message
44 {
45 mailbox_t mailbox;
46 header_t header;
47 message_t *parts;
48 size_t part_num;
49 body_t body;
50 size_t num;
51 attribute_t attribute;
52
53 int (*_get_header) __P ((message_t msg, header_t *hdr));
54 int (*_set_header) __P ((message_t msg, header_t hdr));
55
56 int (*_get_attribute) __P ((message_t msg, attribute_t *attr));
57 int (*_set_attribute) __P ((message_t msg, attribute_t attr));
58
59 int (*_get_content) __P ((message_t msg, char *buf, size_t len,
60 size_t *nread, off_t offset));
61 int (*_set_content) __P ((message_t msg, char *buf, size_t len));
62
63 int (*_size) __P ((message_t msg, size_t *size));
64
65 int (*_clone) __P ((message_t msg, message_t *cmsg));
66 };
67
68 #ifdef _cpluscplus
69 }
70 #endif
71
72 #endif /* _MESSAGE_H */
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #ifdef HAVE_CONFIG_H
19 #include <config.h>
20 #endif
21
22 #include <registrar0.h>
23
24 #include <stdlib.h>
25 #include <string.h>
26 #include <errno.h>
27
28 /*
29 Builtin mailbox types.
30 A circular list is use for the builtin.
31 Proper locking is not done when accessing the list.
32 FIXME: not thread-safe. */
33
34 static struct _registrar registrar [] = {
35 { NULL, NULL, 0, &registrar[1] }, /* sentinel, head list */
36 { &_url_mbox_registrar, &_mailbox_mbox_registrar, 0, &registrar[2] },
37 { &_url_unix_registrar, &_mailbox_unix_registrar, 0, &registrar[3] },
38 { &_url_maildir_registrar, &_mailbox_maildir_registrar, 0, &registrar[4] },
39 { &_url_mmdf_registrar, &_mailbox_mmdf_registrar, 0, &registrar[5] },
40 { &_url_pop_registrar, &_mailbox_pop_registrar, 0, &registrar[6] },
41 { &_url_imap_registrar, &_mailbox_imap_registrar, 0, &registrar[0] },
42 };
43
44 static void
45 free_ureg (struct url_registrar *ureg)
46 {
47 if (ureg)
48 {
49 free (ureg->scheme);
50 free (ureg);
51 }
52 }
53
54 static void
55 free_mreg (struct mailbox_registrar *mreg)
56 {
57 if (mreg)
58 {
59 free (mreg->name);
60 free (mreg);
61 }
62 }
63
64 int
65 registrar_add (struct url_registrar *new_ureg,
66 struct mailbox_registrar *new_mreg, int *id)
67 {
68 struct _registrar *entry;
69 struct url_registrar *ureg = NULL;
70 struct mailbox_registrar *mreg;
71
72 /* Must registrar a mailbox */
73 if (new_mreg == NULL)
74 return EINVAL;
75
76 /* Mailbox */
77 mreg = calloc (1, sizeof (*mreg));
78 if (mreg == NULL)
79 return ENOMEM;
80
81 if (new_mreg->name)
82 {
83 mreg->name = strdup (new_mreg->name);
84 if (mreg->name == NULL)
85 {
86 free (mreg);
87 return ENOMEM;
88 }
89 }
90 mreg->_init = new_mreg->_init;
91 mreg->_destroy = new_mreg->_destroy;
92
93 /* URL */
94 if (new_ureg)
95 {
96 ureg = calloc (1, sizeof (*ureg));
97 if (ureg == NULL)
98 {
99 free_mreg (mreg);
100 return ENOMEM;
101 }
102 if (new_ureg->scheme)
103 {
104 ureg->scheme = strdup (new_ureg->scheme);
105 if (ureg->scheme == NULL)
106 {
107 free_mreg (mreg);
108 free_ureg (ureg);
109 return ENOMEM;
110 }
111 }
112 ureg->_init = new_ureg->_init;
113 ureg->_destroy = new_ureg->_destroy;
114 }
115
116 /* Register them to the list */
117 entry = calloc (1, sizeof (*entry));
118 if (entry == NULL)
119 {
120 free_mreg (mreg);
121 free_ureg (ureg);
122 return ENOMEM;
123 }
124 entry->ureg = ureg;
125 entry->mreg = mreg;
126 entry->is_allocated = 1;
127 entry->next = registrar->next;
128 registrar->next = entry;
129 if (id)
130 *id = (int)entry;
131 return 0;
132 }
133
134 int
135 registrar_remove (int id)
136 {
137 struct _registrar *current, *previous;
138 for (previous = registrar, current = registrar->next;
139 current != registrar;
140 previous = current, current = current->next)
141 {
142 if ((int)current == id)
143 {
144 previous->next = current->next;
145 if (current->is_allocated)
146 {
147 free_ureg (current->ureg);
148 free_mreg (current->mreg);
149 }
150 free (current);
151 return 0;;
152 }
153 }
154 return EINVAL;
155 }
156
157 int
158 registrar_get (int id,
159 struct url_registrar **ureg, struct mailbox_registrar **mreg)
160 {
161 struct _registrar *current;
162 for (current = registrar->next; current != registrar;
163 current = current->next)
164 {
165 if ((int)current == id)
166 {
167 if (mreg)
168 *mreg = current->mreg;
169 if (ureg)
170 *ureg = current->ureg;
171 return 0;
172 }
173 }
174 return EINVAL;
175 }
176
177 int
178 registrar_list (struct url_registrar **ureg, struct mailbox_registrar **mreg,
179 int *id, registrar_t *reg)
180 {
181 struct _registrar *current;
182
183 if (reg == NULL)
184 return EINVAL;
185
186 current = *reg;
187
188 if (current == NULL)
189 current = registrar;
190
191 if (current->next == registrar)
192 return -1;
193
194 if (ureg)
195 *ureg = current->ureg;
196
197 if (mreg)
198 *mreg = current->mreg;
199
200 if (id)
201 *id = (int)current;
202
203 *reg = current->next;
204
205 return 0;
206 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #ifndef _REGISTRAR_H
19 #define _REGISTRAR_H
20
21 #include <sys/types.h>
22
23 #include <url.h>
24 #include <mailbox.h>
25
26 #ifndef __P
27 # ifdef __STDC__
28 # define __P(args) args
29 # else
30 # define __P(args) ()
31 # endif
32 #endif /*__P */
33
34 #ifdef _cpluscplus
35 extern "C" {
36 #endif
37
38 struct url_registrar
39 {
40 char *scheme;
41 int (*_init) __P ((url_t *, const char * name));
42 void (*_destroy) __P ((url_t *));
43 };
44
45 struct mailbox_registrar
46 {
47 char *name;
48 int (*_init) __P ((mailbox_t *, const char *name));
49 void (*_destroy) __P ((mailbox_t *));
50 };
51
52 struct _registrar;
53
54 typedef struct _registrar* registrar_t;
55
56 /* mailbox registration */
57 extern int registrar_add __P ((struct url_registrar *ureg,
58 struct mailbox_registrar *mreg, int *id));
59 extern int registrar_remove __P ((int id));
60 extern int registrar_get __P ((int id, struct url_registrar **ureg,
61 struct mailbox_registrar **mreg));
62 extern int registrar_list __P ((struct url_registrar **ureg,
63 struct mailbox_registrar **mreg,
64 int *id, registrar_t *reg));
65 #ifdef _cpluscplus
66 }
67 #endif
68
69 #endif /* _REGISTRAR_H */
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #ifndef _REGISTRAR0_H
19 #define _REGISTRAR0_H
20
21 #include <registrar.h>
22
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 #ifndef __P
29 # ifdef __STDC__
30 # define __P(args) args
31 # else
32 # define __P(args) ()
33 # endif
34 #endif /*__P */
35
36 /*
37 Builtin mailbox types.
38 A circular list is use for the builtin.
39 Proper locking is not done when accessing the list.
40 FIXME: not thread-safe. */
41 struct _registrar
42 {
43 struct url_registrar *ureg;
44 struct mailbox_registrar *mreg;
45 int is_allocated;
46 struct _registrar *next;
47 };
48
49 /* IMAP */
50 extern struct mailbox_registrar _mailbox_imap_registrar;
51 extern struct url_registrar _url_imap_registrar;
52
53 /* MBOX */
54 extern struct mailbox_registrar _mailbox_mbox_registrar;
55 extern struct url_registrar _url_mbox_registrar;
56
57 /* MAILTO */
58 extern struct mailbox_registrar _mailbox_mailto_registrar;
59 extern struct url_registrar _url_mailto_registrar;
60
61 /* MDIR */
62 extern struct mailbox_registrar _mailbox_maildir_registrar;
63 extern struct url_registrar _url_maildir_registrar;
64
65 /* MMDF */
66 extern struct mailbox_registrar _mailbox_mmdf_registrar;
67 extern struct url_registrar _url_mmdf_registrar;
68
69 /* UNIX */
70 extern struct mailbox_registrar _mailbox_unix_registrar;
71 extern struct url_registrar _url_unix_registrar;
72
73 /* POP */
74 extern struct mailbox_registrar _mailbox_pop_registrar;
75 extern struct url_registrar _url_pop_registrar;
76
77 #ifdef __cplusplus
78 }
79 #endif
80
81 #endif /* _REGISTRAR0_H */
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18
19 #ifdef HAVE_CONFIG_H
20 # include "config.h"
21 #endif
22
23 #include <header0.h>
24 #include <string.h>
25 #include <stdlib.h>
26 #include <errno.h>
27
28 static int rfc822_parse (header_t h, const char *blurb, size_t len);
29 static int rfc822_set_value (header_t h, const char *fn, const char *fb,
30 size_t n, int replace);
31 ssize_t rfc822_get_data (header_t h, char *buf, size_t buflen,
32 off_t off, int *err);
33 static int rfc822_get_value (header_t h, const char *fn,
34 char *fb, size_t len, size_t *n);
35
36 struct _rfc822
37 {
38 char *blurb;
39 size_t blurb_len;
40 size_t hdr_count;
41 struct _hdr *hdr;
42 };
43
44 typedef struct _rfc822 * rfc822_t;
45
46
47 int
48 rfc822_init (header_t *ph, const char *blurb, size_t len)
49 {
50 header_t h;
51 int status;
52 h = calloc (1, sizeof (*h));
53 if (h == NULL)
54 return ENOMEM;
55 h->_init = rfc822_init;
56 h->_destroy = rfc822_destroy;
57 h->_parse = rfc822_parse;
58 h->_get_value = rfc822_get_value;
59 h->_set_value = rfc822_set_value;
60 h->_get_data = rfc822_get_data;
61
62 status = h->_parse (h, blurb, len);
63 if (status != 0)
64 free (h);
65 *ph = h;
66 return status;
67 }
68
69 void
70 rfc822_destroy (header_t *ph)
71 {
72 if (ph && *ph)
73 {
74 header_t h = *ph;
75 /* own by a message */
76 if (h->message)
77 {
78 *ph = NULL;
79 return;
80 }
81 if (h->data)
82 {
83 rfc822_t rfc = (rfc822_t)h->data;
84 free (rfc->hdr);
85 free (rfc->blurb);
86 free (rfc);
87 }
88 free (h);
89 *ph = NULL;
90 }
91 }
92
93 static int
94 rfc822_parse (header_t h, const char *blurb, size_t len)
95 {
96 rfc822_t rfc;
97 char *header_end;
98 char *header_start;
99 char *header_start2;
100 struct _hdr *hdr;
101
102 if (h == NULL || blurb == NULL || len == 0)
103 return EINVAL;
104
105 rfc = calloc (1, sizeof (*rfc));
106 if (rfc == NULL)
107 return ENOMEM;
108
109 rfc->blurb = calloc (1, len);
110 if (rfc->blurb == NULL)
111 {
112 free (rfc);
113 return ENOMEM;
114 }
115 rfc->blurb_len = len;
116 memcpy (rfc->blurb, blurb, len);
117
118 for (header_start = rfc->blurb;; header_start = ++header_end)
119 {
120 /* get a header, a header is :
121 field-name ':' field-body1
122 [ ' ' '\t' field-body2 ] '\r' '\n'
123 */
124 for (header_start2 = header_start;;header_start2 = ++header_end)
125 {
126 header_end = memchr (header_start2, '\n', len);
127 if (header_end == NULL)
128 break;
129 else
130 {
131 len -= (header_end - header_start2 + 1);
132 if (len == 0)
133 {
134 header_end = NULL;
135 break;
136 }
137 if (header_end[1] != ' '
138 && header_end[1] != '\t')
139 break; /* new header break the inner for */
140 }
141 /* *header_end = ' '; smash LF */
142 }
143
144 if (header_end == NULL)
145 break; /* bail out */
146
147 hdr = realloc (rfc->hdr, (rfc->hdr_count + 1) * sizeof (*hdr));
148 if (hdr == NULL)
149 {
150 free (rfc->blurb);
151 free (rfc->hdr);
152 free (rfc);
153 return ENOMEM;
154 }
155 rfc->hdr = hdr;
156 rfc->hdr_count++;
157 /* Treats unix "From " specially */
158 if ((header_end - header_start >= 5)
159 && strncmp (header_start, "From ", 5) == 0)
160 {
161 rfc->hdr[rfc->hdr_count - 1].fn = header_start;
162 rfc->hdr[rfc->hdr_count - 1].fn_end = header_start + 6;
163 rfc->hdr[rfc->hdr_count - 1].fv = header_start + 6;
164 rfc->hdr[rfc->hdr_count - 1].fv_end = header_end;
165 }
166 else
167 {
168 char *colon = memchr (header_start, ':', header_end - header_start);
169 if (colon == NULL)
170 {
171 /* Houston we have a problem */
172 free (rfc->blurb);
173 free (rfc->hdr);
174 free (rfc);
175 return EINVAL;
176 }
177 rfc->hdr[rfc->hdr_count - 1].fn = header_start;
178 rfc->hdr[rfc->hdr_count - 1].fn_end = colon;
179 /* skip leading spaces */
180 while (*(++colon) == ' ');
181 rfc->hdr[rfc->hdr_count - 1].fv = colon;
182 rfc->hdr[rfc->hdr_count - 1].fv_end = header_end;
183 }
184 }
185 h->data = rfc;
186 return 0;
187 }
188
189 static int
190 rfc822_set_value (header_t h, const char *fn, const char *fv,
191 size_t n, int replace)
192 {
193 (void)h; (void)fn; (void)fv; (void)n; (void)replace;
194 return ENOSYS;
195 }
196
197 static int
198 rfc822_get_value (header_t h, const char *fn, char *fv, size_t len, size_t *n)
199 {
200 size_t i = 0;
201 size_t j = 0;
202 size_t name_len, fn_len, fv_len;
203 rfc822_t rfc;
204
205 if (h == NULL || fn == NULL || (rfc = (rfc822_t)h->data) == NULL)
206 return EINVAL;
207
208 for (name_len = strlen (fn), i = 0; i < rfc->hdr_count; i++)
209 {
210 fn_len = rfc->hdr[i].fn_end - rfc->hdr[i].fn;
211 if (fn_len == name_len && memcmp (rfc->hdr[i].fn, fn, fn_len) == 0)
212 {
213 fv_len = rfc->hdr[i].fv_end - rfc->hdr[i].fv;
214 j = (len < fv_len) ? len : fv_len;
215 if (fv)
216 memcpy (fv, rfc->hdr[i].fv, j);
217 break;
218 }
219 }
220 if (fv)
221 fv[j] = '\0'; /* null terminated */
222 if (n)
223 *n = fv_len;
224 return 0;
225 }
226
227 ssize_t
228 rfc822_get_data (header_t h, char *buf, size_t buflen, off_t off, int *err)
229 {
230 rfc822_t rfc;
231 ssize_t len;
232
233 if (h == NULL || (rfc = (rfc822_t)h->data) == NULL)
234 {
235 if (err)
236 *err = EINVAL;
237 return -1;
238 }
239
240 len = rfc->blurb_len - off;
241 if ((rfc->blurb_len - off) > 0)
242 {
243 if (buf)
244 {
245 len = (buflen < (size_t)len) ? buflen : len;
246 memcpy (buf, rfc->blurb + off, len);
247 }
248 }
249 else
250 len = 0;
251
252 return len;
253 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <url0.h>
23 #include <registrar.h>
24 #include <cpystr.h>
25
26 #include <string.h>
27 #include <stdlib.h>
28 #include <errno.h>
29
30
31 /* Forward prototypes */
32 static int get_scheme (const url_t, char *, size_t, size_t *);
33 static int get_user (const url_t, char *, size_t, size_t *);
34 static int get_passwd (const url_t, char *, size_t, size_t *);
35 static int get_host (const url_t, char *, size_t, size_t *);
36 static int get_port (const url_t, long *);
37 static int get_path (const url_t, char *, size_t, size_t *);
38 static int get_query (const url_t, char *, size_t, size_t *);
39 static int get_id (const url_t, int *);
40
41 int
42 url_init (url_t * purl, const char *name)
43 {
44 int status = EINVAL;
45 struct url_registrar *ureg;
46 struct mailbox_registrar *mreg;
47 registrar_t reg = NULL;
48 size_t name_len;
49 int id;
50
51 /* Sanity checks */
52 if (name == NULL || *name == '\0')
53 return status;
54
55 name_len = strlen (name);
56
57 /* Search for a known scheme */
58 while (registrar_list (&ureg, &mreg, &id, &reg) == 0)
59 {
60 size_t scheme_len;
61 if (ureg && ureg->scheme &&
62 name_len > (scheme_len = strlen (ureg->scheme)) &&
63 memcmp (name, ureg->scheme, scheme_len) == 0)
64 {
65 status = 0;
66 break;
67 }
68 }
69
70 /* Found one initialize it */
71 if (status == 0)
72 {
73 status = ureg->_init (purl, name);
74 if (status == 0)
75 {
76 url_t url = *purl;
77 url->id = id;
78 if (url->_get_id == NULL)
79 url->_get_id = get_id;
80 if (url->_get_scheme == NULL)
81 url->_get_scheme = get_scheme;
82 if (url->_get_user == NULL)
83 url->_get_user = get_user;
84 if (url->_get_passwd == NULL)
85 url->_get_passwd = get_passwd;
86 if (url->_get_host == NULL)
87 url->_get_host = get_host;
88 if (url->_get_port == NULL)
89 url->_get_port = get_port;
90 if (url->_get_path == NULL)
91 url->_get_path = get_path;
92 if (url->_get_query == NULL)
93 url->_get_query = get_query;
94 }
95 }
96 return status;
97 }
98
99 void
100 url_destroy (url_t *purl)
101 {
102 if (purl && *purl)
103 {
104 struct url_registrar *ureg;
105 int id;
106 url_get_id (*purl, &id);
107 registrar_get (id, &ureg, NULL);
108 ureg->_destroy(purl);
109 (*purl) = NULL;
110 }
111 }
112
113 int (url_get_scheme) (const url_t url, char *scheme, size_t len, size_t *n)
114 {
115 return (url) ? url->_get_scheme(url, scheme, len, n) : EINVAL;
116 }
117
118 int (url_get_user) (const url_t url, char *user, size_t len, size_t *n)
119 {
120 return (url) ? url->_get_user(url, user, len, n) : EINVAL;
121 }
122
123 int (url_get_passwd) (const url_t url, char *passwd, size_t len, size_t *n)
124 {
125 return (url) ? url->_get_passwd(url, passwd, len, n) : EINVAL;
126 }
127
128 int (url_get_host) (const url_t url, char *host, size_t len, size_t *n)
129 {
130 return (url) ? url->_get_host(url, host, len, n) : EINVAL;
131 }
132
133 int (url_get_port) (const url_t url, long *port)
134 {
135 return (url) ? url->_get_port(url, port) : EINVAL;
136 }
137
138 int (url_get_path) (const url_t url, char *path, size_t len, size_t *n)
139 {
140 return (url) ? url->_get_path(url, path, len, n) : EINVAL;
141 }
142
143 int (url_get_query) (const url_t url, char *query, size_t len, size_t *n)
144 {
145 return (url) ? url->_get_query(url, query, len, n) : EINVAL;
146 }
147
148 int (url_get_id) (const url_t url, int *id)
149 {
150 return (url) ? url->_get_id (url, id) : EINVAL;
151 }
152
153 /* Simple stub functions they all call _cpystr */
154
155 static int
156 get_scheme (const url_t u, char *s, size_t len, size_t *n)
157 {
158 size_t i;
159 if (u == NULL)
160 return EINVAL;
161 i = _cpystr (s, u->scheme, len);
162 if (n)
163 *n = i;
164 return 0;
165 }
166
167 static int
168 get_user (const url_t u, char *s, size_t len, size_t *n)
169 {
170 size_t i;
171 if (u == NULL)
172 return EINVAL;
173 i = _cpystr (s, u->user, len);
174 if (n)
175 *n = i;
176 return 0;
177 }
178
179 /* FIXME: We should not store passwd in clear, but rather
180 have a simple encoding, and decoding mechanism */
181 static int
182 get_passwd (const url_t u, char *s, size_t len, size_t *n)
183 {
184 size_t i;
185 if (u == NULL)
186 return EINVAL;
187 i = _cpystr (s, u->passwd, len);
188 if (n)
189 *n = i;
190 return 0;
191 }
192
193 static int
194 get_host (const url_t u, char *s, size_t len, size_t *n)
195 {
196 size_t i;
197 if (u == NULL)
198 return EINVAL;
199 i = _cpystr (s, u->host, len);
200 if (n)
201 *n = i;
202 return 0;
203 }
204
205 static int
206 get_port (const url_t u, long * p)
207 {
208 *p = u->port;
209 return 0;
210 }
211
212 static int
213 get_path (const url_t u, char *s, size_t len, size_t *n)
214 {
215 size_t i;
216 if (u == NULL)
217 return EINVAL;
218 i = _cpystr(s, u->path, len);
219 if (n)
220 *n = i;
221 return 0;
222 }
223
224 static int
225 get_query (const url_t u, char *s, size_t len, size_t *n)
226 {
227 size_t i;
228 if (u == NULL)
229 return EINVAL;
230 i = _cpystr(s, u->query, len);
231 if (n)
232 *n = i;
233 return 0;
234 }
235
236 static int
237 get_id (const url_t u, int *id)
238 {
239 if (id)
240 *id = u->id;
241 return 0;
242 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #ifndef _URL_H
19 #define _URL_H 1
20
21 #include <sys/types.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 #ifndef __P
28 # if __STDC__
29 # define __P(args) args
30 # else
31 # define __P(args) ()
32 # endif
33 #endif /*!__P */
34
35 /* forward declaration */
36 struct _url;
37 typedef struct _url * url_t;
38
39 extern int url_init __P ((url_t *, const char *name));
40 extern void url_destroy __P ((url_t *));
41
42 extern int url_get_id __P ((const url_t, int *id));
43
44 extern int url_get_scheme __P ((const url_t, char *sch,
45 size_t, size_t *));
46 extern int url_get_mscheme __P ((const url_t, char **, size_t *));
47
48 extern int url_get_user __P ((const url_t, char *usr,
49 size_t, size_t *));
50 extern int url_get_muser __P ((const url_t, char **, size_t *));
51
52 extern int url_get_passwd __P ((const url_t, char *passwd,
53 size_t, size_t *));
54 extern int url_get_mpasswd __P ((const url_t, char **, size_t *));
55
56 extern int url_get_host __P ((const url_t, char *host,
57 size_t, size_t *));
58 extern int url_get_mhost __P ((const url_t, char **, size_t *));
59
60 extern int url_get_port __P ((const url_t, long *port));
61
62 extern int url_get_path __P ((const url_t, char *path,
63 size_t, size_t *));
64 extern int url_get_mpath __P ((const url_t, char **, size_t *));
65
66 extern int url_get_query __P ((const url_t, char *qeury,
67 size_t, size_t *));
68 extern int url_get_mquery __P ((const url_t, char **, size_t *));
69
70 #ifdef __cplusplus
71 }
72 #endif
73
74 #endif /* URL_H */
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #ifndef _URL0_H
19 #define _URL0_H 1
20
21 #include <url.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 #ifndef __P
28 # if __STDC__
29 # define __P(args) args
30 # else
31 # define __P(args) ()
32 # endif
33 #endif /*!__P */
34
35 struct _url
36 {
37 /* Data */
38 char *scheme;
39 char *user;
40 char *passwd; /* encoded ?? */
41 char *host;
42 long port;
43 char *path;
44 char *query;
45 int id;
46
47
48 void *data;
49
50 int (*_init) __P ((url_t *url, const char *name));
51 void (*_destroy) __P ((url_t *url));
52
53 /* Methods */
54 int (*_get_id) __P ((const url_t, int *id));
55
56 int (*_get_scheme) __P ((const url_t, char *scheme,
57 size_t len, size_t *n));
58 int (*_get_mscheme) __P ((const url_t, char **, size_t *n));
59
60 int (*_get_user) __P ((const url_t, char *user,
61 size_t len, size_t *n));
62 int (*_get_muser) __P ((const url_t, char **, size_t *n));
63
64 int (*_get_passwd) __P ((const url_t, char *passwd,
65 size_t len, size_t *n));
66 int (*_get_mpasswd) __P ((const url_t, char **, size_t *n));
67
68 int (*_get_host) __P ((const url_t, char *host,
69 size_t len, size_t *n));
70 int (*_get_mhost) __P ((const url_t, char **, size_t *n));
71
72 int (*_get_port) __P ((const url_t, long *port));
73
74 int (*_get_path) __P ((const url_t, char *path,
75 size_t len, size_t *n));
76 int (*_get_mpath) __P ((const url_t, char **, size_t *n));
77
78 int (*_get_query) __P ((const url_t, char *query,
79 size_t len, size_t *n));
80 int (*_get_mquery) __P ((const url_t, char **, size_t *n));
81 };
82
83
84 /* IMAP */
85
86 /* Mailto */
87
88 /* UNIX MBOX */
89
90 /* Maildir */
91
92 /* MMDF */
93
94 /* POP3 */
95 struct _url_pop;
96 typedef struct _url_pop * url_pop_t;
97
98 struct _url_pop
99 {
100 /* we use the fields from url_t */
101 /* user, passwd, host, port */
102 char * auth;
103 int (*_get_auth) __P ((const url_pop_t, char *, size_t, size_t *));
104 };
105
106 #define MU_POP_PORT 110
107
108 /* pop*/
109 extern int url_pop_get_auth (const url_t, char *, size_t, size_t *);
110
111 /* UNIX MBOX */
112
113 #ifdef __cplusplus
114 }
115 #endif
116
117 #endif /* URL_H */
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <url0.h>
19 #include <registrar.h>
20 #include <errno.h>
21
22 static int url_imap_init (url_t *purl, const char *name);
23 static void url_imap_destroy (url_t *purl);
24
25 struct url_registrar _url_imap_registrar =
26 {
27 "imap://",
28 url_imap_init, url_imap_destroy
29 };
30
31 static void
32 url_imap_destroy (url_t *purl)
33 {
34 (void)purl;
35 return;
36 }
37
38 static int
39 url_imap_init (url_t *purl, const char *name)
40 {
41 (void)purl; (void)name;
42 return ENOSYS;
43 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <url0.h>
19 #include <registrar.h>
20 #include <errno.h>
21
22 static int url_mailto_init (url_t *purl, const char *name);
23 static void url_mailto_destroy (url_t *purl);
24
25 struct url_registrar _url_mailto_registrar =
26 {
27 "mailto:",
28 url_mailto_init, url_mailto_destroy
29 };
30
31 static void
32 url_mailto_destroy (url_t *purl)
33 {
34 (void)purl;
35 return;
36 }
37
38 static int
39 url_mailto_init (url_t *purl, const char *name)
40 {
41 (void)purl; (void)name;
42 return ENOSYS;
43 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <url0.h>
19 #include <registrar.h>
20
21 #include <errno.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 static void url_mbox_destroy (url_t *purl);
26 static int url_mbox_init (url_t *purl, const char *name);
27
28 struct url_registrar _url_mbox_registrar =
29 {
30 "/",
31 url_mbox_init, url_mbox_destroy
32 };
33
34 static void
35 url_mbox_destroy (url_t *purl)
36 {
37 if (purl && *purl)
38 {
39 url_t url = *purl;
40 free (url->scheme);
41 free (url->path);
42 free (url);
43 *purl = NULL;
44 }
45 }
46
47 /*
48 UNIX box
49 */
50 static int
51 url_mbox_init (url_t *purl, const char *name)
52 {
53 url_t url;
54 struct url_registrar *ureg = &_url_mbox_registrar;
55
56 /* reject the obvious */
57 if (name == NULL || *name == '\0')
58 return EINVAL;
59
60 /* FIXME: do I need to decode url encoding '% hex hex' ? */
61
62 url = calloc(1, sizeof (*url));
63 if (url == NULL)
64 return ENOMEM;
65
66 /* TYPE */
67 url->_init = ureg->_init;
68 url->_destroy = ureg->_destroy;
69
70 /* SCHEME */
71 url->scheme = strdup (ureg->scheme);
72 if (url->scheme == NULL)
73 {
74 ureg->_destroy (&url);
75 return ENOMEM;
76 }
77
78 /* PATH */
79 url->path = strdup (name);
80 if (url->path == NULL)
81 {
82 ureg->_destroy (&url);
83 return ENOMEM;
84 }
85
86 *purl = url;
87 return 0;
88 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <url0.h>
19 #include <registrar.h>
20
21 #include <errno.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 static void url_maildir_destroy (url_t *purl);
26 static int url_maildir_init (url_t *purl, const char *name);
27
28 struct url_registrar _url_maildir_registrar =
29 {
30 "maildir:",
31 url_maildir_init, url_maildir_destroy
32 };
33
34 static void
35 url_maildir_destroy (url_t *purl)
36 {
37 if (purl && *purl)
38 {
39 url_t url = *purl;
40 free (url->scheme);
41 free (url->path);
42 free (url);
43 *purl = NULL;
44 }
45 }
46
47 /*
48 MAILDIR URL
49 maildir:
50 */
51 static int
52 url_maildir_init (url_t *purl, const char *name)
53 {
54 url_t url;
55 struct url_registrar *ureg = &_url_maildir_registrar;
56 size_t len, scheme_len = strlen (ureg->scheme);
57
58 /* reject the obvious */
59 if (name == NULL || strncmp (ureg->scheme, name, scheme_len) != 0
60 || (len = strlen (name)) < (scheme_len + 1) /* (scheme)+1(path)*/)
61 return EINVAL;
62
63 /* do I need to decode url encoding '% hex hex' ? */
64
65 url = calloc(1, sizeof (*url));
66 if (url == NULL)
67 return EINVAL;
68
69 /* TYPE */
70 url->_init = ureg->_init;
71 url->_destroy = ureg->_destroy;
72
73 /* SCHEME */
74 url->scheme = strdup (ureg->scheme);
75 if (url->scheme == NULL)
76 {
77 ureg->_destroy (&url);
78 return ENOMEM;
79 }
80
81 /* PATH */
82 name += scheme_len; /* pass the scheme */
83 url->path = strdup (name);
84 if (url->path == NULL)
85 {
86 ureg->_destroy (&url);
87 return ENOMEM;
88 }
89
90 *purl = url;
91 return 0;
92 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <url0.h>
19 #include <registrar.h>
20
21 #include <errno.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 static void url_mh_destroy (url_t *purl);
26 static int url_mh_init (url_t *purl, const char *name);
27
28 struct url_registrar _url_mh_registrar =
29 {
30 "mh:",
31 url_mh_init, url_mh_destroy
32 };
33
34 static void
35 url_mh_destroy (url_t *purl)
36 {
37 if (purl && *purl)
38 {
39 url_t url = *purl;
40 free (url->scheme);
41 free (url->path);
42 free (url);
43 *purl = NULL;
44 }
45 }
46
47 /*
48 MH URL
49 mh:
50 */
51 static int
52 url_mh_init (url_t *purl, const char *name)
53 {
54 url_t url;
55 struct url_registrar *ureg = &_url_mh_registrar;
56 size_t len, scheme_len = strlen (ureg->scheme);
57
58 /* reject the obvious */
59 if (name == NULL || strncmp (ureg->scheme, name, scheme_len) != 0
60 || (len = strlen (name)) < (scheme_len + 1) /* (scheme)+1(path)*/)
61 return EINVAL;
62
63 /* do I need to decode url encoding '% hex hex' ? */
64
65 url = calloc(1, sizeof (*url));
66 if (url == NULL)
67 return ENOMEM;
68
69 /* TYPE */
70 url->_init = ureg->_init;
71 url->_destroy = ureg->_destroy;
72
73 /* SCHEME */
74 url->scheme = strdup (ureg->scheme);
75 if (url->scheme == NULL)
76 {
77 ureg->_destroy (&url);
78 return ENOMEM;
79 }
80
81 /* PATH */
82 name += scheme_len; /* pass the scheme */
83 url->path = strdup (name);
84 if (url->path == NULL)
85 {
86 ureg->_destroy (&url);
87 return ENOMEM;
88 }
89
90 *purl = url;
91 return 0;
92 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <url0.h>
19 #include <registrar.h>
20
21 #include <errno.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 static void url_mmdf_destroy (url_t *purl);
26 static int url_mmdf_init (url_t *purl, const char *name);
27
28 struct url_registrar _url_mmdf_registrar =
29 {
30 "mmdf:",
31 url_mmdf_init, url_mmdf_destroy
32 };
33
34 static void
35 url_mmdf_destroy (url_t *purl)
36 {
37 if (purl && *purl)
38 {
39 url_t url = *purl;
40 free (url->scheme);
41 free (url->path);
42 free (url);
43 *purl = NULL;
44 }
45 }
46
47 /*
48 MMDF URL
49 mmdf:
50 */
51 static int
52 url_mmdf_init (url_t *purl, const char *name)
53 {
54 url_t url;
55 struct url_registrar *ureg = &_url_mmdf_registrar;
56 size_t len, scheme_len = strlen (ureg->scheme);
57
58 /* reject the obvious */
59 if (name == NULL || strncmp (ureg->scheme, name, scheme_len) != 0
60 || (len = strlen (name)) < 8 /* 7(scheme)+1(path)*/)
61 return EINVAL;
62
63 /* do I need to decode url encoding '% hex hex' ? */
64
65 url = calloc(1, sizeof (*url));
66 if (url == NULL)
67 return ENOMEM;
68
69 /* TYPE */
70 url->_init = ureg->_init;
71 url->_destroy = ureg->_destroy;
72
73 /* SCHEME */
74 url->scheme = strdup (ureg->scheme);
75 if (url->scheme == NULL)
76 {
77 ureg->_destroy (&url);
78 return ENOMEM;
79 }
80
81 /* PATH */
82 name += scheme_len; /* pass the scheme */
83 url->path = strdup (name);
84 if (url->path == NULL)
85 {
86 ureg->_destroy (&url);
87 return ENOMEM;
88 }
89
90 *purl = url;
91 return 0;
92 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <url0.h>
19 #include <registrar.h>
20
21 #include <errno.h>
22 #include <cpystr.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <errno.h>
26
27 static void url_pop_destroy (url_t *purl);
28 static int url_pop_init (url_t *purl, const char *name);
29
30 struct url_registrar _url_pop_registrar =
31 {
32 "pop://",
33 url_pop_init, url_pop_destroy
34 };
35
36 static int get_auth (const url_pop_t up, char *s, size_t len, size_t *);
37
38 static int
39 get_auth (const url_pop_t up, char *s, size_t len, size_t *n)
40 {
41 size_t i;
42 if (up)
43 return EINVAL;
44 i = _cpystr (s, up->auth, len);
45 if (n)
46 *n = i;
47 return 0;
48 }
49
50 int
51 (url_pop_get_auth) (const url_t url, char *auth, size_t len, size_t *n)
52 {
53 return (url) ?
54 ((url_pop_t)(url->data))->_get_auth(url->data, auth, len, n) : EINVAL;
55 }
56
57 static void
58 url_pop_destroy (url_t *purl)
59 {
60 if (purl && *purl)
61 {
62 url_t url = *purl;
63 free (url->scheme);
64 free (url->user);
65 free (url->passwd);
66 free (url->host);
67 if (url->data)
68 {
69 url_pop_t up = url->data;
70 free (up->auth);
71 }
72 free (url->data);
73 free (url);
74 *purl = NULL;
75 }
76 }
77
78 /*
79 POP URL
80 pop://<user>;AUTH=<auth>@<host>:<port>
81 */
82 static int
83 url_pop_init (url_t *purl, const char *name)
84 {
85 const char *host_port, *index;
86 struct url_registrar *ureg = &_url_pop_registrar;
87 size_t len, scheme_len = strlen (ureg->scheme);
88 url_t url;
89 url_pop_t up;
90
91 /* reject the obvious */
92 if (name == NULL || strncmp (ureg->scheme, name, scheme_len) != 0
93 || (host_port = strchr (name, '@')) == NULL
94 || (len = strlen (name)) < 9 /* 6(scheme)+1(user)+1(@)+1(host)*/)
95 return ENOMEM;
96
97 /* do I need to decode url encoding '% hex hex' ? */
98
99 url = calloc(1, sizeof (*url));
100 url->data = up = calloc(1, sizeof(*up));
101 up->_get_auth = get_auth;
102
103 /* TYPE */
104 url->_init = _url_pop_registrar._init;
105 url->_destroy = _url_pop_registrar._destroy;
106
107 /* SCHEME */
108 url->scheme = strdup ("pop://");
109 if (url->scheme == NULL)
110 {
111 url_pop_destroy (&url);
112 return ENOMEM;
113 }
114
115 name += scheme_len; /* pass the scheme */
116
117 /* looking for "user;auth=auth-enc" */
118 for (index = name; index != host_port; index++)
119 {
120 /* Auth ? */
121 if (*index == ';')
122 {
123 /* make sure it the token */
124 if (strncasecmp(index + 1, "auth=", 5) == 0)
125 break;
126 }
127 }
128
129 if (index == name)
130 {
131 url_pop_destroy (&url);
132 return -1;
133 }
134
135 /* USER */
136 url->user = malloc(index - name + 1);
137 if (url->user == NULL)
138 {
139 url_pop_destroy (&url);
140 return -1;
141 }
142 ((char *)memcpy(url->user, name, index - name))[index - name] = '\0';
143
144 /* AUTH */
145 if ((host_port - index) <= 6 /*strlen(";AUTH=")*/)
146 {
147 /* Use default AUTH '*' */
148 up->auth = malloc (1 + 1);
149 if (up->auth)
150 {
151 up->auth[0] = '*';
152 up->auth[1] = '\0';
153 }
154 }
155 else
156 {
157 /* move pass AUTH= */
158 index += 6;
159 up->auth = malloc (host_port - index + 1);
160 if (up->auth)
161 {
162 ((char *)memcpy (up->auth, index, host_port - index))
163 [host_port - index] = '\0';
164 }
165 }
166
167 if (up->auth == NULL)
168 {
169 url_pop_destroy (&url);
170 return -1;
171 }
172
173 /* HOST:PORT */
174 index = strchr (++host_port, ':');
175 if (index == NULL)
176 {
177 url->host = strdup (host_port);
178 url->port = MU_POP_PORT;
179 }
180 else
181 {
182 long p = strtol(index + 1, NULL, 10);
183 url->host = malloc (index - host_port + 1);
184 if (url->host)
185 {
186 ((char *)memcpy (url->host, host_port, index - host_port))
187 [index - host_port]='\0';
188 url->port = (p == 0) ? MU_POP_PORT : p;
189 }
190 }
191
192 if (url->host == NULL)
193 {
194 url_pop_destroy (&url);
195 return ENOMEM;
196 }
197
198 *purl = url;
199 return 0;
200 }
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <url0.h>
19 #include <registrar.h>
20
21 #include <errno.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 static void url_unix_destroy (url_t *purl);
26 static int url_unix_init (url_t *purl, const char *name);
27
28 struct url_registrar _url_unix_registrar =
29 {
30 "unix:",
31 url_unix_init, url_unix_destroy
32 };
33
34 static void
35 url_unix_destroy (url_t *purl)
36 {
37 if (purl && *purl)
38 {
39 url_t url = *purl;
40 free (url->scheme);
41 free (url->path);
42 free (url);
43 *purl = NULL;
44 }
45 }
46
47 /*
48 UNIX Mbox
49 unix:/path
50 */
51 static int
52 url_unix_init (url_t *purl, const char *name)
53 {
54 url_t url;
55 struct url_registrar *ureg = &_url_unix_registrar;
56 size_t len, scheme_len = strlen (ureg->scheme);
57
58 /* reject the obvious */
59 if (name == NULL || strncmp (ureg->scheme, name, scheme_len) != 0
60 || (len = strlen (name)) < scheme_len + 1 /* 7(scheme)+1(path)*/)
61 return EINVAL;
62
63 /* do I need to decode url encoding '% hex hex' ? */
64
65 url = calloc(1, sizeof (*url));
66 if (url == NULL)
67 return ENOMEM;
68
69 /* TYPE */
70 url->_init = ureg->_init;
71 url->_destroy = ureg->_destroy;
72
73 /* SCHEME */
74 url->scheme = strdup (ureg->scheme);
75 if (url->scheme == NULL)
76 {
77 ureg->_destroy (&url);
78 return ENOMEM;
79 }
80
81 /* PATH */
82 name += scheme_len; /* pass the scheme */
83 url->path = strdup (name);
84 if (url->path == NULL)
85 {
86 ureg->_destroy (&url);
87 return ENOMEM;
88 }
89
90 *purl = url;
91 return 0;
92 }