A C library for interacting with the Neocities API. This library provides functions for uploading files, managing site content, and retrieving site statistics.
- Include the library headers:
#include "neocities.h"
- Link against the library:
gcc -o your_program your_program.c -lneocities -lcurl
// Initialize the library
struct Neocities* neo = neocities_init("username", "password");
if (!neo) {
fprintf(stderr, "Failed to initialize\n");
return 1;
}
// Use the library functions
// ...
// Cleanup when done
neocities_cleanup(neo);
Initializes the library with your Neocities credentials.
- Parameters:
username
: Your Neocities usernamepassword
: Your Neocities password
- Returns: Pointer to Neocities structure or NULL on failure
Uploads one or more files to your Neocities site.
- Parameters:
neo
: Neocities structure from initfiles
: Array of UploadFile structuresfile_count
: Number of files to upload
- Returns: true on success, false on failure
Deletes one or more files from your Neocities site.
- Parameters:
neo
: Neocities structure from initfilenames
: Array of filenames to deletefilename_count
: Number of files to delete
- Returns: true on success, false on failure
Lists files in the specified directory.
- Parameters:
neo
: Neocities structure from initpath
: Directory path (NULL for root)
- Returns: JSON string containing file list (must be freed) or NULL on failure
Gets information about a Neocities site.
- Parameters:
neo
: Neocities structure from initsitename
: Site to get information about
- Returns: JSON string containing site info (must be freed) or NULL on failure
Gets the number of hits for a site.
- Parameters:
neo
: Neocities structure from initsitename
: Site to get hits for
- Returns: Number of hits or -1 on failure
Gets the number of views for a site.
- Parameters:
neo
: Neocities structure from initsitename
: Site to get views for
- Returns: Number of views or -1 on failure
Gets the tags for a site.
- Parameters:
neo
: Neocities structure from initsitename
: Site to get tags fortag_count
: Pointer to store number of tags
- Returns: Array of strings containing tags (must be freed with neocities_free_tags) or NULL on failure
Gets the creation date of a site.
- Parameters:
neo
: Neocities structure from initsitename
: Site to get creation date for
- Returns: Unix timestamp of creation date or 0 on failure
Cleans up and frees resources.
- Parameters:
neo
: Neocities structure to cleanup
Frees tag array returned by neocities_get_tags.
- Parameters:
tags
: Array of tags to freetag_count
: Number of tags
Holds authentication information.
struct Neocities {
char* username;
char* password;
};
Holds information about a file to upload.
struct UploadFile {
char* filename; // Name to use on the server
char* filepath; // Local path to the file
};
Most functions return either:
NULL
or-1
on failure- A valid pointer or non-negative number on success
Error messages are printed to stderr.
struct UploadFile file = {
.filename = "index.html",
.filepath = "local/path/to/index.html"
};
if (neocities_upload(neo, &file, 1)) {
printf("Upload successful\n");
} else {
fprintf(stderr, "Upload failed\n");
}
int views = neocities_get_views(neo, "sitename");
if (views >= 0) {
printf("Site views: %d\n", views);
}
size_t tag_count;
char** tags = neocities_get_tags(neo, "sitename", &tag_count);
if (tags) {
printf("Site tags:\n");
for (size_t i = 0; i < tag_count; i++) {
printf(" - %s\n", tags[i]);
}
neocities_free_tags(tags, tag_count);
}