durable_rules 0.34.31 → 0.34.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 695edb93b0911210ca53350c02bc61c77bf9ccd2
4
- data.tar.gz: 425666b29236c98d761f50e43a5494f2d6cce21c
3
+ metadata.gz: df480880781f625f6d6c574922212f450018587e
4
+ data.tar.gz: 3bfca807e9d3749a23fb7da99ca813fe902ddcda
5
5
  SHA512:
6
- metadata.gz: 2624ce379aa4e8986b1800c79b4381eb4d0c94dab5e9b070ca14fff4a5ea0bfac37e87c004729c9b27a683de200fd63e79a9c989c2b55c6a068887b9986dce9e
7
- data.tar.gz: d296bc9d28874dc3519d5938d10003880338372d834c0215dcbd4342615547af96dbba834af84f2ba938f05a43078eed7e4eae1fb585bb91cef2391381b6eecb
6
+ metadata.gz: 9aa3ce726b7b4505293a64a05e793b707b94534c282f1d151f68a512bc9f76c41108e26884dd1d5df236e54466e45cd17e4a6f30d20620b24e950836eea26b82
7
+ data.tar.gz: b650ece290ba8e7135f55a2e7fb175f171a47a47f09b34204746eaa9cd113ef877ad7e947de134d09fcf2c146b73a221fea88e81deebbc1f51af92375454c876
data/src/rules/events.c CHANGED
@@ -1135,7 +1135,7 @@ static unsigned int handleMessageCore(ruleset *tree,
1135
1135
  mid,
1136
1136
  message,
1137
1137
  jo,
1138
- actionType,
1138
+ actionType == ACTION_REMOVE_FACT ? ACTION_RETRACT_FACT : actionType,
1139
1139
  evalKeys,
1140
1140
  evalCount,
1141
1141
  &evalCommand);
@@ -1234,6 +1234,9 @@ static unsigned int handleMessage(ruleset *tree,
1234
1234
  NULL,
1235
1235
  NULL,
1236
1236
  JSON_OBJECT_SEQUENCED,
1237
+ actionType == ACTION_ASSERT_FACT ||
1238
+ actionType == ACTION_RETRACT_FACT ||
1239
+ actionType == ACTION_REMOVE_FACT,
1237
1240
  &jo,
1238
1241
  &next);
1239
1242
  if (result != RULES_OK) {
@@ -1272,6 +1275,9 @@ static unsigned int handleMessages(void *handle,
1272
1275
  NULL,
1273
1276
  NULL,
1274
1277
  JSON_OBJECT_SEQUENCED,
1278
+ actionType == ACTION_ASSERT_FACT ||
1279
+ actionType == ACTION_RETRACT_FACT ||
1280
+ actionType == ACTION_REMOVE_FACT,
1275
1281
  &jo,
1276
1282
  &last) == RULES_OK) {
1277
1283
 
data/src/rules/json.h CHANGED
@@ -20,6 +20,9 @@
20
20
  #define FNV_32_OFFSET_BASIS 0x811c9dc5
21
21
  #define FNV_32_PRIME 16777619
22
22
 
23
+ #define FNV_64_OFFSET_BASIS 0xcbf29ce484222325
24
+ #define FNV_64_PRIME 1099511628211
25
+
23
26
  unsigned int readNextName(char *start, char **first, char **last, unsigned int *hash);
24
27
  unsigned int readNextValue(char *start, char **first, char **last, unsigned char *type);
25
28
  unsigned int readNextArrayValue(char *start, char **first, char **last, unsigned char *type);
data/src/rules/net.c CHANGED
@@ -2377,7 +2377,7 @@ unsigned int formatEvalMessage(void *rulesBinding,
2377
2377
  if (actionType == ACTION_RETRACT_FACT || actionType == ACTION_RETRACT_EVENT) {
2378
2378
  propertiesLength = 0;
2379
2379
  }
2380
-
2380
+
2381
2381
  binding *bindingContext = (binding*)rulesBinding;
2382
2382
  time_t currentTime = time(NULL);
2383
2383
  char score[11];
@@ -2467,6 +2467,7 @@ unsigned int formatStoreMessage(void *rulesBinding,
2467
2467
  unsigned int keysLength,
2468
2468
  char **command) {
2469
2469
  unsigned int propertiesLength = jo->propertiesLength;
2470
+
2470
2471
  binding *bindingContext = (binding*)rulesBinding;
2471
2472
  char keysLengthString[5];
2472
2473
  #ifdef _WIN32
data/src/rules/state.c CHANGED
@@ -162,14 +162,85 @@ static stateEntry *getEntry(ruleset *tree, char *sid, unsigned int sidHash) {
162
162
  return NULL;
163
163
  }
164
164
 
165
- static unsigned int fixupIds(jsonObject *jo) {
165
+ static void insertSortProperties(jsonObject *jo, jsonProperty **properties) {
166
+ for (unsigned short i = 1; i < jo->propertiesLength; ++i) {
167
+ unsigned short ii = i;
168
+ while (properties[ii]->hash < properties[ii - 1]->hash) {
169
+ jsonProperty *temp = properties[ii];
170
+ properties[ii] = properties[ii - 1];
171
+ properties[ii - 1] = temp;
172
+ --ii;
173
+ }
174
+ }
175
+ }
176
+
177
+ static void radixSortProperties(jsonObject *jo, jsonProperty **properties) {
178
+ unsigned char counts[43] = {};
179
+ for (unsigned char i = 0; i < jo->propertiesLength; ++i) {
180
+ unsigned char mostSignificant = jo->properties[i].hash / 100000000;
181
+ ++counts[mostSignificant];
182
+ }
183
+
184
+ unsigned char previousCount = 0;
185
+ for (unsigned char i = 0; i < 43; ++i) {
186
+ unsigned char nextCount = counts[i] + previousCount;
187
+ counts[i] = previousCount;
188
+ previousCount = nextCount;
189
+ }
190
+
191
+ for (unsigned char i = 0; i < jo->propertiesLength; ++i) {
192
+ unsigned char mostSignificant = jo->properties[i].hash / 100000000;
193
+ properties[counts[mostSignificant]] = &jo->properties[i];
194
+ ++counts[mostSignificant];
195
+ }
196
+ }
197
+
198
+ static void calculateId(jsonObject *jo) {
199
+
200
+ #ifdef _WIN32
201
+ jsonProperty **properties = (jsonProperty *)_alloca(sizeof(jsonProperty *) * (jo->propertiesLength));
202
+ #else
203
+ jsonProperty *properties[jo->propertiesLength];
204
+ #endif
205
+
206
+ radixSortProperties(jo, properties);
207
+ insertSortProperties(jo, properties);
208
+
209
+ unsigned long long hash = FNV_64_OFFSET_BASIS;
210
+ for (unsigned short i = 0; i < jo->propertiesLength; ++i) {
211
+ jsonProperty *property = properties[i];
212
+ for (unsigned short ii = 0; ii < property->nameLength; ++ii) {
213
+ hash ^= property->name[ii];
214
+ hash *= FNV_64_PRIME;
215
+ }
216
+
217
+ unsigned short valueLength = property->valueLength;
218
+ if (property->type != JSON_STRING) {
219
+ ++valueLength;
220
+ }
221
+
222
+ for (unsigned short ii = 0; ii < valueLength; ++ii) {
223
+ hash ^= property->valueString[ii];
224
+ hash *= FNV_64_PRIME;
225
+ }
226
+ }
227
+
228
+ #ifdef _WIN32
229
+ sprintf_s(jo->idBuffer, sizeof(char) * 21, "%020llu", hash);
230
+ #else
231
+ snprintf(jo->idBuffer, sizeof(char) * 21, "%020llu", hash);
232
+ #endif
233
+ jo->properties[jo->idIndex].valueLength = 20;
234
+ }
235
+
236
+ static unsigned int fixupIds(jsonObject *jo, char generateId) {
166
237
  jsonProperty *property;
167
238
  // id and sid are coerced to strings
168
239
  // to avoid unnecessary conversions
169
240
  if (jo->sidIndex != UNDEFINED_INDEX && jo->properties[jo->sidIndex].type != JSON_NIL) {
170
241
  //coerce value to string
171
242
  property = &jo->properties[jo->sidIndex];
172
- if (property->type == JSON_DOUBLE || property->type == JSON_INT) {
243
+ if (property->type != JSON_STRING) {
173
244
  ++property->valueLength;
174
245
  }
175
246
 
@@ -195,7 +266,7 @@ static unsigned int fixupIds(jsonObject *jo) {
195
266
  if (jo->idIndex != UNDEFINED_INDEX && jo->properties[jo->idIndex].type != JSON_NIL) {
196
267
  //coerce value to string
197
268
  property = &jo->properties[jo->idIndex];
198
- if (property->type == JSON_DOUBLE || property->type == JSON_INT) {
269
+ if (property->type != JSON_STRING) {
199
270
  ++property->valueLength;
200
271
  }
201
272
 
@@ -216,6 +287,9 @@ static unsigned int fixupIds(jsonObject *jo) {
216
287
  strncpy(property->name, "id", 2);
217
288
  property->nameLength = 2;
218
289
  property->type = JSON_STRING;
290
+ if (generateId) {
291
+ calculateId(jo);
292
+ }
219
293
  }
220
294
 
221
295
  return RULES_OK;
@@ -225,6 +299,7 @@ unsigned int constructObject(char *root,
225
299
  char *parentName,
226
300
  char *object,
227
301
  char layout,
302
+ char generateId,
228
303
  jsonObject *jo,
229
304
  char **next) {
230
305
  char *firstName;
@@ -304,16 +379,17 @@ unsigned int constructObject(char *root,
304
379
  } else {
305
380
 
306
381
  #ifdef _WIN32
307
- char *newParent = (char *)_alloca(sizeof(char)*(nameLength + 1));
382
+ char *newParent = (char *)_alloca(sizeof(char)*(nameLength + 1));
308
383
  #else
309
- char newParent[nameLength + 1];
384
+ char newParent[nameLength + 1];
310
385
  #endif
311
386
  strncpy(newParent, firstName, nameLength);
312
387
  newParent[nameLength] = '\0';
313
388
  result = constructObject(root,
314
389
  newParent,
315
390
  first,
316
- layout,
391
+ layout,
392
+ 0,
317
393
  jo,
318
394
  next);
319
395
  if (result != RULES_OK) {
@@ -337,7 +413,7 @@ unsigned int constructObject(char *root,
337
413
  #ifdef _WIN32
338
414
  char *fullName = (char *)_alloca(sizeof(char)*(fullNameLength + 1));
339
415
  #else
340
- char fullName[fullNameLength + 1];
416
+ char fullName[fullNameLength + 1];
341
417
  #endif
342
418
  strncpy(fullName, parentName, parentNameLength);
343
419
  fullName[parentNameLength] = '.';
@@ -346,7 +422,8 @@ unsigned int constructObject(char *root,
346
422
  result = constructObject(root,
347
423
  fullName,
348
424
  first,
349
- layout,
425
+ layout,
426
+ 0,
350
427
  jo,
351
428
  next);
352
429
  if (result != RULES_OK) {
@@ -360,7 +437,7 @@ unsigned int constructObject(char *root,
360
437
  }
361
438
 
362
439
  if (!parentName) {
363
- int idResult = fixupIds(jo);
440
+ int idResult = fixupIds(jo, generateId);
364
441
  if (idResult != RULES_OK) {
365
442
  return idResult;
366
443
  }
@@ -457,6 +534,7 @@ unsigned int refreshState(void *handle,
457
534
  NULL,
458
535
  NULL,
459
536
  JSON_OBJECT_HASHED,
537
+ 0,
460
538
  &entry->jo,
461
539
  &next);
462
540
  if (result != RULES_OK) {
data/src/rules/state.h CHANGED
@@ -10,7 +10,7 @@
10
10
  #define JSON_OBJECT_SEQUENCED 1
11
11
  #define JSON_OBJECT_HASHED 2
12
12
 
13
- #define MAX_OBJECT_PROPERTIES 64
13
+ #define MAX_OBJECT_PROPERTIES 128
14
14
 
15
15
  typedef struct jsonProperty {
16
16
  unsigned int hash;
@@ -29,7 +29,7 @@ typedef struct jsonProperty {
29
29
 
30
30
  typedef struct jsonObject {
31
31
  jsonProperty properties[MAX_OBJECT_PROPERTIES];
32
- unsigned int propertiesLength;
32
+ unsigned char propertiesLength;
33
33
  unsigned int idIndex;
34
34
  unsigned int sidIndex;
35
35
  char sidBuffer[SID_BUFFER_LENGTH];
@@ -58,6 +58,7 @@ unsigned int constructObject(char *root,
58
58
  char *parentName,
59
59
  char *object,
60
60
  char layout,
61
+ char generateId,
61
62
  jsonObject *jo,
62
63
  char **next);
63
64
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: durable_rules
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.34.31
4
+ version: 0.34.32
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesus Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-27 00:00:00.000000000 Z
11
+ date: 2017-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake