-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTryTeaseSearch.q
215 lines (184 loc) · 4.56 KB
/
TryTeaseSearch.q
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/sh
set -x
set -e
. json_dd_reader.sh
##
## place content with teaser,
## search content using "search-msg"
##
## type SearchDD struct {
## Keys string `json:"keywords"`
## Idx1 string `json:"city"`
## Idx2 string `json:"state"`
## Teas string `json:"teaser"`
## }
##
## type SearchResults struct {
## Key string `json:"keywords"`
## Res []string `json:"results"`
## }
##
## type WriteDD struct {
## Cmd string `json:"cmd"`
## Wrt string `json:"writer_token"`
## Pub string `json:"publish"`
## Data string `json:"data"`
## TTL int `json:"ttl"`
## Keys string `json:"keywords"`
## Idx1 string `json:"city"`
## Idx2 string `json:"state"`
## Teas string `json:"teaser"`
## Pal bool `json:"from_pal"`
## }
##
## type ReadDeleteDD struct {
## Cmd string `json:"cmd"`
## Own string `json:"owner_token"`
## }
##
IP=$1
KEY=$(date +"LA_%s_RC")
ECHO=/bin/echo
GUIDLEN=36
TTL=10
write_msg() {
Ck=cmd
Wk=writer_token
Pk=publish
Dk=data
Tk=ttl
Kk=keywords
I1k=city
I2k=state
TZk=teaser
C=write-dd
if [ $# -lt 5 ]; then
echo "need data (d), ttl (t), keyword (k), index 1 (i1), index 2 (i2), [teaser (tz)]"
exit 1
fi
DD=`echo '{"cmd":"create-dd"}' | nc ${IP} 8089`
if [ -z ${DD} ]; then
echo could not create owner/writer ...
exit 1
fi
RET= ; json_2_create_dd ${DD}
W=$(basename ${RET})
P=$(dirname ${RET})
D=$1 ; shift 1
T=$1 ; shift 1
K=$1 ; shift 1
I1=$1 ; shift 1
I2=$1 ; shift 1
if [ $# -eq 1 ]; then
TZ=$1
else
TZ=""
fi
D="${D} -- Tokens: ${P}/${W}"
ID=`echo '{
"'${Ck}'":"'${C}'",
"'${Pk}'":"'${P}'",
"'${Tk}'":'${T}',
"'${Wk}'":"'${W}'",
"'${Dk}'":"'${D}'",
"'${Kk}'":"'${K}'",
"'${I1k}'":"'${I1}'",
"'${I2k}'":"'${I2}'",
"'${TZk}'":"'${TZ}'"}' | nc ${IP} 8089`
if [ -z ${ID} ]; then
echo message id was not returned ...
exit 1
fi
## echo "Not to be used in production, but here's the message identifier: ${ID}"
}
read_msg() {
Ck=cmd
C=read-entry
Ok=owner_token
if [ $# -ne 1 ]; then
echo "need owner (o)"
exit 1
fi
O=$1
M=$(echo '{ "'${Ck}'":"'${C}'","'${Ok}'":"'${O}'"}' | nc ${IP} 8089)
if [ -z ${M} ]; then
return
fi
RET= ; json_2_read_msg $M
if [ -z ${RET} ]; then
return
fi
MSGS=${RET}
while [ ${MSGS} != "/" ]; do
MSG=$(basename ${MSGS})
MSGS=$(dirname ${MSGS})
echo ${MSG} | base64 -D
echo ""
done
}
search_msg() {
Ck=cmd
C=search-msg
Kk=keywords
I1k=city
I2k=state
TZk=teaser
if [ $# -lt 3 ]; then
echo "need keywords (k) index 1 (i1), index 2 (i2), teaser (tz)"
exit 1
fi
K=$1 ; shift 1
I1=$1 ; shift 1
I2=$1 ; shift 1
if [ $# -eq 1 ]; then
TZ=$1 ; shift 1
else
TZ=""
fi
SRCH=`echo '{
"'${Ck}'":"'${C}'",
"'${Kk}'":"'${K}'",
"'${I1k}'":"'${I1}'",
"'${I2k}'":"'${I2}'",
"'${TZk}'":"'${TZ}'"}' | nc ${IP} 8089`
if [ -z ${SRCH} ]; then
echo no search token found ...
exit 1
fi
RET= ; json_2_search_msg ${SRCH}
if [ -z ${RET} ]; then
return
fi
DDS=$RET
while [ ${DDS} != "/" ]; do
DD=$(basename ${DDS})
DDS=$(dirname ${DDS})
DDn=$(${ECHO} -n ${DD} | awk '{print length($0);}')
if [ ${GUIDLEN} -ne ${DDn} ]; then
break
fi
read_msg ${DD}
if [ -z ${DDS} ]; then
break
fi
done
}
if [ $# -ne 1 ]; then
echo "need ip address ..."
exit 1
fi
check_pu() {
write_msg "${KEY} : Here is some public data ttl ${TTL}, Eng/Photo/Crap Du Bob ..." ${TTL} Eng Photo "Crap Du Bob"
write_msg "${KEY} : Here is some more public data ttl ${TTL}, Eng/Photo/Crap Du Bob ..." ${TTL} Eng Photo "Crap Du Bob"
${ECHO} -n "begin search KEY:${KEY} ... " ; read A
search_msg Eng Photo "Crap Du Bob"
}
check_pv() {
##
## key must be unique!! (means only one message per private invite ...)
##
write_msg "${KEY} : Here is some private data ttl ${TTL}, Eng/Photo/Crap Du Bob ..." ${TTL} Eng Photo "Crap Du Bob" ${KEY}
${ECHO} -n "begin search KEY:${KEY} ... " ; read A
search_msg Eng Photo "Crap Du Bob" ${KEY}
}
check_pu