#include "asterisk.h"
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <osp/osp.h>
#include <osp/osputils.h>
#include "asterisk/lock.h"
#include "asterisk/config.h"
#include "asterisk/utils.h"
#include "asterisk/causes.h"
#include "asterisk/channel.h"
#include "asterisk/app.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/options.h"
#include "asterisk/cli.h"
#include "asterisk/logger.h"
#include "asterisk/astosp.h"
Include dependency graph for app_osplookup.c:

Go to the source code of this file.
Data Structures | |
| struct | osp_provider |
| struct | osp_result |
Defines | |
| #define | OSP_AUDIT_URL ((const char*)"localhost") |
| #define | OSP_CONFIG_FILE ((const char*)"osp.conf") |
| #define | OSP_CUSTOMER_ID ((const char*)"") |
| #define | OSP_DEF_AUTHPOLICY ((enum osp_authpolicy)OSP_AUTH_YES) |
| #define | OSP_DEF_DESTINATIONS ((unsigned int)5) |
| #define | OSP_DEF_MAXCONNECTIONS ((unsigned int)20) |
| #define | OSP_DEF_PROVIDER ((const char*)"default") |
| #define | OSP_DEF_RETRYDELAY ((unsigned int)0) |
| #define | OSP_DEF_RETRYLIMIT ((unsigned int)2) |
| #define | OSP_DEF_TIMELIMIT ((unsigned int)0) |
| #define | OSP_DEF_TIMEOUT ((unsigned int)500) |
| #define | OSP_DEVICE_ID ((const char*)"") |
| #define | OSP_GENERAL_CAT ((const char*)"general") |
| #define | OSP_HTTP_PERSISTENCE ((int)1) |
| #define | OSP_INTSTR_SIZE ((unsigned int)16) |
| #define | OSP_INVALID_HANDLE ((int)-1) |
| #define | OSP_LOCAL_VALIDATION ((int)1) |
| #define | OSP_MAX_CERTS ((unsigned int)10) |
| #define | OSP_MAX_MAXCONNECTIONS ((unsigned int)1000) |
| #define | OSP_MAX_RETRYDELAY ((unsigned int)10) |
| #define | OSP_MAX_RETRYLIMIT ((unsigned int)100) |
| #define | OSP_MAX_SRVS ((unsigned int)10) |
| #define | OSP_MAX_TIMEOUT ((unsigned int)10000) |
| #define | OSP_MIN_MAXCONNECTIONS ((unsigned int)1) |
| #define | OSP_MIN_RETRYDELAY ((unsigned int)0) |
| #define | OSP_MIN_RETRYLIMIT ((unsigned int)0) |
| #define | OSP_MIN_TIMEOUT ((unsigned int)200) |
| #define | OSP_NORSTR_SIZE ((unsigned int)256) |
| #define | OSP_SSL_LIFETIME ((unsigned int)300) |
| #define | OSP_TOKSTR_SIZE ((unsigned int)4096) |
Enumerations | |
| enum | osp_authpolicy { OSP_AUTH_NO, OSP_AUTH_YES, OSP_AUTH_EXCLUSIVE } |
Functions | |
| AST_MODULE_INFO (ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,"Open Settlement Protocol Applications",.load=load_module,.unload=unload_module,.reload=reload,) | |
| AST_MUTEX_DEFINE_STATIC (osplock) | |
| static enum OSPEFAILREASON | asterisk2osp (int cause) |
| Convert Asterisk status to TC code. | |
| static int | load_module (void) |
| static int | osp_auth (const char *provider, int *transaction, const char *source, const char *calling, const char *called, const char *token, unsigned int *timelimit) |
| OSP Authentication function. | |
| static int | osp_check_destination (const char *called, const char *calling, char *destination, unsigned int tokenlen, const char *token, enum OSPEFAILREASON *reason, struct osp_result *result) |
| Choose min duration limit. | |
| static unsigned int | osp_choose_timelimit (unsigned int in, unsigned int out) |
| Choose min duration limit. | |
| static void | osp_convert_address (const char *src, char *dst, int buffersize) |
| Convert address to "[x.x.x.x]" or "host.domain" format. | |
| static int | osp_create_provider (struct ast_config *cfg, const char *provider) |
| Create OSP provider handle according to configuration. | |
| static int | osp_create_transaction (const char *provider, int *transaction, unsigned int sourcesize, char *source) |
| Create OSP transaction handle. | |
| static int | osp_finish (int handle, int recorded, int cause, time_t start, time_t connect, time_t end, unsigned int release) |
| OSP Finish function. | |
| static int | osp_get_policy (const char *provider, int *policy) |
| Get OSP authenticiation policy of provider. | |
| static int | osp_load (void) |
| static int | osp_lookup (const char *provider, const char *srcdev, const char *calling, const char *called, struct osp_result *result) |
| OSP Lookup function. | |
| static int | osp_next (int cause, struct osp_result *result) |
| OSP Lookup Next function. | |
| static int | osp_show (int fd, int argc, char *argv[]) |
| static int | osp_unload (void) |
| static int | osp_validate_token (int transaction, const char *source, const char *dest, const char *calling, const char *called, const char *token, unsigned int *timelimit) |
| Validate OSP token of inbound call. | |
| static int | ospauth_exec (struct ast_channel *chan, void *data) |
| OSP Application OSPAuth. | |
| static int | ospfinished_exec (struct ast_channel *chan, void *data) |
| OSP Application OSPFinish. | |
| static int | osplookup_exec (struct ast_channel *chan, void *data) |
| OSP Application OSPLookup. | |
| static int | ospnext_exec (struct ast_channel *chan, void *data) |
| OSP Application OSPNext. | |
| static int | reload (void) |
| static int | unload_module (void) |
Variables | |
| static const char * | app1 = "OSPAuth" |
| static const char * | app2 = "OSPLookup" |
| static const char * | app3 = "OSPNext" |
| static const char * | app4 = "OSPFinish" |
| static struct ast_cli_entry | cli_osp [] |
| static const char * | descrip1 |
| static const char * | descrip2 |
| static const char * | descrip3 |
| static const char * | descrip4 |
| static int | osp_hardware = 0 |
| static int | osp_initialized = 0 |
| static unsigned int | osp_tokenformat = TOKEN_ALGO_SIGNED |
| static const char | osp_usage [] |
| static struct osp_provider * | ospproviders = NULL |
| static const char * | synopsis1 = "OSP authentication" |
| static const char * | synopsis2 = "Lookup destination by OSP" |
| static const char * | synopsis3 = "Lookup next destination by OSP" |
| static const char * | synopsis4 = "Record OSP entry" |
Definition in file app_osplookup.c.
| #define OSP_AUDIT_URL ((const char*)"localhost") |
Definition at line 83 of file app_osplookup.c.
| #define OSP_CONFIG_FILE ((const char*)"osp.conf") |
| #define OSP_CUSTOMER_ID ((const char*)"") |
Definition at line 87 of file app_osplookup.c.
| #define OSP_DEF_AUTHPOLICY ((enum osp_authpolicy)OSP_AUTH_YES) |
| #define OSP_DEF_DESTINATIONS ((unsigned int)5) |
| #define OSP_DEF_MAXCONNECTIONS ((unsigned int)20) |
| #define OSP_DEF_PROVIDER ((const char*)"default") |
| #define OSP_DEF_RETRYDELAY ((unsigned int)0) |
| #define OSP_DEF_RETRYLIMIT ((unsigned int)2) |
| #define OSP_DEF_TIMELIMIT ((unsigned int)0) |
Definition at line 90 of file app_osplookup.c.
Referenced by osp_auth(), osp_choose_timelimit(), osp_lookup(), osp_next(), ospauth_exec(), osplookup_exec(), and ospnext_exec().
| #define OSP_DEF_TIMEOUT ((unsigned int)500) |
| #define OSP_DEVICE_ID ((const char*)"") |
Definition at line 88 of file app_osplookup.c.
| #define OSP_GENERAL_CAT ((const char*)"general") |
| #define OSP_HTTP_PERSISTENCE ((int)1) |
Definition at line 86 of file app_osplookup.c.
| #define OSP_INTSTR_SIZE ((unsigned int)16) |
Definition at line 59 of file app_osplookup.c.
Referenced by ospauth_exec(), and ospfinished_exec().
| #define OSP_INVALID_HANDLE ((int)-1) |
Definition at line 64 of file app_osplookup.c.
Referenced by osp_auth(), osp_create_provider(), osp_create_transaction(), osp_finish(), osp_lookup(), osp_next(), ospfinished_exec(), osplookup_exec(), and ospnext_exec().
| #define OSP_LOCAL_VALIDATION ((int)1) |
Definition at line 84 of file app_osplookup.c.
| #define OSP_MAX_CERTS ((unsigned int)10) |
| #define OSP_MAX_MAXCONNECTIONS ((unsigned int)1000) |
| #define OSP_MAX_RETRYDELAY ((unsigned int)10) |
| #define OSP_MAX_RETRYLIMIT ((unsigned int)100) |
| #define OSP_MAX_SRVS ((unsigned int)10) |
| #define OSP_MAX_TIMEOUT ((unsigned int)10000) |
| #define OSP_MIN_MAXCONNECTIONS ((unsigned int)1) |
| #define OSP_MIN_RETRYDELAY ((unsigned int)0) |
| #define OSP_MIN_RETRYLIMIT ((unsigned int)0) |
| #define OSP_MIN_TIMEOUT ((unsigned int)200) |
| #define OSP_NORSTR_SIZE ((unsigned int)256) |
Definition at line 60 of file app_osplookup.c.
Referenced by osp_auth(), osp_lookup(), osp_next(), and osp_validate_token().
| #define OSP_SSL_LIFETIME ((unsigned int)300) |
Definition at line 85 of file app_osplookup.c.
| #define OSP_TOKSTR_SIZE ((unsigned int)4096) |
Definition at line 61 of file app_osplookup.c.
Referenced by osp_lookup(), osp_next(), osp_validate_token(), osplookup_exec(), and ospnext_exec().
| enum osp_authpolicy |
Definition at line 93 of file app_osplookup.c.
00093 { 00094 OSP_AUTH_NO, /* Accept any call */ 00095 OSP_AUTH_YES, /* Accept call with valid OSP token or without OSP token */ 00096 OSP_AUTH_EXCLUSIVE /* Only accept call with valid OSP token */ 00097 };
| AST_MODULE_INFO | ( | ASTERISK_GPL_KEY | , | |
| AST_MODFLAG_DEFAULT | , | |||
| "Open Settlement Protocol Applications" | , | |||
| . | load = load_module, |
|||
| . | unload = unload_module, |
|||
| . | reload = reload | |||
| ) |
| AST_MUTEX_DEFINE_STATIC | ( | osplock | ) |
| static enum OSPEFAILREASON asterisk2osp | ( | int | cause | ) | [static] |
Convert Asterisk status to TC code.
| cause | Asterisk hangup cause |
Definition at line 567 of file app_osplookup.c.
Referenced by osp_finish(), and osp_next().
| static int load_module | ( | void | ) | [static] |
Definition at line 1633 of file app_osplookup.c.
References ast_cli_register_multiple(), AST_MODULE_LOAD_DECLINE, ast_register_application(), cli_osp, osp_load(), ospauth_exec(), ospfinished_exec(), osplookup_exec(), and ospnext_exec().
01634 { 01635 int res; 01636 01637 if(!osp_load()) 01638 return AST_MODULE_LOAD_DECLINE; 01639 01640 ast_cli_register_multiple(cli_osp, sizeof(cli_osp) / sizeof(struct ast_cli_entry)); 01641 res = ast_register_application(app1, ospauth_exec, synopsis1, descrip1); 01642 res |= ast_register_application(app2, osplookup_exec, synopsis2, descrip2); 01643 res |= ast_register_application(app3, ospnext_exec, synopsis3, descrip3); 01644 res |= ast_register_application(app4, ospfinished_exec, synopsis4, descrip4); 01645 01646 return res; 01647 }
| static int osp_auth | ( | const char * | provider, | |
| int * | transaction, | |||
| const char * | source, | |||
| const char * | calling, | |||
| const char * | called, | |||
| const char * | token, | |||
| unsigned int * | timelimit | |||
| ) | [static] |
OSP Authentication function.
| provider | OSP provider context name | |
| transaction | OSP transaction handle, output | |
| source | Source of inbound call | |
| calling | Calling number | |
| called | Called number | |
| token | OSP token, may be empty | |
| timelimit | Call duration limit, output |
Definition at line 583 of file app_osplookup.c.
References ast_log(), ast_strlen_zero(), LOG_DEBUG, OSP_AUTH_EXCLUSIVE, OSP_AUTH_NO, OSP_AUTH_YES, osp_create_transaction(), OSP_DEF_TIMELIMIT, osp_get_policy(), OSP_INVALID_HANDLE, OSP_NORSTR_SIZE, and osp_validate_token().
Referenced by ospauth_exec().
00584 { 00585 int res; 00586 int policy = OSP_AUTH_YES; 00587 char dest[OSP_NORSTR_SIZE]; 00588 00589 *transaction = OSP_INVALID_HANDLE; 00590 *timelimit = OSP_DEF_TIMELIMIT; 00591 res = osp_get_policy(provider, &policy); 00592 if (!res) { 00593 ast_log(LOG_DEBUG, "OSP: Unabe to find OSP authentication policy\n"); 00594 return res; 00595 } 00596 00597 switch (policy) { 00598 case OSP_AUTH_NO: 00599 res = 1; 00600 break; 00601 case OSP_AUTH_EXCLUSIVE: 00602 if (ast_strlen_zero(token)) { 00603 res = 0; 00604 } else if ((res = osp_create_transaction(provider, transaction, sizeof(dest), dest)) <= 0) { 00605 ast_log(LOG_DEBUG, "OSP: Unable to generate transaction handle\n"); 00606 *transaction = OSP_INVALID_HANDLE; 00607 res = 0; 00608 } else if((res = osp_validate_token(*transaction, source, dest, calling, called, token, timelimit)) <= 0) { 00609 OSPPTransactionRecordFailure(*transaction, OSPC_FAIL_CALL_REJECTED); 00610 } 00611 break; 00612 case OSP_AUTH_YES: 00613 default: 00614 if (ast_strlen_zero(token)) { 00615 res = 1; 00616 } else if ((res = osp_create_transaction(provider, transaction, sizeof(dest), dest)) <= 0) { 00617 ast_log(LOG_DEBUG, "OSP: Unable to generate transaction handle\n"); 00618 *transaction = OSP_INVALID_HANDLE; 00619 res = 0; 00620 } else if((res = osp_validate_token(*transaction, source, dest, calling, called, token, timelimit)) <= 0) { 00621 OSPPTransactionRecordFailure(*transaction, OSPC_FAIL_CALL_REJECTED); 00622 } 00623 break; 00624 } 00625 00626 return res; 00627 }
| static int osp_check_destination | ( | const char * | called, | |
| const char * | calling, | |||
| char * | destination, | |||
| unsigned int | tokenlen, | |||
| const char * | token, | |||
| enum OSPEFAILREASON * | reason, | |||
| struct osp_result * | result | |||
| ) | [static] |
Choose min duration limit.
| called | Called number | |
| calling | Calling number | |
| destination | Destination IP in '[x.x.x.x]' format | |
| tokenlen | OSP token length | |
| token | OSP token | |
| reason | Failure reason, output | |
| result | OSP lookup results, in/output |
Definition at line 498 of file app_osplookup.c.
References ast_base64encode(), ast_log(), osp_result::calling, osp_result::dest, enabled, LOG_DEBUG, osp_result::outhandle, osp_result::tech, and osp_result::token.
Referenced by osp_lookup(), and osp_next().
00499 { 00500 int res; 00501 OSPE_DEST_OSP_ENABLED enabled; 00502 OSPE_DEST_PROT protocol; 00503 int error; 00504 00505 if (strlen(destination) <= 2) { 00506 ast_log(LOG_DEBUG, "OSP: Wrong destination format '%s'\n", destination); 00507 *reason = OSPC_FAIL_NORMAL_UNSPECIFIED; 00508 return -1; 00509 } 00510 00511 if ((error = OSPPTransactionIsDestOSPEnabled(result->outhandle, &enabled)) != OSPC_ERR_NO_ERROR) { 00512 ast_log(LOG_DEBUG, "OSP: Unable to get destination OSP version, error '%d'\n", error); 00513 *reason = OSPC_FAIL_NORMAL_UNSPECIFIED; 00514 return -1; 00515 } 00516 00517 if (enabled == OSPE_OSP_FALSE) { 00518 result->token[0] = '\0'; 00519 } else { 00520 ast_base64encode(result->token, (const unsigned char *) token, tokenlen, sizeof(result->token) - 1); 00521 } 00522 00523 if ((error = OSPPTransactionGetDestProtocol(result->outhandle, &protocol)) != OSPC_ERR_NO_ERROR) { 00524 ast_log(LOG_DEBUG, "OSP: Unable to get destination protocol, error '%d'\n", error); 00525 *reason = OSPC_FAIL_NORMAL_UNSPECIFIED; 00526 result->token[0] = '\0'; 00527 return -1; 00528 } 00529 00530 res = 1; 00531 /* Strip leading and trailing brackets */ 00532 destination[strlen(destination) - 1] = '\0'; 00533 switch(protocol) { 00534 case OSPE_DEST_PROT_H323_SETUP: 00535 ast_log(LOG_DEBUG, "OSP: protocol '%d'\n", protocol); 00536 ast_copy_string(result->tech, "H323", sizeof(result->tech)); 00537 snprintf(result->dest, sizeof(result->dest), "%s@%s", called, destination + 1); 00538 ast_copy_string(result->calling, calling, sizeof(result->calling)); 00539 break; 00540 case OSPE_DEST_PROT_SIP: 00541 ast_log(LOG_DEBUG, "OSP: protocol '%d'\n", protocol); 00542 ast_copy_string(result->tech, "SIP", sizeof(result->tech)); 00543 snprintf(result->dest, sizeof(result->dest), "%s@%s", called, destination + 1); 00544 ast_copy_string(result->calling, calling, sizeof(result->calling)); 00545 break; 00546 case OSPE_DEST_PROT_IAX: 00547 ast_log(LOG_DEBUG, "OSP: protocol '%d'\n", protocol); 00548 ast_copy_string(result->tech, "IAX", sizeof(result->tech)); 00549 snprintf(result->dest, sizeof(result->dest), "%s@%s", called, destination + 1); 00550 ast_copy_string(result->calling, calling, sizeof(result->calling)); 00551 break; 00552 default: 00553 ast_log(LOG_DEBUG, "OSP: Unknown protocol '%d'\n", protocol); 00554 *reason = OSPC_FAIL_PROTOCOL_ERROR; 00555 result->token[0] = '\0'; 00556 res = 0; 00557 } 00558 00559 return res; 00560 }
| static unsigned int osp_choose_timelimit | ( | unsigned int | in, | |
| unsigned int | out | |||
| ) | [static] |
Choose min duration limit.
| in | Inbound duration limit | |
| out | Outbound duration limit |
Definition at line 476 of file app_osplookup.c.
References OSP_DEF_TIMELIMIT.
Referenced by osp_lookup(), and osp_next().
00477 { 00478 if (in == OSP_DEF_TIMELIMIT) { 00479 return out; 00480 } else if (out == OSP_DEF_TIMELIMIT) { 00481 return in; 00482 } else { 00483 return in < out ? in : out; 00484 } 00485 }
| static void osp_convert_address | ( | const char * | src, | |
| char * | dst, | |||
| int | buffersize | |||
| ) | [static] |
Convert address to "[x.x.x.x]" or "host.domain" format.
| src | Source address string | |
| dst | Destination address string | |
| buffersize | Size of dst buffer |
Definition at line 406 of file app_osplookup.c.
Referenced by osp_lookup(), and osp_validate_token().
00410 { 00411 struct in_addr inp; 00412 00413 if (inet_aton(src, &inp) != 0) { 00414 snprintf(dst, buffersize, "[%s]", src); 00415 } else { 00416 snprintf(dst, buffersize, "%s", src); 00417 } 00418 }
| static int osp_create_provider | ( | struct ast_config * | cfg, | |
| const char * | provider | |||
| ) | [static] |
Create OSP provider handle according to configuration.
| cfg | OSP configuration | |
| provider | OSP provider context name |
Definition at line 146 of file app_osplookup.c.
References ast_calloc, ast_config_AST_KEY_DIR, ast_log(), ast_variable_browse(), free, ast_variable::lineno, LOG_DEBUG, LOG_ERROR, LOG_WARNING, ast_variable::name, ast_variable::next, OSP_AUTH_NO, OSP_AUTH_YES, OSP_DEF_AUTHPOLICY, OSP_DEF_MAXCONNECTIONS, OSP_DEF_RETRYDELAY, OSP_DEF_RETRYLIMIT, OSP_DEF_TIMEOUT, OSP_INVALID_HANDLE, OSP_MAX_CERTS, OSP_MAX_MAXCONNECTIONS, OSP_MAX_RETRYDELAY, OSP_MAX_RETRYLIMIT, OSP_MAX_SRVS, OSP_MAX_TIMEOUT, OSP_MIN_MAXCONNECTIONS, OSP_MIN_RETRYDELAY, OSP_MIN_RETRYLIMIT, OSP_MIN_TIMEOUT, t, and ast_variable::value.
Referenced by osp_load().
00147 { 00148 int res; 00149 unsigned int t, i, j; 00150 struct osp_provider* p; 00151 struct ast_variable* v; 00152 OSPTPRIVATEKEY privatekey; 00153 OSPTCERT localcert; 00154 const char* psrvpoints[OSP_MAX_SRVS]; 00155 OSPTCERT cacerts[OSP_MAX_CERTS]; 00156 const OSPTCERT* pcacerts[OSP_MAX_CERTS]; 00157 int error = OSPC_ERR_NO_ERROR; 00158 00159 if (!(p = ast_calloc(1, sizeof(*p)))) { 00160 ast_log(LOG_ERROR, "Out of memory\n"); 00161 return -1; 00162 } 00163 00164 ast_copy_string(p->name, provider, sizeof(p->name)); 00165 snprintf(p->privatekey, sizeof(p->privatekey), "%s/%s-privatekey.pem", ast_config_AST_KEY_DIR, provider); 00166 snprintf(p->localcert, sizeof(p->localcert), "%s/%s-localcert.pem", ast_config_AST_KEY_DIR, provider); 00167 p->maxconnections = OSP_DEF_MAXCONNECTIONS; 00168 p->retrydelay = OSP_DEF_RETRYDELAY; 00169 p->retrylimit = OSP_DEF_RETRYLIMIT; 00170 p->timeout = OSP_DEF_TIMEOUT; 00171 p->authpolicy = OSP_DEF_AUTHPOLICY; 00172 p->handle = OSP_INVALID_HANDLE; 00173 00174 v = ast_variable_browse(cfg, provider); 00175 while(v) { 00176 if (!strcasecmp(v->name, "privatekey")) { 00177 if (v->value[0] == '/') { 00178 ast_copy_string(p->privatekey, v->value, sizeof(p->privatekey)); 00179 } else { 00180 snprintf(p->privatekey, sizeof(p->privatekey), "%s/%s", ast_config_AST_KEY_DIR, v->value); 00181 } 00182 ast_log(LOG_DEBUG, "OSP: privatekey '%s'\n", p->privatekey); 00183 } else if (!strcasecmp(v->name, "localcert")) { 00184 if (v->value[0] == '/') { 00185 ast_copy_string(p->localcert, v->value, sizeof(p->localcert)); 00186 } else { 00187 snprintf(p->localcert, sizeof(p->localcert), "%s/%s", ast_config_AST_KEY_DIR, v->value); 00188 } 00189 ast_log(LOG_DEBUG, "OSP: localcert '%s'\n", p->localcert); 00190 } else if (!strcasecmp(v->name, "cacert")) { 00191 if (p->cacount < OSP_MAX_CERTS) { 00192 if (v->value[0] == '/') { 00193 ast_copy_string(p->cacerts[p->cacount], v->value, sizeof(p->cacerts[0])); 00194 } else { 00195 snprintf(p->cacerts[p->cacount], sizeof(p->cacerts[0]), "%s/%s", ast_config_AST_KEY_DIR, v->value); 00196 } 00197 ast_log(LOG_DEBUG, "OSP: cacert[%d]: '%s'\n", p->cacount, p->cacerts[p->cacount]); 00198 p->cacount++; 00199 } else { 00200 ast_log(LOG_WARNING, "OSP: Too many CA Certificates at line %d\n", v->lineno); 00201 } 00202 } else if (!strcasecmp(v->name, "servicepoint")) { 00203 if (p->spcount < OSP_MAX_SRVS) { 00204 ast_copy_string(p->srvpoints[p->spcount], v->value, sizeof(p->srvpoints[0])); 00205 ast_log(LOG_DEBUG, "OSP: servicepoint[%d]: '%s'\n", p->spcount, p->srvpoints[p->spcount]); 00206 p->spcount++; 00207 } else { 00208 ast_log(LOG_WARNING, "OSP: Too many Service Points at line %d\n", v->lineno); 00209 } 00210 } else if (!strcasecmp(v->name, "maxconnections")) { 00211 if ((sscanf(v->value, "%d", &t) == 1) && (t >= OSP_MIN_MAXCONNECTIONS) && (t <= OSP_MAX_MAXCONNECTIONS)) { 00212 p->maxconnections = t; 00213 ast_log(LOG_DEBUG, "OSP: maxconnections '%d'\n", t); 00214 } else { 00215 ast_log(LOG_WARNING, "OSP: maxconnections should be an integer from %d to %d, not '%s' at line %d\n", 00216 OSP_MIN_MAXCONNECTIONS, OSP_MAX_MAXCONNECTIONS, v->value, v->lineno); 00217 } 00218 } else if (!strcasecmp(v->name, "retrydelay")) { 00219 if ((sscanf(v->value, "%d", &t) == 1) && (t >= OSP_MIN_RETRYDELAY) && (t <= OSP_MAX_RETRYDELAY)) { 00220 p->retrydelay = t; 00221 ast_log(LOG_DEBUG, "OSP: retrydelay '%d'\n", t); 00222 } else { 00223 ast_log(LOG_WARNING, "OSP: retrydelay should be an integer from %d to %d, not '%s' at line %d\n", 00224 OSP_MIN_RETRYDELAY, OSP_MAX_RETRYDELAY, v->value, v->lineno); 00225 } 00226 } else if (!strcasecmp(v->name, "retrylimit")) { 00227 if ((sscanf(v->value, "%d", &t) == 1) && (t >= OSP_MIN_RETRYLIMIT) && (t <= OSP_MAX_RETRYLIMIT)) { 00228 p->retrylimit = t; 00229 ast_log(LOG_DEBUG, "OSP: retrylimit '%d'\n", t); 00230 } else { 00231 ast_log(LOG_WARNING, "OSP: retrylimit should be an integer from %d to %d, not '%s' at line %d\n", 00232 OSP_MIN_RETRYLIMIT, OSP_MAX_RETRYLIMIT, v->value, v->lineno); 00233 } 00234 } else if (!strcasecmp(v->name, "timeout")) { 00235 if ((sscanf(v->value, "%d", &t) == 1) && (t >= OSP_MIN_TIMEOUT) && (t <= OSP_MAX_TIMEOUT)) { 00236 p->timeout = t; 00237 ast_log(LOG_DEBUG, "OSP: timeout '%d'\n", t); 00238 } else { 00239 ast_log(LOG_WARNING, "OSP: timeout should be an integer from %d to %d, not '%s' at line %d\n", 00240 OSP_MIN_TIMEOUT, OSP_MAX_TIMEOUT, v->value, v->lineno); 00241 } 00242 } else if (!strcasecmp(v->name, "source")) { 00243 ast_copy_string(p->source, v->value, sizeof(p->source)); 00244 ast_log(LOG_DEBUG, "OSP: source '%s'\n", p->source); 00245 } else if (!strcasecmp(v->name, "authpolicy")) { 00246 if ((sscanf(v->value, "%d", &t) == 1) && ((t == OSP_AUTH_NO) || (t == OSP_AUTH_YES) || (t == OSP_AUTH_EXCLUSIVE))) { 00247 p->authpolicy = t; 00248 ast_log(LOG_DEBUG, "OSP: authpolicy '%d'\n", t); 00249 } else { 00250 ast_log(LOG_WARNING, "OSP: authpolicy should be %d, %d or %d, not '%s' at line %d\n", 00251 OSP_AUTH_NO, OSP_AUTH_YES, OSP_AUTH_EXCLUSIVE, v->value, v->lineno); 00252 } 00253 } 00254 v = v->next; 00255 } 00256 00257 error = OSPPUtilLoadPEMPrivateKey((unsigned char *) p->privatekey, &privatekey); 00258 if (error != OSPC_ERR_NO_ERROR) { 00259 ast_log(LOG_WARNING, "OSP: Unable to load privatekey '%s', error '%d'\n", p->privatekey, error); 00260 free(p); 00261 return 0; 00262 } 00263 00264 error = OSPPUtilLoadPEMCert((unsigned char *) p->localcert, &localcert); 00265 if (error != OSPC_ERR_NO_ERROR) { 00266 ast_log(LOG_WARNING, "OSP: Unable to load localcert '%s', error '%d'\n", p->localcert, error); 00267 if (privatekey.PrivateKeyData) { 00268 free(privatekey.PrivateKeyData); 00269 } 00270 free(p); 00271 return 0; 00272 } 00273 00274 if (p->cacount < 1) { 00275 snprintf(p->cacerts[p->cacount], sizeof(p->cacerts[0]), "%s/%s-cacert.pem", ast_config_AST_KEY_DIR, provider); 00276 ast_log(LOG_DEBUG, "OSP: cacert[%d]: '%s'\n", p->cacount, p->cacerts[p->cacount]); 00277 p->cacount++; 00278 } 00279 for (i = 0; i < p->cacount; i++) { 00280 error = OSPPUtilLoadPEMCert((unsigned char *) p->cacerts[i], &cacerts[i]); 00281 if (error != OSPC_ERR_NO_ERROR) { 00282 ast_log(LOG_WARNING, "OSP: Unable to load cacert '%s', error '%d'\n", p->cacerts[i], error); 00283 for (j = 0; j < i; j++) { 00284 if (cacerts[j].CertData) { 00285 free(cacerts[j].CertData); 00286 } 00287 } 00288 if (localcert.CertData) { 00289 free(localcert.CertData); 00290 } 00291 if (privatekey.PrivateKeyData) { 00292 free(privatekey.PrivateKeyData); 00293 } 00294 free(p); 00295 return 0; 00296 } 00297 pcacerts[i] = &cacerts[i]; 00298 } 00299 00300 for (i = 0; i < p->spcount; i++) { 00301 psrvpoints[i] = p->srvpoints[i]; 00302 } 00303 00304 error = OSPPProviderNew(p->spcount, psrvpoints, NULL, OSP_AUDIT_URL, &privatekey, &localcert, p->cacount, pcacerts, OSP_LOCAL_VALIDATION, 00305 OSP_SSL_LIFETIME, p->maxconnections, OSP_HTTP_PERSISTENCE, p->retrydelay, p->retrylimit,p->timeout, OSP_CUSTOMER_ID, 00306 OSP_DEVICE_ID, &p->handle); 00307 if (error != OSPC_ERR_NO_ERROR) { 00308 ast_log(LOG_WARNING, "OSP: Unable to create provider '%s', error '%d'\n", provider, error); 00309 free(p); 00310 res = -1; 00311 } else { 00312 ast_log(LOG_DEBUG, "OSP: provider '%s'\n", provider); 00313 ast_mutex_lock(&osplock); 00314 p->next = ospproviders; 00315 ospproviders = p; 00316 ast_mutex_unlock(&osplock); 00317 res = 1; 00318 } 00319 00320 for (i = 0; i < p->cacount; i++) { 00321 if (cacerts[i].CertData) { 00322 free(cacerts[i].CertData); 00323 } 00324 } 00325 if (localcert.CertData) { 00326 free(localcert.CertData); 00327 } 00328 if (privatekey.PrivateKeyData) { 00329 free(privatekey.PrivateKeyData); 00330 } 00331 00332 return res; 00333 }
| static int osp_create_transaction | ( | const char * | provider, | |
| int * | transaction, | |||
| unsigned int | sourcesize, | |||
| char * | source | |||
| ) | [static] |
Create OSP transaction handle.
| provider | OSP provider context name | |
| transaction | OSP transaction handle, output | |
| sourcesize | Size of source buffer, in/output | |
| source | Source of provider, output |
Definition at line 370 of file app_osplookup.c.
References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), osp_provider::handle, LOG_DEBUG, osp_provider::name, osp_provider::next, OSP_INVALID_HANDLE, ospproviders, and osp_provider::source.
Referenced by osp_auth(), and osp_lookup().
00371 { 00372 int res = 0; 00373 struct osp_provider* p; 00374 int error; 00375 00376 ast_mutex_lock(&osplock); 00377 p = ospproviders; 00378 while(p) { 00379 if (!strcasecmp(p->name, provider)) { 00380 error = OSPPTransactionNew(p->handle, transaction); 00381 if (error == OSPC_ERR_NO_ERROR) { 00382 ast_log(LOG_DEBUG, "OSP: transaction '%d'\n", *transaction); 00383 ast_copy_string(source, p->source, sourcesize); 00384 ast_log(