├── Makefile ├── test └── index.js ├── .github └── dependabot.yml ├── package.json ├── .eslintrc.json ├── README.md ├── index.js └── LICENSE /Makefile: -------------------------------------------------------------------------------- 1 | test: 2 | ./node_modules/.bin/mocha --reporter spec 3 | 4 | .PHONY: test 5 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | var should = require('chai').should(), 2 | hepnode = require('../index'), 3 | encode = hepnode.encode, 4 | decode = hepnode.decode; 5 | 6 | describe('#escape', function() { 7 | it('HEP Encoder', function() { 8 | encode('HEP3').should.equal('HEP3').toString("binary"); 9 | }); 10 | 11 | }); 12 | 13 | describe('#unescape', function() { 14 | it('HEP Decoder', function() { 15 | decode(('HEP3').toString("binary")).should.equal('HEP3'); 16 | }); 17 | 18 | }); 19 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "npm" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "weekly" 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hep-js", 3 | "version": "1.0.22", 4 | "description": "HEP3 Library for Node.JS", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "make test" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "http://github.com/sipcapture/hep-js" 12 | }, 13 | "keywords": [ 14 | "hep", 15 | "hep3", 16 | "encapsulation", 17 | "encoder", 18 | "decoder", 19 | "packet", 20 | "pcap", 21 | "homer", 22 | "sipcapture", 23 | "pcapture", 24 | "sip", 25 | "voip", 26 | "logs", 27 | "cdr" 28 | ], 29 | "author": "Lorenzo Mangani (http://sipcapture.org/)", 30 | "license": "GPLv2", 31 | "bugs": { 32 | "url": "https://github.com/sipcapture/hep-js/issues" 33 | }, 34 | "devDependencies": { 35 | "mocha": "~11.6.0", 36 | "chai": "~3.0.0" 37 | }, 38 | "dependencies": { 39 | "binary-parser": "^1.3.2", 40 | "mixin-deep": "^2.0.1" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "parserOptions": { 3 | "ecmaVersion": 5, 4 | "sourceType": "script", 5 | "ecmaFeatures": {} 6 | }, 7 | "rules": { 8 | "constructor-super": 2, 9 | "for-direction": 2, 10 | "getter-return": 2, 11 | "no-async-promise-executor": 2, 12 | "no-case-declarations": 2, 13 | "no-class-assign": 2, 14 | "no-compare-neg-zero": 2, 15 | "no-cond-assign": 2, 16 | "no-const-assign": 2, 17 | "no-debugger": 2, 18 | "no-delete-var": 2, 19 | "no-dupe-args": 2, 20 | "no-dupe-class-members": 2, 21 | "no-dupe-keys": 2, 22 | "no-duplicate-case": 2, 23 | "no-empty": 2, 24 | "no-empty-character-class": 2, 25 | "no-empty-pattern": 2, 26 | "no-ex-assign": 2, 27 | "no-extra-boolean-cast": 2, 28 | "no-extra-semi": 2, 29 | "no-fallthrough": 2, 30 | "no-func-assign": 2, 31 | "no-global-assign": 2, 32 | "no-inner-declarations": 2, 33 | "no-invalid-regexp": 2, 34 | "no-irregular-whitespace": 2, 35 | "no-misleading-character-class": 2, 36 | "no-new-symbol": 2, 37 | "no-obj-calls": 2, 38 | "no-octal": 2, 39 | "no-prototype-builtins": 2, 40 | "no-redeclare": 2, 41 | "no-regex-spaces": 2, 42 | "no-self-assign": 2, 43 | "no-shadow-restricted-names": 2, 44 | "no-sparse-arrays": 2, 45 | "no-this-before-super": 2, 46 | "no-undef": 2, 47 | "no-unexpected-multiline": 2, 48 | "no-unreachable": 2, 49 | "no-unsafe-finally": 2, 50 | "no-unsafe-negation": 2, 51 | "no-unused-labels": 2, 52 | "no-unused-vars": ["error", {"args": "none"}], 53 | "no-useless-catch": 2, 54 | "no-with": 2, 55 | "require-atomic-updates": 2, 56 | "require-yield": 2, 57 | "use-isnan": 2, 58 | "valid-typeof": 2, 59 | "radix": 2 60 | }, 61 | "env": { 62 | "browser": true, 63 | "node": true, 64 | "shared-node-browser": true 65 | } 66 | } 67 | 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Dependency Status](https://david-dm.org/sipcapture/hep-js.svg)](https://david-dm.org/sipcapture/hep-js) 2 | ![npm](https://img.shields.io/npm/dm/hep-js.svg) 3 | 4 | 5 | 6 | # HEP-js 7 | HEP: Javascript/Node implementation of HEP/EEP Encapsulation Protocol 8 | 9 | 10 | This module provides Node with [HEP/EEP](http://hep.sipcapture.org) packet encapsulation and decapsulation capabilities. 11 | 12 | For more information about HEP and SIPCAPTURE Projects, please visit [http://sipcapture.org](http://sipcapture.org) 13 | 14 | ### Install: 15 | ``` 16 | npm install hep-js 17 | ``` 18 | 19 | 20 | ### Example Usage: 21 | ``` 22 | const HEPjs = require('hep-js'); 23 | var hep_encoder = HEPjs.encapsulate(payload,rcinfo); // returns data buffer 24 | var hep_decoder = HEPjs.decapsulate(buffer); // returns JSON Object {payload,rcinfo} 25 | 26 | ``` 27 | 28 | #### Example: payload 29 | ``` 30 | ACK sip:883510000000091@domain.net SIP/2.0 31 | Via: SIP/2.0/UDP 192.168.1.23:5060;rport;branch=z9hG4bK484759904 32 | From: ;tag=412285373 33 | To: ;tag=1d24a28a0bded6c40d31e6db8aab9ac6.4679 34 | Call-ID: 1003554701 35 | CSeq: 20 ACK 36 | Content-Length: 0 37 | ``` 38 | 39 | #### Example: rcinfo 40 | ``` 41 | rcinfo = { type: 'HEP', 42 | version: 3, 43 | payload_type: 'SIP', 44 | captureId: '2001', 45 | capturePass: 'myHep', 46 | ip_family: 2, 47 | time_sec: 1433719443, 48 | time_usec: 979, 49 | protocol: 17, 50 | proto_type: 1, 51 | srcIp: '192.168.100.1', 52 | dstIp: '192.168.1.23', 53 | srcPort: 5060, 54 | dstPort: 5060 55 | } 56 | ``` 57 | 58 | #### Example: Adding vendor extensions 59 | ```js 60 | var HEPjs = require('./index'); 61 | HEPjs.addVendorExtensions({ 62 | 0x0008: { 63 | 0x0080: { 64 | keyName: "conversationId" 65 | }, 66 | 0x0081: { 67 | keyName: "organizationId" 68 | }, 69 | 0x0082: { 70 | keyName: "siteId" 71 | }, 72 | 0x0083: { 73 | keyName: "trunkBaseId" 74 | }, 75 | 0x0084: { 76 | keyName: "edgeId" 77 | }, 78 | 0x0085: { 79 | keyName: "testUInt8", 80 | type: "UInt8" 81 | }, 82 | 0x0086: { 83 | keyName: "testUInt16", 84 | type: "UInt16" 85 | }, 86 | 0x0087: { 87 | keyName: "testUInt32", 88 | type: "UInt32" 89 | } 90 | } 91 | }); 92 | 93 | var hepData = { 94 | "rcinfo": { 95 | "protocolFamily": 2, 96 | "protocol": 6, 97 | "srcIp": "172.26.26.72", 98 | "dstIp": "172.26.21.185", 99 | "srcPort": 64831, 100 | "dstPort": 8060, 101 | "timeSeconds": 1592975786, 102 | "timeUseconds": 669278, 103 | "payloadType": 1, 104 | "captureId": 8, 105 | "organizationId": "3bac7742-243f-4af7-ba39-f4098b941eda", 106 | "edgeId": "268c720e-b939-4484-966d-80a1123e3810", 107 | "conversationId": "", 108 | "siteId": "", 109 | "trunkBaseId": "", 110 | "testUInt8": 5, 111 | "testUInt16": 10, 112 | "testUInt32": 20 113 | }, 114 | "payload": "INVITE sip:BellUser2@172.26.21.185:8060;transport=tls SIP/2.0\r\nTo: \r\nFrom: ;tag=974329\r\ncall-id: 3935064a-294e-44d8-930d-1a87b90515bb\r\nCSeq: 1 INVITE\r\nallow-events: conference, talk, hold\r\nContact: \r\nx-phonesim-proxy-type: primary\r\ncontent-type: application/sdp\r\nx-edge-id: 268c720e-b939-4484-966d-80a1123e3810\r\nx-edge-name: qf-bell\r\nx-test-id: Station2Station\r\nx-test-name: Station to Station Keyword Test\r\nUser-Agent: PolycomSoundPointIP-SPIP_450-UA/4.0.10.0689_000025CC0001\r\nx-phonesim: 1.0.0-534\r\ncontent-length: 567\r\nVia: SIP/2.0/TLS qf-lempel:5060;branch=z9hG4bK416647af6e43448b8fc9c8b804713a0e\r\n\r\nv=0\r\no=- 4056025290 3801964586 IN IP4 172.26.26.72\r\ns= \r\nt=0 0\r\na=group:ANAT 1 2\r\nm=audio 20522 RTP/SAVP 0 8 9 101\r\nc=IN IP4 172.26.26.72\r\na=mid:1\r\na=rtpmap:101 telephone-event/8000\r\na=fmtp:101 0-15\r\na=crypto:1 AES_CM_256_HMAC_SHA1_80 inline:ba6DaKfQLSQQbYNMtL1ng2xCVbJuihEgzeajdEWIHT4qGpfrPwuTMDIasyhSOA\r\na=sendrecv\r\nm=audio 23824 RTP/SAVP 0 8 9 101\r\nc=IN IP6 2620:102:c000:f10:d::6050\r\na=mid:2\r\na=rtpmap:101 telephone-event/8000\r\na=fmtp:101 0-15\r\na=crypto:1 AES_CM_256_HMAC_SHA1_80 inline:ba6DaKfQLSQQbYNMtL1ng2xCVbJuihEgzeajdEWIHT4qGpfrPwuTMDIasyhSOA\r\na=sendrecv\r\n" 115 | }; 116 | 117 | var hepBuf = HEPjs.encapsulate(hepData.payload, hepData.rcinfo); 118 | console.log(JSON.stringify(HEPjs.decapsulate(hepBuf), undefined, 2)); 119 | 120 | // Output: 121 | 122 | // { 123 | // "rcinfo": { 124 | // "protocolFamily": 2, 125 | // "protocol": 6, 126 | // "srcIp": "172.26.26.72", 127 | // "dstIp": "172.26.21.185", 128 | // "srcPort": 64831, 129 | // "dstPort": 8060, 130 | // "timeSeconds": 1592975786, 131 | // "timeUseconds": 669278, 132 | // "payloadType": 1, 133 | // "captureId": 8, 134 | // "hepNodeName": "8", 135 | // "conversationId": "", 136 | // "organizationId": "3bac7742-243f-4af7-ba39-f4098b941eda", 137 | // "siteId": "", 138 | // "trunkBaseId": "", 139 | // "edgeId": "268c720e-b939-4484-966d-80a1123e3810", 140 | // "testUInt8": 5, 141 | // "testUInt16": 10, 142 | // "testUInt32": 20 143 | // }, 144 | // "payload": "INVITE sip:BellUser2@172.26.21.185:8060;transport=tls SIP/2.0\r\nTo: \r\nFrom: ;tag=974329\r\ncall-id: 3935064a-294e-44d8-930d-1a87b90515bb\r\nCSeq: 1 INVITE\r\nallow-events: conference, talk, hold\r\nContact: \r\nx-phonesim-proxy-type: primary\r\ncontent-type: application/sdp\r\nx-edge-id: 268c720e-b939-4484-966d-80a1123e3810\r\nx-edge-name: qf-bell\r\nx-test-id: Station2Station\r\nx-test-name: Station to Station Keyword Test\r\nUser-Agent: PolycomSoundPointIP-SPIP_450-UA/4.0.10.0689_000025CC0001\r\nx-phonesim: 1.0.0-534\r\ncontent-length: 567\r\nVia: SIP/2.0/TLS qf-lempel:5060;branch=z9hG4bK416647af6e43448b8fc9c8b804713a0e\r\n\r\nv=0\r\no=- 4056025290 3801964586 IN IP4 172.26.26.72\r\ns= \r\nt=0 0\r\na=group:ANAT 1 2\r\nm=audio 20522 RTP/SAVP 0 8 9 101\r\nc=IN IP4 172.26.26.72\r\na=mid:1\r\na=rtpmap:101 telephone-event/8000\r\na=fmtp:101 0-15\r\na=crypto:1 AES_CM_256_HMAC_SHA1_80 inline:ba6DaKfQLSQQbYNMtL1ng2xCVbJuihEgzeajdEWIHT4qGpfrPwuTMDIasyhSOA\r\na=sendrecv\r\nm=audio 23824 RTP/SAVP 0 8 9 101\r\nc=IN IP6 2620:102:c000:f10:d::6050\r\na=mid:2\r\na=rtpmap:101 telephone-event/8000\r\na=fmtp:101 0-15\r\na=crypto:1 AES_CM_256_HMAC_SHA1_80 inline:ba6DaKfQLSQQbYNMtL1ng2xCVbJuihEgzeajdEWIHT4qGpfrPwuTMDIasyhSOA\r\na=sendrecv\r\n" 145 | // } 146 | ``` 147 | 148 | #### HEP/EEP Specs: 149 | 150 | http://hep.sipcapture.org/ 151 | 152 | 153 | ###### This Project is sponsored by [QXIP BV](http://qxip.net) 154 | 155 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * HEP-js: A simple HEP3 Library for Node.JS 3 | * 4 | * Copyright (C) 2015 Lorenzo Mangani (SIPCAPTURE.ORG) 5 | * Copyright (C) 2015 Alexandr Dubovikov (SIPCAPTURE.ORG) 6 | * Copyright (C) 2019 QXIP BV (QXIP.NET) 7 | * 8 | * Project Homepage: http://github.com/sipcapture 9 | * 10 | * This file is part of HEP-js 11 | * 12 | * HEP-js is free software: you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation, either version 2 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * HEP-js is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * 24 | **/ 25 | 26 | var debug = false; 27 | 28 | // Module import 29 | var Parser = require("binary-parser").Parser; 30 | var mixinDeep = require('mixin-deep'); 31 | var extensions = {}; 32 | 33 | module.exports = { 34 | /** 35 | * Decode HEP3 Packet to JSON Object. 36 | * 37 | * @param {Buffer} hep message 38 | * @return {Object} 39 | */ 40 | decapsulate: function(message) { 41 | if (debug) console.log('Decoding HEP3 Packet...'); 42 | try { 43 | var HEP = hepHeader.parse(message); 44 | if(HEP.payload && HEP.payload.length>0){ 45 | var data = HEP.payload; 46 | var tot = 0; 47 | var decoded = {}; 48 | var PAYLOAD; 49 | while(true){ 50 | PAYLOAD = hepParse.parse( data.slice(tot) ); 51 | var tmp = hepDecode(PAYLOAD); 52 | decoded = mixinDeep(decoded, tmp); 53 | tot += PAYLOAD.length; 54 | if(tot>=HEP.payload.length) { break; } 55 | } 56 | if(debug) console.log(decoded); 57 | return decoded; 58 | } 59 | } catch(e) { 60 | return false; 61 | } 62 | 63 | }, 64 | /** 65 | * Encode HEP3 Packet from JSON Object. 66 | * 67 | * @param {String} sip_msg 68 | * @param {String} hep_json 69 | * @return {Buffer} hep message 70 | */ 71 | encapsulate: function(msg,rcinfo) { 72 | if (debug) console.log('Sending HEP3 Packet...'); 73 | var header = Buffer.allocUnsafe(6); 74 | header.write ("HEP3"); 75 | 76 | var ip_family = Buffer.allocUnsafe(7); 77 | ip_family.writeUInt16BE(0x0000, 0); 78 | ip_family.writeUInt16BE(0x0001,2); 79 | ip_family.writeUInt8(rcinfo.protocolFamily,6); 80 | ip_family.writeUInt16BE(ip_family.length,4); 81 | 82 | var ip_proto = Buffer.allocUnsafe(7); 83 | ip_proto.writeUInt16BE(0x0000, 0); 84 | ip_proto.writeUInt16BE(0x0002, 2); 85 | ip_proto.writeUInt8(rcinfo.protocol,6); 86 | ip_proto.writeUInt16BE(ip_proto.length,4); 87 | 88 | /*ip*/ 89 | var d = rcinfo.srcIp ? rcinfo.srcIp.split('.') : ['127','0','0','1']; 90 | var tmpip = ((((((+d[0])*256)+(+d[1]))*256)+(+d[2]))*256)+(+d[3]); 91 | 92 | var src_ip4 = Buffer.allocUnsafe(10); 93 | src_ip4.writeUInt16BE(0x0000, 0); 94 | src_ip4.writeUInt16BE(0x0003, 2); 95 | src_ip4.writeUInt32BE(tmpip,6); 96 | src_ip4.writeUInt16BE(src_ip4.length,4); 97 | 98 | d = rcinfo.dstIp ? rcinfo.dstIp.split('.') : ['127','0','0','1']; 99 | tmpip = ((((((+d[0])*256)+(+d[1]))*256)+(+d[2]))*256)+(+d[3]); 100 | 101 | var dst_ip4 = Buffer.allocUnsafe(10); 102 | dst_ip4.writeUInt16BE(0x0000, 0); 103 | dst_ip4.writeUInt16BE(0x0004, 2); 104 | dst_ip4.writeUInt32BE(tmpip,6); 105 | dst_ip4.writeUInt16BE(dst_ip4.length,4); 106 | 107 | var src_port = Buffer.allocUnsafe(8); 108 | var tmpA = rcinfo.srcPort ? parseInt(rcinfo.srcPort,10) : 0; 109 | src_port.writeUInt16BE(0x0000, 0); 110 | src_port.writeUInt16BE(0x0007, 2); 111 | src_port.writeUInt16BE(tmpA,6); 112 | src_port.writeUInt16BE(src_port.length,4); 113 | 114 | var dst_port = Buffer.allocUnsafe(8); 115 | tmpA = rcinfo.dstPort ? parseInt(rcinfo.dstPort, 10) : 0; 116 | dst_port.writeUInt16BE(0x0000, 0); 117 | dst_port.writeUInt16BE(0x0008, 2); 118 | dst_port.writeUInt16BE(tmpA,6); 119 | dst_port.writeUInt16BE(dst_port.length,4); 120 | 121 | tmpA = ToUint32(rcinfo.timeSeconds); 122 | var time_sec = Buffer.allocUnsafe(10); 123 | time_sec.writeUInt16BE(0x0000, 0); 124 | time_sec.writeUInt16BE(0x0009, 2); 125 | time_sec.writeUInt32BE(tmpA,6); 126 | time_sec.writeUInt16BE(time_sec.length,4); 127 | 128 | tmpA = ToUint32(rcinfo.timeUseconds); 129 | var time_usec = Buffer.allocUnsafe(10); 130 | time_usec.writeUInt16BE(0x0000, 0); 131 | time_usec.writeUInt16BE(0x000a, 2); 132 | time_usec.writeUInt32BE(tmpA,6); 133 | time_usec.writeUInt16BE(time_usec.length,4); 134 | 135 | var proto_type = Buffer.allocUnsafe(7); 136 | proto_type.writeUInt16BE(0x0000, 0); 137 | proto_type.writeUInt16BE(0x000b,2); 138 | proto_type.writeUInt8(rcinfo.payloadType,6); 139 | proto_type.writeUInt16BE(proto_type.length,4); 140 | 141 | tmpA = ToUint32(rcinfo.captureId); 142 | var capt_id = Buffer.allocUnsafe(10); 143 | capt_id.writeUInt16BE(0x0000, 0); 144 | capt_id.writeUInt16BE(0x000c, 2); 145 | capt_id.writeUInt32BE(tmpA,6); 146 | capt_id.writeUInt16BE(capt_id.length,4); 147 | 148 | // HEPNodeName w/ Fallback to HEP Capture ID 149 | tmpA = rcinfo.hepNodeName ? rcinfo.hepNodeName : "" + rcinfo.captureId; 150 | var hepnodename_chunk = Buffer.allocUnsafe(6 + tmpA.length); 151 | hepnodename_chunk.writeUInt16BE(0x0000, 0); 152 | hepnodename_chunk.writeUInt16BE(0x0013, 2); 153 | hepnodename_chunk.write(tmpA,6, tmpA.length); 154 | hepnodename_chunk.writeUInt16BE(hepnodename_chunk.length,4); 155 | 156 | var auth_chunk; 157 | if(typeof rcinfo.capturePass === 'string') { 158 | auth_chunk = Buffer.allocUnsafe(6 + rcinfo.capturePass.length); 159 | auth_chunk.writeUInt16BE(0x0000, 0); 160 | auth_chunk.writeUInt16BE(0x000e, 2); 161 | auth_chunk.write(rcinfo.capturePass,6, rcinfo.capturePass.length); 162 | auth_chunk.writeUInt16BE(auth_chunk.length,4); 163 | } 164 | else { 165 | auth_chunk = Buffer.allocUnsafe(0); 166 | } 167 | 168 | var payload_chunk = Buffer.allocUnsafe(6 + msg.length); 169 | payload_chunk.writeUInt16BE(0x0000, 0); 170 | payload_chunk.writeUInt16BE(0x000f, 2); 171 | payload_chunk.write(msg, 6, msg.length); 172 | payload_chunk.writeUInt16BE(payload_chunk.length,4); 173 | 174 | var extensions_chunk = Buffer.allocUnsafe(0); 175 | for(var i in extensions) { 176 | for(var j in extensions[i]) { 177 | var extdef = extensions[i][j]; 178 | if(typeof extdef === "object" && 179 | typeof extdef.keyName === "string" && 180 | typeof rcinfo[extdef.keyName] !== 'undefined') { 181 | var this_chunk; 182 | var data = rcinfo[extdef.keyName]; 183 | var failed = true; 184 | if(/\d{1,}/.test(extdef.type)) { 185 | var bitLength = extdef.type.match(/\d{1,}/)[0]; 186 | var size = Math.floor(bitLength/8)+6; 187 | this_chunk = Buffer.allocUnsafe(size); 188 | this_chunk.writeUInt16BE(i, 0); 189 | this_chunk.writeUInt16BE(j, 2); 190 | if(typeof this_chunk["write"+extdef.type] === 'function') { 191 | this_chunk['write'+extdef.type](data ,6); 192 | failed = false; 193 | } 194 | else if(typeof this_chunk["write"+extdef.type+"BE"] === 'function') { 195 | this_chunk['write'+extdef.type+"BE"](data ,6); 196 | failed = false; 197 | } 198 | this_chunk.writeUInt16BE(this_chunk.length,4); 199 | } 200 | else if(/string$/.test(extdef.type) || extdef.type === undefined) { 201 | this_chunk = Buffer.allocUnsafe(6+data.length); 202 | this_chunk.writeUInt16BE(i, 0); 203 | this_chunk.writeUInt16BE(j, 2); 204 | this_chunk.write(data, 6, data.length); 205 | this_chunk.writeUInt16BE(this_chunk.length, 4); 206 | failed = false; 207 | } 208 | if(typeof this_chunk !== 'undefined' && !failed) { 209 | extensions_chunk = Buffer.concat([extensions_chunk, this_chunk]); 210 | } 211 | } 212 | } 213 | } 214 | 215 | var hep_message, correlation_chunk; 216 | 217 | if ((rcinfo.proto_type == 32 || rcinfo.proto_type == 35 ) && rcinfo.correlation_id.length) { 218 | 219 | // create correlation chunk 220 | correlation_chunk = Buffer.allocUnsafe(6 + rcinfo.correlation_id.length); 221 | correlation_chunk.writeUInt16BE(0x0000, 0); 222 | correlation_chunk.writeUInt16BE(0x0011, 2); 223 | correlation_chunk.write(rcinfo.correlation_id,6, rcinfo.correlation_id.length); 224 | correlation_chunk.writeUInt16BE(correlation_chunk.length,4); 225 | 226 | tmpA = ToUint16(rcinfo.mos); 227 | var mos = Buffer.allocUnsafe(8); 228 | mos.writeUInt16BE(0x0000, 0); 229 | mos.writeUInt16BE(0x0020, 2); 230 | mos.writeUInt16BE(tmpA,6); 231 | mos.writeUInt16BE(mos.length,4); 232 | 233 | hep_message = Buffer.concat([ 234 | header, 235 | ip_family, 236 | ip_proto, 237 | src_ip4, 238 | dst_ip4, 239 | src_port, 240 | dst_port, 241 | time_sec, 242 | time_usec, 243 | proto_type, 244 | capt_id, 245 | hepnodename_chunk, 246 | auth_chunk, 247 | correlation_chunk, 248 | mos, 249 | payload_chunk, 250 | extensions_chunk 251 | ]); 252 | 253 | } 254 | // HEP TYPE 101 w/ mandatory json_chunk (string) 255 | else if (rcinfo.transaction_type && rcinfo.transaction_type.length && rcinfo.correlation_id.length) { 256 | 257 | // create correlation chunk 258 | correlation_chunk = Buffer.allocUnsafe(6 + rcinfo.correlation_id.length); 259 | correlation_chunk.writeUInt16BE(0x0000, 0); 260 | correlation_chunk.writeUInt16BE(0x0011, 2); 261 | correlation_chunk.write(rcinfo.correlation_id,6, rcinfo.correlation_id.length); 262 | correlation_chunk.writeUInt16BE(correlation_chunk.length,4); 263 | 264 | // create transaction_type chunk 265 | var transaction_type = Buffer.allocUnsafe(6 + rcinfo.transaction_type.length); 266 | transaction_type.writeUInt16BE(0x0000, 0); 267 | transaction_type.writeUInt16BE(0x0024, 2); 268 | transaction_type.write(rcinfo.transaction_type,6, rcinfo.transaction_type.length); 269 | transaction_type.writeUInt16BE(transaction_type.length,4); 270 | 271 | hep_message = Buffer.concat([ 272 | header, 273 | ip_family, 274 | ip_proto, 275 | src_ip4, 276 | dst_ip4, 277 | src_port, 278 | dst_port, 279 | time_sec, 280 | time_usec, 281 | proto_type, 282 | capt_id, 283 | hepnodename_chunk, 284 | auth_chunk, 285 | correlation_chunk, 286 | transaction_type, 287 | payload_chunk, 288 | extensions_chunk 289 | ]); 290 | 291 | } 292 | else if (rcinfo.correlation_id && rcinfo.correlation_id.length) { 293 | 294 | // create correlation chunk 295 | correlation_chunk = Buffer.allocUnsafe(6 + rcinfo.correlation_id.length); 296 | correlation_chunk.writeUInt16BE(0x0000, 0); 297 | correlation_chunk.writeUInt16BE(0x0011, 2); 298 | correlation_chunk.write(rcinfo.correlation_id,6, rcinfo.correlation_id.length); 299 | correlation_chunk.writeUInt16BE(correlation_chunk.length,4); 300 | 301 | hep_message = Buffer.concat([ 302 | header, 303 | ip_family, 304 | ip_proto, 305 | src_ip4, 306 | dst_ip4, 307 | src_port, 308 | dst_port, 309 | time_sec, 310 | time_usec, 311 | proto_type, 312 | capt_id, 313 | hepnodename_chunk, 314 | auth_chunk, 315 | correlation_chunk, 316 | payload_chunk, 317 | extensions_chunk 318 | ]); 319 | } 320 | else { 321 | 322 | hep_message = Buffer.concat([ 323 | header, 324 | ip_family, 325 | ip_proto, 326 | src_ip4, 327 | dst_ip4, 328 | src_port, 329 | dst_port, 330 | time_sec, 331 | time_usec, 332 | proto_type, 333 | capt_id, 334 | hepnodename_chunk, 335 | auth_chunk, 336 | payload_chunk, 337 | extensions_chunk 338 | ]); 339 | 340 | } 341 | hep_message.writeUInt16BE(hep_message.length, 4); 342 | return hep_message; 343 | 344 | }, 345 | 346 | encode: function(json) { 347 | return String(json) 348 | .toString("binary"); 349 | }, 350 | 351 | decode: function(hep) { 352 | return String(hep) 353 | .toString('utf8'); 354 | }, 355 | 356 | addVendorExtensions: function(json) { 357 | extensions = mixinDeep(extensions, json); 358 | } 359 | }; 360 | 361 | 362 | /* Functions */ 363 | 364 | var modulo = function (a, b) { 365 | return a - Math.floor(a/b)*b; 366 | }; 367 | 368 | var ToUint32 = function (x) { 369 | return modulo(ToInteger(x), Math.pow(2, 32)); 370 | }; 371 | 372 | var ToUint16 = function (x) { 373 | return modulo(ToInteger(x), Math.pow(2, 16)); 374 | }; 375 | 376 | var ToInteger =function (x) { 377 | x = Number(x); 378 | return x < 0 ? Math.ceil(x) : Math.floor(x); 379 | }; 380 | 381 | var ntohl = function (val) { 382 | return ((val & 0xFF) << 24) 383 | | ((val & 0xFF00) << 8) 384 | | ((val >> 8) & 0xFF00) 385 | | ((val >> 24) & 0xFF); 386 | }; 387 | 388 | var inet_pton = function inet_pton(a) { 389 | 390 | var r, m, x, i, j, f = String.fromCharCode; 391 | // IPv4 392 | m = a.match(/^(?:\d{1,3}(?:\.|$)){4}/); 393 | if (m) { 394 | m = m[0].split('.'); 395 | m = f(m[0]) + f(m[1]) + f(m[2]) + f(m[3]); 396 | // Return if 4 bytes, otherwise false. 397 | return m.length === 4 ? m : false; 398 | } 399 | r = /^((?:[\da-f]{1,4}(?::|)){0,8})(::)?((?:[\da-f]{1,4}(?::|)){0,8})$/; 400 | // IPv6 401 | m = a.match(r); 402 | if (m) { 403 | // Translate each hexadecimal value. 404 | for (j = 1; j < 4; j++) { 405 | // Indice 2 is :: and if no length, continue. 406 | if (j === 2 || m[j].length === 0) { 407 | continue; 408 | } 409 | m[j] = m[j].split(':'); 410 | for (i = 0; i < m[j].length; i++) { 411 | m[j][i] = parseInt(m[j][i], 16); 412 | // Would be NaN if it was blank, return false. 413 | if (isNaN(m[j][i])) { 414 | // Invalid IP. 415 | return false; 416 | } 417 | m[j][i] = f(m[j][i] >> 8) + f(m[j][i] & 0xFF); 418 | } 419 | m[j] = m[j].join(''); 420 | } 421 | x = m[1].length + m[3].length; 422 | if (x === 16) { 423 | return m[1] + m[3]; 424 | } else if (x < 16 && m[2].length > 0) { 425 | return m[1] + (new Array(16 - x + 1)) 426 | .join('\x00') + m[3]; 427 | } 428 | } 429 | // Invalid IP. 430 | return false; 431 | }; 432 | 433 | // Build an IP packet header Parser 434 | var hepHeader = new Parser() 435 | .endianess("big") 436 | .string("hep", { length: 4, stripNull: true, assert: "HEP3" }) 437 | .uint16("hepLength") 438 | .buffer("payload", { length: function () {return this.hepLength - 6; } }); // Length of HepMessage is defined including the 6 Byte Header 439 | 440 | var hepParse = new Parser() 441 | .endianess("big") 442 | .uint16("vendor") 443 | .uint16("type") 444 | .uint16("length") 445 | .buffer("chunk", { length: function () {return this.length-6;} }); // Length of Chunk is defined including the 6 Byte header 446 | 447 | var hepIps = new Parser() 448 | .endianess("big") 449 | .array("ip",{ 450 | type: "uint8", 451 | length: 4 452 | }); 453 | 454 | var hepDecode = function(data){ 455 | switch(data.type) { 456 | case 1: 457 | return { rcinfo: { protocolFamily: data.chunk.readUInt8() } }; 458 | case 2: 459 | return { rcinfo: { protocol: data.chunk.readUInt8() } }; 460 | case 3: 461 | return { rcinfo: { srcIp: hepIps.parse(data.chunk).ip.join('.') } }; 462 | case 4: 463 | return { rcinfo: { dstIp: hepIps.parse(data.chunk).ip.join('.') } }; 464 | case 7: 465 | return { rcinfo: { srcPort: data.chunk.readUInt16BE() } }; 466 | case 8: 467 | return { rcinfo: { dstPort: data.chunk.readUInt16BE() } }; 468 | case 9: 469 | return { rcinfo: { timeSeconds: data.chunk.readUInt32BE() } }; 470 | case 10: 471 | return { rcinfo: { timeUseconds: data.chunk.readUInt32BE() } }; 472 | case 11: 473 | return { rcinfo: { payloadType: data.chunk.readUInt8() } }; 474 | case 12: 475 | return { rcinfo: { captureId: data.chunk.readUInt32BE() } }; 476 | case 14: 477 | return { rcinfo: { capturePass: data.chunk.toString() } }; 478 | case 15: 479 | return { payload: data.chunk.toString() }; 480 | case 17: 481 | return { rcinfo: { correlation_id: data.chunk.toString() } }; 482 | case 19: 483 | return { rcinfo: { hepNodeName: data.chunk.toString() } }; 484 | case 32: 485 | return { rcinfo: { mos: data.chunk.readUInt16BE() } }; 486 | case 36: 487 | return { rcinfo: { transaction_type: data.chunk.readUInt16BE() } }; 488 | default: 489 | var returnData = {}; 490 | if(typeof extensions[data.vendor] === 'object' && 491 | typeof extensions[data.vendor][data.type] === 'object' && 492 | typeof extensions[data.vendor][data.type].keyName) { 493 | returnData.rcinfo = {}; 494 | var keyName = extensions[data.vendor][data.type].keyName; 495 | var type = extensions[data.vendor][data.type].type; 496 | if(typeof type === 'string') { 497 | if(typeof data.chunk['read'+type] === 'function') { 498 | returnData.rcinfo[keyName] = data.chunk['read'+type](); 499 | } 500 | else if(typeof data.chunk['read'+type+"BE"] === 'function') { 501 | returnData.rcinfo[keyName] = data.chunk['read'+type+"BE"](); 502 | } 503 | } 504 | else { 505 | returnData.rcinfo[keyName] = data.chunk.toString(); 506 | } 507 | } 508 | return returnData; 509 | } 510 | }; 511 | 512 | function deepMerge(o1,o2) { 513 | for (var k in o2) { 514 | if (typeof(o2[k])=='object') { 515 | if(!o1[k]) o1[k] = {}; 516 | //console.log(merge(o1[k],o2[k]) ); 517 | o1[k] = deepMerge(o1[k],o2[k]); 518 | } else { 519 | o1[k] = o2[k]; 520 | } 521 | } 522 | return o1; 523 | } 524 | 525 | 526 | /* 527 | Appendix A: HEP3 JSON Format (prototype) 528 | */ 529 | 530 | /* 531 | var hepPacket = { 532 | "type": "HEP", 533 | "version": 3, 534 | "rcinfo": { 535 | "protocolFamily": 2, 536 | "protocol": 17, 537 | "srcIp": "192.168.3.12", 538 | "srcPort": 5060, 539 | "dstIp": "192.168.3.11", 540 | "dstPort": 5060, 541 | "timestamp": "2015-06-11T12:36:08:222Z", 542 | "timestampUSecs": 0, 543 | "captureId": 241, 544 | "hepNodeName": "ams01-voip", 545 | "capturePass": "myHep", 546 | "payload_type": "SIP" 547 | }, 548 | "payload": { 549 | "data": "INVITE sip:9999@homer SIP/2.0\r\n..." 550 | } 551 | }; 552 | 553 | */ 554 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | --------------------------------------------------------------------------------