2 * Copyright (c) 1997, 2002 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 * -----------------------------------
32 * last edit-date: [Sat May 13 13:05:52 2006]
34 *---------------------------------------------------------------------------*/
38 /*---------------------------------------------------------------------------*
39 * select the first remote number to dial according to the
41 *---------------------------------------------------------------------------*/
43 select_first_dialno(cfg_entry_t *cep)
47 if(cep->keypad[0] != '\0')
50 if(cep->remote_numbers_count < 1)
52 llog(LL_ERR, "select_first_dialno: remote_numbers_count < 1!");
56 if(cep->remote_numbers_count == 1)
58 strcpy(cep->remote_phone_dialout.number, cep->remote_numbers[0].number);
59 strcpy(cep->remote_phone_dialout.subaddr, cep->remote_numbers[0].subaddr);
60 DBGL(DL_DIAL, (llog(LL_DBG, "select_first_dialno: only one no, no = %s", cep->remote_phone_dialout.number)));
61 cep->last_remote_number = 0;
65 if(cep->remote_numbers_handling == RNH_FIRST)
67 strcpy(cep->remote_phone_dialout.number, cep->remote_numbers[0].number);
68 strcpy(cep->remote_phone_dialout.subaddr, cep->remote_numbers[0].subaddr);
69 DBGL(DL_DIAL, (llog(LL_DBG, "select_first_dialno: use first, no = %s", cep->remote_phone_dialout.number)));
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.number, cep->remote_numbers[i].number);
83 strcpy(cep->remote_phone_dialout.subaddr, cep->remote_numbers[i].subaddr);
84 DBGL(DL_DIAL, (llog(LL_DBG, "select_first_dialno: use last, no = %s", cep->remote_phone_dialout.number)));
85 cep->last_remote_number = i;
90 if(++i >= cep->remote_numbers_count)
93 strcpy(cep->remote_phone_dialout.number, cep->remote_numbers[i].number);
94 strcpy(cep->remote_phone_dialout.subaddr, cep->remote_numbers[i].subaddr);
95 DBGL(DL_DIAL, (llog(LL_DBG, "select_first_dialno: use next, no = %s", cep->remote_phone_dialout.number)));
96 cep->last_remote_number = i;
101 if(++i >= cep->remote_numbers_count)
104 strcpy(cep->remote_phone_dialout.number, cep->remote_numbers[0].number);
105 DBGL(DL_DIAL, (llog(LL_DBG, "select_first_dialno: no last found (use 0), no = %s", cep->remote_phone_dialout.number)));
106 cep->last_remote_number = 0;
109 /*---------------------------------------------------------------------------*
110 * select next remote number to dial (last was unsuccesfull)
111 *---------------------------------------------------------------------------*/
113 select_next_dialno(cfg_entry_t *cep)
115 if(cep->remote_numbers_count < 1)
117 llog(LL_ERR, "select_next_dialno: remote_numbers_count < 1!");
121 if(cep->remote_numbers_count == 1)
123 strcpy(cep->remote_phone_dialout.number, cep->remote_numbers[0].number);
124 strcpy(cep->remote_phone_dialout.subaddr, cep->remote_numbers[0].subaddr);
125 DBGL(DL_DIAL, (llog(LL_DBG, "select_next_dialno: only one no, no = %s", cep->remote_phone_dialout.number)));
126 cep->last_remote_number = 0;
130 /* mark last try as bad */
132 cep->remote_numbers[cep->last_remote_number].flag = RNF_IDLE;
134 /* next one to try */
136 cep->last_remote_number++;
138 if(cep->last_remote_number >= cep->remote_numbers_count)
139 cep->last_remote_number = 0;
141 strcpy(cep->remote_phone_dialout.number, cep->remote_numbers[cep->last_remote_number].number);
143 DBGL(DL_DIAL, (llog(LL_DBG, "select_next_dialno: index=%d, no=%s",
144 cep->last_remote_number,
145 cep->remote_numbers[cep->last_remote_number].number)));
148 /*---------------------------------------------------------------------------*
149 * dial succeded, store this number as the last successful
150 *---------------------------------------------------------------------------*/
152 select_this_dialno(cfg_entry_t *cep)
154 cep->remote_numbers[cep->last_remote_number].flag = RNF_SUCC;
156 DBGL(DL_DIAL, (llog(LL_DBG, "select_this_dialno: index = %d, no = %s",
157 cep->last_remote_number,
158 cep->remote_numbers[cep->last_remote_number].number)));