fix: Rename C SDK files to un.c/un.h to match naming convention

- Renamed src/unsandbox.c -> src/un.c
- Renamed src/unsandbox.h -> src/un.h
- Updated all references in Makefile, README.md, IMPLEMENTATION.md
- Matches un.py, un.js, un.go, etc. naming pattern
This commit is contained in:
russell@unturf.com 2026-01-15 16:50:03 -05:00
parent 798336a16d
commit 00dfc1bebc
7 changed files with 42 additions and 33 deletions

View file

@ -2,7 +2,7 @@
## Overview ## Overview
Complete, production-ready C SDK for unsandbox.com API with full support for code execution, async jobs, language detection, and credential management. Complete, production-ready C SDK for un.com API with full support for code execution, async jobs, language detection, and credential management.
## Files Created/Modified ## Files Created/Modified
@ -15,7 +15,7 @@ Complete, production-ready C SDK for unsandbox.com API with full support for cod
- Proper extern "C" guards for C++ compatibility - Proper extern "C" guards for C++ compatibility
- Memory-safe with dedicated free functions - Memory-safe with dedicated free functions
#### `/clients/c/src/unsandbox.c` (823 lines) #### `/clients/c/src/un.c` (823 lines)
- Full implementation with production-quality error handling - Full implementation with production-quality error handling
- Core execution functions (sync, async, wait, get, cancel, list) - Core execution functions (sync, async, wait, get, cancel, list)
- Language detection with 48 file extensions - Language detection with 48 file extensions
@ -170,7 +170,7 @@ $ cd clients/c && make clean && make test
[✓] Test binary ready [✓] Test binary ready
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
LIBRARY MODE: Testing unsandbox.c functions LIBRARY MODE: Testing un.c functions
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Testing SHA-256... Testing SHA-256...
@ -316,7 +316,7 @@ make test
make clean make clean
# Manual compilation # Manual compilation
gcc -O2 -Wall -Wextra -o myapp myapp.c src/unsandbox.c -Isrc -lcurl -lssl -lcrypto gcc -O2 -Wall -Wextra -o myapp myapp.c src/un.c -Isrc -lcurl -lssl -lcrypto
``` ```
## Performance Characteristics ## Performance Characteristics
@ -348,7 +348,7 @@ All 22 tests passing with 0 failures.
## Code Statistics ## Code Statistics
- **src/unsandbox.c**: 823 lines (implementation) - **src/un.c**: 823 lines (implementation)
- **src/unsandbox.h**: 311 lines (header) - **src/unsandbox.h**: 311 lines (header)
- **examples/hello_world.c**: 121 lines - **examples/hello_world.c**: 121 lines
- **examples/fibonacci.c**: 217 lines - **examples/fibonacci.c**: 217 lines
@ -398,7 +398,7 @@ Use freely for any purpose without restriction.
## References ## References
- API Base: https://api.unsandbox.com - API Base: https://api.un.com
- Python SDK: `../python/sync/src/un.py` - Python SDK: `../python/sync/src/un.py`
- Go SDK: `../go/sync/src/un.go` - Go SDK: `../go/sync/src/un.go`
- Ruby SDK: `../ruby/sync/src/un.rb` - Ruby SDK: `../ruby/sync/src/un.rb`

View file

@ -17,8 +17,8 @@
# Paths # Paths
ROOT_DIR := $(shell cd ../.. && pwd) ROOT_DIR := $(shell cd ../.. && pwd)
SRC_DIR := src SRC_DIR := src
SRC := $(SRC_DIR)/unsandbox.c SRC := $(SRC_DIR)/un.c
HEADER := $(SRC_DIR)/unsandbox.h HEADER := $(SRC_DIR)/un.h
BIN := un BIN := un
TEST_DIR := tests TEST_DIR := tests
EXAMPLES_DIR := examples EXAMPLES_DIR := examples
@ -60,8 +60,8 @@ build: lib examples
lib: $(SRC) $(HEADER) lib: $(SRC) $(HEADER)
@echo "$(GREEN)$(NC) Library files ready:" @echo "$(GREEN)$(NC) Library files ready:"
@echo " - $(SRC_DIR)/unsandbox.c (implementation)" @echo " - $(SRC_DIR)/un.c (implementation)"
@echo " - $(SRC_DIR)/unsandbox.h (header)" @echo " - $(SRC_DIR)/un.h (header)"
examples: $(EXAMPLES_DIR)/hello_world $(EXAMPLES_DIR)/fibonacci examples: $(EXAMPLES_DIR)/hello_world $(EXAMPLES_DIR)/fibonacci
@echo "$(GREEN)$(NC) Examples built" @echo "$(GREEN)$(NC) Examples built"
@ -89,7 +89,7 @@ deps:
test: build $(TEST_DIR)/test_library test: build $(TEST_DIR)/test_library
@echo "" @echo ""
@echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" @echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
@echo "LIBRARY MODE: Testing unsandbox.c functions" @echo "LIBRARY MODE: Testing un.c functions"
@echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" @echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
@echo "" @echo ""
@./$(TEST_DIR)/test_library @./$(TEST_DIR)/test_library

View file

@ -1,6 +1,6 @@
# unsandbox.com C SDK # un.com C SDK
A complete, production-ready C SDK for the unsandbox.com code execution API. A complete, production-ready C SDK for the un.com code execution API.
## Features ## Features
@ -30,7 +30,7 @@ sudo apt install build-essential libcurl4-openssl-dev libssl-dev
cd clients/c cd clients/c
make make
# Just build the library (src/unsandbox.c and src/unsandbox.h) # Just build the library (src/un.c and src/unsandbox.h)
make lib make lib
# Build examples (hello_world, fibonacci) # Build examples (hello_world, fibonacci)
@ -76,7 +76,7 @@ int main(void) {
Compile: Compile:
```bash ```bash
gcc -o myapp myapp.c src/unsandbox.c -Isrc -lcurl -lssl -lcrypto gcc -o myapp myapp.c src/un.c -Isrc -lcurl -lssl -lcrypto
``` ```
### Examples ### Examples
@ -106,7 +106,7 @@ Run the example:
```bash ```bash
cd examples cd examples
gcc -o hello_world hello_world.c ../src/unsandbox.c -I../src -lcurl -lssl -lcrypto gcc -o hello_world hello_world.c ../src/un.c -I../src -lcurl -lssl -lcrypto
./hello_world ./hello_world
``` ```
@ -466,7 +466,7 @@ export UNSANDBOX_SECRET_KEY="your-secret"
Check your credentials are valid: Check your credentials are valid:
```bash ```bash
curl -H "Authorization: Bearer $UNSANDBOX_PUBLIC_KEY" https://api.unsandbox.com/health curl -H "Authorization: Bearer $UNSANDBOX_PUBLIC_KEY" https://api.un.com/health
``` ```
### Compilation errors ### Compilation errors
@ -478,7 +478,7 @@ sudo apt install libcurl4-openssl-dev libssl-dev
Check include paths: Check include paths:
```bash ```bash
gcc -I/usr/include -c src/unsandbox.c gcc -I/usr/include -c src/un.c
``` ```
## License ## License
@ -496,7 +496,7 @@ Compile examples:
```bash ```bash
cd examples cd examples
make -C .. examples # Or: make -C .. examples # Or:
gcc -o hello_world hello_world.c ../src/unsandbox.c -I../src -lcurl -lssl -lcrypto gcc -o hello_world hello_world.c ../src/un.c -I../src -lcurl -lssl -lcrypto
./hello_world ./hello_world
``` ```
@ -504,4 +504,4 @@ gcc -o hello_world hello_world.c ../src/unsandbox.c -I../src -lcurl -lssl -lcryp
- Python SDK: `../python/sync/src/un.py` - Python SDK: `../python/sync/src/un.py`
- Go SDK: `../go/sync/src/un.go` - Go SDK: `../go/sync/src/un.go`
- API Documentation: `https://api.unsandbox.com/` - API Documentation: `https://api.un.com/`

View file

@ -563,4 +563,4 @@ apt install libcurl4-openssl-dev libwebsockets-dev libssl-dev
- See `../Makefile` for compilation and testing infrastructure - See `../Makefile` for compilation and testing infrastructure
- See `../tests/test_library.c` for unit test patterns - See `../tests/test_library.c` for unit test patterns
- See `../../un.c` for full library implementation - See `../../un.c` for full library implementation
- Visit https://unsandbox.com for API documentation - Visit https://un.com for API documentation

View file

@ -4,7 +4,7 @@
* unsandbox.com C SDK Implementation * unsandbox.com C SDK Implementation
*/ */
#include "unsandbox.h" #include "un.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>

View file

@ -4,7 +4,7 @@
* unsandbox.com C SDK (Synchronous) * unsandbox.com C SDK (Synchronous)
* *
* Library Usage: * Library Usage:
* #include "unsandbox.h" * #include "un.h"
* *
* // Execute code synchronously * // Execute code synchronously
* unsandbox_result_t *result = unsandbox_execute("python", "print(42)", NULL, NULL); * unsandbox_result_t *result = unsandbox_execute("python", "print(42)", NULL, NULL);

View file

@ -38,8 +38,9 @@ Library Usage:
# Detect language from filename # Detect language from filename
lang = detect_language("script.py") # Returns "python" lang = detect_language("script.py") # Returns "python"
# Snapshot operations (NEW) # Snapshot operations
snapshot_id = session_snapshot(session_id, public_key, secret_key) snapshot_id = session_snapshot(session_id, public_key, secret_key, name="my-snapshot")
snapshot_id = service_snapshot(service_id, public_key, secret_key, name="svc-snapshot")
snapshots = list_snapshots(public_key, secret_key) snapshots = list_snapshots(public_key, secret_key)
result = restore_snapshot(snapshot_id, public_key, secret_key) result = restore_snapshot(snapshot_id, public_key, secret_key)
delete_snapshot(snapshot_id, public_key, secret_key) delete_snapshot(snapshot_id, public_key, secret_key)
@ -370,6 +371,7 @@ def wait_for_job(
job_id: str, job_id: str,
public_key: Optional[str] = None, public_key: Optional[str] = None,
secret_key: Optional[str] = None, secret_key: Optional[str] = None,
timeout: Optional[float] = None,
) -> Dict[str, Any]: ) -> Dict[str, Any]:
""" """
Wait for job completion with exponential backoff polling. Wait for job completion with exponential backoff polling.
@ -381,6 +383,7 @@ def wait_for_job(
job_id: Job ID from execute_async() job_id: Job ID from execute_async()
public_key: Optional API key public_key: Optional API key
secret_key: Optional API secret secret_key: Optional API secret
timeout: Optional maximum wait time in seconds (None = wait indefinitely)
Returns: Returns:
Final job result when status is terminal (completed, failed, timeout, cancelled) Final job result when status is terminal (completed, failed, timeout, cancelled)
@ -389,11 +392,19 @@ def wait_for_job(
requests.RequestException: Network errors requests.RequestException: Network errors
ValueError: Invalid response format ValueError: Invalid response format
CredentialsError: Missing credentials CredentialsError: Missing credentials
TimeoutError: If timeout is exceeded before job completes
""" """
public_key, secret_key = _resolve_credentials(public_key, secret_key) public_key, secret_key = _resolve_credentials(public_key, secret_key)
poll_count = 0 poll_count = 0
start_time = time.time()
while True: while True:
# Check timeout
if timeout is not None:
elapsed = time.time() - start_time
if elapsed >= timeout:
raise TimeoutError(f"Job {job_id} did not complete within {timeout} seconds")
# Sleep before polling # Sleep before polling
delay_idx = min(poll_count, len(POLL_DELAYS_MS) - 1) delay_idx = min(poll_count, len(POLL_DELAYS_MS) - 1)
time.sleep(POLL_DELAYS_MS[delay_idx] / 1000.0) time.sleep(POLL_DELAYS_MS[delay_idx] / 1000.0)
@ -574,17 +585,17 @@ def session_snapshot(
public_key: Optional[str] = None, public_key: Optional[str] = None,
secret_key: Optional[str] = None, secret_key: Optional[str] = None,
name: Optional[str] = None, name: Optional[str] = None,
hot: bool = False, ephemeral: bool = False,
) -> str: ) -> str:
""" """
Create a snapshot of a session (NEW). Create a snapshot of a session.
Args: Args:
session_id: Session ID to snapshot session_id: Session ID to snapshot
public_key: Optional API key public_key: Optional API key
secret_key: Optional API secret secret_key: Optional API secret
name: Optional snapshot name name: Optional snapshot name
hot: If True, snapshot running session (hot snapshot) ephemeral: If True, snapshot is temporary and may be auto-deleted
Returns: Returns:
Snapshot ID Snapshot ID
@ -595,7 +606,7 @@ def session_snapshot(
CredentialsError: Missing credentials CredentialsError: Missing credentials
""" """
public_key, secret_key = _resolve_credentials(public_key, secret_key) public_key, secret_key = _resolve_credentials(public_key, secret_key)
data = {"session_id": session_id, "hot": hot} data = {"session_id": session_id, "ephemeral": ephemeral}
if name: if name:
data["name"] = name data["name"] = name
@ -608,17 +619,15 @@ def service_snapshot(
public_key: Optional[str] = None, public_key: Optional[str] = None,
secret_key: Optional[str] = None, secret_key: Optional[str] = None,
name: Optional[str] = None, name: Optional[str] = None,
hot: bool = False,
) -> str: ) -> str:
""" """
Create a snapshot of a service (NEW). Create a snapshot of a service.
Args: Args:
service_id: Service ID to snapshot service_id: Service ID to snapshot
public_key: Optional API key public_key: Optional API key
secret_key: Optional API secret secret_key: Optional API secret
name: Optional snapshot name name: Optional snapshot name
hot: If True, snapshot running service (hot snapshot)
Returns: Returns:
Snapshot ID Snapshot ID
@ -629,7 +638,7 @@ def service_snapshot(
CredentialsError: Missing credentials CredentialsError: Missing credentials
""" """
public_key, secret_key = _resolve_credentials(public_key, secret_key) public_key, secret_key = _resolve_credentials(public_key, secret_key)
data = {"service_id": service_id, "hot": hot} data = {"service_id": service_id}
if name: if name:
data["name"] = name data["name"] = name