Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pike
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pikelang
pike
Commits
cc56ce4b
Commit
cc56ce4b
authored
26 years ago
by
Henrik (Grubba) Grubbström
Browse files
Options
Downloads
Plain Diff
Merge 'heads/0.6': Added support for asynchronous lookup.
parents
6ac78b5f
df0bb9e0
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/modules/Protocols.pmod/Ident.pmod
+137
-1
137 additions, 1 deletion
lib/modules/Protocols.pmod/Ident.pmod
with
137 additions
and
1 deletion
lib/modules/Protocols.pmod/Ident.pmod
+
137
−
1
View file @
cc56ce4b
// An implementation of the IDENT protocol, specified in RFC 931.
//
// $Id: Ident.pmod,v 1.
4
1998/05/2
7
0
5:47:41 neotron
Exp $
// $Id: Ident.pmod,v 1.
5
1998/05/2
8
0
0:13:41 grubba
Exp $
#define IDENT_DEBUG
class lookup_async
{
object con;
function(array(string), mixed ...:void) callback;
array cb_args;
string query;
string read_buf = "";
void do_callback(array(string) reply)
{
#ifdef IDENT_DEBUG
werror("Protocols.Ident: calling callback\n");
#endif /* IDENT_DEBUG */
mixed err;
if (callback) {
err = catch {
callback(reply, @cb_args);
};
callback = 0;
cb_args = 0;
}
if (con) {
con->close();
destruct(con);
}
query = "";
read_buf = "";
con = 0;
if (err) {
throw(err);
}
}
void write_cb()
{
#ifdef IDENT_DEBUG
werror("Protocols.Ident: sending query\n");
#endif /* IDENT_DEBUG */
int i = con->write(query);
if (i >= 0) {
query = query[i..];
if (sizeof(query)) {
return;
}
con->set_write_callback(0);
} else {
do_callback(({ "ERROR", "FAILED TO SEND REQUEST" }));
}
}
void read_cb(mixed ignored, string data)
{
#ifdef IDENT_DEBUG
werror("Protocols.Ident: reading data\n");
#endif /* IDENT_DEBUG */
read_buf += data;
int i = search(read_buf, "\r\n");
if (i != -1) {
string reply = read_buf[..i-1];
read_buf = read_buf[i+1..];
array(string) response = reply/":";
if (sizeof(response) < 2) {
do_callback(({ "ERROR", "BAD REPLY" }));
} else {
do_callback(response[1..]);
}
} else if (sizeof(read_buf) > 1024) {
do_callback(({ "ERROR", "REPLY TOO LARGE" }));
}
}
void close_cb()
{
#ifdef IDENT_DEBUG
werror("Protocols.Ident: Connection closed\n");
#endif /* IDENT_DEBUG */
do_callback(({ "ERROR", "CONNECTION CLOSED" }));
}
void timeout()
{
#ifdef IDENT_DEBUG
werror("Protocols.Ident: Timeout\n");
#endif /* IDENT_DEBUG */
do_callback(({ "ERROR", "TIMEOUT" }));
}
void create(object fd, function(array(string), mixed ...:void) cb,
mixed ... args)
{
string|array(string) raddr = fd->query_address();
string|array(string) laddr = fd->query_address(1);
if(!raddr || !laddr) {
// Does this ever happen?
error("Protocols.Ident - cannot lookup address");
}
laddr = laddr / " ";
raddr = raddr / " ";
query = raddr[1]+","+laddr[1]+"\r\n";
con = Stdio.File();
if (!con->open_socket(0, laddr[0])) {
destruct(con);
error("Protocols.Ident: open_socket() failed.");
}
mixed err;
if (err = catch(con->connect(raddr[0], 113))) {
destruct(con);
throw(err);
}
#ifdef IDENT_DEBUG
werror(sprintf("Protocols.Ident: Connection OK, query:%O\n", query));
#endif /* IDENT_DEBUG */
callback = cb;
cb_args = args;
con->set_nonblocking(read_cb, write_cb, close_cb);
call_out(timeout, 60);
}
}
int|array (string) lookup(object fd)
{
mixed raddr; // Remote Address.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment