| r1676 | r2638 | |
| 1 | 1 | /* |
| 2 | | * Asterisk -- An open source telephony toolkit. |
| 2 | * CallWeaver -- An open source telephony toolkit. |
| 3 | 3 | * |
| 4 | 4 | * Copyright (C) 1999 - 2005, Digium, Inc. |
| 5 | 5 | * |
| 6 | 6 | * Mark Spencer <markster@digium.com> |
| 7 | 7 | * |
| 8 | | * See http://www.asterisk.org for more information about |
| 9 | | * the Asterisk project. Please do not directly contact |
| 8 | * See http://www.callweaver.org for more information about |
| 9 | * the CallWeaver project. Please do not directly contact |
| 10 | 10 | * any of the maintainers of this project for assistance; |
| 11 | 11 | * the project provides a web site, mailing lists and IRC |
| 12 | 12 | * channels for your use. |
| --- | --- | |
| 32 | 32 | * On ISDN Caller ID names are 7 bit, Almost ASCII |
| 33 | 33 | * (See http://www.zytrax.com/tech/ia5.html ) |
| 34 | 34 | * |
| 35 | | * \note Asterisk does not currently support SIP utf8 caller ID names or caller ID's. |
| 35 | * \note CallWeaver does not currently support SIP utf8 caller ID names or caller ID's. |
| 36 | 36 | * |
| 37 | 37 | * \par See also |
| 38 | 38 | * \arg \ref callerid.c |
| --- | --- | |
| 40 | 40 | * \arg \ref Def_CallerPres |
| 41 | 41 | */ |
| 42 | 42 | |
| 43 | | #ifndef _ASTERISK_CALLERID_H |
| 44 | | #define _ASTERISK_CALLERID_H |
| 43 | #ifndef _CALLWEAVER_CALLERID_H |
| 44 | #define _CALLWEAVER_CALLERID_H |
| 45 | 45 | |
| 46 | 46 | #define MAX_CALLERID_SIZE 32000 |
| 47 | 47 | |
| --- | --- | |
| 60 | 60 | #define CID_START_POLARITY 2 |
| 61 | 61 | |
| 62 | 62 | |
| 63 | | #define AST_LIN2X(a) ((codec == AST_FORMAT_ALAW) ? (AST_LIN2A(a)) : (AST_LIN2MU(a))) |
| 64 | | #define AST_XLAW(a) ((codec == AST_FORMAT_ALAW) ? (AST_ALAW(a)) : (AST_MULAW(a))) |
| 63 | #define OPBX_LIN2X(a) ((codec == OPBX_FORMAT_ALAW) ? (OPBX_LIN2A(a)) : (OPBX_LIN2MU(a))) |
| 64 | #define OPBX_XLAW(a) ((codec == OPBX_FORMAT_ALAW) ? (OPBX_ALAW(a)) : (OPBX_MULAW(a))) |
| 65 | 65 | |
| 66 | 66 | |
| 67 | 67 | struct callerid_state; |
| --- | --- | |
| 79 | 79 | * \param name name to be used |
| 80 | 80 | * \param flags passed flags |
| 81 | 81 | * \param callwaiting callwaiting flag |
| 82 | | * \param codec -- either AST_FORMAT_ULAW or AST_FORMAT_ALAW |
| 82 | * \param codec -- either OPBX_FORMAT_ULAW or OPBX_FORMAT_ALAW |
| 83 | 83 | * This function creates a stream of callerid (a callerid spill) data in ulaw format. |
| 84 | 84 | * \return It returns the size |
| 85 | 85 | * (in bytes) of the data (if it returns a size of 0, there is probably an error) |
| --- | --- | |
| 98 | 98 | * \param cid Which state machine to act upon |
| 99 | 99 | * \param ubuf containing your samples |
| 100 | 100 | * \param samples number of samples contained within the buffer. |
| 101 | | * \param codec which codec (AST_FORMAT_ALAW or AST_FORMAT_ULAW) |
| 101 | * \param codec which codec (OPBX_FORMAT_ALAW or OPBX_FORMAT_ULAW) |
| 102 | 102 | * |
| 103 | 103 | * Send received audio to the Caller*ID demodulator. |
| 104 | 104 | * \return Returns -1 on error, 0 for "needs more samples", |
| --- | --- | |
| 110 | 110 | * \param cid Which state machine to act upon |
| 111 | 111 | * \param ubuf containing your samples |
| 112 | 112 | * \param samples number of samples contained within the buffer. |
| 113 | | * \param codec which codec (AST_FORMAT_ALAW or AST_FORMAT_ULAW) |
| 113 | * \param codec which codec (OPBX_FORMAT_ALAW or OPBX_FORMAT_ULAW) |
| 114 | 114 | * |
| 115 | 115 | * Send received audio to the Caller*ID demodulator (for japanese style lines). |
| 116 | 116 | * \return Returns -1 on error, 0 for "needs more samples", |
| --- | --- | |
| 147 | 147 | */ |
| 148 | 148 | void callerid_free(struct callerid_state *cid); |
| 149 | 149 | |
| 150 | | /*! \brief Generate Caller-ID spill from the "callerid" field of asterisk (in e-mail address like format) |
| 150 | /*! \brief Generate Caller-ID spill from the "callerid" field of CallWeaver (in e-mail address like format) |
| 151 | 151 | * \param buf buffer for output samples. See callerid_generate() for details regarding buffer. |
| 152 | 152 | * \param name Caller-ID Name |
| 153 | 153 | * \param number Caller-ID Number |
| 154 | | * \param codec Asterisk codec (either AST_FORMAT_ALAW or AST_FORMAT_ULAW) |
| 154 | * \param codec CallWeaver codec (either OPBX_FORMAT_ALAW or OPBX_FORMAT_ULAW) |
| 155 | 155 | * |
| 156 | | * Acts like callerid_generate except uses an asterisk format callerid string. |
| 156 | * Acts like callerid_generate except uses an CallWeaver format callerid string. |
| 157 | 157 | */ |
| 158 | | int ast_callerid_generate(unsigned char *buf, const char *name, const char *number, int codec); |
| 158 | int OPBX_callerid_generate(unsigned char *buf, const char *name, const char *number, int codec); |
| 159 | 159 | |
| 160 | 160 | /*! \brief Generate message waiting indicator (stutter tone) */ |
| 161 | 161 | int vmwi_generate(unsigned char *buf, int active, int mdmf, int codec); |
| 162 | 162 | |
| 163 | 163 | /*! \brief Generate Caller-ID spill but in a format suitable for Call Waiting(tm)'s Caller*ID(tm) |
| 164 | | * See ast_callerid_generate() for other details |
| 164 | * See OPBX_callerid_generate() for other details |
| 165 | 165 | */ |
| 166 | | int ast_callerid_callwaiting_generate(unsigned char *buf, const char *name, const char *number, int codec); |
| 166 | int OPBX_callerid_callwaiting_generate(unsigned char *buf, const char *name, const char *number, int codec); |
| 167 | 167 | |
| 168 | 168 | /*! \brief Destructively parse inbuf into name and location (or number) |
| 169 | 169 | * Parses callerid stream from inbuf and changes into useable form, outputed in name and location. |
| --- | --- | |
| 172 | 172 | * \param location address of a pointer-to-char for the phone number value of the stream. |
| 173 | 173 | * \return Returns 0 on success, -1 on failure. |
| 174 | 174 | */ |
| 175 | | int ast_callerid_parse(char *instr, char **name, char **location); |
| 175 | int OPBX_callerid_parse(char *instr, char **name, char **location); |
| 176 | 176 | |
| 177 | 177 | /*! Generate a CAS (CPE Alert Signal) tone for 'n' samples */ |
| 178 | 178 | /*! |
| 179 | 179 | * \param outbuf Allocated buffer for data. Must be at least 2400 bytes unless no SAS is desired |
| 180 | 180 | * \param sas Non-zero if CAS should be preceeded by SAS |
| 181 | 181 | * \param len How many samples to generate. |
| 182 | | * \param codec Which codec (AST_FORMAT_ALAW or AST_FORMAT_ULAW) |
| 182 | * \param codec Which codec (OPBX_FORMAT_ALAW or OPBX_FORMAT_ULAW) |
| 183 | 183 | * \return Returns -1 on error (if len is less than 2400), 0 on success. |
| 184 | 184 | */ |
| 185 | | int ast_gen_cas(unsigned char *outbuf, int sas, int len, int codec); |
| 185 | int OPBX_gen_cas(unsigned char *outbuf, int sas, int len, int codec); |
| 186 | 186 | |
| 187 | 187 | /*! \brief Shrink a phone number in place to just digits (more accurately it just removes ()'s, .'s, and -'s... */ |
| 188 | 188 | /*! |
| 189 | 189 | * \param n The number to be stripped/shrunk |
| 190 | 190 | * \return Returns nothing important |
| 191 | 191 | */ |
| 192 | | void ast_shrink_phone_number(char *n); |
| 192 | void OPBX_shrink_phone_number(char *n); |
| 193 | 193 | |
| 194 | 194 | /*! \brief Check if a string consists only of digits and + \# |
| 195 | 195 | \param n number to be checked. |
| 196 | 196 | \return Returns 0 if n is a number, 1 if it's not. |
| 197 | 197 | */ |
| 198 | | int ast_isphonenumber(const char *n); |
| 198 | int OPBX_isphonenumber(const char *n); |
| 199 | 199 | |
| 200 | 200 | /*! \brief Check if a string consists only of digits and and + \# ( ) - . |
| 201 | | (meaning it can be cleaned with ast_shrink_phone_number) |
| 201 | (meaning it can be cleaned with OPBX_shrink_phone_number) |
| 202 | 202 | \param exten The extension (or URI) to be checked. |
| 203 | 203 | \return Returns 0 if n is a number, 1 if it's not. |
| 204 | 204 | */ |
| 205 | | int ast_is_shrinkable_phonenumber(const char *exten); |
| 205 | int OPBX_is_shrinkable_phonenumber(const char *exten); |
| 206 | 206 | |
| 207 | | int ast_callerid_split(const char *src, char *name, int namelen, char *num, int numlen); |
| 207 | int OPBX_callerid_split(const char *src, char *name, int namelen, char *num, int numlen); |
| 208 | 208 | |
| 209 | | char *ast_callerid_merge(char *buf, int bufsiz, const char *name, const char *num, const char *unknown); |
| 209 | char *OPBX_callerid_merge(char *buf, int bufsiz, const char *name, const char *num, const char *unknown); |
| 210 | 210 | |
| 211 | 211 | /* |
| 212 | 212 | * Caller*ID and other GR-30 compatible generation |
| --- | --- | |
| 238 | 238 | |
| 239 | 239 | #define PUT_AUDIO_SAMPLE(y) do { \ |
| 240 | 240 | int index = (short)(rint(8192.0 * (y))); \ |
| 241 | | *(buf++) = AST_LIN2X(index); \ |
| 241 | *(buf++) = OPBX_LIN2X(index); \ |
| 242 | 242 | bytes++; \ |
| 243 | 243 | } while(0) |
| 244 | 244 | |
| --- | --- | |
| 270 | 270 | |
| 271 | 271 | /* Various defines and bits for handling PRI- and SS7-type restriction */ |
| 272 | 272 | |
| 273 | | #define AST_PRES_NUMBER_TYPE 0x03 |
| 274 | | #define AST_PRES_USER_NUMBER_UNSCREENED 0x00 |
| 275 | | #define AST_PRES_USER_NUMBER_PASSED_SCREEN 0x01 |
| 276 | | #define AST_PRES_USER_NUMBER_FAILED_SCREEN 0x02 |
| 277 | | #define AST_PRES_NETWORK_NUMBER 0x03 |
| 273 | #define OPBX_PRES_NUMBER_TYPE 0x03 |
| 274 | #define OPBX_PRES_USER_NUMBER_UNSCREENED 0x00 |
| 275 | #define OPBX_PRES_USER_NUMBER_PASSED_SCREEN 0x01 |
| 276 | #define OPBX_PRES_USER_NUMBER_FAILED_SCREEN 0x02 |
| 277 | #define OPBX_PRES_NETWORK_NUMBER 0x03 |
| 278 | 278 | |
| 279 | | #define AST_PRES_RESTRICTION 0x60 |
| 280 | | #define AST_PRES_ALLOWED 0x00 |
| 281 | | #define AST_PRES_RESTRICTED 0x20 |
| 282 | | #define AST_PRES_UNAVAILABLE 0x40 |
| 283 | | #define AST_PRES_RESERVED 0x60 |
| 279 | #define OPBX_PRES_RESTRICTION 0x60 |
| 280 | #define OPBX_PRES_ALLOWED 0x00 |
| 281 | #define OPBX_PRES_RESTRICTED 0x20 |
| 282 | #define OPBX_PRES_UNAVAILABLE 0x40 |
| 283 | #define OPBX_PRES_RESERVED 0x60 |
| 284 | 284 | |
| 285 | | #define AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED \ |
| 286 | | AST_PRES_USER_NUMBER_UNSCREENED + AST_PRES_ALLOWED |
| 285 | #define OPBX_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED \ |
| 286 | OPBX_PRES_USER_NUMBER_UNSCREENED + OPBX_PRES_ALLOWED |
| 287 | 287 | |
| 288 | | #define AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN \ |
| 289 | | AST_PRES_USER_NUMBER_PASSED_SCREEN + AST_PRES_ALLOWED |
| 288 | #define OPBX_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN \ |
| 289 | OPBX_PRES_USER_NUMBER_PASSED_SCREEN + OPBX_PRES_ALLOWED |
| 290 | 290 | |
| 291 | | #define AST_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN \ |
| 292 | | AST_PRES_USER_NUMBER_FAILED_SCREEN + AST_PRES_ALLOWED |
| 291 | #define OPBX_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN \ |
| 292 | OPBX_PRES_USER_NUMBER_FAILED_SCREEN + OPBX_PRES_ALLOWED |
| 293 | 293 | |
| 294 | | #define AST_PRES_ALLOWED_NETWORK_NUMBER \ |
| 295 | | AST_PRES_NETWORK_NUMBER + AST_PRES_ALLOWED |
| 294 | #define OPBX_PRES_ALLOWED_NETWORK_NUMBER \ |
| 295 | OPBX_PRES_NETWORK_NUMBER + OPBX_PRES_ALLOWED |
| 296 | 296 | |
| 297 | | #define AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED \ |
| 298 | | AST_PRES_USER_NUMBER_UNSCREENED + AST_PRES_RESTRICTED |
| 297 | #define OPBX_PRES_PROHIB_USER_NUMBER_NOT_SCREENED \ |
| 298 | OPBX_PRES_USER_NUMBER_UNSCREENED + OPBX_PRES_RESTRICTED |
| 299 | 299 | |
| 300 | | #define AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN \ |
| 301 | | AST_PRES_USER_NUMBER_PASSED_SCREEN + AST_PRES_RESTRICTED |
| 300 | #define OPBX_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN \ |
| 301 | OPBX_PRES_USER_NUMBER_PASSED_SCREEN + OPBX_PRES_RESTRICTED |
| 302 | 302 | |
| 303 | | #define AST_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN \ |
| 304 | | AST_PRES_USER_NUMBER_FAILED_SCREEN + AST_PRES_RESTRICTED |
| 303 | #define OPBX_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN \ |
| 304 | OPBX_PRES_USER_NUMBER_FAILED_SCREEN + OPBX_PRES_RESTRICTED |
| 305 | 305 | |
| 306 | | #define AST_PRES_PROHIB_NETWORK_NUMBER \ |
| 307 | | AST_PRES_NETWORK_NUMBER + AST_PRES_RESTRICTED |
| 306 | #define OPBX_PRES_PROHIB_NETWORK_NUMBER \ |
| 307 | OPBX_PRES_NETWORK_NUMBER + OPBX_PRES_RESTRICTED |
| 308 | 308 | |
| 309 | | #define AST_PRES_NUMBER_NOT_AVAILABLE \ |
| 310 | | AST_PRES_NETWORK_NUMBER + AST_PRES_UNAVAILABLE |
| 309 | #define OPBX_PRES_NUMBER_NOT_AVAILABLE \ |
| 310 | OPBX_PRES_NETWORK_NUMBER + OPBX_PRES_UNAVAILABLE |
| 311 | 311 | |
| 312 | | int ast_parse_caller_presentation(const char *data); |
| 313 | | const char *ast_describe_caller_presentation(int data); |
| 312 | int OPBX_parse_caller_presentation(const char *data); |
| 313 | const char *OPBX_describe_caller_presentation(int data); |
| 314 | 314 | |
| 315 | 315 | /*! \page Def_CallerPres Caller ID Presentation |
| 316 | 316 | |
| --- | --- | |
| 320 | 320 | The following values are available to use: |
| 321 | 321 | \arg \b Defined value, text string in config file, explanation |
| 322 | 322 | |
| 323 | | \arg \b AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED, "allowed_not_screened", Presentation Allowed, Not Screened, |
| 324 | | \arg \b AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, "allowed_passed_screen", Presentation Allowed, Passed Screen, |
| 325 | | \arg \b AST_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN, "allowed_failed_screen", Presentation Allowed, Failed Screen, |
| 326 | | \arg \b AST_PRES_ALLOWED_NETWORK_NUMBER, "allowed", Presentation Allowed, Network Number, |
| 327 | | \arg \b AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED, "prohib_not_screened", Presentation Prohibited, Not Screened, |
| 328 | | \arg \b AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN, "prohib_passed_screen", Presentation Prohibited, Passed Screen, |
| 329 | | \arg \b AST_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN, "prohib_failed_screen", Presentation Prohibited, Failed Screen, |
| 330 | | \arg \b AST_PRES_PROHIB_NETWORK_NUMBER, "prohib", Presentation Prohibited, Network Number, |
| 323 | \arg \b OPBX_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED, "allowed_not_screened", Presentation Allowed, Not Screened, |
| 324 | \arg \b OPBX_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, "allowed_passed_screen", Presentation Allowed, Passed Screen, |
| 325 | \arg \b OPBX_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN, "allowed_failed_screen", Presentation Allowed, Failed Screen, |
| 326 | \arg \b OPBX_PRES_ALLOWED_NETWORK_NUMBER, "allowed", Presentation Allowed, Network Number, |
| 327 | \arg \b OPBX_PRES_PROHIB_USER_NUMBER_NOT_SCREENED, "prohib_not_screened", Presentation Prohibited, Not Screened, |
| 328 | \arg \b OPBX_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN, "prohib_passed_screen", Presentation Prohibited, Passed Screen, |
| 329 | \arg \b OPBX_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN, "prohib_failed_screen", Presentation Prohibited, Failed Screen, |
| 330 | \arg \b OPBX_PRES_PROHIB_NETWORK_NUMBER, "prohib", Presentation Prohibited, Network Number, |
| 331 | 331 | |
| 332 | 332 | \par References |
| 333 | 333 | \arg \ref callerid.h Definitions |
| --- | --- | |
| 335 | 335 | \arg \ref CID Caller ID names and numbers |
| 336 | 336 | */ |
| 337 | 337 | |
| 338 | | |
| 339 | | #endif /* _ASTERISK_CALLERID_H */ |
| 338 | #endif |