|
| 1 | +diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c |
| 2 | +index 4d9512aa8e..eb422d2677 100644 |
| 3 | +--- a/channels/chan_dahdi.c |
| 4 | ++++ b/channels/chan_dahdi.c |
| 5 | +@@ -68,8 +68,34 @@ |
| 6 | + * radio. Sig_analog does not currently handle any radio operations. If |
| 7 | + * radio only uses analog signaling, then the radio handling logic could |
| 8 | + * be placed in sig_analog and the duplicated code could be removed. |
| 9 | ++ * Same comment for operator mode. |
| 10 | + */ |
| 11 | + |
| 12 | ++/* Some number of years ago, sig_analog was moved to its own file |
| 13 | ++ * but lots of remnants of it were never cleaned up in chan_dahdi. |
| 14 | ++ * See note above, plus commits for reference: |
| 15 | ++ * aaf5eb105ed55b7856dfd79b352a1669cb51d437 |
| 16 | ++ * b9e898017e0ed295d2ed738bf6b1addb4b503aa2 |
| 17 | ++ * |
| 18 | ++ * This is part 1 of a 2-phase process to finally clean this horrible mess up. |
| 19 | ++ * These macros indicate code that should or can be unreachable because sig_analog handles it. |
| 20 | ++ * If an assertion is triggered, that means we got something wrong. |
| 21 | ++ * After some time if no assertions are triggered, any code in branches |
| 22 | ++ * following these macros can be removed to declutter obsolete code |
| 23 | ++ * in chan_dahdi that unnecessarily duplicates sig_analog. |
| 24 | ++ * This amounts to a significant fraction of dead code (2-3k lines) in chan_dahdi that we should be able to remove. |
| 25 | ++ */ |
| 26 | ++#define SIG_ANALOG_HANDLED 1 |
| 27 | ++#define ANALOG_REACHABLE(p, expected) if ((expected)) { ast_debug(1, "Forcibly using analog handler at line %d (radio %d, oprmode %d)\n", __LINE__, p->radio, p->oprmode); } \ |
| 28 | ++ else { ast_log(LOG_WARNING, "Unexpectedly using analog handler at line %d (radio %d, oprmode %d)\n", __LINE__, p->radio, p->oprmode); ast_assert(0); } |
| 29 | ++#define ANALOG_HANDLER(func, p, ...) func(p->sig_pvt, __VA_ARGS__) |
| 30 | ++#define ANALOG_HANDLER_EVENT(func, p, ast, event) func(p->sig_pvt, ast, dahdievent_to_analogevent(event)) |
| 31 | ++#define ANALOG_UNREACHABLE_EVENT(func, expected, p, event) ANALOG_UNREACHABLE(func, expected, p, dahdievent_to_analogevent(event)) |
| 32 | ++#define ANALOG_UNREACHABLE(func, expected, p, ...) ({ \ |
| 33 | ++ ANALOG_REACHABLE(p, expected); \ |
| 34 | ++ return func(p->sig_pvt, __VA_ARGS__); \ |
| 35 | ++}) |
| 36 | ++ |
| 37 | + #if defined(HAVE_PRI) |
| 38 | + #include "sig_pri.h" |
| 39 | + #ifndef PRI_RESTART |
| 40 | +@@ -6477,6 +6503,7 @@ static int dahdi_hangup(struct ast_channel *ast) |
| 41 | + p->ignoredtmf = 0; |
| 42 | + |
| 43 | + if (idx > -1) { |
| 44 | ++ if (p->channel != CHAN_PSEUDO) ANALOG_UNREACHABLE(analog_hangup, p->radio || p->oprmode, p, ast); /* Medium confidence. */ |
| 45 | + /* Real channel, do some fixup */ |
| 46 | + p->subs[idx].owner = NULL; |
| 47 | + p->subs[idx].needanswer = 0; |
| 48 | +@@ -7539,6 +7566,7 @@ static int dahdi_ring_phone(struct dahdi_pvt *p) |
| 49 | + return res; |
| 50 | + } |
| 51 | + |
| 52 | ++#ifndef SIG_ANALOG_HANDLED |
| 53 | + static void *analog_ss_thread(void *data); |
| 54 | + |
| 55 | + /*! |
| 56 | +@@ -7585,6 +7613,7 @@ static int attempt_transfer(struct dahdi_pvt *p) |
| 57 | + |
| 58 | + return res; |
| 59 | + } |
| 60 | ++#endif /* !defined(SIG_ANALOG_HANDLED) */ |
| 61 | + |
| 62 | + static int check_for_conference(struct dahdi_pvt *p) |
| 63 | + { |
| 64 | +@@ -7796,12 +7825,22 @@ static void handle_alarms(struct dahdi_pvt *p, int alms) |
| 65 | + |
| 66 | + static struct ast_frame *dahdi_handle_event(struct ast_channel *ast) |
| 67 | + { |
| 68 | +- int res, x; |
| 69 | ++ int res; |
| 70 | + int idx, mysig; |
| 71 | ++#if !defined(SIG_ANALOG_HANDLED) || defined(HAVE_PRI) |
| 72 | ++ /* For analog, x isn't used if SIG_ANALOG_HANDLED is defined |
| 73 | ++ * as it's only used in dead code for analog. |
| 74 | ++ * However, there is PRI code that uses it. */ |
| 75 | ++ int x; |
| 76 | ++#endif /* !defined(SIG_ANALOG_HANDLED) || defined(HAVE_PRI) */ |
| 77 | ++#ifndef SIG_ANALOG_HANDLED |
| 78 | + char *c; |
| 79 | ++#endif /* !defined(SIG_ANALOG_HANDLED) */ |
| 80 | + struct dahdi_pvt *p = ast_channel_tech_pvt(ast); |
| 81 | ++#ifndef SIG_ANALOG_HANDLED |
| 82 | + pthread_t threadid; |
| 83 | + struct ast_channel *chan; |
| 84 | ++#endif /* !defined(SIG_ANALOG_HANDLED) */ |
| 85 | + struct ast_frame *f; |
| 86 | + |
| 87 | + idx = dahdi_get_index(ast, p, 0); |
| 88 | +@@ -7939,6 +7978,9 @@ static struct ast_frame *dahdi_handle_event(struct ast_channel *ast) |
| 89 | + #endif |
| 90 | + if (p->inalarm) break; |
| 91 | + if ((p->radio || (p->oprmode < 0))) break; |
| 92 | ++ ANALOG_REACHABLE(p, p->oprmode > 0); |
| 93 | ++ return ANALOG_HANDLER_EVENT(analog_handle_event, p, ast, res); |
| 94 | ++#ifndef SIG_ANALOG_HANDLED |
| 95 | + if (ioctl(p->subs[idx].dfd,DAHDI_DIALING,&x) == -1) { |
| 96 | + ast_debug(1, "DAHDI_DIALING ioctl failed on %s: %s\n",ast_channel_name(ast), strerror(errno)); |
| 97 | + return NULL; |
| 98 | +@@ -7991,6 +8033,7 @@ static struct ast_frame *dahdi_handle_event(struct ast_channel *ast) |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | ++#endif /* !defined(SIG_ANALOG_HANDLED) */ |
| 103 | + break; |
| 104 | + case DAHDI_EVENT_ALARM: |
| 105 | + switch (p->sig) { |
| 106 | +@@ -8049,6 +8092,9 @@ static struct ast_frame *dahdi_handle_event(struct ast_channel *ast) |
| 107 | + } |
| 108 | + break; |
| 109 | + } |
| 110 | ++ ANALOG_REACHABLE(p, p->oprmode > 0); |
| 111 | ++ return ANALOG_HANDLER_EVENT(analog_handle_event, p, ast, res); /* __analog_handle_event */ |
| 112 | ++#ifndef SIG_ANALOG_HANDLED |
| 113 | + switch (p->sig) { |
| 114 | + case SIG_FXOLS: |
| 115 | + case SIG_FXOGS: |
| 116 | +@@ -8147,6 +8193,7 @@ static struct ast_frame *dahdi_handle_event(struct ast_channel *ast) |
| 117 | + dahdi_ec_disable(p); |
| 118 | + return NULL; |
| 119 | + } |
| 120 | ++#endif /* !defined(SIG_ANALOG_HANDLED) */ |
| 121 | + break; |
| 122 | + case DAHDI_EVENT_RINGOFFHOOK: |
| 123 | + if (p->inalarm) break; |
| 124 | +@@ -8168,6 +8215,9 @@ static struct ast_frame *dahdi_handle_event(struct ast_channel *ast) |
| 125 | + p->subs[idx].f.subclass.integer = AST_CONTROL_RADIO_KEY; |
| 126 | + break; |
| 127 | + } |
| 128 | ++ ANALOG_REACHABLE(p, p->oprmode > 0); |
| 129 | ++ return ANALOG_HANDLER_EVENT(analog_handle_event, p, ast, res); /* __analog_handle_event */ |
| 130 | ++#ifndef SIG_ANALOG_HANDLED |
| 131 | + /* for E911, its supposed to wait for offhook then dial |
| 132 | + the second half of the dial string */ |
| 133 | + if (((mysig == SIG_E911) || (mysig == SIG_FGC_CAMA) || (mysig == SIG_FGC_CAMAMF)) && (ast_channel_state(ast) == AST_STATE_DIALING_OFFHOOK)) { |
| 134 | +@@ -8322,6 +8372,7 @@ static struct ast_frame *dahdi_handle_event(struct ast_channel *ast) |
| 135 | + default: |
| 136 | + ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig); |
| 137 | + } |
| 138 | ++#endif /* !defined(SIG_ANALOG_HANDLED) */ |
| 139 | + break; |
| 140 | + case DAHDI_EVENT_RINGBEGIN: |
| 141 | + switch (p->sig) { |
| 142 | +@@ -8377,6 +8428,9 @@ static struct ast_frame *dahdi_handle_event(struct ast_channel *ast) |
| 143 | + } |
| 144 | + break; |
| 145 | + } |
| 146 | ++ ANALOG_REACHABLE(p, 0); |
| 147 | ++ return ANALOG_HANDLER_EVENT(analog_handle_event, p, ast, res); /* __analog_handle_event */ |
| 148 | ++#ifndef SIG_ANALOG_HANDLED |
| 149 | + /* Remember last time we got a flash-hook */ |
| 150 | + p->flashtime = ast_tvnow(); |
| 151 | + switch (mysig) { |
| 152 | +@@ -8607,9 +8661,12 @@ winkflashdone: |
| 153 | + ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig); |
| 154 | + } |
| 155 | + break; |
| 156 | ++#endif /* !defined(SIG_ANALOG_HANDLED) */ |
| 157 | + case DAHDI_EVENT_HOOKCOMPLETE: |
| 158 | + if (p->inalarm) break; |
| 159 | + if ((p->radio || (p->oprmode < 0))) break; |
| 160 | ++ ANALOG_REACHABLE(p, p->oprmode > 0); |
| 161 | ++ return ANALOG_HANDLER_EVENT(analog_handle_event, p, ast, res); /* __analog_handle_event */ |
| 162 | + if (p->waitingfordt.tv_sec) break; |
| 163 | + switch (mysig) { |
| 164 | + case SIG_FXSLS: /* only interesting for FXS */ |
| 165 | +@@ -8720,6 +8777,8 @@ static struct ast_frame *__dahdi_exception(struct ast_channel *ast) |
| 166 | + |
| 167 | + |
| 168 | + if ((!p->owner) && (!(p->radio || (p->oprmode < 0)))) { |
| 169 | ++ /* It's okay to call analog_exception because we haven't called dahdi_get_event yet. */ |
| 170 | ++ ANALOG_UNREACHABLE(analog_exception, p->oprmode > 0, p, ast); |
| 171 | + /* If nobody owns us, absorb the event appropriately, otherwise |
| 172 | + we loop indefinitely. This occurs when, during call waiting, the |
| 173 | + other end hangs up our channel so that it no longer exists, but we |
| 174 | +@@ -9824,7 +9883,7 @@ static struct ast_channel *dahdi_new(struct dahdi_pvt *i, int state, int startpb |
| 175 | + return tmp; |
| 176 | + } |
| 177 | + |
| 178 | +- |
| 179 | ++#ifndef SIG_ANALOG_HANDLED |
| 180 | + static int my_getsigstr(struct ast_channel *chan, char *str, const char *term, int ms) |
| 181 | + { |
| 182 | + char c; |
| 183 | +@@ -9843,6 +9902,7 @@ static int my_getsigstr(struct ast_channel *chan, char *str, const char *term, i |
| 184 | + return 1; |
| 185 | + } |
| 186 | + } |
| 187 | ++#endif /* !defined(SIG_ANALOG_HANDLED) */ |
| 188 | + |
| 189 | + static int dahdi_wink(struct dahdi_pvt *p, int idx) |
| 190 | + { |
| 191 | +@@ -9910,6 +9970,7 @@ static int dahdi_dnd(struct dahdi_pvt *dahdichan, int flag) |
| 192 | + return 0; |
| 193 | + } |
| 194 | + |
| 195 | ++#ifndef SIG_ANALOG_HANDLED |
| 196 | + static int canmatch_featurecode(const char *pickupexten, const char *exten) |
| 197 | + { |
| 198 | + int extlen = strlen(exten); |
| 199 | +@@ -11130,6 +11191,7 @@ quit: |
| 200 | + ast_mutex_unlock(&ss_thread_lock); |
| 201 | + return NULL; |
| 202 | + } |
| 203 | ++#endif /* !defined(SIG_ANALOG_HANDLED) */ |
| 204 | + |
| 205 | + struct mwi_thread_data { |
| 206 | + struct dahdi_pvt *pvt; |
| 207 | +@@ -11155,7 +11217,6 @@ static void *mwi_thread(void *data) |
| 208 | + { |
| 209 | + struct mwi_thread_data *mtd = data; |
| 210 | + struct callerid_state *cs; |
| 211 | +- pthread_t threadid; |
| 212 | + int samples = 0; |
| 213 | + char *name, *number; |
| 214 | + int flags; |
| 215 | +@@ -11227,7 +11288,12 @@ static void *mwi_thread(void *data) |
| 216 | + if (dahdi_analog_lib_handles(mtd->pvt->sig, mtd->pvt->radio, mtd->pvt->oprmode)) { |
| 217 | + result = analog_ss_thread_start(mtd->pvt->sig_pvt, chan); |
| 218 | + } else { |
| 219 | ++ ANALOG_REACHABLE(mtd->pvt, 1); |
| 220 | ++ result = analog_ss_thread_start(mtd->pvt->sig_pvt, chan); |
| 221 | ++#ifndef SIG_ANALOG_HANDLED |
| 222 | ++ pthread_t threadid; |
| 223 | + result = ast_pthread_create_detached(&threadid, NULL, analog_ss_thread, chan); |
| 224 | ++#endif /* !defined(SIG_ANALOG_HANDLED) */ |
| 225 | + } |
| 226 | + if (result) { |
| 227 | + ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", mtd->pvt->channel); |
| 228 | +@@ -11646,10 +11712,12 @@ out: |
| 229 | + static struct dahdi_pvt *handle_init_event(struct dahdi_pvt *i, int event) |
| 230 | + { |
| 231 | + int res; |
| 232 | ++#ifndef SIG_ANALOG_HANDLED |
| 233 | + pthread_t threadid; |
| 234 | + struct ast_channel *chan; |
| 235 | + ast_callid callid = 0; |
| 236 | + int callid_created; |
| 237 | ++#endif /* !defined(SIG_ANALOG_HANDLED) */ |
| 238 | + |
| 239 | + /* Handle an event on a given channel for the monitor thread. */ |
| 240 | + |
| 241 | +@@ -11661,6 +11729,8 @@ static struct dahdi_pvt *handle_init_event(struct dahdi_pvt *i, int event) |
| 242 | + case DAHDI_EVENT_RINGOFFHOOK: |
| 243 | + if (i->inalarm) break; |
| 244 | + if (i->radio) break; |
| 245 | ++ ANALOG_UNREACHABLE_EVENT(analog_handle_init_event, i->oprmode, i, event); |
| 246 | ++#ifndef SIG_ANALOG_HANDLED |
| 247 | + /* Got a ring/answer. What kind of channel are we? */ |
| 248 | + switch (i->sig) { |
| 249 | + case SIG_FXOLS: |
| 250 | +@@ -11760,6 +11830,7 @@ static struct dahdi_pvt *handle_init_event(struct dahdi_pvt *i, int event) |
| 251 | + ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel); |
| 252 | + return NULL; |
| 253 | + } |
| 254 | ++#endif /* !defined(SIG_ANALOG_HANDLED) */ |
| 255 | + break; |
| 256 | + case DAHDI_EVENT_NOALARM: |
| 257 | + switch (i->sig) { |
| 258 | +@@ -11805,6 +11876,7 @@ static struct dahdi_pvt *handle_init_event(struct dahdi_pvt *i, int event) |
| 259 | + case DAHDI_EVENT_ONHOOK: |
| 260 | + if (i->radio) |
| 261 | + break; |
| 262 | ++ ANALOG_UNREACHABLE_EVENT(analog_handle_init_event, i->oprmode, i, event); |
| 263 | + /* Back on hook. Hang up. */ |
| 264 | + switch (i->sig) { |
| 265 | + case SIG_FXOLS: |
| 266 | +@@ -11849,6 +11921,8 @@ static struct dahdi_pvt *handle_init_event(struct dahdi_pvt *i, int event) |
| 267 | + } |
| 268 | + break; |
| 269 | + case DAHDI_EVENT_POLARITY: |
| 270 | ++ ANALOG_UNREACHABLE(analog_handle_init_event, i->radio || i->oprmode, i, event); |
| 271 | ++#ifndef SIG_ANALOG_HANDLED |
| 272 | + switch (i->sig) { |
| 273 | + case SIG_FXSLS: |
| 274 | + case SIG_FXSKS: |
| 275 | +@@ -11880,6 +11954,7 @@ static struct dahdi_pvt *handle_init_event(struct dahdi_pvt *i, int event) |
| 276 | + "polarity reversal on non-FXO (SIG_FXS) " |
| 277 | + "interface %d\n", i->channel); |
| 278 | + } |
| 279 | ++#endif /* !defined(SIG_ANALOG_HANDLED) */ |
| 280 | + break; |
| 281 | + case DAHDI_EVENT_REMOVED: /* destroy channel, will actually do so in do_monitor */ |
| 282 | + ast_log(LOG_NOTICE, |
| 283 | +@@ -12132,14 +12207,16 @@ static void *do_monitor(void *data) |
| 284 | + } else { |
| 285 | + energy = calc_energy((unsigned char *) buf, res, AST_LAW(i)); |
| 286 | + if (!i->mwisendactive && energy > dtmfcid_level) { |
| 287 | +- pthread_t threadid; |
| 288 | +- struct ast_channel *chan; |
| 289 | + ast_mutex_unlock(&iflock); |
| 290 | + if (dahdi_analog_lib_handles(i->sig, i->radio, i->oprmode)) { |
| 291 | + /* just in case this event changes or somehow destroys a channel, set doomed here too */ |
| 292 | + doomed = analog_handle_init_event(i->sig_pvt, ANALOG_EVENT_DTMFCID); |
| 293 | + i->dtmfcid_holdoff_state = 1; |
| 294 | + } else { |
| 295 | ++ ANALOG_UNREACHABLE(analog_handle_init_event, i->radio || i->oprmode, i, ANALOG_EVENT_DTMFCID); |
| 296 | ++#ifndef SIG_ANALOG_HANDLED |
| 297 | ++ pthread_t threadid; |
| 298 | ++ struct ast_channel *chan; |
| 299 | + ast_callid callid = 0; |
| 300 | + int callid_created = ast_callid_threadstorage_auto(&callid); |
| 301 | + chan = dahdi_new(i, AST_STATE_PRERING, 0, SUB_REAL, 0, NULL, NULL, callid); |
| 302 | +@@ -12155,6 +12232,7 @@ static void *do_monitor(void *data) |
| 303 | + } |
| 304 | + } |
| 305 | + ast_callid_threadstorage_auto_clean(callid, callid_created); |
| 306 | ++#endif /* !defined(SIG_ANALOG_HANDLED) */ |
| 307 | + } |
| 308 | + ast_mutex_lock(&iflock); |
| 309 | + } |
| 310 | +diff --git a/channels/sig_analog.c b/channels/sig_analog.c |
| 311 | +index e477d5d0cf..6914449787 100644 |
| 312 | +--- a/channels/sig_analog.c |
| 313 | ++++ b/channels/sig_analog.c |
| 314 | +@@ -2798,7 +2798,13 @@ static void analog_publish_channel_alarm_clear(int channel) |
| 315 | + |
| 316 | + static struct ast_frame *__analog_handle_event(struct analog_pvt *p, struct ast_channel *ast) |
| 317 | + { |
| 318 | +- int res, x; |
| 319 | ++ int res = analog_get_event(p); |
| 320 | ++ return analog_handle_event(p, ast, res); |
| 321 | ++} |
| 322 | ++ |
| 323 | ++struct ast_frame *analog_handle_event(struct analog_pvt *p, struct ast_channel *ast, int res) |
| 324 | ++{ |
| 325 | ++ int x; |
| 326 | + int mysig; |
| 327 | + int idx; |
| 328 | + char *c; |
| 329 | +@@ -2834,8 +2840,6 @@ static struct ast_frame *__analog_handle_event(struct analog_pvt *p, struct ast_ |
| 330 | + p->subs[idx].f.data.ptr = NULL; |
| 331 | + f = &p->subs[idx].f; |
| 332 | + |
| 333 | +- res = analog_get_event(p); |
| 334 | +- |
| 335 | + ast_debug(1, "Got event %s(%d) on channel %d (index %u)\n", analog_event2str(res), res, p->channel, idx); |
| 336 | + |
| 337 | + if (res & (ANALOG_EVENT_PULSEDIGIT | ANALOG_EVENT_DTMFUP)) { |
| 338 | +diff --git a/channels/sig_analog.h b/channels/sig_analog.h |
| 339 | +index 023170cf7f..629268b2d2 100644 |
| 340 | +--- a/channels/sig_analog.h |
| 341 | ++++ b/channels/sig_analog.h |
| 342 | +@@ -259,7 +259,6 @@ struct analog_callback { |
| 343 | + /*! Global analog callbacks to the upper layer. */ |
| 344 | + extern struct analog_callback analog_callbacks; |
| 345 | + |
| 346 | +- |
| 347 | + struct analog_subchannel { |
| 348 | + struct ast_channel *owner; |
| 349 | + struct ast_frame f; /*!< One frame for each channel. How did this ever work before? */ |
| 350 | +@@ -391,6 +390,10 @@ int analog_answer(struct analog_pvt *p, struct ast_channel *ast); |
| 351 | + |
| 352 | + struct ast_frame *analog_exception(struct analog_pvt *p, struct ast_channel *ast); |
| 353 | + |
| 354 | ++/*! \brief Directly handle an analog event (without first querying DAHDI for the event) */ |
| 355 | ++/*! \note This is ONLY intended to be called from within dahdi_handle_event after we already called dahdi_get_event */ |
| 356 | ++struct ast_frame *analog_handle_event(struct analog_pvt *p, struct ast_channel *ast, int res); |
| 357 | ++ |
| 358 | + struct ast_channel * analog_request(struct analog_pvt *p, int *callwait, const struct ast_channel *requestor); |
| 359 | + |
| 360 | + int analog_available(struct analog_pvt *p); |
0 commit comments