forked from xeals/signal-back
/
raw.go
329 lines (315 loc) · 10.2 KB
/
raw.go
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
package types
import (
"strconv"
"github.com/xeals/signal-back/signal"
)
// StatementToStringArray formats a SqlStatement fairly literally as an array.
// Null parameters are left empty.
func StatementToStringArray(sql *signal.SqlStatement) []string {
s := make([]string, len(sql.GetParameters()))
for i, p := range sql.GetParameters() {
if p.IntegerParameter != nil {
s[i] = strconv.Itoa(int(*p.IntegerParameter))
} else if p.StringParamter != nil {
s[i] = *p.StringParamter
}
}
return s
}
// CSV column headers.
var (
SMSCSVHeaders = []string{
"ID",
"THREAD_ID",
"ADDRESS",
"ADDRESS_DEVICE_ID",
"PERSON",
"DATE_RECEIVED",
"DATE_SENT",
"PROTOCOL",
"READ",
"STATUS",
"TYPE",
"REPLY_PATH_PRESENT",
"DELIVERY_RECEIPT_COUNT",
"SUBJECT",
"BODY",
"MISMATCHED_IDENTITIES",
"SERVICE_CENTER",
"SUBSCRIPTION_ID",
"EXPIRES_IN",
"EXPIRE_STARTED",
"NOTIFIED",
"READ_RECEIPT_COUNT",
}
MMSCSVHeaders = []string{
"ID",
"THREAD_ID",
"DATE_SENT",
"DATE_RECEIVED",
"MESSAGE_BOX",
"READ",
"m_id",
"sub",
"sub_cs",
"BODY",
"PART_COUNT",
"ct_t",
"CONTENT_LOCATION",
"ADDRESS",
"ADDRESS_DEVICE_ID",
"EXPIRY",
"m_cls",
"MESSAGE_TYPE",
"v",
"MESSAGE_SIZE",
"pri",
"rr",
"rpt_a",
"resp_st",
"STATUS",
"TRANSACTION_ID",
"retr_st",
"retr_txt",
"retr_txt_cs",
"read_status",
"ct_cls",
"resp_txt",
"d_tm",
"DELIVERY_RECEIPT_COUNT",
"MISMATCHED_IDENTITIES",
"NETWORK_FAILURE",
"d_rpt",
"SUBSCRIPTION_ID",
"EXPIRES_IN",
"EXPIRE_STARTED",
"NOTIFIED",
"READ_RECEIPT_COUNT",
}
)
type SQLSMS struct {
ID uint64
ThreadID *uint64
Address *string
AddressDeviceID uint64 // default 1
Person *uint64
DateReceived *uint64
DateSent *uint64
Protocol uint64 // effectively default 0
Read uint64 // default 0
Status uint64 // default -1
Type *uint64
ReplyPathPresent *uint64
DeliveryReceiptCount uint64 // default 0
Subject *string
Body *string
MismatchedIdentities *string // default null
ServiceCenter *string
SubscriptionID uint64 // default -1
ExpiresIn uint64 // default 0
ExpireStarted uint64 // default 0
Notified uint64 // default 0
ReadReceiptCount uint64 // default 0
}
// StatementToSMS converts a of SQL statement to a single SMS.
func StatementToSMS(sql *signal.SqlStatement) *SQLSMS {
return ParametersToSMS(sql.GetParameters())
}
// ParametersToSMS converts a set of SQL parameters to a single SMS.
func ParametersToSMS(ps []*signal.SqlStatement_SqlParameter) *SQLSMS {
if len(ps) != 22 {
return nil
}
return &SQLSMS{
ID: ps[0].GetIntegerParameter(),
ThreadID: ps[1].IntegerParameter,
Address: ps[2].StringParamter,
AddressDeviceID: ps[3].GetIntegerParameter(),
Person: ps[4].IntegerParameter,
DateReceived: ps[5].IntegerParameter,
DateSent: ps[6].IntegerParameter,
Protocol: ps[7].GetIntegerParameter(),
Read: ps[8].GetIntegerParameter(),
Status: ps[9].GetIntegerParameter(),
Type: ps[10].IntegerParameter,
ReplyPathPresent: ps[11].IntegerParameter,
DeliveryReceiptCount: ps[12].GetIntegerParameter(),
Subject: ps[13].StringParamter,
Body: ps[14].StringParamter,
MismatchedIdentities: ps[15].StringParamter,
ServiceCenter: ps[16].StringParamter,
SubscriptionID: ps[17].GetIntegerParameter(),
ExpiresIn: ps[18].GetIntegerParameter(),
ExpireStarted: ps[19].GetIntegerParameter(),
Notified: ps[20].GetIntegerParameter(),
ReadReceiptCount: ps[21].GetIntegerParameter(),
}
}
type SQLMMS struct {
ID uint64
ThreadID *uint64
DateSent *uint64
DateReceived *uint64
MessageBox *uint64
Read uint64 // default 0
MID *string
Sub *string
SubCs *uint64
Body *string
PartCount *uint64
CtT *string
ContentLocation *string
Address *string
AddressDeviceID *uint64
Expiry *uint64
MCls *string
MessageType *uint64
V *uint64
MessageSize *uint64
Pri *uint64
Rr *uint64
RptA *uint64
RespSt *uint64
Status *uint64
TransactionID *string
RetrSt *uint64
RetrTxt *string
RetrTxtCs *uint64
ReadStatus *uint64
CtCls *uint64
RespTxt *string
DTm *uint64
DeliveryReceiptCount uint64 // default 0
MismatchedIdentities *string // default null
NetworkFailure *string // default null
DRpt *uint64
SubscriptionID uint64 // default -1
ExpiresIn uint64 // default 0
ExpireStarted uint64 // default 0
Notified uint64 // default 0
ReadReceiptCount uint64 // default 0
}
// StatementToMMS converts a of SQL statement to a single MMS.
func StatementToMMS(sql *signal.SqlStatement) *SQLMMS {
return ParametersToMMS(sql.GetParameters())
}
// ParametersToMMS converts a set of SQL parameters to a single MMS.
func ParametersToMMS(ps []*signal.SqlStatement_SqlParameter) *SQLMMS {
if len(ps) != 42 {
return nil
}
return &SQLMMS{
ID: ps[0].GetIntegerParameter(),
ThreadID: ps[1].IntegerParameter,
DateSent: ps[2].IntegerParameter,
DateReceived: ps[3].IntegerParameter,
MessageBox: ps[4].IntegerParameter,
Read: ps[5].GetIntegerParameter(),
MID: ps[6].StringParamter,
Sub: ps[7].StringParamter,
SubCs: ps[8].IntegerParameter,
Body: ps[9].StringParamter,
PartCount: ps[10].IntegerParameter,
CtT: ps[11].StringParamter,
ContentLocation: ps[12].StringParamter,
Address: ps[13].StringParamter,
AddressDeviceID: ps[14].IntegerParameter,
Expiry: ps[15].IntegerParameter,
MCls: ps[16].StringParamter,
MessageType: ps[17].IntegerParameter,
V: ps[18].IntegerParameter,
MessageSize: ps[19].IntegerParameter,
Pri: ps[20].IntegerParameter,
Rr: ps[21].IntegerParameter,
RptA: ps[22].IntegerParameter,
RespSt: ps[23].IntegerParameter,
Status: ps[24].IntegerParameter,
TransactionID: ps[25].StringParamter,
RetrSt: ps[26].IntegerParameter,
RetrTxt: ps[27].StringParamter,
RetrTxtCs: ps[28].IntegerParameter,
ReadStatus: ps[29].IntegerParameter,
CtCls: ps[30].IntegerParameter,
RespTxt: ps[31].StringParamter,
DTm: ps[32].IntegerParameter,
DeliveryReceiptCount: ps[33].GetIntegerParameter(),
MismatchedIdentities: ps[34].StringParamter,
NetworkFailure: ps[35].StringParamter,
DRpt: ps[36].IntegerParameter,
SubscriptionID: ps[37].GetIntegerParameter(),
ExpiresIn: ps[38].GetIntegerParameter(),
ExpireStarted: ps[39].GetIntegerParameter(),
Notified: ps[40].GetIntegerParameter(),
ReadReceiptCount: ps[41].GetIntegerParameter(),
}
}
type SQLPart struct {
RowID uint64 // primary
MmsID *uint64
Seq uint64 // default 0
ContentType *string
Name *string
Chset *uint64
ContentDisposition *string
Fn *string
Cid *string
ContentLocation *string
CttS *uint64
CttT *string
encrypted *uint64
TransferState *uint64
Data *string
Size *uint64
FileName *string
Thumbnail *string
ThumbnailAspectRatio *float64
UniqueID uint64 // not null
Digest []byte
FastPreflightID *string
VoiceNote uint64 // default 0
DataRandom []byte
ThumbnailRandom []byte
Quote uint64 // default 0
Width uint64 // default 0
Height uint64 // default 0
}
// StatementToPart converts a of SQL statement to a single part.
func StatementToPart(sql *signal.SqlStatement) *SQLPart {
return ParametersToPart(sql.GetParameters())
}
// ParametersToPart converts a set of SQL parameters to a single part.
func ParametersToPart(ps []*signal.SqlStatement_SqlParameter) *SQLPart {
if len(ps) != 25 {
return nil
}
return &SQLPart{
RowID: ps[0].GetIntegerParameter(),
MmsID: ps[1].IntegerParameter,
Seq: ps[2].GetIntegerParameter(),
ContentType: ps[3].StringParamter,
Name: ps[4].StringParamter,
Chset: ps[5].IntegerParameter,
ContentDisposition: ps[6].StringParamter,
Fn: ps[7].StringParamter,
Cid: ps[8].StringParamter,
ContentLocation: ps[9].StringParamter,
CttS: ps[10].IntegerParameter,
CttT: ps[11].StringParamter,
encrypted: ps[12].IntegerParameter,
TransferState: ps[13].IntegerParameter,
Data: ps[14].StringParamter,
Size: ps[15].IntegerParameter,
FileName: ps[16].StringParamter,
Thumbnail: ps[17].StringParamter,
ThumbnailAspectRatio: ps[18].DoubleParameter,
UniqueID: ps[19].GetIntegerParameter(),
Digest: ps[20].GetBlobParameter(),
FastPreflightID: ps[21].StringParamter,
VoiceNote: ps[22].GetIntegerParameter(),
DataRandom: ps[23].GetBlobParameter(),
ThumbnailRandom: ps[24].GetBlobParameter(),
Quote: ps[25].GetIntegerParameter(),
Width: ps[26].GetIntegerParameter(),
Height: ps[27].GetIntegerParameter(),
}
}