Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for gopher protocol #16

Merged
merged 2 commits into from
Apr 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ void displayHelp() {
Serial.println("PET MCTERM TR........: ATPETN (N=0,1)"); yield();
Serial.println("NETWORK INFO.........: ATI"); yield();
Serial.println("HTTP GET.............: ATGET<URL>"); yield();
Serial.println("GOPHER REQUEST.......: ATGPH<URL>"); yield();
//Serial.println("SERVER PORT........: AT$SP=N (N=1-65535)"); yield();
Serial.println("AUTO ANSWER..........: ATS0=N (N=0,1)"); yield();
Serial.println("SET BUSY MSG.........: AT$BM=YOUR BUSY MESSAGE"); yield();
Expand Down Expand Up @@ -1468,6 +1469,54 @@ void command()
delete hostChr;
}

/**** Gopher request ****/
else if (upCmd.indexOf("ATGPH") == 0)
{
// From the URL, aquire required variables
// (14 = "ATGPHgopher://")
int portIndex = cmd.indexOf(":", 14); // Index where port number might begin
int pathIndex = cmd.indexOf("/", 14); // Index first host name and possible port ends and path begins
int port;
String path, host;
if (pathIndex < 0)
{
pathIndex = cmd.length();
}
if (portIndex < 0)
{
port = 70;
portIndex = pathIndex;
}
else
{
port = cmd.substring(portIndex + 1, pathIndex).toInt();
}
host = cmd.substring(14, portIndex);
path = cmd.substring(pathIndex, cmd.length());
if (path == "") path = "/";
char *hostChr = new char[host.length() + 1];
host.toCharArray(hostChr, host.length() + 1);

// Establish connection
if (!tcpClient.connect(hostChr, port))
{
sendResult(R_NOCARRIER);
connectTime = 0;
callConnected = false;
setCarrier(callConnected);
}
else
{
sendResult(R_CONNECT);
connectTime = millis();
cmdMode = false;
callConnected = true;
setCarrier(callConnected);
tcpClient.print(path + "\r\n");
}
delete hostChr;
}

/**** Control quiet mode ****/
else if (upCmd.indexOf("ATQ") == 0) {
if (upCmd.substring(3, 4) == "?") {
Expand Down