No empty .Rs/.Re
[netbsd-mini2440.git] / usr.sbin / isdn / isdnd / dial.c
blobb92a69690f27a71664ede9ced3d36c66e4fa009f
1 /*
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
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.5 2003/10/06 09:43:27 itojun Exp $
32 * $FreeBSD$
34 * last edit-date: [Mon Dec 13 21:45:51 1999]
36 *---------------------------------------------------------------------------*/
38 #include "isdnd.h"
40 /*---------------------------------------------------------------------------*
41 * select the first remote number to dial according to the
42 * dial strategy
43 *---------------------------------------------------------------------------*/
44 void
45 select_first_dialno(struct cfg_entry *cep)
47 int i, j;
49 if (cep->remote_numbers_count < 1)
51 logit(LL_ERR, "select_first_dialno: remote_numbers_count < 1!");
52 return;
55 if (cep->remote_numbers_count == 1)
57 strlcpy(cep->remote_phone_dialout,
58 cep->remote_numbers[0].number,
59 sizeof(cep->remote_phone_dialout));
60 DBGL(DL_DIAL, (logit(LL_DBG, "select_first_dialno: only one no, no = %s", cep->remote_phone_dialout)));
61 cep->last_remote_number = 0;
62 return;
65 if (cep->remote_numbers_handling == RNH_FIRST)
67 strlcpy(cep->remote_phone_dialout,
68 cep->remote_numbers[0].number,
69 sizeof(cep->remote_phone_dialout));
70 DBGL(DL_DIAL, (logit(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 strlcpy(cep->remote_phone_dialout,
84 cep->remote_numbers[i].number,
85 sizeof(cep->remote_phone_dialout));
86 DBGL(DL_DIAL, (logit(LL_DBG, "select_first_dialno: use last, no = %s", cep->remote_phone_dialout)));
87 cep->last_remote_number = i;
88 return;
90 else
92 if (++i >= cep->remote_numbers_count)
93 i = 0;
95 strlcpy(cep->remote_phone_dialout,
96 cep->remote_numbers[i].number,
97 sizeof(cep->remote_phone_dialout));
98 DBGL(DL_DIAL, (logit(LL_DBG, "select_first_dialno: use next, no = %s", cep->remote_phone_dialout)));
99 cep->last_remote_number = i;
100 return;
104 if (++i >= cep->remote_numbers_count)
105 i = 0;
107 strlcpy(cep->remote_phone_dialout, cep->remote_numbers[0].number,
108 sizeof(cep->remote_phone_dialout));
109 DBGL(DL_DIAL, (logit(LL_DBG, "select_first_dialno: no last found (use 0), no = %s", cep->remote_phone_dialout)));
110 cep->last_remote_number = 0;
113 /*---------------------------------------------------------------------------*
114 * select next remote number to dial (last was unsuccesfull)
115 *---------------------------------------------------------------------------*/
116 void
117 select_next_dialno(struct cfg_entry *cep)
119 if (cep->remote_numbers_count < 1)
121 logit(LL_ERR, "select_next_dialno: remote_numbers_count < 1!");
122 return;
125 if (cep->remote_numbers_count == 1)
127 strlcpy(cep->remote_phone_dialout,
128 cep->remote_numbers[0].number,
129 sizeof(cep->remote_phone_dialout));
130 DBGL(DL_DIAL, (logit(LL_DBG, "select_next_dialno: only one no, no = %s", cep->remote_phone_dialout)));
131 cep->last_remote_number = 0;
132 return;
135 /* mark last try as bad */
137 cep->remote_numbers[cep->last_remote_number].flag = RNF_IDLE;
139 /* next one to try */
141 cep->last_remote_number++;
143 if (cep->last_remote_number >= cep->remote_numbers_count)
144 cep->last_remote_number = 0;
146 strlcpy(cep->remote_phone_dialout,
147 cep->remote_numbers[cep->last_remote_number].number,
148 sizeof(cep->remote_phone_dialout));
150 DBGL(DL_DIAL, (logit(LL_DBG, "select_next_dialno: index=%d, no=%s",
151 cep->last_remote_number,
152 cep->remote_numbers[cep->last_remote_number].number)));
155 /*---------------------------------------------------------------------------*
156 * dial succeded, store this number as the last successful
157 *---------------------------------------------------------------------------*/
158 void
159 select_this_dialno(struct cfg_entry *cep)
161 cep->remote_numbers[cep->last_remote_number].flag = RNF_SUCC;
163 DBGL(DL_DIAL, (logit(LL_DBG, "select_this_dialno: index = %d, no = %s",
164 cep->last_remote_number,
165 cep->remote_numbers[cep->last_remote_number].number)));
168 /* EOF */