Skip to content

Commit

Permalink
feat: add add_line_processor, aka line_socket.setup_line_processor
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed May 2, 2024
1 parent 2afdb46 commit c8e9e1c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
### [1.7.0] - 2024-04-29

- feat: added HarakaMx #89
- feat: add add_line_processor, aka line_socket.setup_line_processor
- fix(get_public_ip): set timeout in stun request, fixes #84
- test: added get_implicit_mx tests #89
- change: get_mx: don't filter implicit MX errors #89
- fix(get_public_ip): set timeout in stun request, fixes #84

### [1.6.0] - 2024-04-17

Expand Down
22 changes: 22 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,25 @@ exports.get_public_ip = require('./lib/get_public_ip').get_public_ip
exports.get_public_ip_async = require('./lib/get_public_ip').get_public_ip_async

exports.HarakaMx = require('./lib/HarakaMx')

exports.add_line_processor = (socket) => {
const line_regexp = /^([^\n]*\n)/; // utils.line_regexp
let current_data = '';

socket.on('data', (data) => {
current_data += data;
let results;
while ((results = line_regexp.exec(current_data))) {
const this_line = results[1];
current_data = current_data.slice(this_line.length);
socket.emit('line', this_line);
}
})

socket.on('end', () => {
if (current_data.length) {
socket.emit('line', current_data);
}
current_data = '';
})
}

0 comments on commit c8e9e1c

Please sign in to comment.