diff -urN res_auth_new/cdr/cdr_radius.c res_auth_new.utm/cdr/cdr_radius.c --- res_auth_new/cdr/cdr_radius.c 2007-01-04 19:08:34.000000000 +0300 +++ res_auth_new.utm/cdr/cdr_radius.c 2007-04-09 12:47:55.000000000 +0400 @@ -100,6 +100,8 @@ struct tm tm; char timestr[128]; char *tmp; + char buf[253]; + int aux; if (!rc_avpair_add(rh, send, PW_ACCT_STATUS_TYPE, &recordtype, 0, 0)) return -1; @@ -107,15 +109,23 @@ /* Account code */ if (!rc_avpair_add(rh, send, PW_AST_ACCT_CODE, &cdr->accountcode, strlen(cdr->accountcode), VENDOR_CODE)) return -1; - + /* Source */ if (!rc_avpair_add(rh, send, PW_AST_SRC, &cdr->src, strlen(cdr->src), VENDOR_CODE)) return -1; + ast_copy_string(buf, cdr->src, sizeof(buf)); + if (!rc_avpair_add(rh, send, PW_CALLING_STATION_ID, &buf, strlen(buf), 0)) + return -1; + /* Destination */ if (!rc_avpair_add(rh, send, PW_AST_DST, &cdr->dst, strlen(cdr->dst), VENDOR_CODE)) return -1; + ast_copy_string(buf, cdr->dst, sizeof(buf)); + if (!rc_avpair_add(rh, send, PW_CALLED_STATION_ID, &buf, strlen(buf), 0)) + return -1; + /* Destination context */ if (!rc_avpair_add(rh, send, PW_AST_DST_CTX, &cdr->dcontext, strlen(cdr->dcontext), VENDOR_CODE)) return -1; @@ -172,6 +182,9 @@ if (!rc_avpair_add(rh, send, PW_AST_DURATION, &cdr->duration, 0, VENDOR_CODE)) return -1; + if (!rc_avpair_add(rh, send, PW_ACCT_SESSION_TIME, &cdr->duration, 0, 0)) + return -1; + /* Billable seconds */ if (!rc_avpair_add(rh, send, PW_AST_BILL_SEC, &cdr->billsec, 0, VENDOR_CODE)) return -1; @@ -229,6 +242,31 @@ return result; } +static int send_start(struct ast_cdr *cdr) +{ + int result = ERROR_RC; + VALUE_PAIR *send = NULL; + + int recordtype = PW_STATUS_START; + char timestr[128]; + struct tm tm; + + if(!rc_avpair_add(rh, &send, PW_ACCT_STATUS_TYPE, &recordtype, 0, 0)) return -1; + if(!rc_avpair_add(rh, &send, PW_ACCT_SESSION_TIME, &cdr->duration, 0, 0)) return -1; + if(!rc_avpair_add(rh, &send, PW_CALLING_STATION_ID, &cdr->src, strlen(cdr->src), 0)) return -1; + if(!rc_avpair_add(rh, &send, PW_CALLED_STATION_ID, &cdr->dst, strlen(cdr->dst), 0)) return -1; + if(!rc_avpair_add(rh, &send, PW_USER_NAME, &cdr->src, strlen(cdr->src), 0)) return -1; + if(!rc_avpair_add(rh, &send, PW_ACCT_SESSION_ID, &cdr->uniqueid, strlen(cdr->uniqueid), 0)) return -1; + if(!rc_avpair_add(rh, &send, 24, &cdr->uniqueid, strlen(cdr->uniqueid), 9)) return -1; + localtime_r(&(cdr->answer.tv_sec), &tm); + strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm); + if(!rc_avpair_add(rh, &send, 25, timestr, strlen(timestr), 9)) return -1; + + result = rc_acct(rh, 0, send); + + return result; +} + static int unload_module(void) { ast_cdr_unregister(name); @@ -264,7 +302,8 @@ ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n"); return -1; } - + + ast_cdr_reg_start(name, desc, send_start); return ast_cdr_register(name, desc, radius_log); } diff -urN res_auth_new/channels/chan_sip.c res_auth_new.utm/channels/chan_sip.c --- res_auth_new/channels/chan_sip.c 2007-01-08 17:49:32.000000000 +0300 +++ res_auth_new.utm/channels/chan_sip.c 2007-04-09 13:35:48.000000000 +0400 @@ -1003,6 +1003,8 @@ before strolling to the Grokyzpå (A bit unsure of this, please correct if you know more) */ + char max_dialog_time[255]; + char balance[255]; }; static struct sip_pvt *dialoglist = NULL; @@ -8030,7 +8032,9 @@ char a1_hash[256]; char resp_hash[256]=""; char tmp[BUFSIZ * 2]; /* Make a large enough buffer */ + char tmp1[BUFSIZ * 2]; char *c; + char *to; int wrongnonce = FALSE; int good_response; const char *usednonce = p->randdata; @@ -8117,6 +8121,12 @@ strsep(&c, " ,"); } + ast_copy_string(tmp1, get_header(req, "To"), sizeof(tmp)); + c = tmp1; + + strsep(&c,":"); + to = strsep(&c,"@"); + /* Verify that digest username matches the username we auth as */ if (strcmp(username, keys[K_USER].s)) { ast_log(LOG_WARNING, "username mismatch, have <%s>, digest has <%s>\n", @@ -8200,7 +8210,7 @@ ast_copy_string(aux.value, keys[K_USER].s, sizeof(aux.value)); ast_push_digest_attribute(¶ms, &aux); - retval = ast_digest_authenticate(user, ¶ms); + retval = ast_digest_authenticate(user, to, ¶ms, p->max_dialog_time, p->balance); return retval; } @@ -13625,6 +13635,9 @@ if (c) { /* We have a call -either a new call or an old one (RE-INVITE) */ + if (p->max_dialog_time) pbx_builtin_setvar_helper(c, "MAX_DIALOG_TIME", p->max_dialog_time); + if (p->balance) pbx_builtin_setvar_helper(c, "BALANCE", p->balance); + switch(c->_state) { case AST_STATE_DOWN: if (option_debug > 1) @@ -13703,6 +13716,7 @@ if (option_debug > 1) ast_log(LOG_DEBUG, "%s: This call is UP.... \n", c->name); + if (p->t38.state == T38_PEER_REINVITE) { struct ast_channel *bridgepeer = NULL; struct sip_pvt *bridgepvt = NULL; diff -urN res_auth_new/include/asterisk/auth.h res_auth_new.utm/include/asterisk/auth.h --- res_auth_new/include/asterisk/auth.h 2007-01-05 22:49:38.000000000 +0300 +++ res_auth_new.utm/include/asterisk/auth.h 2007-04-06 14:48:59.000000000 +0400 @@ -57,7 +57,7 @@ int ast_push_digest_attribute(struct digest_parameters* , digest_attr_t*); -int ast_digest_authenticate(const char*, struct digest_parameters *); +int ast_digest_authenticate(const char*, const char*, struct digest_parameters *, char*, char*); #endif /* HAVE_RADIUS */ diff -urN res_auth_new/include/asterisk/cdr.h res_auth_new.utm/include/asterisk/cdr.h --- res_auth_new/include/asterisk/cdr.h 2007-01-04 19:08:24.000000000 +0300 +++ res_auth_new.utm/include/asterisk/cdr.h 2007-04-09 12:29:02.000000000 +0400 @@ -102,6 +102,7 @@ typedef int (*ast_cdrbe)(struct ast_cdr *cdr); + /*! \brief Allocate a CDR record * Returns a malloc'd ast_cdr structure, returns NULL on error (malloc failure) */ @@ -160,6 +161,13 @@ */ void ast_cdr_start(struct ast_cdr *cdr); +/*! Send start record to backend*/ +void ast_cdr_send_start(struct ast_cdr *cdr); + +/*! Register start record function from backend*/ +int ast_cdr_reg_start(const char *, const char *, ast_cdrbe); + + /*! Answer a call */ /*! * \param cdr the cdr you wish to associate with the call diff -urN res_auth_new/main/cdr.c res_auth_new.utm/main/cdr.c --- res_auth_new/main/cdr.c 2007-01-04 19:08:29.000000000 +0300 +++ res_auth_new.utm/main/cdr.c 2007-04-09 12:32:37.000000000 +0400 @@ -35,10 +35,10 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision: 49125 $") -#include #include -#include #include +#include +#include #include #include "asterisk/lock.h" @@ -55,6 +55,8 @@ #include "asterisk/cli.h" #include "asterisk/stringfields.h" +#define DATE_FORMAT "%Y-%m-%d %T %z" + /*! Default AMA flag for billing records (CDR's) */ int ast_default_amaflags = AST_CDR_DOCUMENTATION; char ast_default_accountcode[AST_MAX_ACCOUNT_CODE]; @@ -67,6 +69,7 @@ }; static AST_LIST_HEAD_STATIC(be_list, ast_cdr_beitem); +static AST_LIST_HEAD_STATIC(start_list, ast_cdr_beitem); struct ast_cdr_batch_item { struct ast_cdr *cdr; @@ -142,6 +145,59 @@ return 0; } +/*! Send start record to backend*/ +void ast_cdr_send_start(struct ast_cdr *cdr){ + struct ast_cdr_beitem *i; + + for ( ; cdr ; cdr = cdr->next) { + AST_LIST_LOCK(&start_list); + AST_LIST_TRAVERSE(&start_list, i, list) { + i->be(cdr); + } + AST_LIST_UNLOCK(&start_list); + } + +} + +/*! Register start record function from backend*/ +int ast_cdr_reg_start(const char *name, const char *desc, ast_cdrbe be){ + struct ast_cdr_beitem *i; + + if (!name) + return -1; + if (!be) { + ast_log(LOG_WARNING, "Start function for CDR engine '%s' lacks backend\n", name); + return -1; + } + + AST_LIST_LOCK(&start_list); + AST_LIST_TRAVERSE(&start_list, i, list) { + if (!strcasecmp(name, i->name)) + break; + } + AST_LIST_UNLOCK(&start_list); + + if (i) { + ast_log(LOG_WARNING, "Already have a Start function for CDR backend called '%s'\n", name); + return -1; + } + + if (!(i = ast_calloc(1, sizeof(*i)))) + return -1; + + i->be = be; + ast_copy_string(i->name, name, sizeof(i->name)); + ast_copy_string(i->desc, desc, sizeof(i->desc)); + + AST_LIST_LOCK(&start_list); + AST_LIST_INSERT_HEAD(&start_list, i, list); + AST_LIST_UNLOCK(&start_list); + + return 0; + +} + + /*! unregister a CDR driver */ void ast_cdr_unregister(const char *name) { @@ -442,7 +498,6 @@ void ast_cdr_start(struct ast_cdr *cdr) { char *chan; - for (; cdr; cdr = cdr->next) { if (!ast_test_flag(cdr, AST_CDR_FLAG_LOCKED)) { chan = S_OR(cdr->channel, ""); @@ -460,8 +515,10 @@ check_post(cdr); if (cdr->disposition < AST_CDR_ANSWERED) cdr->disposition = AST_CDR_ANSWERED; - if (ast_tvzero(cdr->answer)) + if (ast_tvzero(cdr->answer)){ cdr->answer = ast_tvnow(); + ast_cdr_send_start(cdr); + } } } diff -urN res_auth_new/res/res_auth.c res_auth_new.utm/res/res_auth.c --- res_auth_new/res/res_auth.c 2007-01-05 23:18:40.000000000 +0300 +++ res_auth_new.utm/res/res_auth.c 2007-04-06 14:54:04.000000000 +0400 @@ -360,13 +360,16 @@ \return -1 on error, 0 on authentication success */ -int ast_digest_authenticate(const char* user, struct digest_parameters *params) +int ast_digest_authenticate(const char* user, const char* to, struct digest_parameters *params, char *max_dialog_time, char *balance) { int res; int i; struct digest_parameters aux; VALUE_PAIR *send, *received; char msg[4096]; + char tmp[256]; + char *ptmp; + ast_mutex_lock(&rc_lock); @@ -379,6 +382,11 @@ return -1; } + if (to && strcmp(to,user)) + if (rc_avpair_add(rh, &send, PW_CALLED_STATION_ID, (char *)to, -1, 0) == NULL) { + return -1; + } + /* Fill in Digest-Response */ // strncpy((char*)&aux.digest_response, params->digest_response, sizeof(aux.digest_response)); ast_copy_string(aux.digest_response, params->digest_response, sizeof(aux.digest_response)); @@ -399,8 +407,24 @@ } + res = rc_auth(rh, 0, send, &received, msg); - + + for(i = 0; i < sizeof(tmp); i++) tmp[i]='\0'; + + if(rc_avpair_tostr(rh, rc_avpair_get(received,102,9), msg, sizeof(msg), tmp, sizeof(tmp)) == NULL){ + ptmp=tmp; + strsep(&ptmp,"="); + ast_copy_string(max_dialog_time, ptmp, sizeof(tmp)); + } + if(rc_avpair_tostr(rh, rc_avpair_get(received,101,9), msg, sizeof(msg), tmp, sizeof(tmp)) == NULL){ + ptmp=tmp; + strsep(&ptmp,"="); + ast_copy_string(balance, ptmp, sizeof(tmp)); + ast_verbose(VERBOSE_PREFIX_3 "Balance - %s\n", balance); + } + + /* free resources */ rc_avpair_free(send); if (received)