summaryrefslogtreecommitdiff
path: root/net-misc/asterisk/files/1.8.0/find_call_ids.sh
blob: 321f3dacd624dbc14426d11ddf0f9550a4904e6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#! /bin/bash

logfile=$1
anum=$2
bnum=$3

function usage()
{
	echo "USAGE: $1 logfile anum bnum"
	exit -1
}

[ -r "${logfile}" ] || usage $0
[ -n "${anum}" ] || usage $0
[ -n "${bnum}" ] || usage $0

#echo "Finding calls from '${anum}' to '${bnum}' in ${logfile}."

# modes:
# 0 - not processing an INVITE.
# 1 - processing an INVITE.
# 2 - from matched (processing).
dos2unix < "${logfile}" | awk '
	BEGIN { mode = 0 }
	mode==0 && $4~"^VERBOSE" {
		dt=$1" "$2" "$3
	}

	mode==0 && $1=="INVITE" && $2 ~ "^sip:'"${bnum}"'@" {
		#print

		mode=1

		split($2, a, "[:@]")
		bnum=a[2]
	}

	mode==1 && $1=="From:" {
		#print
		if ($3 ~ "^<sip:'"${anum}"'@.*>") {
			mode=2
			split($3, a, "[:@]")
			anum=a[2]
		} else {
			#print "From does not match ... leaving block."
			mode = 0
		}
	}

	mode!=0 && $1=="Call-ID:" {
		callid=$2

		if (NF!=2) {
			print "WTF @ Call-ID header having NF!=2"
		}
	}

	mode==1 && $0=="" {
		#print "Leaving block (no match)"
		mode = 0
	}

	mode==2 && $0=="" {
		#print "Leaving block (match)"
		print dt " " anum " " bnum " " callid
		mode = 0
	}
'