durable_rules 0.34.07 → 0.34.08

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f801482db85dfb25b213d116aa0d014cdad42084
4
- data.tar.gz: 409a2fcaed3552123300f4198d33f4a31fc77cbd
3
+ metadata.gz: f1e061100199ce15d81d79d7eb1975c492f37e11
4
+ data.tar.gz: e58844ae64ab2ecc1de3ff65f94c5a58dbc321e0
5
5
  SHA512:
6
- metadata.gz: 93816e1cd7f9da714223c40f358f25e4cee82863617721b9d1e47c46a6054b1a3057851a34db7706b717f34788da8460dedd1e68006614f087c94e82f3e3f251
7
- data.tar.gz: d8dc3652fc040a1b0f4c255858c89b55652e9870547153eb1d9a7e4d8bed4ff952c3dcac6e2689c9d25edcb729fbfdbead94e0b620aff9231c6cdafd71057625
6
+ metadata.gz: eebe19864a213b180be28a4851217aa785ed186d69a9d6b68716ef3307a1ea54275704291ecb0fe0aff06c372b488df0181c00f4a76209caf7e68284edbd0899
7
+ data.tar.gz: 0e7dc295427568f9ab95410527633b288eca2e822dd7bfc21dbdf2d30c94f44276135a19cb3398690aa38270f402728901496add972b943268190a354e5a19de
data/librb/durable.rb CHANGED
@@ -154,7 +154,11 @@ module Durable
154
154
  end
155
155
 
156
156
  def default(name, value=nil)
157
- @left = name
157
+ if @left
158
+ @left = "#{@left}.#{name}"
159
+ else
160
+ @left = name
161
+ end
158
162
  self
159
163
  end
160
164
 
@@ -262,7 +266,11 @@ module Durable
262
266
  private
263
267
 
264
268
  def default(name, value=nil)
265
- @left = name
269
+ if @left
270
+ @left = "#{@left}.#{name}"
271
+ else
272
+ @left = name
273
+ end
266
274
  self
267
275
  end
268
276
 
data/src/rules/events.c CHANGED
@@ -1262,8 +1262,9 @@ static unsigned int handleMessage(ruleset *tree,
1262
1262
  unsigned int midIndex = UNDEFINED_INDEX;
1263
1263
  unsigned int sidIndex = UNDEFINED_INDEX;
1264
1264
  jsonProperty properties[MAX_EVENT_PROPERTIES];
1265
- int result = constructObject(NULL,
1266
- message,
1265
+ int result = constructObject(message,
1266
+ NULL,
1267
+ NULL,
1267
1268
  0,
1268
1269
  MAX_EVENT_PROPERTIES,
1269
1270
  properties,
@@ -1274,7 +1275,7 @@ static unsigned int handleMessage(ruleset *tree,
1274
1275
  if (result != RULES_OK) {
1275
1276
  return result;
1276
1277
  }
1277
-
1278
+
1278
1279
  return handleMessageCore(tree,
1279
1280
  state,
1280
1281
  message,
@@ -1309,8 +1310,9 @@ static unsigned int handleMessages(void *handle,
1309
1310
  ++first;
1310
1311
  }
1311
1312
 
1312
- while (constructObject(NULL,
1313
- first,
1313
+ while (constructObject(first,
1314
+ NULL,
1315
+ NULL,
1314
1316
  0,
1315
1317
  MAX_EVENT_PROPERTIES,
1316
1318
  properties,
data/src/rules/net.c CHANGED
@@ -1082,6 +1082,37 @@ static unsigned int loadPeekActionCommand(ruleset *tree, binding *rulesBinding)
1082
1082
  " end\n"
1083
1083
  " return sid, name, frame\n"
1084
1084
  "end\n"
1085
+ "local fixup_frame = function(frame)\n"
1086
+ " for message_name, message in pairs(frame) do\n"
1087
+ " if message ~= \"$n\" then\n"
1088
+ " for key, value in pairs(message) do\n"
1089
+ " local start = 1\n"
1090
+ " local sub_message = message\n"
1091
+ " local name = key\n"
1092
+ " local next = nil\n"
1093
+ " repeat\n"
1094
+ " next = string.find(key, \"%%.\", start)\n"
1095
+ " if next then\n"
1096
+ " name = string.sub(key, start, next - 1)\n"
1097
+ " if sub_message[name] then\n"
1098
+ " sub_message = sub_message[name]\n"
1099
+ " else\n"
1100
+ " local new_sub_message = {}\n"
1101
+ " sub_message[name] = new_sub_message\n"
1102
+ " sub_message = new_sub_message\n"
1103
+ " end\n"
1104
+ " start = next + 1\n"
1105
+ " else\n"
1106
+ " name = string.sub(key, start)\n"
1107
+ " end\n"
1108
+ " until not next\n"
1109
+ " message[key] = nil\n"
1110
+ " sub_message[name] = value\n"
1111
+ " end\n"
1112
+ " end\n"
1113
+ " end\n"
1114
+ " return frame\n"
1115
+ "end\n"
1085
1116
  "get_context = function(action_key)\n"
1086
1117
  " if context_directory[action_key] then\n"
1087
1118
  " return context_directory[action_key]\n"
@@ -1099,9 +1130,9 @@ static unsigned int loadPeekActionCommand(ruleset *tree, binding *rulesBinding)
1099
1130
  " redis.call(\"zadd\", action_key, tonumber(ARGV[1]), new_sid)\n"
1100
1131
  " if #ARGV == 2 then\n"
1101
1132
  " local state = redis.call(\"hget\", state_key, new_sid)\n"
1102
- " return {new_sid, state, cjson.encode({[action_name] = frame})}\n"
1133
+ " return {new_sid, state, cjson.encode({[action_name] = fixup_frame(frame)})}\n"
1103
1134
  " else\n"
1104
- " return {new_sid, cjson.encode({[action_name] = frame})}\n"
1135
+ " return {new_sid, cjson.encode({[action_name] = fixup_frame(frame)})}\n"
1105
1136
  " end\n"
1106
1137
  "end\n",
1107
1138
  name,
@@ -2339,7 +2370,7 @@ unsigned int formatEvalMessage(void *rulesBinding,
2339
2370
 
2340
2371
  unsigned int offset = 8 + keysLength;
2341
2372
  for (unsigned int i = 0; i < propertiesLength; ++i) {
2342
- argv[offset + i * 3] = message + allProperties[i].nameOffset;
2373
+ argv[offset + i * 3] = allProperties[i].name;
2343
2374
  argvl[offset + i * 3] = allProperties[i].nameLength;
2344
2375
  argv[offset + i * 3 + 1] = message + allProperties[i].valueOffset;
2345
2376
  if (allProperties[i].type == JSON_STRING) {
@@ -2419,7 +2450,7 @@ unsigned int formatStoreMessage(void *rulesBinding,
2419
2450
 
2420
2451
  unsigned int offset = 6 + keysLength;
2421
2452
  for (unsigned int i = 0; i < propertiesLength; ++i) {
2422
- argv[offset + i * 3] = message + allProperties[i].nameOffset;
2453
+ argv[offset + i * 3] = allProperties[i].name;
2423
2454
  argvl[offset + i * 3] = allProperties[i].nameLength;
2424
2455
  argv[offset + i * 3 + 1] = message + allProperties[i].valueOffset;
2425
2456
  if (allProperties[i].type == JSON_STRING) {
data/src/rules/rete.c CHANGED
@@ -32,6 +32,7 @@
32
32
  #define HASH_DIV 2087879820 // $div
33
33
  #define HASH_L 5861205 // $l
34
34
  #define HASH_R 5861211 //$r
35
+ #define HASH_FORWARD 1810358942 // $forward
35
36
 
36
37
  typedef struct path {
37
38
  unsigned char operator;
@@ -995,7 +996,7 @@ static unsigned int findAlpha(ruleset *tree,
995
996
  if (result != RULES_OK) {
996
997
  return result;
997
998
  }
998
-
999
+
999
1000
  newAlpha->nameOffset = stringOffset;
1000
1001
  newAlpha->type = NODE_ALPHA;
1001
1002
  newAlpha->value.a.hash = hash;
@@ -1048,6 +1049,22 @@ static void getSetting(unsigned int settingHash, char *rule, unsigned short *val
1048
1049
  }
1049
1050
  }
1050
1051
 
1052
+ static unsigned int createForwardAlpha(ruleset *tree,
1053
+ unsigned int *newOffset) {
1054
+ node *newAlpha;
1055
+ unsigned int result = storeAlpha(tree, &newAlpha, newOffset);
1056
+ if (result != RULES_OK) {
1057
+ return result;
1058
+ }
1059
+
1060
+ newAlpha->nameOffset = 0;
1061
+ newAlpha->type = NODE_ALPHA;
1062
+ newAlpha->value.a.hash = HASH_FORWARD;
1063
+ newAlpha->value.a.operator = OP_NEX;
1064
+
1065
+ return RULES_OK;
1066
+ }
1067
+
1051
1068
  static unsigned int createAlpha(ruleset *tree,
1052
1069
  char *rule,
1053
1070
  expression *expr,
@@ -1097,27 +1114,51 @@ static unsigned int createAlpha(ruleset *tree,
1097
1114
  unsigned int resultOffset = parentOffset;
1098
1115
  result = readNextArrayValue(first, &first, &last, &type);
1099
1116
  while (result == PARSE_OK) {
1100
- createAlpha(tree, first, expr, 0, &resultOffset);
1117
+ result = createAlpha(tree, first, expr, 0, &resultOffset);
1118
+ if (result != RULES_OK) {
1119
+ return result;
1120
+ }
1121
+
1101
1122
  previousOffset = resultOffset;
1102
1123
  result = readNextArrayValue(last, &first, &last, &type);
1103
1124
  }
1125
+ *newOffset = previousOffset;
1104
1126
 
1105
1127
  result = appendTerm(expr, tree->endNodeOffset);
1106
1128
  if (result != RULES_OK) {
1107
1129
  return result;
1108
1130
  }
1109
- return linkAlpha(tree, previousOffset, nextOffset);
1131
+
1132
+ if (nextOffset != 0) {
1133
+ return linkAlpha(tree, previousOffset, nextOffset);
1134
+ }
1135
+
1136
+ return RULES_OK;
1110
1137
  case HASH_OR:
1111
1138
  result = appendTerm(expr, tree->orNodeOffset);
1112
1139
  if (result != RULES_OK) {
1113
1140
  return result;
1114
1141
  }
1115
1142
 
1143
+ result = createForwardAlpha(tree, newOffset);
1144
+ if (result != RULES_OK) {
1145
+ return result;
1146
+ }
1147
+
1116
1148
  readNextValue(last, &first, &last, &type);
1117
1149
  result = readNextArrayValue(first, &first, &last, &type);
1118
1150
  while (result == PARSE_OK) {
1119
1151
  unsigned int single_offset = parentOffset;
1120
- createAlpha(tree, first, expr, nextOffset, &single_offset);
1152
+ result = createAlpha(tree, first, expr, 0, &single_offset);
1153
+ if (result != RULES_OK) {
1154
+ return result;
1155
+ }
1156
+
1157
+ result = linkAlpha(tree, single_offset, *newOffset);
1158
+ if (result != RULES_OK) {
1159
+ return result;
1160
+ }
1161
+
1121
1162
  result = readNextArrayValue(last, &first, &last, &type);
1122
1163
  }
1123
1164
 
@@ -1125,6 +1166,11 @@ static unsigned int createAlpha(ruleset *tree,
1125
1166
  if (result != RULES_OK) {
1126
1167
  return result;
1127
1168
  }
1169
+
1170
+ if (nextOffset != 0) {
1171
+ return linkAlpha(tree, *newOffset, nextOffset);
1172
+ }
1173
+
1128
1174
  return RULES_OK;
1129
1175
  }
1130
1176
 
data/src/rules/rules.h CHANGED
@@ -38,6 +38,7 @@
38
38
  #define ERR_STATE_NOT_LOADED 403
39
39
  #define ERR_STALE_STATE 404
40
40
  #define ERR_PROPERTY_NOT_FOUND 405
41
+ #define ERR_MAX_PROPERTY_NAME_LENGTH 406
41
42
 
42
43
  #define NEXT_BUCKET_LENGTH 512
43
44
  #define NEXT_LIST_LENGTH 32
data/src/rules/state.c CHANGED
@@ -164,7 +164,8 @@ static stateEntry *getEntry(ruleset *tree, char *sid, unsigned int sidHash) {
164
164
  return NULL;
165
165
  }
166
166
 
167
- unsigned int constructObject(char *parentName,
167
+ unsigned int constructObject(char *root,
168
+ char *parentName,
168
169
  char *object,
169
170
  char createHashtable,
170
171
  unsigned int maxProperties,
@@ -180,16 +181,61 @@ unsigned int constructObject(char *parentName,
180
181
  unsigned char type;
181
182
  unsigned int hash;
182
183
  int parentNameLength = (parentName ? strlen(parentName): 0);
184
+ object = (object ? object : root);
183
185
  unsigned int result = readNextName(object, &firstName, &lastName, &hash);
184
186
  while (result == PARSE_OK) {
185
187
  result = readNextValue(lastName, &first, &last, &type);
186
188
  if (result != PARSE_OK) {
187
189
  return result;
188
190
  }
191
+
192
+ jsonProperty *property = NULL;
193
+ if (type != JSON_OBJECT) {
194
+ if (!createHashtable) {
195
+ property = &properties[*propertiesLength];
196
+ if (hash == HASH_ID) {
197
+ *midIndex = *propertiesLength;
198
+ } else if (hash == HASH_SID) {
199
+ *sidIndex = *propertiesLength;
200
+ }
201
+ } else {
202
+ unsigned int candidate = hash % maxProperties;
203
+ while (properties[candidate].type != 0) {
204
+ candidate = (candidate + 1) % maxProperties;
205
+ }
206
+
207
+ if (hash == HASH_ID) {
208
+ *midIndex = candidate;
209
+ } else if (hash == HASH_SID) {
210
+ *sidIndex = candidate;
211
+ }
212
+
213
+ property = &properties[candidate];
214
+ }
215
+
216
+ *propertiesLength = *propertiesLength + 1;
217
+ if (*propertiesLength == maxProperties) {
218
+ return ERR_EVENT_MAX_PROPERTIES;
219
+ }
220
+
221
+ property->isMaterial = 0;
222
+ property->valueOffset = first - root;
223
+ property->valueLength = last - first;
224
+ property->type = type;
225
+ }
189
226
 
190
227
  if (!parentName) {
191
- if (type == JSON_OBJECT) {
192
- int nameLength = lastName - firstName;
228
+ int nameLength = lastName - firstName;
229
+ if (nameLength > MAX_NAME_LENGTH) {
230
+ return ERR_MAX_PROPERTY_NAME_LENGTH;
231
+ }
232
+
233
+ if (type != JSON_OBJECT) {
234
+ strncpy(property->name, firstName, nameLength);
235
+ property->nameLength = nameLength;
236
+ property->hash = hash;
237
+ } else {
238
+
193
239
  #ifdef _WIN32
194
240
  char *newParent = (char *)_alloca(sizeof(char)*(nameLength + 1));
195
241
  #else
@@ -197,7 +243,8 @@ unsigned int constructObject(char *parentName,
197
243
  #endif
198
244
  strncpy(newParent, firstName, nameLength);
199
245
  newParent[nameLength] = '\0';
200
- return constructObject(newParent,
246
+ result = constructObject(root,
247
+ newParent,
201
248
  first,
202
249
  createHashtable,
203
250
  maxProperties,
@@ -206,22 +253,35 @@ unsigned int constructObject(char *parentName,
206
253
  midIndex,
207
254
  sidIndex,
208
255
  next);
256
+ if (result != RULES_OK) {
257
+ return result;
258
+ }
209
259
  }
210
260
  } else {
211
261
  int nameLength = lastName - firstName;
212
262
  int fullNameLength = nameLength + parentNameLength + 1;
263
+ if (fullNameLength > MAX_NAME_LENGTH) {
264
+ return ERR_MAX_PROPERTY_NAME_LENGTH;
265
+ }
266
+
267
+ if (type != JSON_OBJECT) {
268
+ strncpy(property->name, parentName, parentNameLength);
269
+ property->name[parentNameLength] = '.';
270
+ strncpy(&property->name[parentNameLength + 1], firstName, nameLength);
271
+ property->nameLength = fullNameLength;
272
+ property->hash = djbHash(property->name, fullNameLength);
273
+ } else {
213
274
  #ifdef _WIN32
214
- char *fullName = (char *)_alloca(sizeof(char)*(fullNameLength + 1));
275
+ char *fullName = (char *)_alloca(sizeof(char)*(fullNameLength + 1));
215
276
  #else
216
- char fullName[fullNameLength + 1];
277
+ char fullName[fullNameLength + 1];
217
278
  #endif
218
- strncpy(fullName, firstName, nameLength);
219
- fullName[nameLength] = '.';
220
- strncpy(&fullName[nameLength + 1], parentName, parentNameLength);
221
- fullName[fullNameLength] = '\0';
222
- hash = djbHash(fullName, fullNameLength);
223
- if (type == JSON_OBJECT) {
224
- return constructObject(fullName,
279
+ strncpy(fullName, parentName, parentNameLength);
280
+ fullName[parentNameLength] = '.';
281
+ strncpy(&fullName[parentNameLength + 1], firstName, nameLength);
282
+ fullName[fullNameLength] = '\0';
283
+ result = constructObject(root,
284
+ fullName,
225
285
  first,
226
286
  createHashtable,
227
287
  maxProperties,
@@ -230,46 +290,12 @@ unsigned int constructObject(char *parentName,
230
290
  midIndex,
231
291
  sidIndex,
232
292
  next);
293
+ if (result != RULES_OK) {
294
+ return result;
295
+ }
233
296
  }
234
297
  }
235
-
236
- jsonProperty *property = NULL;
237
- if (!createHashtable) {
238
- property = &properties[*propertiesLength];
239
- if (hash == HASH_ID) {
240
- *midIndex = *propertiesLength;
241
- } else if (hash == HASH_SID) {
242
- *sidIndex = *propertiesLength;
243
- }
244
- } else {
245
- unsigned int candidate = hash % maxProperties;
246
- while (properties[candidate].type != 0) {
247
- candidate = (candidate + 1) % maxProperties;
248
- }
249
-
250
- if (hash == HASH_ID) {
251
- *midIndex = candidate;
252
- } else if (hash == HASH_SID) {
253
- *sidIndex = candidate;
254
- }
255
-
256
- property = &properties[candidate];
257
- }
258
-
259
-
260
-
261
- *propertiesLength = *propertiesLength + 1;
262
- if (*propertiesLength == maxProperties) {
263
- return ERR_EVENT_MAX_PROPERTIES;
264
- }
265
298
 
266
- property->isMaterial = 0;
267
- property->hash = hash;
268
- property->valueOffset = first - object;
269
- property->valueLength = last - first;
270
- property->nameOffset = firstName - object;
271
- property->nameLength = lastName - firstName;
272
- property->type = type;
273
299
  *next = last;
274
300
  result = readNextName(last, &firstName, &lastName, &hash);
275
301
  }
@@ -365,8 +391,9 @@ unsigned int refreshState(void *handle,
365
391
  char *next;
366
392
  unsigned int midIndex = UNDEFINED_INDEX;
367
393
  unsigned int sidIndex = UNDEFINED_INDEX;
368
- result = constructObject(NULL,
369
- entry->state,
394
+ result = constructObject(entry->state,
395
+ NULL,
396
+ NULL,
370
397
  1,
371
398
  MAX_STATE_PROPERTIES,
372
399
  entry->properties,
data/src/rules/state.h CHANGED
@@ -3,6 +3,7 @@
3
3
  #define HASH_SID 193505797
4
4
  #define UNDEFINED_INDEX 0xFFFFFFFF
5
5
  #define MAX_STATE_PROPERTIES 64
6
+ #define MAX_NAME_LENGTH 256
6
7
  #define UNDEFINED_HASH_OFFSET 0xFFFFFFFF
7
8
 
8
9
  typedef struct jsonProperty {
@@ -11,7 +12,7 @@ typedef struct jsonProperty {
11
12
  unsigned char isMaterial;
12
13
  unsigned short valueOffset;
13
14
  unsigned short valueLength;
14
- unsigned short nameOffset;
15
+ char name[MAX_NAME_LENGTH];
15
16
  unsigned short nameLength;
16
17
  union {
17
18
  long i;
@@ -36,7 +37,8 @@ typedef struct stateEntry {
36
37
  unsigned int djbHash(char *str, unsigned int len);
37
38
  void rehydrateProperty(jsonProperty *property, char *state);
38
39
  unsigned int refreshState(void *tree, char *sid);
39
- unsigned int constructObject(char *parentName,
40
+ unsigned int constructObject(char *root,
41
+ char *parentName,
40
42
  char *object,
41
43
  char createHashtable,
42
44
  unsigned int maxProperties,
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.07
4
+ version: 0.34.08
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesus Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-19 00:00:00.000000000 Z
11
+ date: 2016-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake