const REPLY_ADDRESS_TYPE_NOT_SUPPORTED = 0x08; const REPLY_UNASSIGNED = 0xff;
162722
function getHostType(host) {
  if (net.isIPv4(host)) {
    return ATYP_V4;
  }
  if (net.isIPv6(host)) {
    return ATYP_V6;
  }
  return ATYP_DOMAIN;
}
1340261
function (inputModel, iElem, customFunc) {

            var errMsg = customFunc(inputModel);
            var tf = !errMsg;

            return sendError(iElem, tf, errMsg);
        }
883458
function _handleAddress(tokens) {
    var token,
        isGroup = false,
        state = 'text',
        address,
        addresses = [],
        data = {
            address: [],
            comment: [],
            group: [],
            text: []
        },
        i, len;

    // Filter out <addresses>, (comments) and regular text
    for (i=0, len = tokens.length; i<len; i++) {
        token = tokens[i];

        if (token.type == 'operator') {
            switch(token.value) {
                case '<':
                    state = 'address';
                    break;
                case '(':
                    state = 'comment';
                    break;
                case ':':
                    state = 'group';
                    isGroup = true;
                    break;
                default:
                    state = 'text';
            }
        } else {
            if (token.value) {
                data[state].push(token.value);
            }
        }
    }

    // If there is no text but a comment, replace the two
    if (!data.text.length && data.comment.length) {
        data.text = data.comment;
        data.comment = [];
    }

    if (isGroup) {
        // http://tools.ietf.org/html/rfc2822#appendix-A.1.3
        data.text = data.text.join(' ');
        addresses.push({
            name: data.text,
            group: data.group.length ? parse(data.group.join(',')) : []
        });
    } else {
        // If no address was found, try to detect one from regular text
        if (!data.address.length && data.text.length) {
            for (i = data.text.length - 1; i>=0; i--) {
                if (data.text[i].match(/^[^@\s]+@[^@\s]+$/)) {
                    data.address = data.text.splice(i,1);
                    break;
                }
            }

            var _regexHandler = function(address) {
                if (!data.address.length) {
                    data.address = [address.trim()];
                    return ' ';
                } else {
                    return address;
                }
            };

            // still no address
            if (!data.address.length) {
                for (i = data.text.length - 1; i>=0; i--) {
                    data.text[i] = data.text[i].replace(/\s*\b[^@\s]+@[^@\s]+\b\s*/, _regexHandler).trim();
                    if (data.address.length) {
                        break;
                    }
                }
            }
        }

        // If there's still is no text but a comment exixts, replace the two
        if (!data.text.length && data.comment.length) {
            data.text = data.comment;
            data.comment = [];
        }

        // Keep only the first address occurence, push others to regular text
        if (data.address.length > 1) {
            data.text = data.text.concat(data.address.splice(1));
        }

        // Join values with spaces
        data.text = data.text.join(' ');
        data.address = data.address.join(' ');

        if (!data.address && isGroup) {
            return [];
        } else {
            address = {
                address: data.address || data.text || '',
                name: data.text || data.address || ''
            };

            if (address.address == address.name) {
                if ((address.address || '').match(/@/)) {
                    address.name = '';
                } else {
                    address.address = '';
                }

            }

            addresses.push(address);
        }
    }

    return addresses;
}
808915
function (buffer) {
        var header = new Uint32Array(buffer, 0, 4);
        if (header[0] !== 0x46546C67) {
            this.trigger('error', 'Invalid glTF binary format: Invalid header');
            return;
        }
        if (header[0] < 2) {
            this.trigger('error', 'Only glTF2.0 is supported.');
            return;
        }

        var dataView = new DataView(buffer, 12);

        var json;
        var buffers = [];
        // Read chunks
        for (var i = 0; i < dataView.byteLength;) {
            var chunkLength = dataView.getUint32(i, true);
            i += 4;
            var chunkType = dataView.getUint32(i, true);
            i += 4;

            // json
            if (chunkType === 0x4E4F534A) {
                var arr = new Uint8Array(buffer, i + 12, chunkLength);
                // TODO, for the browser not support TextDecoder.
                var decoder = new TextDecoder();
                var str = decoder.decode(arr);
                try {
                    json = JSON.parse(str);
                }
                catch (e) {
                    this.trigger('error', 'JSON Parse error:' + e.toString());
                    return;
                }
            }
            else if (chunkType === 0x004E4942) {
                buffers.push(buffer.slice(i + 12, i + 12 + chunkLength));
            }

            i += chunkLength;
        }
        if (!json) {
            this.trigger('error', 'Invalid glTF binary format: Can\'t find JSON.');
            return;
        }

        return this.parse(json, buffers);
    }
896857
function encodeInputs(inputs, add_address_to_previous_output_index) {
    //Initialize buffer and offset
    let offset = 0;
    var buffer = Buffer.allocUnsafe(100000);
    //Write number of inputs
    offset += bufferutils.writeVarInt(buffer, inputs.length, offset);

    inputs.forEach((input, index) => {
        //Write reversed hash
        offset += Buffer.from(input.previous_output.hash, 'hex').reverse().copy(buffer, offset);
        //Index
        offset = buffer.writeUInt32LE(input.previous_output.index, offset);
        if (add_address_to_previous_output_index !== undefined) {
            if (index == add_address_to_previous_output_index) {
                let lockregex = /^\[\ ([a-f0-9]+)\ \]\ numequalverify dup\ hash160\ \[ [a-f0-9]+\ \]\ equalverify\ checksig$/gi;
                if (input.previous_output.script && input.previous_output.script.match(lockregex)) {
                    let locktime = lockregex.exec(input.previous_output.script.match(lockregex)[0])[1];
                    offset = writeScriptLockedPayToPubKeyHash(input.previous_output.address, locktime, buffer, offset);
                } else {
                    if (Script.hasAttenuationModel(input.previous_output.script)) {
                        let params = Script.getAttenuationParams(input.previous_output.script);
                        offset = writeAttenuationScript(params.model, (params.hash !== '0000000000000000000000000000000000000000000000000000000000000000') ? params.hash : undefined, (params.index >= 0) ? params.index : undefined, input.previous_output.address, buffer, offset);
                    } else {
                        if (Script.isP2SH(input.previous_output.script)) {
                            let script_buffer = Buffer.from(input.redeem, 'hex');
                            offset += bufferutils.writeVarInt(buffer, script_buffer.length, offset);
                            offset += script_buffer.copy(buffer, offset);
                        } else {
                            if (input.previous_output.script) {
                                let script_buffer = Script.fromASM(input.previous_output.script).toBuffer()
                                offset += bufferutils.writeVarInt(buffer, script_buffer.length, offset);
                                offset += script_buffer.copy(buffer, offset);
                            } else {
                                offset = writeScriptPayToPubKeyHash(input.previous_output.address, buffer, offset);
                            }
                        }
                    }
                }
            } else {
                offset = buffer.writeUInt8(0, offset);
            }
        } else {
            //input script
            let script_buffer = encodeInputScript(input.script);
            offset += bufferutils.writeVarInt(buffer, script_buffer.length, offset);
            offset += script_buffer.copy(buffer, offset);
        }

        offset = buffer.writeUInt32LE(input.sequence, offset);
    });
    return buffer.slice(0, offset);
}
899837
function _utf8ArrayToStr(data) {
    const extraByteMap = [1, 1, 1, 1, 2, 2, 3, 0];
    var count = data.length;
    var str = "";

    for (var index = 0; index < count;) {
        var ch = data[index++];
        if (ch & 0x80) {
            var extra = extraByteMap[(ch >> 3) & 0x07];
            if (!(ch & 0x40) || !extra || ((index + extra) > count))
                return null;

            ch = ch & (0x3F >> extra);
            for (; extra > 0; extra -= 1) {
                var chx = data[index++];
                if ((chx & 0xC0) != 0x80)
                    return null;

                ch = (ch << 6) | (chx & 0x3F);
            }
        }

        str += String.fromCharCode(ch);
    }

    return str;
}
917975
function decoded(err, reply) {
  //console.error('got decoder err %s', err );
  //console.error('got decoder reply %j',reply );
  var res = new Response(this), req, cmd, args;
  if(err) {
    // return decoder errors to the client
    return res.send(err);
  }

  // we should only be handling array request types
  if(!Array.isArray(reply)) {
    return res.send(new Error('bad request, array expected'));
  }else if(!reply.length) {
    return res.send(new Error('bad request, empty array invalid'));
  }

  cmd = reply.shift();

  if(cmd instanceof Buffer) cmd = cmd.toString();

  if(typeof cmd !== 'string') {
    return res.send(new Error('bad request, string command expected'));
  }

  cmd = cmd.toLowerCase();

  // keep track of last command
  this._client.cmd = cmd;

  //console.error('got decoder cmd %s', cmd );
  //console.error('got decoder args %j', reply );

  req = new Request(this, cmd, reply);

  this.emit('command', req, res);
}
875909
function (preserveFormatting, cb) {
    var lines = [];
    fs.createReadStream(HOSTS, 'utf8')
      .pipe(split())
      .pipe(through(function (line) {
        var matches = /^\s*?([^#]+?)\s+([^#]+?)$/.exec(line);
        if (matches && matches.length === 3) {
          // Found a hosts entry
          var ip = matches[1];
          var host = matches[2];
          lines.push([ip, host]);
        } else {
          // Found a comment, blank line, or something else
          if (preserveFormatting) {
            lines.push(line);
          }
        }
      }))
      .on('close', function () {
        cb(null, lines);
      })
      .on('error', cb);
  }
539200
function disallowed(code) {
  return (
    (code >= 0x0001 && code <= 0x0008) ||
    code === 0x000b ||
    (code >= 0x000d && code <= 0x001f) ||
    (code >= 0x007f && code <= 0x009f) ||
    (code >= 0xfdd0 && code <= 0xfdef) ||
    (code & 0xffff) === 0xffff ||
    (code & 0xffff) === 0xfffe
  )
}
77593
function fromCodePoint(cp) {
        return (cp < 0x10000) ? String.fromCharCode(cp) :
            String.fromCharCode(0xD800 + ((cp - 0x10000) >> 10)) +
            String.fromCharCode(0xDC00 + ((cp - 0x10000) & 1023));
    }
362878
function parseError (parser) {
  var string = parseSimpleString(parser)
  if (string !== undefined) {
    if (parser.optionReturnBuffers === true) {
      string = string.toString()
    }
    return new ReplyError(string)
  }
}
1038958
function utf8Substr(str, startInBytes, lengthInBytes) {
	const strBytes = stringToByteArray(str);
	const subStrBytes = [];
	let count = 0;

	for (let i = startInBytes; count < lengthInBytes; i++) {
		subStrBytes.push(strBytes[i]);
		count++;
	}

	return byteArrayToString(subStrBytes);

	// Converts the byte array to a UTF-8 string.
	// From http://stackoverflow.com/questions/1240408/reading-bytes-from-a-javascript-string?lq=1
	function byteArrayToString(byteArray) {
		let str = '';
		for (let i = 0; i < byteArray.length; i++) {
			str += byteArray[i] <= 0x7F ? byteArray[i] === 0x25 ? '%25' : // %
				String.fromCharCode(byteArray[i]) : '%' + byteArray[i].toString(16).toUpperCase();
		}

		return decodeURIComponent(str);
	}
}
520744
private void processReply(ProxyMessage reply)throws SocksException{
      localPort = reply.port;
      /*
       * If the server have assigned same host as it was contacted on
       * it might return an address of all zeros
       */
      if(reply.host.equals("0.0.0.0")){
         localIP = proxy.proxyIP;
         localHost = localIP.getHostName();
      }else{
         localHost = reply.host;
         localIP = reply.ip;
      }
   }
998573
function respondWithCode(res, code, message) {
            /* eslint-disable */
            res._headers = {};
            res._headerNames = {};
            res.statusCode = code;
            /* eslint-enable */
            res.setHeader('Content-Type', 'text/plain; charset=UTF-8');
            res.setHeader('Content-Length', Buffer.byteLength(message));
            res.setHeader('X-Content-Type-Options', 'nosniff');
            res.end(message);
        }
580825
def send_reply_to(address, reply=EMPTY):
    
    _logger.debug("Sending reply %s to %s", reply, address)
    return sockets._sockets.send_reply_to(address, reply)
481252
function (geoTiffData, byteOffset, numOfBytes, isLittleEndian, isSigned) {
                if (numOfBytes <= 0) {
                    throw new ArgumentError(
                        Logger.logMessage(Logger.LEVEL_SEVERE, "GeoTiffReader", "getBytes", "noBytesRequested"));
                } else if (numOfBytes <= 1) {
                    if (isSigned) {
                        return geoTiffData.getInt8(byteOffset, isLittleEndian);
                    }
                    else {
                        return geoTiffData.getUint8(byteOffset, isLittleEndian);
                    }
                } else if (numOfBytes <= 2) {
                    if (isSigned) {
                        return geoTiffData.getInt16(byteOffset, isLittleEndian);
                    }
                    else {
                        return geoTiffData.getUint16(byteOffset, isLittleEndian);
                    }
                } else if (numOfBytes <= 3) {
                    if (isSigned) {
                        return geoTiffData.getInt32(byteOffset, isLittleEndian) >>> 8;
                    }
                    else {
                        return geoTiffData.getUint32(byteOffset, isLittleEndian) >>> 8;
                    }
                } else if (numOfBytes <= 4) {
                    if (isSigned) {
                        return geoTiffData.getInt32(byteOffset, isLittleEndian);
                    }
                    else {
                        return geoTiffData.getUint32(byteOffset, isLittleEndian);
                    }
                } else if (numOfBytes <= 8) {
                    return geoTiffData.getFloat64(byteOffset, isLittleEndian);
                } else {
                    throw new ArgumentError(
                        Logger.logMessage(Logger.LEVEL_SEVERE, "GeoTiffReader", "getBytes", "tooManyBytesRequested"));
                }
            }
545858
function(functions, payload, error) {
		var payloadLength = payload.readUInt32LE(0);
		var identifierEndPosition = 8 + payload.readUInt32LE(4);
		var identifier = payload.slice(8, identifierEndPosition).toString(module.exports.encoding);
		
		var position = identifierEndPosition;
		
		var response = [ new Buffer(1) /* Status code response */ ];
		if(identifier in functions) {
			var args = [];
			for(; position < payloadLength;) {
				var dataType = payload.readUInt8(position++);
				var dataSize = payload.readUInt32LE(position);
				position += 4;
				var value = undefined;
				switch(dataType) {
					case module.exports.EnumDataType.byte:
						value = payload.readInt8(position);
						position++;
						break;
					case module.exports.EnumDataType.ubyte:
						value = payload.readUInt8(position);
						position++;
						break;
					case module.exports.EnumDataType.short:
						value = payload.readInt16LE(position);
						position += 2;
						break;
					case module.exports.EnumDataType.ushort:
						value = payload.readUInt16LE(position);
						position += 2;
						break;
					case module.exports.EnumDataType.int:
						value = payload.readInt32LE(position);
						position += 4;
						break;
					case module.exports.EnumDataType.uint:
						value = payload.readUInt32LE(position);
						position += 4;
						break;
					case module.exports.EnumDataType.float:
						value = payload.readFloatLE(position);
						position += 4;
						break;
					case module.exports.EnumDataType.double:
						value = payload.readDoubleLE(position);
						position += 8;
						break;
					case module.exports.EnumDataType.string:
						var next = position + dataSize;
						value = payload.slice(position, next).toString(module.exports.encoding);
						position = next;
						break;
					case module.exports.EnumDataType.boolean:
						value = payload.readUInt8(position) > 0;
						position++;
						break;
					case module.exports.EnumDataType.undefined:
						value = undefined;
						break;
					case module.exports.EnumDataType.null:
						value = null;
						break;
					default:
						error(new Error('Unsupported data type argument received from client'));
						response[0].writeUInt8(module.exports.EnumNodeResponse.NodeError, 0);
						return response[0]; // Early exit
				}
				
				args.push(value);
			}
	
			var result = functions[identifier].callback.apply(this, args);
			if(result === undefined) {
				// TODO: Will be removed in future versions. This response type is now handled
				// in the "Okay" response as the "undefined" datatype.
				response[0].writeUInt8(module.exports.EnumNodeResponse.NoResult, 0);
			}
			else {
				response[0].writeUInt8(module.exports.EnumNodeResponse.Okay, 0);
				
				var argtype = functions[identifier].responseType;
				
				if(!argtype) {
					if(result === null) {
						argtype = 'null';
					}
					else {
						switch(typeof result) {
							case 'number':
								if(result === (result|0)) {
									argtype = 'int'; // Default to int for normal numbers
								}
								else {
									argtype = 'float'; // float for anything else
								}
								break;
							case 'string':
								argtype = 'string';
								break;
							case 'boolean':
								argtype = 'boolean';
								break;
							case 'undefined':
								argtype = 'undefiend';
								break;
						}
					}
					functions[identifier].responseType = argtype;
				}
				
				var tempBuf = undefined;
				var dataType = module.exports.EnumDataType[argtype];
				if(dataType !== undefined) {
					switch(dataType) {
						case module.exports.EnumDataType.byte:
							tempBuf = new Buffer(1);
							tempBuf.writeInt8(result, 0);
							break;
						case module.exports.EnumDataType.ubyte:
							tempBuf = new Buffer(1);
							tempBuf.writeUInt8(result, 0);
							break;
						case module.exports.EnumDataType.short:
							tempBuf = new Buffer(2);
							tempBuf.writeInt16LE(result, 0);
							break;
						case module.exports.EnumDataType.ushort:
							tempBuf = new Buffer(2);
							tempBuf.writeUInt16LE(result, 0);
							break;
						case module.exports.EnumDataType.int:
							tempBuf = new Buffer(4);
							tempBuf.writeInt32LE(result, 0);
							break;
						case module.exports.EnumDataType.uint:
							tempBuf = new Buffer(4);
							tempBuf.writeUInt32LE(result, 0);
							break;
						case module.exports.EnumDataType.float:
							tempBuf = new Buffer(4);
							tempBuf.writeFloatLE(result, 0);
							break;
						case module.exports.EnumDataType.double:
							tempBuf = new Buffer(8);
							tempBuf.writeDoubleLE(result, 0);
							break;
						case module.exports.EnumDataType.string:
							tempBuf = new Buffer(result);
							break;
						case module.exports.EnumDataType.boolean:
							tempBuf = new Buffer(1);
							tempBuf.writeUInt8(result ? 0x1 : 0x0, 0);
							break;
						case module.exports.EnumDataType.undefined:
						case module.exports.EnumDataType.null:
							tempBuf = new Buffer(0);
							break;
						default:
							error(new Error('Data type' + dataType + ' has gone unhandled by this node implementation'));
							response[0].writeUInt8(module.exports.EnumNodeResponse.NodeError, 0);
							break;
					}
					
					if(dataType < module.exports.EnumDataType._max) {
						var argHeader = new Buffer(5);
						argHeader.writeUInt8(dataType, 0);
						argHeader.writeUInt32LE(tempBuf.length, 1);
						response.push(argHeader);
						response.push(tempBuf);
					}
				}
				else {
					error(new Error('Unsupported data type returned from nodesocket function'));
					response[0].writeUInt8(module.exports.EnumNodeResponse.NodeError, 0);
				}
			}
		}
		else {
			response[0].writeUInt8(module.exports.EnumNodeResponse.InvalidFunction, 0);
		}
	
		return makeBufferPosResponse(Buffer.concat(response), position);
	}