Added
Showing
3 changed files
with
227 additions
and
0 deletions
auth/lbuf.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2003 Free Software Foundation, Inc. | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Lesser General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library 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 GNU | ||
12 | Lesser General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Lesser General Public | ||
15 | License along with this library; if not, write to the Free Software | ||
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ | ||
17 | |||
18 | #ifdef HAVE_CONFIG_H | ||
19 | # include <config.h> | ||
20 | #endif | ||
21 | #include <stdlib.h> | ||
22 | #include <string.h> | ||
23 | #include <errno.h> | ||
24 | #include <lbuf.h> | ||
25 | |||
26 | struct _line_buffer { | ||
27 | char *buffer; /* Line buffer */ | ||
28 | size_t size; /* Allocated size */ | ||
29 | size_t level; /* Current filling level */ | ||
30 | }; | ||
31 | |||
32 | int | ||
33 | _auth_lb_create (struct _line_buffer **s) | ||
34 | { | ||
35 | *s = malloc (sizeof (**s)); | ||
36 | if (!*s) | ||
37 | return ENOMEM; | ||
38 | (*s)->buffer = NULL; | ||
39 | (*s)->size = 0; | ||
40 | (*s)->level = 0; | ||
41 | return 0; | ||
42 | } | ||
43 | |||
44 | void | ||
45 | _auth_lb_destroy (struct _line_buffer **s) | ||
46 | { | ||
47 | if (s && *s) | ||
48 | { | ||
49 | free ((*s)->buffer); | ||
50 | free (*s); | ||
51 | *s = NULL; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | void | ||
56 | _auth_lb_drop (struct _line_buffer *s) | ||
57 | { | ||
58 | s->level = 0; | ||
59 | } | ||
60 | |||
61 | int | ||
62 | _auth_lb_grow (struct _line_buffer *s, const char *ptr, size_t size) | ||
63 | { | ||
64 | if (!s->buffer) | ||
65 | { | ||
66 | s->buffer = malloc (size); | ||
67 | s->size = size; | ||
68 | s->level = 0; | ||
69 | } | ||
70 | else if (s->size - s->level < size) | ||
71 | { | ||
72 | size_t newsize = s->size + size; | ||
73 | s->buffer = realloc (s->buffer, newsize); | ||
74 | if (s->buffer) | ||
75 | s->size = newsize; | ||
76 | } | ||
77 | |||
78 | if (!s->buffer) | ||
79 | return ENOMEM; | ||
80 | |||
81 | memcpy (s->buffer + s->level, ptr, size); | ||
82 | s->level += size; | ||
83 | return 0; | ||
84 | } | ||
85 | |||
86 | int | ||
87 | _auth_lb_read (struct _line_buffer *s, const char *optr, size_t osize) | ||
88 | { | ||
89 | int len; | ||
90 | |||
91 | len = s->level > osize ? osize : s->level; | ||
92 | memcpy (optr, s->buffer, len); | ||
93 | if (s->level > len) | ||
94 | { | ||
95 | memmove (s->buffer, s->buffer + len, s->level - len); | ||
96 | s->level -= len; | ||
97 | } | ||
98 | else if (s->level == len) | ||
99 | s->level = 0; | ||
100 | |||
101 | return len; | ||
102 | } | ||
103 | |||
104 | int | ||
105 | _auth_lb_readline (struct _line_buffer *s, const char *ptr, size_t size) | ||
106 | { | ||
107 | char *p = strchr (s->buffer, '\n'); | ||
108 | |||
109 | if (p && p - s->buffer + 1 < size) | ||
110 | size = p - s->buffer + 1; | ||
111 | return _auth_lb_read (s, ptr, size); | ||
112 | } | ||
113 | |||
114 | int | ||
115 | _auth_lb_level (struct _line_buffer *s) | ||
116 | { | ||
117 | return s->level; | ||
118 | } | ||
119 | |||
120 | char * | ||
121 | _auth_lb_data (struct _line_buffer *s) | ||
122 | { | ||
123 | return s->buffer; | ||
124 | } |
auth/lbuf.h
0 → 100644
1 | struct _line_buffer; | ||
2 | |||
3 | int _auth_lb_create (struct _line_buffer **s); | ||
4 | void _auth_lb_destroy (struct _line_buffer **s); | ||
5 | void _auth_lb_drop (struct _line_buffer *s); | ||
6 | |||
7 | int _auth_lb_grow (struct _line_buffer *s, const char *ptr, size_t size); | ||
8 | int _auth_lb_read (struct _line_buffer *s, const char *ptr, size_t size); | ||
9 | int _auth_lb_readline (struct _line_buffer *s, const char *ptr, size_t size); | ||
10 | int _auth_lb_level (struct _line_buffer *s); | ||
11 | char *_auth_lb_data (struct _line_buffer *s); | ||
12 | |||
13 |
mailbox/mbox/file.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Lesser General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library 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 GNU | ||
12 | Lesser General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Lesser General Public | ||
15 | License along with this library; if not, write to the Free Software | ||
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ | ||
17 | |||
18 | #ifdef HAVE_CONFIG_H | ||
19 | # include <config.h> | ||
20 | #endif | ||
21 | |||
22 | #include <string.h> | ||
23 | #include <errno.h> | ||
24 | #include <stdlib.h> | ||
25 | #include <sys/stat.h> | ||
26 | |||
27 | #include <mailutils/url.h> | ||
28 | |||
29 | #include <mailbox0.h> | ||
30 | #include <registrar0.h> | ||
31 | |||
32 | /* | ||
33 | Caveat there is no specific URL for file mailbox or simple path name, | ||
34 | <path_name> | ||
35 | file:<path_name> | ||
36 | |||
37 | It would be preferrable to use : | ||
38 | maildir:<path> | ||
39 | unix:<path> | ||
40 | mmdf:<path> | ||
41 | This would eliminate heuristic discovery that would turn | ||
42 | out to be wrong. | ||
43 | */ | ||
44 | |||
45 | int | ||
46 | _mailbox_file_init (mailbox_t mbox) | ||
47 | { | ||
48 | struct stat st; | ||
49 | size_t len = 0; | ||
50 | char *path; | ||
51 | int status; | ||
52 | |||
53 | status = url_get_path (mbox->url, NULL, 0, &len); | ||
54 | if (status != 0) | ||
55 | return status; | ||
56 | path = calloc (len + 1, sizeof (char)); | ||
57 | if (path == NULL) | ||
58 | return ENOMEM; | ||
59 | status = url_get_path (mbox->url, path, len + 1, NULL); | ||
60 | if (status != 0) | ||
61 | { | ||
62 | free (path); | ||
63 | return status; | ||
64 | } | ||
65 | |||
66 | /* Sigh, if they want to creat ??? they should know the type of ??? | ||
67 | What is the best course of action ? For the default is mbox if the | ||
68 | file does not exist. */ | ||
69 | if (stat (path, &st) < 0) | ||
70 | { | ||
71 | status = _mailbox_mbox_init (mbox); | ||
72 | } | ||
73 | else if (S_ISDIR (st.st_mode)) | ||
74 | { | ||
75 | /* Is that true ? Are all directories Maildir ?? */ | ||
76 | /* NOT SUPPORTED: status = _mailbox_maildir_init (mbox);*/ | ||
77 | status = ENOSYS; | ||
78 | } | ||
79 | else | ||
80 | { | ||
81 | /* | ||
82 | FIXME: We should do an open() and try | ||
83 | to do a better reconnaissance of the type, | ||
84 | maybe MMDF. For now assume Unix MBox */ | ||
85 | status = _mailbox_mbox_init (mbox); | ||
86 | } | ||
87 | |||
88 | free (path); | ||
89 | return status; | ||
90 | } |
-
Please register or sign in to post a comment