Live data from Hacker News

Show HN: Gemini web client in 100 lines of C

github.com

31–40 of 47 posts

Re: Show HN: Gemini web client in 100 lines of C

#31
post #28

I remember gplaces, but it doesn't compile under OpenBSD. It needs lots of fixes to be built on systems beside GNU/Linux. On golang, Bombadillo today supports "images" with Unicode-art and searching inside the "pages" a la ctrl-f in browsers, so it's better than Amfora and one of the best TUI clients ever. Also, it does gopher and https thru external tools like lynx.

Besides GNU/Linux I compiled on MacOS. I made no effort to test on BSD systems or Windows. I included only few std libs so I wonder - what exactly makes it not compatible with OpenBSD?

Re: Show HN: Gemini web client in 100 lines of C

#32
post #22
post #18

It's a nice project, but - I guess as is tradition with the majority of C projects - it has resource leaks and buffer overflows. There is at least one resource leak, namely, `sfd` is not closed when certain `WARN()` invocations jump back to the `start` label; for example, when `gethostbyname()` fails (i.e. try a non-existent domain and observe that the sockets remain open with `lsof`). (It also seems to be leaked in…

This is such a great feedback. Thank you a lot. OFC I will try to correct my mistakes. Not to make any excuses, just for the context. I'm a beginner in C programming and I wrote only few small programs. My tooling is basically non existent. I will try to improve tho.

There's a page on the net somewhere, which was on HN front-page a while ago too, that listed all the useful warning flags for gcc, with an explanation.

I'd look for it, as a C programmer. On phone now, so sadly don't have it handy.

Re: Show HN: Gemini web client in 100 lines of C

#33
post #30

Earlier quoted context omitted.

I've only ever heard it called "Gemini", not "Gemini web". "Gemini web" is a bad name because Gemini's not being part of the web was the main motive in Gemini's creation. "Geminisphere" or "Geminiverse" would be fine with me as a name for the totality of Gemini servers considered collectively.

Gemini being part of the web is pretty baked-in. You can link to http:// pages from gemini, and gemini:// pages from HTTP. And all these links participate in the hyperlinked "Web". It even supports mime types, you can serve text/gemini from an HTTP server, or a text/html file from a Gemini server.

That's true and many Gemini clients supports multiple protocols. But in case of this "gmi100" only gemini:// protocol is supported.

Re: Show HN: Gemini web client in 100 lines of C

#34
post #14

Earlier quoted context omitted.

If you're going to nitpick you could nitpick on the use of "web" (though, as others note, that's not wholly inaccurate), but there are plenty of command-line web clients. For example, wget and curl.

Yes, wget and curl are web clients. This is not.

Right, but that has nothing to do with it being a command line app, which is what OP was objecting to.

Re: Show HN: Gemini web client in 100 lines of C

#35

Arthur Whitney, is that you? [1] [1] https://code.jsoftware.com/wiki/Essays/Incunabulum

The way he seems to have written 'C' is to use the C preprocessor and Macros to create a domain specific language and then write the program in that! Mind Blown!

Re: Show HN: Gemini web client in 100 lines of C

#36
post #30

Earlier quoted context omitted.

I've only ever heard it called "Gemini", not "Gemini web". "Gemini web" is a bad name because Gemini's not being part of the web was the main motive in Gemini's creation. "Geminisphere" or "Geminiverse" would be fine with me as a name for the totality of Gemini servers considered collectively.

Gemini being part of the web is pretty baked-in. You can link to http:// pages from gemini, and gemini:// pages from HTTP. And all these links participate in the hyperlinked "Web". It even supports mime types, you can serve text/gemini from an HTTP server, or a text/html file from a Gemini server.

[deleted]

Re: Show HN: Gemini web client in 100 lines of C

#38
post #31
post #28

I remember gplaces, but it doesn't compile under OpenBSD. It needs lots of fixes to be built on systems beside GNU/Linux. On golang, Bombadillo today supports "images" with Unicode-art and searching inside the "pages" a la ctrl-f in browsers, so it's better than Amfora and one of the best TUI clients ever. Also, it does gopher and https thru external tools like lynx.

Besides GNU/Linux I compiled on MacOS. I made no effort to test on BSD systems or Windows. I included only few std libs so I wonder - what exactly makes it not compatible with OpenBSD?

No, gplaces didn't work. Yours' work fine with a just an extra #include for inet.

Re: Show HN: Gemini web client in 100 lines of C

#39
post #22

Earlier quoted context omitted.

This is such a great feedback. Thank you a lot. OFC I will try to correct my mistakes. Not to make any excuses, just for the context. I'm a beginner in C programming and I wrote only few small programs. My tooling is basically non existent. I will try to improve tho.

There's a page on the net somewhere, which was on HN front-page a while ago too, that listed all the useful warning flags for gcc, with an explanation. I'd look for it, as a C programmer. On phone now, so sadly don't have it handy.

If you or someone else finds the link to this, I would love this!

Re: Show HN: Gemini web client in 100 lines of C

#40
This is cool. I asked ChatGPT4 to explain to me what it does, and it gives a useful overview:

This is a minimal Gemini protocol client written in C. The Gemini protocol is an application-level internet protocol for serving hypertext documents over secure connections.

The code includes various standard C libraries and the OpenSSL library for secure connections. The `WARN` macro definition is used to print warning messages to `stderr` and jump to the `start:` label.

In the `main` function, it defines variables and initializes certain structs, like `struct sockaddr_in addr` that is used for internet socket addresses. It then opens a connection with the Gemini server on port 1965 (the standard port for the Gemini protocol). The connection is encrypted using the OpenSSL library functions. It also opens two file streams, one for history (`.gmi100`) and another for a temporary file. The file names and locations are generated by the `tmpnam()` function.

The main loop reads commands from `stdin`. Depending on the command, it can execute system commands (when the input starts with '!'), navigate through the history (when input starts with a digit), process a variety of single-letter commands (like 'q' for quit, 'r' for refresh, 'c' to print current URI, 'u' for up a level, 'b' for back in history), or interpret the input as a URL or a part of a URL to be navigated to.

For URL navigation, it creates a TCP socket connection with the Gemini server, sets up an SSL connection over that socket, and sends a request to the server for the resource identified by the URL. The client handles the server response depending on the status code. For example, if the status code is '1' it's a request for input and if it's '3' it's a redirect. It prints the response to `stdout` and also stores it in the temporary file.

For `text/*` type responses, it additionally parses any lines that start with '=>' as links and assigns them a number, storing this in the temporary file for later navigation. If the line starts with '=>' but doesn't have a description, it goes back to reading the rest of the description.

After processing the server response, it uses the `less` command to display the content of the temporary file, allowing the user to scroll through it if it's longer than the screen. Before each new iteration of the main loop, it flushes the temporary file and goes back to the `start:` label. If the user quits, the function returns 0 and the program terminates.

Overall, this program is a command-line based Gemini client that allows a user to navigate the geminispace, issue queries, and view text documents served over the Gemini protocol. It also keeps a history of visited URIs in the `.gmi100` file.

source: https://sharegpt.com/c/xscNWg6

Post reply on HN