Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions c_sourcecode/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SUBDIRS = src

EXTRA_DIST = README.md

# Clean up autotools-generated files
CLEANFILES = *~

# Distribution files
dist_doc_DATA = README.md
76 changes: 76 additions & 0 deletions c_sourcecode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Crashupload C Implementation - Skeleton Code

This directory contains skeleton C implementation for the crashupload migration from shell scripts to C.

## Architecture

Based on **optimized design** from:
- `docs/migration/hld/updateduploadDumps-hld.md`
- `docs/migration/lld/updateduploadDumps-lld.md`
- `docs/migration/diagrams/flowcharts/optimizeduploadDumps-flowcharts.md`
- `docs/migration/diagrams/sequence/updateuploadDumps-sequence.md`
- `docs/migration/requirements/uploadDumps-requirements.md`

## Structure

```
c_sourcecode/
β”œβ”€β”€ common/ # Common type definitions, constants, errors
β”‚ β”œβ”€β”€ types.h
β”‚ β”œβ”€β”€ constants.h
β”‚ └── errors.h
β”œβ”€β”€ src/ # Source code
β”‚ β”œβ”€β”€ main.c # Main entry point (7-step optimized flow)
β”‚ β”œβ”€β”€ init/ # Consolidated initialization
β”‚ β”œβ”€β”€ config/ # Configuration management
β”‚ β”œβ”€β”€ platform/ # Platform abstraction
β”‚ β”œβ”€β”€ core/ # Core processing modules
β”‚ β”‚ β”œβ”€β”€ scanner.* # Dump file scanner
β”‚ β”‚ β”œβ”€β”€ archive_smart.* # Smart archive creator
β”‚ β”‚ β”œβ”€β”€ upload_typeaware.* # Type-aware upload
β”‚ β”‚ └── ratelimit_unified.* # Unified rate limiter
β”‚ β”œβ”€β”€ utils/ # Utility modules
β”‚ β”‚ β”œβ”€β”€ prerequisites.* # Combined network+time check
β”‚ β”‚ β”œβ”€β”€ privacy.* # Unified privacy check
β”‚ β”‚ β”œβ”€β”€ cleanup_batch.* # Batch cleanup
β”‚ β”‚ β”œβ”€β”€ lock_manager.* # Process locking
β”‚ β”‚ └── logger.* # Logging
β”‚ └── Makefile # Build system
```

## Key Optimizations

1. **Consolidated Initialization** - Single `system_initialize()` call (3 steps β†’ 1)
2. **Combined Prerequisites** - `prerequisites_wait()` checks network + time together
3. **Unified Privacy** - `privacy_uploads_blocked()` combines opt-out + privacy mode
4. **Smart Archive** - Direct compression first, /tmp fallback if needed
5. **Type-Aware Upload** - Minidump (5 retries, 3s delay) vs Coredump (3 retries, 10s delay)
6. **Unified Rate Limit** - Single check for recovery + 10/10min limit
7. **Batch Cleanup** - Single directory scan for all cleanup operations

## Building

```bash
cd src
make
```

## Status

**SKELETON**: All files contain function signatures and data structures from the design documents, but function bodies need implementation. Each TODO comment indicates what needs to be implemented.

## Next Steps

1. Implement function bodies following TODO markers
2. Add unit tests (GTest framework recommended)
3. Build and test incrementally
4. Validate against shell script behavior
5. Performance test on target platforms

## Performance Targets

Based on optimized design:
- Startup: 100-120ms (vs 150-200ms standard)
- Memory: 6-8MB (vs 8-10MB standard)
- Binary: ~35KB (vs ~45KB standard)
- Decision points: 22 (vs 35 standard) - 37% reduction
55 changes: 55 additions & 0 deletions c_sourcecode/common/constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @file constants.h
* @brief Constants and macros for crashupload C implementation
*
* Based on docs/migration/requirements/uploadDumps-requirements.md
* Following optimized design specifications
*/

#ifndef CRASHUPLOAD_CONSTANTS_H
#define CRASHUPLOAD_CONSTANTS_H

/* Application constants */
#define APP_NAME "crashupload"
#define APP_VERSION "2.0.0"

/* Path constants */
#define MAX_PATH_LEN 512
#define MAX_FILENAME_LEN 256
#define ECRYPTFS_MAX_FILENAME 135

/* Upload constants */
#define DEFAULT_UPLOAD_TIMEOUT 45
#define MAX_RETRIES_MINIDUMP 5
#define MAX_RETRIES_COREDUMP 3
#define RETRY_DELAY_MINIDUMP 3
#define RETRY_DELAY_COREDUMP 10

/* Rate limiting constants */
#define RATE_LIMIT_MAX_UPLOADS 10
#define RATE_LIMIT_WINDOW_SEC 600 /* 10 minutes */
#define CRASHLOOP_MAX_UPLOADS 5
#define CRASHLOOP_WINDOW_SEC 60 /* 1 minute */
#define RECOVERY_BLOCK_FILE "/tmp/.crashupload_recovery"
#define RATELIMIT_STATE_FILE "/tmp/.crashupload_ratelimit"

/* Processing constants */
#define MAX_DUMPS_PER_RUN 100
#define FILE_AGE_CLEANUP_DAYS 2

/* Lock constants */
#define LOCK_FILE "/var/run/crashupload.lock"
#define LOCK_TIMEOUT_SEC 300

/* Configuration file paths */
#define DEVICE_PROPERTIES "/etc/device.properties"
#define INCLUDE_PROPERTIES "/etc/include.properties"

/* Logging constants */
#define LOG_BUFFER_SIZE 512

/* Network constants */
#define PREREQUISITE_TIMEOUT_SEC 120
#define NETWORK_CHECK_INTERVAL_SEC 5

#endif /* CRASHUPLOAD_CONSTANTS_H */
64 changes: 64 additions & 0 deletions c_sourcecode/common/errors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* @file errors.h
* @brief Error codes for crashupload C implementation
*
* Based on docs/migration/lld/updateduploadDumps-lld.md
* Consistent error code scheme across all modules
*/

#ifndef CRASHUPLOAD_ERRORS_H
#define CRASHUPLOAD_ERRORS_H

/* Success */
#define ERR_SUCCESS 0

/* General errors (1-19) */
#define ERR_GENERAL_FAILURE 1
#define ERR_INVALID_ARGUMENT 2
#define ERR_OUT_OF_MEMORY 3
#define ERR_NOT_IMPLEMENTED 4

/* Configuration errors (20-39) */
#define ERR_CONFIG_LOAD_FAILED 20
#define ERR_CONFIG_INVALID 21
#define ERR_CONFIG_MISSING_REQUIRED 22

/* Platform errors (40-59) */
#define ERR_PLATFORM_INIT_FAILED 40
#define ERR_PLATFORM_UNSUPPORTED 41
#define ERR_PLATFORM_MAC_FAILED 42
#define ERR_PLATFORM_MODEL_FAILED 43

/* Scanner errors (60-79) */
#define ERR_SCANNER_NO_DUMPS 60
#define ERR_SCANNER_PATH_INVALID 61
#define ERR_SCANNER_READ_FAILED 62

/* Archive errors (80-99) */
#define ERR_ARCHIVE_CREATE_FAILED 80
#define ERR_ARCHIVE_COMPRESS_FAILED 81
#define ERR_ARCHIVE_FALLBACK_FAILED 82

/* Upload errors (100-119) */
#define ERR_UPLOAD_FAILED 100
#define ERR_UPLOAD_NETWORK 101
#define ERR_UPLOAD_TIMEOUT 102
#define ERR_UPLOAD_SERVER_ERROR 103

/* Rate limit errors (120-139) */
#define ERR_RATELIMIT_EXCEEDED 120
#define ERR_RATELIMIT_RECOVERY_MODE 121
#define ERR_RATELIMIT_STATE_FAILED 122

/* Lock errors (140-159) */
#define ERR_LOCK_FAILED 140
#define ERR_LOCK_TIMEOUT 141
#define ERR_LOCK_ALREADY_HELD 142

/* Privacy/prerequisite errors (160-179) */
#define ERR_PRIVACY_BLOCKED 160
#define ERR_PREREQUISITE_TIMEOUT 161
#define ERR_NETWORK_NOT_READY 162
#define ERR_TIME_NOT_SYNCED 163

#endif /* CRASHUPLOAD_ERRORS_H */
89 changes: 89 additions & 0 deletions c_sourcecode/common/types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* @file types.h
* @brief Common type definitions for crashupload C implementation
*
* Based on docs/migration/hld/updateduploadDumps-hld.md
* Following optimized architecture with consolidated modules
*/

#ifndef CRASHUPLOAD_TYPES_H
#define CRASHUPLOAD_TYPES_H

#include <stdint.h>
#include <stdbool.h>
#include <time.h>

/* Device types */
typedef enum {
DEVICE_TYPE_BROADBAND,
DEVICE_TYPE_VIDEO,
DEVICE_TYPE_EXTENDER,
DEVICE_TYPE_MEDIACLIENT,
DEVICE_TYPE_UNKNOWN
} device_type_t;

/* Dump file types */
typedef enum {
DUMP_TYPE_MINIDUMP,
DUMP_TYPE_COREDUMP,
DUMP_TYPE_UNKNOWN
} dump_type_t;

/* Upload result types */
typedef enum {
UPLOAD_SUCCESS,
UPLOAD_FAILURE_RETRY,
UPLOAD_FAILURE_REMOVE,
UPLOAD_FAILURE_SAVE
} upload_result_t;

/* Rate limit decision */
typedef enum {
RATELIMIT_ALLOW,
RATELIMIT_BLOCK_RECOVERY,
RATELIMIT_BLOCK_LIMIT
} ratelimit_decision_t;

/* Configuration structure (consolidated from HLD) */
typedef struct {
device_type_t device_type;
char upload_url[512];
char dump_path[256];
char core_path[256];
char minidump_path[256];
char archive_path[256];
char log_file[256];
bool t2_enabled;
bool privacy_mode;
bool opt_out;
int max_dumps_per_run;
int upload_timeout;
} config_t;

/* Platform configuration structure */
typedef struct {
char mac_address[18];
char ip_address[16];
char model[64];
char device_id[128];
char firmware_version[64];
char platform_sha1[41];
} platform_config_t;

/* Dump file metadata */
typedef struct {
char filepath[512];
char basename[256];
dump_type_t type;
time_t mtime;
off_t size;
} dump_file_t;

/* Archive info structure */
typedef struct {
char archive_path[512];
char archive_name[256];
bool created_in_tmp;
} archive_info_t;

#endif /* CRASHUPLOAD_TYPES_H */
53 changes: 53 additions & 0 deletions c_sourcecode/configure.ac
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT([crashupload], [1.0], [support@rdkcentral.com])
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects])
AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_HEADERS([config.h])

# Checks for programs.
AC_PROG_CC
AC_PROG_CC_C11
AM_PROG_AR

# Checks for libraries.
PKG_CHECK_MODULES([LIBCURL], [libcurl >= 7.0])
PKG_CHECK_MODULES([OPENSSL], [openssl >= 1.0])
PKG_CHECK_MODULES([ZLIB], [zlib >= 1.2])

# Checks for header files.
AC_CHECK_HEADERS([fcntl.h stdlib.h string.h sys/time.h unistd.h])
AC_CHECK_HEADERS([curl/curl.h openssl/ssl.h zlib.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_TYPE_UINT64_T

# Checks for library functions.
AC_FUNC_MALLOC
AC_CHECK_FUNCS([gettimeofday memset strchr strdup strerror])

# Compiler flags
CFLAGS="$CFLAGS -Wall -Werror -O2 -std=c11"
CFLAGS="$CFLAGS -D_POSIX_C_SOURCE=200809L"

AC_CONFIG_FILES([Makefile
src/Makefile])
AC_OUTPUT

echo ""
echo "Configuration Summary:"
echo "======================"
echo " Package: ${PACKAGE_NAME} ${PACKAGE_VERSION}"
echo " C Compiler: ${CC}"
echo " CFLAGS: ${CFLAGS}"
echo " LIBCURL_CFLAGS: ${LIBCURL_CFLAGS}"
echo " LIBCURL_LIBS: ${LIBCURL_LIBS}"
echo " OPENSSL_CFLAGS: ${OPENSSL_CFLAGS}"
echo " OPENSSL_LIBS: ${OPENSSL_LIBS}"
echo " ZLIB_CFLAGS: ${ZLIB_CFLAGS}"
echo " ZLIB_LIBS: ${ZLIB_LIBS}"
echo ""
Loading
Loading