2 * Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 *---------------------------------------------------------------------------
27 * isdntel - isdn4bsd telephone answering machine support
28 * ======================================================
30 * $Id: files.c,v 1.5 2004/10/30 08:31:39 dsl Exp $
34 * last edit-date: [Sat Jan 6 13:04:44 2001]
36 *----------------------------------------------------------------------------*/
40 struct onefile
* store(struct onefile
*new, struct onefile
*top
);
43 /*---------------------------------------------------------------------------*
44 * create a doubly linked list in sorted order, return pointer to new
45 * first element of list
46 *---------------------------------------------------------------------------*/
48 (struct onefile
*new, /* new entry to store into list */
49 struct onefile
*top
) /* current first entry in list */
51 struct onefile
*old
, *p
;
53 if (last
== NULL
) /* enter very first element ? */
57 last
= new; /* init last */
58 return (new); /* return new first */
60 p
= top
; /* p = old first element */
64 if ((strcmp(p
->fname
, new->fname
)) < 0) /* current less new ? */
70 { /* current >= new */
93 /*---------------------------------------------------------------------------*
94 * read current directory and build up a doubly linked sorted list
95 *---------------------------------------------------------------------------*/
99 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
100 register struct dirent
*dp
;
102 register struct direct
*dp
;
104 register struct onefile
*new_entry
;
110 if ((dirp
= opendir(spooldir
)) == NULL
)
111 fatal("cannot open spooldirectory %s!\n", spooldir
);
113 for (dp
= readdir(dirp
); dp
!= NULL
; dp
= readdir(dirp
))
115 if (!isdigit((unsigned char)*(dp
->d_name
)))
118 if ((new_entry
= (struct onefile
*) malloc(sizeof(struct onefile
))) == NULL
)
120 fatal("files.c, fill_list(): structure onefile malloc failed");
123 /* alloc filename memory and copy name into it */
125 if ((new_entry
->fname
= strdup(dp
->d_name
)) == NULL
)
127 fatal("files.c, fill_list(): malloc filename string memory failed");
130 /* fill in remaining fields from filename */
132 tmp
[0] = dp
->d_name
[4]; /* day msb */
133 tmp
[1] = dp
->d_name
[5]; /* day lsb */
135 tmp
[3] = dp
->d_name
[2]; /* month msb */
136 tmp
[4] = dp
->d_name
[3]; /* month lsb */
138 tmp
[6] = dp
->d_name
[0]; /* year msb */
139 tmp
[7] = dp
->d_name
[1]; /* year lsb */
142 if ((new_entry
->date
= strdup(tmp
)) == NULL
)
144 fatal("files.c, fill_list(): malloc date string memory failed");
147 tmp
[0] = dp
->d_name
[6]; /* hour msb */
148 tmp
[1] = dp
->d_name
[7]; /* hour lsb */
150 tmp
[3] = dp
->d_name
[8]; /* minute msb */
151 tmp
[4] = dp
->d_name
[9]; /* minute lsb */
153 tmp
[6] = dp
->d_name
[10]; /* second msb */
154 tmp
[7] = dp
->d_name
[11]; /* second lsb */
157 if ((new_entry
->time
= strdup(tmp
)) == NULL
)
159 fatal("files.c, fill_list(): malloc time string memory failed");
162 /* destination number */
167 while(*s
&& (*s
!= '-'))
172 if ((new_entry
->dstnumber
= strdup(tmp
)) == NULL
)
174 fatal("files.c, fill_list(): malloc dstnumber string memory failed");
182 while(*s
&& (*s
!= '-'))
187 if ((new_entry
->srcnumber
= strdup(tmp
)) == NULL
)
189 fatal("files.c, fill_list(): malloc srcnumber string memory failed");
192 /* length in seconds */
197 while(*s
&& (*s
!= '-'))
202 if ((new_entry
->seconds
= strdup(tmp
)) == NULL
)
204 fatal("files.c, fill_list(): malloc seconds string memory failed");
207 /* search for alias and add if found */
209 new_entry
->alias
= get_alias(new_entry
->srcnumber
);
211 /* sort entry into linked list */
213 first
= store(new_entry
, first
);
215 flcnt
++; /* increment file count */
217 closedir(dirp
); /* close current dir */
218 return(flcnt
); /* ok return */
221 /*---------------------------------------------------------------------------*
222 * free the current malloc'ed list
223 *---------------------------------------------------------------------------*/
227 register struct onefile
*dir
;
228 register struct onefile
*tmp
;
230 dir
= first
; /* start of linked list */
232 while (dir
) /* free all */
234 tmp
= dir
->next
; /* save ptr to next entry */
235 free(dir
->fname
); /* free filename space */
238 free(dir
->srcnumber
);
239 free(dir
->dstnumber
);
241 free(dir
); /* free struct space */
242 dir
= tmp
; /* ptr = ptr to next entry */
244 first
= NULL
; /* first ptr = NULL */
245 last
= NULL
; /* last ptr = NULL */
248 /*---------------------------------------------------------------------------*
250 *---------------------------------------------------------------------------*/
252 delete(struct onefile
*this)
254 char buffer
[MAXPATHLEN
+1];
259 snprintf(buffer
, sizeof(buffer
), "%s", this->fname
);
270 /*---------------------------------------------------------------------------*
271 * reread the spool directory
272 *---------------------------------------------------------------------------*/
283 /*---------------------------------------------------------------------------*
285 *---------------------------------------------------------------------------*/
287 play(struct onefile
*this)
289 char buffer
[MAXPATHLEN
+1];
294 snprintf(buffer
, sizeof(buffer
), playstring
, this->fname
);
299 /*---------------------------------- EOF -------------------------------------*/