Giter VIP home page Giter VIP logo

mousygem's Introduction

Mousygem

Mousygem is a simple C++ based library for writing Gemini servers. It handles creating sockets, (most) OpenSSL functions, accepting clients, receiving/parsing URIs, and formatting/sending responses to the client.

You can find out more information about the gemini protocol here: https://gemini.circumlunar.space/

Requirements

  • C++17 compiler
  • OpenSSL (latest recommended)
  • CMake 3.12 or newer

Example implementation

Here is a very simple implementation of a working server in 31 lines of C++ code.

#include <cstdint>
#include <openssl/ssl.h>
#include <mousygem/mousygem.hpp>

using namespace Mousygem;
using namespace std;

// Inherit the abstract class, Mousygem::Server
class MyServer : public Server {
public:
    MyServer(const char *ip, uint16_t port) : Server(ip, port) {} // just pass the ip/port

private:
    // Override respond(). Respond with "Hello world" and the path requested by the client.
    Response respond(const URI &uri, const Client &client) override {
        return Response(Response::Success, "text/gemini", string("# Hello world\r\n\r\nPath: ") + uri.path());
    }
};

int main() {
    // Initialize OpenSSL (required before we can create a server since we use OpenSSL)
    OpenSSL_add_ssl_algorithms();
    
    // Create server. Specify IP, port, key, and certificate.
    MyServer server(nullptr, 1965); // Passing nullptr as the IP binds to all addresses.
    server.use_certificate_file("cert.pem");
    server.use_private_key_file("key.pem");
    
    // Start the server (sets up sockets, calls bind() and listen(), begins accepting clients)
    server.accept_clients();
}

Use a gemini client to connect to it.

$ gmnlm gemini://localhost/path/to/resource?someinput
#  Hello world
   
   Path: /path/to/resource

text/gemini at gemini://localhost/path/to/resource?someinput
[N]: follow Nth link; [q]uit; [?]; or type a URL
=>

mousygem's People

Contributors

snowymouse avatar

Watchers

 avatar

mousygem's Issues

Implement Windows support

Some headers need changed. Some things may need ifdef'd. And, of course, our old friend, Winsock, needs to work.

Right now this library really only works on Linux, and while 100% of the users (which... right now is just me) run it on Linux, Windows support may be appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.