More minor IPI work.
[dragonfly/vkernel-mp.git] / usr.sbin / i4b / isdnd / dial.c
blob9da464c10999eb6204c70687c68f38ad74c46dcf
1 /*
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
6 * are met:
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
23 * SUCH DAMAGE.
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 $
33 * $DragonFly: src/usr.sbin/i4b/isdnd/dial.c,v 1.2 2003/06/17 06:29:54 dillon Exp $
35 * last edit-date: [Mon Dec 13 21:45:51 1999]
37 *---------------------------------------------------------------------------*/
39 #include "isdnd.h"
41 /*---------------------------------------------------------------------------*
42 * select the first remote number to dial according to the
43 * dial strategy
44 *---------------------------------------------------------------------------*/
45 void
46 select_first_dialno(cfg_entry_t *cep)
48 int i, j;
50 if(cep->keypad[0] != '\0')
51 return;
53 if(cep->remote_numbers_count < 1)
55 log(LL_ERR, "select_first_dialno: remote_numbers_count < 1!");
56 return;
59 if(cep->remote_numbers_count == 1)
61 strcpy(cep->remote_phone_dialout, cep->remote_numbers[0].number);
62 DBGL(DL_DIAL, (log(LL_DBG, "select_first_dialno: only one no, no = %s", cep->remote_phone_dialout)));
63 cep->last_remote_number = 0;
64 return;
67 if(cep->remote_numbers_handling == RNH_FIRST)
69 strcpy(cep->remote_phone_dialout, cep->remote_numbers[0].number);
70 DBGL(DL_DIAL, (log(LL_DBG, "select_first_dialno: use first, no = %s", cep->remote_phone_dialout)));
71 cep->last_remote_number = 0;
72 return;
75 i = cep->last_remote_number;
77 for(j = cep->remote_numbers_count; j > 0; j--)
79 if(cep->remote_numbers[i].flag == RNF_SUCC)
81 if(cep->remote_numbers_handling == RNH_LAST)
83 strcpy(cep->remote_phone_dialout, cep->remote_numbers[i].number);
84 DBGL(DL_DIAL, (log(LL_DBG, "select_first_dialno: use last, no = %s", cep->remote_phone_dialout)));
85 cep->last_remote_number = i;
86 return;
88 else
90 if(++i >= cep->remote_numbers_count)
91 i = 0;
93 strcpy(cep->remote_phone_dialout, cep->remote_numbers[i].number);
94 DBGL(DL_DIAL, (log(LL_DBG, "select_first_dialno: use next, no = %s", cep->remote_phone_dialout)));
95 cep->last_remote_number = i;
96 return;
100 if(++i >= cep->remote_numbers_count)
101 i = 0;
103 strcpy(cep->remote_phone_dialout, cep->remote_numbers[0].number);
104 DBGL(DL_DIAL, (log(LL_DBG, "select_first_dialno: no last found (use 0), no = %s", cep->remote_phone_dialout)));
105 cep->last_remote_number = 0;
108 /*---------------------------------------------------------------------------*
109 * select next remote number to dial (last was unsuccesfull)
110 *---------------------------------------------------------------------------*/
111 void
112 select_next_dialno(cfg_entry_t *cep)
114 if(cep->remote_numbers_count < 1)
116 log(LL_ERR, "select_next_dialno: remote_numbers_count < 1!");
117 return;
120 if(cep->remote_numbers_count == 1)
122 strcpy(cep->remote_phone_dialout, cep->remote_numbers[0].number);
123 DBGL(DL_DIAL, (log(LL_DBG, "select_next_dialno: only one no, no = %s", cep->remote_phone_dialout)));
124 cep->last_remote_number = 0;
125 return;
128 /* mark last try as bad */
130 cep->remote_numbers[cep->last_remote_number].flag = RNF_IDLE;
132 /* next one to try */
134 cep->last_remote_number++;
136 if(cep->last_remote_number >= cep->remote_numbers_count)
137 cep->last_remote_number = 0;
139 strcpy(cep->remote_phone_dialout, cep->remote_numbers[cep->last_remote_number].number);
141 DBGL(DL_DIAL, (log(LL_DBG, "select_next_dialno: index=%d, no=%s",
142 cep->last_remote_number,
143 cep->remote_numbers[cep->last_remote_number].number)));
146 /*---------------------------------------------------------------------------*
147 * dial succeded, store this number as the last successful
148 *---------------------------------------------------------------------------*/
149 void
150 select_this_dialno(cfg_entry_t *cep)
152 cep->remote_numbers[cep->last_remote_number].flag = RNF_SUCC;
154 DBGL(DL_DIAL, (log(LL_DBG, "select_this_dialno: index = %d, no = %s",
155 cep->last_remote_number,
156 cep->remote_numbers[cep->last_remote_number].number)));
159 /* EOF */