Refactored code by breaking the main.c up into BUD files.
This commit is contained in:
121
src/ginxsom.h
121
src/ginxsom.h
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Ginxsom Blossom Server Header
|
||||
*
|
||||
*
|
||||
* This header contains all function declarations and type definitions
|
||||
* organized by BUD (Blossom Unified Draft) sections.
|
||||
*/
|
||||
@@ -43,18 +43,44 @@ void handle_head_request(const char* uri);
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Authorization header parsing
|
||||
int parse_authorization_header(const char* auth_header, char* event_json, size_t json_size);
|
||||
|
||||
// Blossom event validation (specific to kind 24242)
|
||||
int validate_blossom_event(cJSON* event, const char* expected_hash, const char* method);
|
||||
|
||||
// Main authentication orchestrator
|
||||
int authenticate_request(const char* auth_header, const char* method, const char* file_hash);
|
||||
// NOTE: Old authentication functions removed - now handled by nostr_core_lib unified system
|
||||
// Use nostr_validate_request() from request_validator.h for all authentication needs
|
||||
|
||||
// Upload handling
|
||||
void handle_upload_request(void);
|
||||
|
||||
// Blob metadata structure
|
||||
typedef struct {
|
||||
char sha256[65];
|
||||
long size;
|
||||
char type[128];
|
||||
long uploaded_at;
|
||||
char filename[256];
|
||||
int found;
|
||||
} blob_metadata_t;
|
||||
|
||||
// Blob metadata database operations
|
||||
int insert_blob_metadata(const char* sha256, long size, const char* type,
|
||||
long uploaded_at, const char* uploader_pubkey,
|
||||
const char* filename);
|
||||
int get_blob_metadata(const char* sha256, blob_metadata_t* metadata);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
// BUD 04 - Mirroring
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Mirror request handling
|
||||
void handle_mirror_request(void);
|
||||
|
||||
// URL validation for mirroring
|
||||
int validate_mirror_url(const char* url);
|
||||
|
||||
// Content type detection for mirrored blobs
|
||||
const char* determine_blob_content_type(const char* url, const char* header_content_type,
|
||||
const unsigned char* data, size_t size);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
// BUD 06 - Upload Requirements
|
||||
@@ -64,6 +90,54 @@ void handle_upload_request(void);
|
||||
// Upload policy management (for future implementation)
|
||||
void handle_upload_requirements_request(void);
|
||||
|
||||
// BUD-06 specific functions
|
||||
void handle_head_upload_request(void);
|
||||
int validate_upload_headers(const char** sha256, const char** content_type,
|
||||
long* content_length, char* error_reason, size_t reason_size);
|
||||
void send_upload_error_response(int status_code, const char* error_type,
|
||||
const char* message, const char* x_reason);
|
||||
void send_upload_success_response(const char* sha256, const char* content_type, long content_length);
|
||||
int validate_content_length(const char* content_length_str, long* parsed_length);
|
||||
int check_blob_exists(const char* sha256);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
// BUD 09 - Blob Report (NIP-56 Report Events)
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Report event validation
|
||||
int validate_report_event_structure(cJSON* event);
|
||||
int extract_blob_hashes_from_report(cJSON* event, char blob_hashes[][65], int max_hashes);
|
||||
int validate_report_types(cJSON* event);
|
||||
|
||||
// Report storage and handling
|
||||
int store_blob_report(const char* event_json, const char* reporter_pubkey);
|
||||
void handle_report_request(void);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
// BUD 08 - NIP-94 File Metadata Tags
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// NIP-94 configuration and control
|
||||
int nip94_is_enabled(void);
|
||||
int nip94_get_origin(char* out, size_t out_size);
|
||||
|
||||
// MIME type and file extension handling
|
||||
const char* mime_to_extension(const char* mime_type);
|
||||
void nip94_build_blob_url(const char* origin, const char* sha256, const char* mime_type, char* out, size_t out_size);
|
||||
|
||||
// Image dimension parsing
|
||||
int parse_png_dimensions(const unsigned char* data, size_t size, int* width, int* height);
|
||||
int parse_jpeg_dimensions(const unsigned char* data, size_t size, int* width, int* height);
|
||||
int parse_webp_dimensions(const unsigned char* data, size_t size, int* width, int* height);
|
||||
int nip94_get_dimensions(const unsigned char* data, size_t size, const char* mime_type, int* width, int* height);
|
||||
|
||||
// NIP-94 metadata emission
|
||||
void nip94_emit_field(const char* url, const char* mime, const char* sha256, long size, int width, int height);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
// UTILITY FUNCTIONS
|
||||
@@ -77,6 +151,35 @@ void send_json_response(int status_code, const char* json_content);
|
||||
// Logging utilities
|
||||
void log_request(const char* method, const char* uri, const char* auth_status, int status_code);
|
||||
|
||||
// SHA-256 validation helper (used by multiple BUDs)
|
||||
int validate_sha256_format(const char* sha256);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
// ADMIN API ENDPOINTS
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Admin API request handler
|
||||
void handle_admin_api_request(const char* method, const char* uri);
|
||||
|
||||
// Individual endpoint handlers
|
||||
void handle_stats_api(void);
|
||||
void handle_config_get_api(void);
|
||||
void handle_config_put_api(void);
|
||||
void handle_files_api(void);
|
||||
void handle_health_api(void);
|
||||
|
||||
// Admin authentication functions
|
||||
int authenticate_admin_request(const char* auth_header);
|
||||
int is_admin_enabled(void);
|
||||
int verify_admin_pubkey(const char* event_pubkey);
|
||||
|
||||
// Admin API utility functions
|
||||
void send_json_response(int status, const char* json_content);
|
||||
void send_json_error(int status, const char* error, const char* message);
|
||||
int parse_query_params(const char* query_string, char params[][256], int max_params);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user