Beispiel #1
0
static void *do_monitor(void *data)
{
    int result = ERROR_RC;
    char cdr_full_path[256];
    DIR *cdr_dir;
	VALUE_PAIR *resend = NULL;
	struct dirent *dir_s = NULL;
	int count = 0; // times of resend
	int wait_time = 0;
	
	for(;;){
        sleep(1); /* sleep 1 minute */
		/* Open dir */
		if((cdr_dir=opendir(cdr_directory)) == NULL){
			ast_log(LOG_ERROR,"Failed to open %s\n",cdr_directory);
		} else {
		/* open */
			while((dir_s=readdir(cdr_dir))!=NULL) {
				if(!strcmp(dir_s->d_name,".") || !strcmp(dir_s->d_name,".."))
					continue;
				memset(cdr_full_path,0,sizeof(cdr_full_path));
				snprintf(cdr_full_path,sizeof(cdr_full_path),"%s/%s",cdr_directory,dir_s->d_name);
				resend = get_avp(cdr_full_path);
				if(resend){
					result = rc_acct(rh,0,resend);
				}else{
					ast_log(LOG_ERROR, "get avp return null!");
				}
				if(result != OK_RC){
					ast_log(LOG_ERROR, "Failed to re-record Radius CDR record!\n");
					if(resend){
						ast_avpair_free(resend);
						resend = NULL;
					}
					count++;
					wait_time = count * 60; // reterval to resend cdr record: 60s, 120s,180s,240s......
					ast_log(LOG_DEBUG,"----------wait_time:%d-----------\n", wait_time);
					break;
				}else{
				ast_log(LOG_DEBUG,"----------cdr_full_path:%s send OK!-----------\n", cdr_full_path);
				wait_time = 0;
				count = 0;
				if(remove(cdr_full_path) != 0)
					ast_log(LOG_WARNING,"Failed to delete %s\n",cdr_full_path);
			}
			if(resend){
				ast_avpair_free(resend);
				resend = NULL;
			}
		}
		closedir(cdr_dir);
		}
		
		if (wait_time > 0) {
			ast_log(LOG_DEBUG,"if-wait_time>0----------wait_time:%d-----------\n", wait_time);
			sleep(wait_time);
		}
	}
	return NULL;
}
Beispiel #2
0
/**
 * Returns the Result-Code AVP from a Diameter message.
 * @param msg - the Diameter message
 * @returns 1 on success or 0 on error
 */
inline int get_result_code(AAAMessage *msg, int *data)
{
	str s;
	s = get_avp(msg,
		AVP_Result_Code,
		0,
		__FUNCTION__);
	if (!s.s) return 0;
	*data = get_4bytes(s.s);
	return 1;
}