@yuneta/gobj-js 7.26.23 → 7.26.25

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.
@@ -869,6 +869,112 @@
869
869
  var INT64_MIN = -(2n ** 63n);
870
870
  var INT64_MAX = 2n ** 63n - 1n;
871
871
  var REFUSED_TEXT = "a text that does not read as one";
872
+ var JSON_NUMBER_TOKEN = /-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?/y;
873
+ function is_surrogate_pair(high, low) {
874
+ return high >= 55296 && high <= 56319 && low >= 56320 && low <= 57343;
875
+ }
876
+ var JSON_MAX_DEPTH = 2048;
877
+ function json_text_refused_by_c(s) {
878
+ const n = s.length;
879
+ let i = 0;
880
+ let depth = 0;
881
+ const in_object = [];
882
+ let key_next = false;
883
+ while (i < n) {
884
+ const c = s.charCodeAt(i);
885
+ if (c === 123 || c === 91) {
886
+ depth++;
887
+ if (depth > JSON_MAX_DEPTH) return true;
888
+ in_object.push(c === 123);
889
+ key_next = c === 123;
890
+ i++;
891
+ continue;
892
+ }
893
+ if (c === 125 || c === 93) {
894
+ depth--;
895
+ in_object.pop();
896
+ key_next = false;
897
+ i++;
898
+ continue;
899
+ }
900
+ if (c === 44) {
901
+ key_next = in_object.length > 0 && in_object[in_object.length - 1];
902
+ i++;
903
+ continue;
904
+ }
905
+ if (c === 58) {
906
+ key_next = false;
907
+ i++;
908
+ continue;
909
+ }
910
+ if (c === 116 || c === 102 || c === 110) {
911
+ if (depth + 1 > JSON_MAX_DEPTH) return true;
912
+ i += c === 102 ? 5 : 4;
913
+ continue;
914
+ }
915
+ if (c === 34) {
916
+ if (!key_next && depth + 1 > JSON_MAX_DEPTH) return true;
917
+ key_next = false;
918
+ i++;
919
+ while (i < n) {
920
+ const d = s.charCodeAt(i);
921
+ if (d === 34) {
922
+ i++;
923
+ break;
924
+ }
925
+ if (d === 92 && s[i + 1] === "u") {
926
+ const u = parseInt(s.substring(i + 2, i + 6), 16);
927
+ if (u === 0) return true;
928
+ if (u >= 55296 && u <= 57343) {
929
+ if (!is_surrogate_pair(u, s[i + 6] === "\\" && s[i + 7] === "u" ? parseInt(s.substring(i + 8, i + 12), 16) : -1)) return true;
930
+ i += 12;
931
+ continue;
932
+ }
933
+ i += 6;
934
+ continue;
935
+ }
936
+ if (d === 92) {
937
+ i += 2;
938
+ continue;
939
+ }
940
+ if (d >= 55296 && d <= 57343) {
941
+ if (!is_surrogate_pair(d, s.charCodeAt(i + 1))) return true;
942
+ i += 2;
943
+ continue;
944
+ }
945
+ i++;
946
+ }
947
+ continue;
948
+ }
949
+ if (c === 45 || c >= 48 && c <= 57) {
950
+ if (depth + 1 > JSON_MAX_DEPTH) return true;
951
+ JSON_NUMBER_TOKEN.lastIndex = i;
952
+ const m = JSON_NUMBER_TOKEN.exec(s);
953
+ if (!m) return true;
954
+ const token = m[0];
955
+ if (/[.eE]/.test(token)) {
956
+ if (!Number.isFinite(Number(token))) return true;
957
+ } else {
958
+ const big = BigInt(token);
959
+ if (big < INT64_MIN || big > INT64_MAX) return true;
960
+ }
961
+ i += token.length;
962
+ continue;
963
+ }
964
+ i++;
965
+ }
966
+ return false;
967
+ }
968
+ function parse_json_text_as_c(s) {
969
+ let jn;
970
+ try {
971
+ jn = JSON.parse(s);
972
+ } catch (e) {
973
+ return;
974
+ }
975
+ if (json_text_refused_by_c(s)) return;
976
+ return jn;
977
+ }
872
978
  function value_has_shape(type, value) {
873
979
  if (DTP_IS_STRING(type)) return is_string(value);
874
980
  if (DTP_IS_DICT(type)) return is_object(value);
@@ -880,7 +986,7 @@
880
986
  if (is_array(value)) return "an array";
881
987
  if (is_object(value)) return "an object";
882
988
  if (is_string(value)) return REFUSED_TEXT;
883
- if (typeof value === "number") return Number.isInteger(value) ? "an integer" : "a real";
989
+ if (typeof value === "number") return Number.isInteger(value) && Math.abs(value) <= 0x8000000000000000 ? "an integer" : "a real";
884
990
  if (typeof value === "boolean") return "a boolean";
885
991
  return "null";
886
992
  }
@@ -901,7 +1007,7 @@
901
1007
  value: value ? 1 : 0,
902
1008
  refused: null
903
1009
  };
904
- if (!(value >= -0x8000000000000000 && value < 0x8000000000000000)) return {
1010
+ if (!(value >= -0x8000000000000000 && value <= 0x8000000000000000)) return {
905
1011
  value: void 0,
906
1012
  refused: "a number out of its range"
907
1013
  };
@@ -972,16 +1078,8 @@
972
1078
  };
973
1079
  }
974
1080
  if (DTP_IS_DICT(type) || DTP_IS_LIST(type)) {
975
- let jn;
976
- try {
977
- jn = JSON.parse(s);
978
- } catch (e) {
979
- return {
980
- value: void 0,
981
- refused: REFUSED_TEXT
982
- };
983
- }
984
- if (!value_has_shape(type, jn)) return {
1081
+ const jn = parse_json_text_as_c(s);
1082
+ if (jn === void 0 || !value_has_shape(type, jn)) return {
985
1083
  value: void 0,
986
1084
  refused: REFUSED_TEXT
987
1085
  };
@@ -990,12 +1088,12 @@
990
1088
  refused: null
991
1089
  };
992
1090
  }
993
- if (DTP_IS_JSON(type)) try {
994
- return {
995
- value: JSON.parse(s),
1091
+ if (DTP_IS_JSON(type)) {
1092
+ const jn = parse_json_text_as_c(s);
1093
+ if (jn !== void 0) return {
1094
+ value: jn,
996
1095
  refused: null
997
1096
  };
998
- } catch (e) {
999
1097
  const t = s.replace(/^[ \t]+/, "");
1000
1098
  if (t.startsWith("{") || t.startsWith("[") || t.startsWith("\"")) return {
1001
1099
  value: void 0,
@@ -1070,6 +1168,10 @@
1070
1168
  refused: shape_of_value(value)
1071
1169
  };
1072
1170
  if (DTP_IS_NUMBER(type)) return number_as_type(type, value);
1171
+ if (!is_json_value(value)) return {
1172
+ value: void 0,
1173
+ refused: NO_JSON_TEXT
1174
+ };
1073
1175
  return {
1074
1176
  value,
1075
1177
  refused: null
@@ -1088,8 +1190,44 @@
1088
1190
  data_type_t.DTP_LIST,
1089
1191
  data_type_t.DTP_DICT
1090
1192
  ];
1193
+ var LEAVE_NODE = Symbol("leave");
1194
+ function is_json_value(value) {
1195
+ const on_path = /* @__PURE__ */ new Set();
1196
+ const stack = [value];
1197
+ while (stack.length) {
1198
+ const v = stack.pop();
1199
+ if (v === LEAVE_NODE) {
1200
+ on_path.delete(stack.pop());
1201
+ continue;
1202
+ }
1203
+ if (typeof v === "bigint") return false;
1204
+ if (v === null || typeof v !== "object") continue;
1205
+ if (on_path.has(v)) return false;
1206
+ const array = Array.isArray(v);
1207
+ if (!array) {
1208
+ const proto = Object.getPrototypeOf(v);
1209
+ if (proto !== Object.prototype && proto !== null) return false;
1210
+ }
1211
+ on_path.add(v);
1212
+ stack.push(v, LEAVE_NODE);
1213
+ if (array) for (let i = 0; i < v.length; i++) stack.push(v[i]);
1214
+ else for (const key of Object.keys(v)) stack.push(v[key]);
1215
+ }
1216
+ return true;
1217
+ }
1218
+ var NO_JSON_TEXT = "a value with no json text";
1219
+ function json_text_of(value) {
1220
+ if (!is_json_value(value)) return;
1221
+ try {
1222
+ const s = JSON.stringify(value);
1223
+ return is_string(s) ? s : void 0;
1224
+ } catch (e) {
1225
+ return;
1226
+ }
1227
+ }
1091
1228
  function log_attr_value_refused(gobj, it, value, refused) {
1092
1229
  const types = {
1230
+ [data_type_t.DTP_STRING]: "a string",
1093
1231
  [data_type_t.DTP_BOOLEAN]: "a boolean",
1094
1232
  [data_type_t.DTP_INTEGER]: "an integer",
1095
1233
  [data_type_t.DTP_REAL]: "a real",
@@ -1099,7 +1237,8 @@
1099
1237
  let shown;
1100
1238
  if (it.flag & sdata_flag_t.SDF_SECRET) shown = "********";
1101
1239
  else {
1102
- shown = is_string(value) ? value : String(JSON.stringify(value === void 0 ? null : value));
1240
+ shown = is_string(value) ? value : json_text_of(value === void 0 ? null : value);
1241
+ if (shown === void 0) shown = `<${NO_JSON_TEXT}>`;
1103
1242
  const masked = mask_secrets_inline(shown);
1104
1243
  if (masked !== null) shown = masked;
1105
1244
  if (shown.length > ATTR_VALUE_SHOWN) {
@@ -1121,8 +1260,11 @@
1121
1260
  if (jn_value_ === null || jn_value_ === void 0) jn_value2 = "";
1122
1261
  else if (is_string(jn_value_)) jn_value2 = String(jn_value_);
1123
1262
  else {
1124
- let s = JSON.stringify(jn_value_);
1125
- if (s) jn_value2 = String(s);
1263
+ jn_value2 = json_text_of(jn_value_);
1264
+ if (jn_value2 === void 0) {
1265
+ log_attr_value_refused(gobj, it, jn_value_, NO_JSON_TEXT);
1266
+ return -1;
1267
+ }
1126
1268
  }
1127
1269
  break;
1128
1270
  case data_type_t.DTP_BOOLEAN:
@@ -2570,15 +2712,20 @@
2570
2712
  * The value a typed writer writes, read as ITS type by the grammar of
2571
2713
  * json2item() (a C writer takes its C type: a string is never read as a
2572
2714
  * number there). Return {value} or {refused} (logged): the attr keeps its
2573
- * value. A string writer never refuses: null and undefined are "", any
2574
- * other json its text, as a DTP_STRING attr reads them.
2715
+ * value. A string writer takes null and undefined as "", any other json
2716
+ * as its text, as a DTP_STRING attr reads them; it refuses only a value
2717
+ * with no json text (circular, a BigInt).
2575
2718
  ***************************************************************************/
2576
2719
  function typed_writer_value(gobj, name, type, value) {
2720
+ let r;
2577
2721
  if (DTP_IS_STRING(type)) {
2578
2722
  if (value === null || value === void 0) return { value: "" };
2579
- return { value: is_string(value) ? value : String(JSON.stringify(value)) };
2580
- }
2581
- const r = command_parameter_from_json(type, value);
2723
+ if (is_string(value)) return { value };
2724
+ r = {
2725
+ value: json_text_of(value),
2726
+ refused: NO_JSON_TEXT
2727
+ };
2728
+ } else r = command_parameter_from_json(type, value);
2582
2729
  if (r.value === void 0) {
2583
2730
  let holder = gobj;
2584
2731
  while (holder && !gobj_has_attr(holder, name)) holder = holder.bottom_gobj;
@@ -3023,9 +3170,9 @@
3023
3170
  }
3024
3171
  }
3025
3172
  const frame = push_dispatch_frame(dst, event, frame_kind_t.FRAME_ACTION);
3026
- if (event_action.next_state) gobj_change_state(dst, event_action.next_state);
3027
3173
  let ret = -1;
3028
3174
  try {
3175
+ if (event_action.next_state) gobj_change_state(dst, event_action.next_state);
3029
3176
  if (event_action.action) ret = event_action.action(dst, event, kw, src);
3030
3177
  } catch (e) {
3031
3178
  __inside__--;
@@ -3049,18 +3196,23 @@
3049
3196
  __own_event__: 4
3050
3197
  });
3051
3198
  /***************************************************************************
3052
- * The event type of `event_name` in any registered gclass, null if none.
3053
- * The C kernel's gobj_find_event_type(): any case, gclasses only.
3199
+ * The event type of `event_name` in any registered gclass whose flags
3200
+ * hold one of `event_flag` (0: any), null if none. The C kernel's
3201
+ * gobj_find_event_type(): any case, gclasses only. With `verbose` a miss
3202
+ * is logged, with the name as it was given: never verbose for a name
3203
+ * that came from a peer.
3054
3204
  ***************************************************************************/
3055
- function _find_event_type_in_gclasses(event_name) {
3205
+ function gobj_find_event_type(event_name, event_flag, verbose) {
3056
3206
  let lower = String(event_name).toLowerCase();
3057
3207
  for (let gclass_name in _gclass_register) {
3058
3208
  let dl = _gclass_register[gclass_name].dl_events;
3059
3209
  for (let i = 0; i < dl.length; i++) {
3060
3210
  let event_type = dl[i];
3211
+ if (event_flag && !(event_type.event_flag & event_flag)) continue;
3061
3212
  if (event_type.event_name && event_type.event_name.toLowerCase() === lower) return event_type;
3062
3213
  }
3063
3214
  }
3215
+ if (verbose) log_error(`EVENT NOT FOUND: ${event_name}`);
3064
3216
  return null;
3065
3217
  }
3066
3218
  var subscription_desc = [
@@ -3097,7 +3249,7 @@
3097
3249
  json_object_set_new(subs, "__config__", kw_clone);
3098
3250
  let renamed_event = kw_get_str(publisher, kw_clone, "__rename_event_name__", "");
3099
3251
  if (!empty_string(renamed_event)) {
3100
- let event_type = _find_event_type_in_gclasses(renamed_event);
3252
+ let event_type = gobj_find_event_type(renamed_event, 0, false);
3101
3253
  if (event_type) {
3102
3254
  json_object_set_new(subs, "renamed_event", event_type.event_name);
3103
3255
  delete kw_clone.__rename_event_name__;
@@ -3158,7 +3310,7 @@
3158
3310
  kw_match.__config__ = config_match;
3159
3311
  let renamed_event = "";
3160
3312
  let rename = config_match.__rename_event_name__;
3161
- let event_type = typeof rename === "string" && !empty_string(rename) ? _find_event_type_in_gclasses(rename) : null;
3313
+ let event_type = typeof rename === "string" && !empty_string(rename) ? gobj_find_event_type(rename, 0, false) : null;
3162
3314
  if (event_type) {
3163
3315
  renamed_event = event_type.event_name;
3164
3316
  delete config_match.__rename_event_name__;
@@ -4024,6 +4176,35 @@
4024
4176
  }
4025
4177
  return secret_name_check(str, i, to, true, by_segments);
4026
4178
  }
4179
+ function param_name_tail_from(str, from, to) {
4180
+ let bytes = 0;
4181
+ let i = to;
4182
+ while (i > from) {
4183
+ const code = str.charCodeAt(i - 1);
4184
+ let n = 3;
4185
+ let units = 1;
4186
+ if (code < 128) n = 1;
4187
+ else if (code < 2048) n = 2;
4188
+ else if (code >= 56320 && code <= 57343 && i - 2 >= from) {
4189
+ const high = str.charCodeAt(i - 2);
4190
+ if (high >= 55296 && high <= 56319) {
4191
+ n = 4;
4192
+ units = 2;
4193
+ }
4194
+ }
4195
+ if (bytes + n > MASK_MAX_NAME) return -1;
4196
+ if (code === 38 || code === 63 || code === 59) return i;
4197
+ bytes += n;
4198
+ i -= units;
4199
+ }
4200
+ return -1;
4201
+ }
4202
+ function is_param_name_secret(str, from, to, names) {
4203
+ const tail = names === NAMES_NOW ? param_name_tail_from(str, from, to) : -1;
4204
+ if (tail < 0) return is_secret_name_tail(str, from, to, names);
4205
+ if (is_secret_name_tail(str, from, to, NAMES_7_26_9)) return true;
4206
+ return is_secret_name_tail(str, from, to, NAMES_NOW) && secret_name_check(str, tail, to, false, true);
4207
+ }
4027
4208
  /************************************************************
4028
4209
  * Where an unquoted secret value that begins at `p` ends: at
4029
4210
  * the end, at the quote that closes an outer quoted value, or
@@ -4321,13 +4502,14 @@
4321
4502
  }
4322
4503
  const name_from = word;
4323
4504
  word = p + 1;
4324
- const secret = is_secret_name_tail(str, name_from, p, names);
4325
- if (secret && names === NAMES_NOW && !is_secret_name_tail(str, name_from, p, NAMES_7_26_9)) not_7_26_9 = true;
4505
+ const secret = is_param_name_secret(str, name_from, p, names);
4506
+ if (secret && names === NAMES_NOW && !not_7_26_9 && !is_secret_name_tail(str, name_from, p, NAMES_7_26_9)) not_7_26_9 = true;
4326
4507
  if (!(secret || value_is_secret && p - name_from === 5 && ascii_case_equal(str, name_from, "value"))) {
4327
- if (judged && query_name_from(str, p) === name_from) judged[p] = 1;
4508
+ if (judged && query_name_from(str, p) === name_from) judged[p] = JUDGED_NOT_SECRET;
4328
4509
  p++;
4329
4510
  continue;
4330
4511
  }
4512
+ if (judged && secret && query_name_from(str, p) === name_from) judged[p] = JUDGED_SECRET;
4331
4513
  p++;
4332
4514
  let end;
4333
4515
  const quote = p < str.length && (str[p] === "\"" || str[p] === "'") ? str[p] : "";
@@ -4390,23 +4572,99 @@
4390
4572
  while (n > 0 && eq - n < MASK_MAX_NAME && is_name_char_code(str.charCodeAt(n - 1))) n--;
4391
4573
  return n;
4392
4574
  }
4575
+ var JUDGED_NOT_SECRET = 1;
4576
+ var JUDGED_SECRET = 2;
4577
+ function hex_digit_value(code) {
4578
+ if (code >= 48 && code <= 57) return code - 48;
4579
+ if (code >= 97 && code <= 102) return code - 87;
4580
+ if (code >= 65 && code <= 70) return code - 55;
4581
+ return -1;
4582
+ }
4583
+ function is_written_name_bracket_code(code) {
4584
+ return code === 91 || code === 93 || code === 39 || code === 34;
4585
+ }
4586
+ function is_written_name_code(code) {
4587
+ return is_name_char_code(code) || code === 37 || is_written_name_bracket_code(code);
4588
+ }
4589
+ function written_name_is_secret(str, eq) {
4590
+ let n = eq;
4591
+ let plain = -1;
4592
+ while (n > 0 && eq - n < MASK_MAX_NAME && is_written_name_code(str.charCodeAt(n - 1))) {
4593
+ n--;
4594
+ if (plain < 0 && !is_name_char_code(str.charCodeAt(n))) plain = n + 1;
4595
+ }
4596
+ if (plain < 0) return false;
4597
+ const to = str.charCodeAt(plain - 1) === 37 ? eq : plain - 1;
4598
+ let encoded = false;
4599
+ for (let s = n; s < to && !encoded; s++) encoded = str.charCodeAt(s) === 37;
4600
+ let name = str;
4601
+ let from = n;
4602
+ let end = to;
4603
+ if (encoded) {
4604
+ name = "";
4605
+ for (let s = n; s < to; s++) {
4606
+ const hi = str.charCodeAt(s) === 37 && to - s > 2 ? hex_digit_value(str.charCodeAt(s + 1)) : -1;
4607
+ const lo = hi >= 0 ? hex_digit_value(str.charCodeAt(s + 2)) : -1;
4608
+ if (lo >= 0) {
4609
+ name += String.fromCharCode(hi * 16 + lo);
4610
+ s += 2;
4611
+ } else name += str[s];
4612
+ }
4613
+ from = 0;
4614
+ end = name.length;
4615
+ }
4616
+ let seg = from;
4617
+ for (let i = from; i <= end; i++) {
4618
+ if (i < end && !is_written_name_bracket_code(name.charCodeAt(i))) continue;
4619
+ if (i - seg >= 3 && secret_name_check(name, seg, i, true, true)) return true;
4620
+ seg = i + 1;
4621
+ }
4622
+ return false;
4623
+ }
4624
+ function mark_query_value(str, eq, marks) {
4625
+ const v = eq + 1;
4626
+ if (v < str.length && (str[v] === "\"" || str[v] === "'")) return mark_run(str, v + 1, QUOTE_STOPS[str[v]], marks);
4627
+ mark_scheme_value(str, v, PARAM_VALUE_STOPS, marks);
4628
+ return mark_run(str, v, PARAM_VALUE_STOPS, marks);
4629
+ }
4630
+ var WRITTEN_NAME_MARKS = /[[\]%'"]/;
4393
4631
  function mark_query_params(str, marks, judged) {
4394
4632
  let frontier = 0;
4395
- for (let p = 1; p < str.length; p++) {
4396
- if (p < frontier) {
4397
- p = frontier - 1;
4398
- continue;
4399
- }
4400
- if (str.charCodeAt(p) !== 61) continue;
4401
- if (judged[p]) continue;
4402
- const n = query_name_from(str, p);
4403
- if (n === p || !secret_name_check(str, n, p, true, true)) continue;
4404
- const v = p + 1;
4405
- if (v < str.length && (str[v] === "\"" || str[v] === "'")) frontier = mark_run(str, v + 1, QUOTE_STOPS[str[v]], marks);
4406
- else {
4407
- mark_scheme_value(str, v, PARAM_VALUE_STOPS, marks);
4408
- frontier = mark_run(str, v, PARAM_VALUE_STOPS, marks);
4633
+ let frontier_written = WRITTEN_NAME_MARKS.test(str) ? 0 : str.length;
4634
+ let p = str.indexOf("=", 1);
4635
+ while (p > 0) {
4636
+ if (p >= frontier) {
4637
+ let secret = judged[p] === JUDGED_SECRET;
4638
+ if (!judged[p]) {
4639
+ const n = query_name_from(str, p);
4640
+ secret = n < p && secret_name_check(str, n, p, true, true);
4641
+ }
4642
+ if (secret) frontier = mark_query_value(str, p, marks);
4643
+ }
4644
+ if (p >= frontier_written && written_name_is_secret(str, p)) frontier_written = mark_query_value(str, p, marks);
4645
+ p = str.indexOf("=", p + 1);
4646
+ }
4647
+ }
4648
+ var URL_AUTHORITY_STOPS = stop_table("/?#\"'<> ");
4649
+ function mark_url_passwords(str, marks) {
4650
+ let p = str.indexOf("://", 1);
4651
+ while (p > 0) {
4652
+ let next = p + 1;
4653
+ if (is_ascii_alnum_code(str.charCodeAt(p - 1))) {
4654
+ let colon = -1;
4655
+ let at = -1;
4656
+ let e = p + 3;
4657
+ while (e < str.length) {
4658
+ const code = str.charCodeAt(e);
4659
+ if (code < 128 && URL_AUTHORITY_STOPS[code]) break;
4660
+ if (code === 64) at = e;
4661
+ else if (code === 58 && colon < 0) colon = e;
4662
+ e++;
4663
+ }
4664
+ if (colon >= 0 && at > colon) mark_range(marks, colon + 1, at);
4665
+ next = e - 1;
4409
4666
  }
4667
+ p = str.indexOf("://", next);
4410
4668
  }
4411
4669
  }
4412
4670
  function mark_shapes(str, marks) {
@@ -4431,7 +4689,7 @@
4431
4689
  p++;
4432
4690
  continue;
4433
4691
  }
4434
- if (!is_secret_name_tail(str, word, p, NAMES_NOW)) {
4692
+ if (!is_param_name_secret(str, word, p, NAMES_NOW)) {
4435
4693
  p++;
4436
4694
  word = p;
4437
4695
  continue;
@@ -4460,6 +4718,50 @@
4460
4718
  }
4461
4719
  return false;
4462
4720
  }
4721
+ function mark_inline_rules_of_now(str, marks) {
4722
+ const value_is_secret = inline_value_is_secret(str, NAMES_NOW);
4723
+ const judged = new Uint8Array(str.length);
4724
+ mark_params(str, value_is_secret, READ_NOW, marks, judged);
4725
+ mark_query_params(str, marks, judged);
4726
+ mark_url_passwords(str, marks);
4727
+ mark_shapes(str, marks);
4728
+ mark_labels(str, marks);
4729
+ }
4730
+ var MASK_MAX_DECODINGS = 2;
4731
+ function encoded_ascii_at(str, p) {
4732
+ if (p + 3 > str.length || str.charCodeAt(p) !== 37) return -1;
4733
+ const hi = hex_digit_value(str.charCodeAt(p + 1));
4734
+ const lo = hi >= 0 ? hex_digit_value(str.charCodeAt(p + 2)) : -1;
4735
+ if (lo < 0) return -1;
4736
+ const c = hi * 16 + lo;
4737
+ return c > 0 && c < 128 ? c : -1;
4738
+ }
4739
+ function mark_decoded_view(str, marks, decodings) {
4740
+ if (decodings >= MASK_MAX_DECODINGS) return;
4741
+ const pieces = [];
4742
+ let last = 0;
4743
+ let p = str.indexOf("%");
4744
+ while (p >= 0) {
4745
+ const c = encoded_ascii_at(str, p);
4746
+ if (c >= 0) {
4747
+ pieces.push(str.substring(last, p), String.fromCharCode(c));
4748
+ last = p + 3;
4749
+ p = str.indexOf("%", last);
4750
+ } else p = str.indexOf("%", p + 1);
4751
+ }
4752
+ if (pieces.length === 0) return;
4753
+ pieces.push(str.substring(last));
4754
+ const view = pieces.join("");
4755
+ const view_marks = new Uint8Array(view.length);
4756
+ mark_inline_rules_of_now(view, view_marks);
4757
+ mark_decoded_view(view, view_marks, decodings + 1);
4758
+ let q = 0;
4759
+ for (let i = 0; i < view.length; i++) {
4760
+ const n = encoded_ascii_at(str, q) >= 0 ? 3 : 1;
4761
+ if (view_marks[i]) mark_range(marks, q, q + n);
4762
+ q += n;
4763
+ }
4764
+ }
4463
4765
  function mark_inline_secrets(str, marks) {
4464
4766
  const value_is_secret = inline_value_is_secret(str, NAMES_NOW);
4465
4767
  const value_is_secret_7_26_9 = inline_value_is_secret(str, NAMES_7_26_9);
@@ -4467,8 +4769,10 @@
4467
4769
  if (mark_params(str, value_is_secret, READ_NOW, marks, judged) || value_is_secret !== value_is_secret_7_26_9) mark_params(str, value_is_secret_7_26_9, READ_AS_7_26_9, marks, null);
4468
4770
  if (has_shape_js_7_26_20(str)) mark_params(str, value_is_secret, READ_AS_GOBJ_JS_7_26_20, marks, null);
4469
4771
  mark_query_params(str, marks, judged);
4772
+ mark_url_passwords(str, marks);
4470
4773
  mark_shapes(str, marks);
4471
4774
  mark_labels(str, marks);
4775
+ mark_decoded_view(str, marks, 0);
4472
4776
  }
4473
4777
  /************************************************************
4474
4778
  * A text (a command line) with the secrets that can be told
@@ -4480,13 +4784,14 @@
4480
4784
  * same for a "name: value", its name in quotes or not (a json, a
4481
4785
  * header, a label: "password": x, Authorization: Basic x, bearer:
4482
4786
  * tok); and a JWT or the credential after "Bearer " or "Basic ",
4483
- * wherever they are, whatever names them. Each rule judges the text
4484
- * as it came. Return null when there was nothing to mask. As the C
4485
- * kernel's mask_secrets_inline().
4787
+ * wherever they are, whatever names them; in a URL or a query
4788
+ * %-encoded inside a value, the same read decoded (mark_decoded_view()).
4789
+ * Each rule judges the text as it came. Return null when there was
4790
+ * nothing to mask. As the C kernel's mask_secrets_inline().
4486
4791
  ************************************************************/
4487
4792
  function mask_secrets_inline(str) {
4488
4793
  if (typeof str !== "string") return null;
4489
- if (str.indexOf("=") < 0 && str.indexOf(":") < 0 && str.indexOf("eyJ") < 0 && !/bearer|basic/i.test(str)) return null;
4794
+ if (str.indexOf("=") < 0 && str.indexOf(":") < 0 && str.indexOf("%") < 0 && str.indexOf("eyJ") < 0 && !/bearer|basic/i.test(str)) return null;
4490
4795
  if (str.length > MASK_MAX_BYTES) return MASK_TOO_LARGE;
4491
4796
  const marks = new Uint8Array(str.length);
4492
4797
  mark_inline_secrets(str, marks);
@@ -8249,7 +8554,8 @@
8249
8554
  inform_on_close: false,
8250
8555
  websocket: null,
8251
8556
  inside_on_open: false,
8252
- retry_ms: 0
8557
+ retry_ms: 0,
8558
+ retry_ms_before_session: 0
8253
8559
  };
8254
8560
  var __gclass__ = null;
8255
8561
  /******************************
@@ -8300,6 +8606,7 @@
8300
8606
  function mt_start(gobj) {
8301
8607
  let priv = gobj.priv;
8302
8608
  priv.retry_ms = 0;
8609
+ priv.retry_ms_before_session = 0;
8303
8610
  if (gobj_current_state(gobj) !== "ST_DISCONNECTED") {
8304
8611
  gobj_send_event(gobj, "EV_ON_CLOSE", {
8305
8612
  url: priv.url,
@@ -8499,13 +8806,33 @@
8499
8806
  }
8500
8807
  }
8501
8808
  /***************************************************************
8809
+ * Close the channel for a fault of the server: a message for a role
8810
+ * or a yuno that is not this one, an event out of its place.
8811
+ *
8812
+ * Not with 1000: EV_ON_CLOSE would say the session ended well. A
8813
+ * browser closes a WebSocket only with 1000 or 3000-4999 (1002, the
8814
+ * protocol error, throws there), so it is 4002 -- and the server
8815
+ * echoes it, so EV_ON_CLOSE carries it.
8816
+ *
8817
+ * And a session the server broke was not a session reached: the
8818
+ * backoff the ack reset is put back, or a server that breaks every
8819
+ * session is reconnected at the first delay for ever, with an
8820
+ * EV_ON_OPEN and an EV_ON_CLOSE in the app per round.
8821
+ ***************************************************************/
8822
+ var CLOSE_PEER_FAULT = 4002;
8823
+ function close_for_peer_fault(gobj, reason) {
8824
+ let priv = gobj.priv;
8825
+ if (gobj_current_state(gobj) === "ST_SESSION") priv.retry_ms = priv.retry_ms_before_session;
8826
+ close_websocket(gobj, CLOSE_PEER_FAULT, reason);
8827
+ }
8828
+ /***************************************************************
8502
8829
  * A text of the server -- a frame, the name of an event, of a
8503
8830
  * service, of a role -- as a log shows it: masked, then capped on a
8504
8831
  * whole character (capped first, a credential the cap cut would
8505
8832
  * show its first characters). As the C kernel shows the name of an
8506
8833
  * event that is not public (mask_secrets_inline_capped()).
8507
8834
  ***************************************************************/
8508
- var PEER_NAME_SHOWN = 64;
8835
+ var PEER_NAME_SHOWN = 128;
8509
8836
  var PEER_FRAME_SHOWN = 256;
8510
8837
  function peer_text_shown(text, max) {
8511
8838
  let s = String(text);
@@ -8728,7 +9055,8 @@
8728
9055
  let url = kw.url;
8729
9056
  if (kw.ws_seq !== void 0 && kw.ws_seq !== priv.ws_seq) return 0;
8730
9057
  set_remote_log_functions();
8731
- if (is_traffic_tracing(gobj)) trace_msg(`${gobj_short_name(gobj)}: WebSocket closed ${url} (Code: ${kw.code}, Reason: "${peer_text_shown(kw.reason, PEER_FRAME_SHOWN)}", Clean: ${kw.was_clean})`);
9058
+ const reason_shown = peer_text_shown(kw.reason === void 0 ? "" : kw.reason, PEER_FRAME_SHOWN);
9059
+ if (is_traffic_tracing(gobj)) trace_msg(`${gobj_short_name(gobj)}: WebSocket closed ${url} (Code: ${kw.code}, Reason: "${reason_shown}", Clean: ${kw.was_clean})`);
8732
9060
  if (priv.websocket) {
8733
9061
  priv.websocket.onopen = null;
8734
9062
  priv.websocket.onmessage = null;
@@ -8738,21 +9066,25 @@
8738
9066
  }
8739
9067
  if (priv.inform_on_close) {
8740
9068
  priv.inform_on_close = false;
9069
+ if ((!kw.was_clean || kw.code !== 1e3 && kw.code !== 1001) && gobj_is_running(gobj)) log_warning(`${gobj_short_name(gobj)}: session closed ${url} (Code: ${kw.code}, Reason: "${reason_shown}", Clean: ${kw.was_clean})`);
8741
9070
  gobj_publish_event(gobj, "EV_ON_CLOSE", {
8742
9071
  url,
8743
9072
  remote_yuno_name: priv.remote_yuno_name,
8744
9073
  remote_yuno_role: priv.remote_yuno_role,
8745
- remote_yuno_service: priv.remote_yuno_service
9074
+ remote_yuno_service: priv.remote_yuno_service,
9075
+ code: kw.code,
9076
+ reason: reason_shown,
9077
+ was_clean: kw.was_clean
8746
9078
  });
8747
9079
  } else if (!gobj_is_running(gobj)) {} else {
8748
- log_warning(`${gobj_short_name(gobj)}: EV_ON_OPEN_ERROR cannot open ${url} (Code: ${kw.code}, Reason: "${peer_text_shown(kw.reason, PEER_FRAME_SHOWN)}", Clean: ${kw.was_clean})`);
9080
+ log_warning(`${gobj_short_name(gobj)}: EV_ON_OPEN_ERROR cannot open ${url} (Code: ${kw.code}, Reason: "${reason_shown}", Clean: ${kw.was_clean})`);
8749
9081
  gobj_publish_event(gobj, "EV_ON_OPEN_ERROR", {
8750
9082
  url,
8751
9083
  remote_yuno_name: priv.remote_yuno_name,
8752
9084
  remote_yuno_role: priv.remote_yuno_role,
8753
9085
  remote_yuno_service: priv.remote_yuno_service,
8754
9086
  code: kw.code,
8755
- reason: kw.reason,
9087
+ reason: reason_shown,
8756
9088
  was_clean: kw.was_clean
8757
9089
  });
8758
9090
  }
@@ -8775,7 +9107,8 @@
8775
9107
  *
8776
9108
  * Reset to zero when a session is actually reached
8777
9109
  * (ac_identity_card_ack), so a link that flaps once does not carry a
8778
- * minute-long penalty into its next real drop.
9110
+ * minute-long penalty into its next real drop -- and put back when the
9111
+ * server breaks that session (close_for_peer_fault()).
8779
9112
  ***************************************************************/
8780
9113
  function next_retry(gobj) {
8781
9114
  let priv = gobj.priv;
@@ -8825,6 +9158,7 @@
8825
9158
  } else {
8826
9159
  gobj_change_state(gobj, "ST_SESSION");
8827
9160
  priv.inside_on_open = true;
9161
+ priv.retry_ms_before_session = priv.retry_ms;
8828
9162
  priv.retry_ms = 0;
8829
9163
  if (!priv.inform_on_close) {
8830
9164
  priv.inform_on_close = true;
@@ -8861,19 +9195,26 @@
8861
9195
  let iev_event = iev_msg.event;
8862
9196
  let iev_kw = iev_msg.kw;
8863
9197
  if (gobj_current_state(gobj) !== "ST_SESSION") {
8864
- if (gobj_has_event(gobj, iev_event, event_flag_t.EVF_PUBLIC_EVENT)) {
8865
- if (!(gobj_send_event(gobj, iev_event, iev_kw, gobj) < 0)) return 0;
8866
- } else log_error(`${gobj_short_name(gobj)}: event UNKNOWN in not-session state ${peer_text_shown(iev_event, PEER_NAME_SHOWN)}`);
8867
- close_websocket(gobj);
9198
+ if (String(iev_event).toLowerCase() === "ev_identity_card_ack") {
9199
+ if (!(gobj_send_event(gobj, "EV_IDENTITY_CARD_ACK", iev_kw, gobj) < 0)) return 0;
9200
+ } else log_warning(`${gobj_short_name(gobj)}: event UNKNOWN in not-session state ${peer_text_shown(iev_event, PEER_NAME_SHOWN)}`);
9201
+ close_for_peer_fault(gobj, "event out of session");
8868
9202
  return -1;
8869
9203
  }
8870
9204
  iev_msg = null;
8871
9205
  let msg_type = msg_iev_get_msg_type(gobj, iev_kw);
8872
9206
  let event_id = msg_iev_get_stack(gobj, iev_kw, IEVENT_STACK_ID);
8873
9207
  let iev_dst_role = kw_get_str(gobj, event_id, "dst_role", "");
8874
- if (iev_dst_role.toLowerCase() !== gobj_yuno_role().toLowerCase()) {
8875
- log_error(`"It's not my role, dst_role: ${peer_text_shown(iev_dst_role, PEER_NAME_SHOWN)}, my_role: ${gobj_yuno_role()}`);
8876
- return 0;
9208
+ if (!empty_string(iev_dst_role) && iev_dst_role.toLowerCase() !== String(gobj_yuno_role()).toLowerCase()) {
9209
+ log_warning(`${gobj_short_name(gobj)}: It's not my role, dst_role: ${peer_text_shown(iev_dst_role, PEER_NAME_SHOWN)}, my_role: ${gobj_yuno_role()}, event: ${peer_text_shown(iev_event, PEER_NAME_SHOWN)}`);
9210
+ close_for_peer_fault(gobj, "not my role");
9211
+ return -1;
9212
+ }
9213
+ let iev_dst_yuno = kw_get_str(gobj, event_id, "dst_yuno", "");
9214
+ if (!empty_string(iev_dst_yuno) && iev_dst_yuno.toLowerCase() !== String(gobj_yuno_name()).toLowerCase()) {
9215
+ log_warning(`${gobj_short_name(gobj)}: It's not my name, dst_yuno: ${peer_text_shown(iev_dst_yuno, PEER_NAME_SHOWN)}, my_name: ${gobj_yuno_name()}, event: ${peer_text_shown(iev_event, PEER_NAME_SHOWN)}`);
9216
+ close_for_peer_fault(gobj, "not my name");
9217
+ return -1;
8877
9218
  }
8878
9219
  let iev_dst_service = kw_get_str(gobj, event_id, "dst_service", "");
8879
9220
  if (msg_type === "__subscribing__") {
@@ -8884,8 +9225,14 @@
8884
9225
  log_warning(`${gobj_short_name(gobj)}: unsubscription event ignored, I'm client (service: ${peer_text_shown(iev_dst_service, PEER_NAME_SHOWN)}, event: ${peer_text_shown(iev_event, PEER_NAME_SHOWN)})`);
8885
9226
  return -1;
8886
9227
  }
8887
- if (gobj_has_event(gobj, iev_event, event_flag_t.EVF_PUBLIC_EVENT)) {
8888
- gobj_send_event(gobj, iev_event, iev_kw, gobj);
9228
+ const declared = gobj_find_event_type(iev_event, 0, false);
9229
+ if (declared && gobj_has_event(gobj, declared.event_name, 0)) {
9230
+ const own_event = declared.event_name;
9231
+ if (!gobj_has_event(gobj, own_event, event_flag_t.EVF_PUBLIC_EVENT) || own_event === "EV_IDENTITY_CARD_ACK") {
9232
+ log_warning(`${gobj_short_name(gobj)}: event of the transport itself, or out of its place, DROPPED: ev '${peer_text_shown(iev_event, PEER_NAME_SHOWN)}'`);
9233
+ return -1;
9234
+ }
9235
+ gobj_send_event(gobj, own_event, iev_kw, gobj);
8889
9236
  return 0;
8890
9237
  }
8891
9238
  if (!empty_string(iev_dst_service)) {
@@ -8895,13 +9242,18 @@
8895
9242
  return 0;
8896
9243
  }
8897
9244
  if (!gobj_has_event(gobj_service, iev_event, event_flag_t.EVF_PUBLIC_EVENT)) {
8898
- log_error(`${gobj_short_name(gobj)}: Service found but no event or not public, service '${gobj_short_name(gobj_service)}', ev '${peer_text_shown(iev_event, PEER_NAME_SHOWN)}'`);
9245
+ log_warning(`${gobj_short_name(gobj)}: Service found but no event or not public, DROPPED: service '${gobj_short_name(gobj_service)}', ev '${peer_text_shown(iev_event, PEER_NAME_SHOWN)}'`);
8899
9246
  return -1;
8900
9247
  }
8901
9248
  gobj_send_event(gobj_service, iev_event, iev_kw, gobj);
8902
9249
  return 0;
8903
9250
  }
8904
- gobj_publish_event(gobj, iev_event, iev_kw);
9251
+ let event_type = gobj_find_event_type(iev_event, event_flag_t.EVF_PUBLIC_EVENT, false);
9252
+ if (!event_type) {
9253
+ log_warning(`${gobj_short_name(gobj)}: event that no gclass declares public, DROPPED: ev '${peer_text_shown(iev_event, PEER_NAME_SHOWN)}'`);
9254
+ return -1;
9255
+ }
9256
+ gobj_publish_event(gobj, event_type.event_name, iev_kw);
8905
9257
  return 0;
8906
9258
  }
8907
9259
  /***************************************************************************
@@ -9021,7 +9373,7 @@
9021
9373
  __gclass__ = gclass_create(gclass_name, [
9022
9374
  ["EV_ON_MESSAGE", event_flag_t.EVF_OUTPUT_EVENT],
9023
9375
  ["EV_IDENTITY_CARD_ACK", event_flag_t.EVF_PUBLIC_EVENT],
9024
- ["EV_ON_ID_NAK", event_flag_t.EVF_PUBLIC_EVENT | event_flag_t.EVF_OUTPUT_EVENT],
9376
+ ["EV_ON_ID_NAK", event_flag_t.EVF_OUTPUT_EVENT],
9025
9377
  ["EV_MT_STATS", event_flag_t.EVF_PUBLIC_EVENT],
9026
9378
  ["EV_MT_COMMAND", event_flag_t.EVF_PUBLIC_EVENT],
9027
9379
  ["EV_ON_OPEN", event_flag_t.EVF_OUTPUT_EVENT | event_flag_t.EVF_NO_WARN_SUBS],
@@ -9116,6 +9468,7 @@
9116
9468
  exports.gobj_deliver_posted_events = gobj_deliver_posted_events;
9117
9469
  exports.gobj_destroy = gobj_destroy;
9118
9470
  exports.gobj_find_child = gobj_find_child;
9471
+ exports.gobj_find_event_type = gobj_find_event_type;
9119
9472
  exports.gobj_find_gobj = gobj_find_gobj;
9120
9473
  exports.gobj_find_service = gobj_find_service;
9121
9474
  exports.gobj_find_subscribings = gobj_find_subscribings;