forked from RangeNetworks/subscriberRegistry
-
Notifications
You must be signed in to change notification settings - Fork 1
/
regs.gawk
145 lines (140 loc) · 4.85 KB
/
regs.gawk
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/gawk
BEGIN {
#print "Success = " success
#print "Failure = " failure
#print "Json = " json
state = 0 # each line represents a different state, this is used for message processing flow
first="true"
if (json == "true") {
print "{"
} else {
printf "%-32s %-9s %-20s\n", "TIME", "ID", "IMSI", "KI"
printf "================================ ========= ====================\n"
}
debugState=0 # set to 1 to debug
line=0
start=systime()
#print "Start @ " start
}
{
++line
#printf "line %d\r", line
switch (state) {
case 0: # Initial state - this is the state that process the initial select id from sip_buddies line
# We stay in this state until we get a "select id from sip_buddies
# where username= type message
timestamp=$1
query=$0
sub(/^.*SubscriberRegistry.cpp:[0-9]*:/,"",query)
$0 = query
if (debugState != 0) print "Line: " line ", State: " state ", Message: '" query "'"
if (/^sqlLocal: select id from sip_buddies where username = "/) {
imsi = $9
sub(/"/,"",imsi) # leading quote
sub(/"/,"",imsi) # trailing quote
id = ""
ki = ""
state = 1 # Determine if success or failure
} else
{
state = 0
}
break
case 1: # Determine if success or failure
# Result = ### line
# or not found: select id... line
query=$0
sub(/^.*SubscriberRegistry.cpp:[0-9]*:/,"",query)
$0 = query
if (debugState != 0) print "Line: " line ", State: " state ", Message: '" query "'"
if (/^.*not found: select id.*$/) {
#print "Not found"
if (failure == "true") {
if (json == "true") {
printf " "
if (first == "true") {
first = "false"
printf " "
} else {
printf ","
}
printf "{ \"timestamp\": \"%s\", \"id\": \"%s\", \"imsi\": \"%s\" }\n",
timestamp, "NOT FOUND", imsi
} else {
printf "%-32s %-9s %-20s\n", timestamp, "NOT FOUND", imsi
}
}
state=0
} else {
# This should be a "result = " line with an id
#print "We have an entry"
id = $4
state=2
}
break
################################################################
################################################################
## ##
## This set of steps is for the case where we found the entry ##
## ##
################################################################
################################################################
case 2: # skip the KI query
# select ki from sip_buddies where username =
query=$0
sub(/^.*SubscriberRegistry.cpp:[0-9]*:/,"",query)
$0 = query
if (/^sqlLocal: select ki from sip_buddies where username = "/) {
if (debugState != 0) print "Line: " line ", State: " state ", Message: '" query "'"
# Next state
state=3
} else {
# stay in the state - a spurrious result line
}
break
case 3: # KI result
query=$0
sub(/^.*SubscriberRegistry.cpp:[0-9]*:/,"",query)
$0 = query
if (debugState != 0) print "Line: " line ", State: " state ", Message: '" query "'"
if (/^sqlQuery: result = /) {
ki = $4
#print "Success finished"
if (success == "true") {
if (json == "true") {
printf " "
if (first == "true") {
first = "false"
printf " "
} else {
printf ","
}
printf "{ \"timestamp\": \"%s\", \"id\": %s, \"imsi\": \"%s\" }\n",
timestamp, id, imsi
} else {
printf "%-32s %-9s %-20s\n", timestamp, id, imsi
}
}
state=0
} else {
# stay in the state - a spurrious line
}
break
default:
print "Unknown state " state
state=0
break
}
}
END {
end=systime()
#print "End @ " end
if (json == "true") {
print " ,{ \"lines\": " line ", \"Duration\" : " end - start " }"
print "}"
} else
{
print "Lines: " line
print "Duration: " end - start " seconds"
}
}