2 * Copyright (c) 1997, 2001 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 * i4b daemon - dial handling routines
28 * -----------------------------------
30 * $Id: dial.c,v 1.8 1999/12/13 21:25:24 hm Exp $
32 * $FreeBSD: src/usr.sbin/i4b/isdnd/dial.c,v 1.6.2.2 2001/12/16 15:13:38 hm Exp $
34 * last edit-date: [Mon Dec 13 21:45:51 1999]
36 *---------------------------------------------------------------------------*/
40 /*---------------------------------------------------------------------------*
41 * select the first remote number to dial according to the
43 *---------------------------------------------------------------------------*/
45 select_first_dialno(cfg_entry_t *cep)
49 if(cep->keypad[0] != '\0')
52 if(cep->remote_numbers_count < 1)
54 log(LL_ERR, "select_first_dialno: remote_numbers_count < 1!");
58 if(cep->remote_numbers_count == 1)
60 strcpy(cep->remote_phone_dialout, cep->remote_numbers[0].number);
61 DBGL(DL_DIAL, (log(LL_DBG, "select_first_dialno: only one no, no = %s", cep->remote_phone_dialout)));
62 cep->last_remote_number = 0;
66 if(cep->remote_numbers_handling == RNH_FIRST)
68 strcpy(cep->remote_phone_dialout, cep->remote_numbers[0].number);
69 DBGL(DL_DIAL, (log(LL_DBG, "select_first_dialno: use first, no = %s", cep->remote_phone_dialout)));
70 cep->last_remote_number = 0;
74 i = cep->last_remote_number;
76 for(j = cep->remote_numbers_count; j > 0; j--)
78 if(cep->remote_numbers[i].flag == RNF_SUCC)
80 if(cep->remote_numbers_handling == RNH_LAST)
82 strcpy(cep->remote_phone_dialout, cep->remote_numbers[i].number);
83 DBGL(DL_DIAL, (log(LL_DBG, "select_first_dialno: use last, no = %s", cep->remote_phone_dialout)));
84 cep->last_remote_number = i;
89 if(++i >= cep->remote_numbers_count)
92 strcpy(cep->remote_phone_dialout, cep->remote_numbers[i].number);
93 DBGL(DL_DIAL, (log(LL_DBG, "select_first_dialno: use next, no = %s", cep->remote_phone_dialout)));
94 cep->last_remote_number = i;
99 if(++i >= cep->remote_numbers_count)
102 strcpy(cep->remote_phone_dialout, cep->remote_numbers[0].number);
103 DBGL(DL_DIAL, (log(LL_DBG, "select_first_dialno: no last found (use 0), no = %s", cep->remote_phone_dialout)));
104 cep->last_remote_number = 0;
107 /*---------------------------------------------------------------------------*
108 * select next remote number to dial (last was unsuccesfull)
109 *---------------------------------------------------------------------------*/
111 select_next_dialno(cfg_entry_t *cep)
113 if(cep->remote_numbers_count < 1)
115 log(LL_ERR, "select_next_dialno: remote_numbers_count < 1!");
119 if(cep->remote_numbers_count == 1)
121 strcpy(cep->remote_phone_dialout, cep->remote_numbers[0].number);
122 DBGL(DL_DIAL, (log(LL_DBG, "select_next_dialno: only one no, no = %s", cep->remote_phone_dialout)));
123 cep->last_remote_number = 0;
127 /* mark last try as bad */
129 cep->remote_numbers[cep->last_remote_number].flag = RNF_IDLE;
131 /* next one to try */
133 cep->last_remote_number++;
135 if(cep->last_remote_number >= cep->remote_numbers_count)
136 cep->last_remote_number = 0;
138 strcpy(cep->remote_phone_dialout, cep->remote_numbers[cep->last_remote_number].number);
140 DBGL(DL_DIAL, (log(LL_DBG, "select_next_dialno: index=%d, no=%s",
141 cep->last_remote_number,
142 cep->remote_numbers[cep->last_remote_number].number)));
145 /*---------------------------------------------------------------------------*
146 * dial succeded, store this number as the last successful
147 *---------------------------------------------------------------------------*/
149 select_this_dialno(cfg_entry_t *cep)
151 cep->remote_numbers[cep->last_remote_number].flag = RNF_SUCC;
153 DBGL(DL_DIAL, (log(LL_DBG, "select_this_dialno: index = %d, no = %s",
154 cep->last_remote_number,
155 cep->remote_numbers[cep->last_remote_number].number)));