Skip to content

Commit 3d86950

Browse files
Update for sh_integration v4.0.0 refactoring
1 parent 65458e4 commit 3d86950

7 files changed

Lines changed: 47 additions & 45 deletions

File tree

extractor/main.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ void index_file(char *path, char* filename, bool new) {
187187
fileTypeEndPointer = b64Pointer;
188188
}
189189

190-
char* fileType = malloc(fileTypeEndPointer - fileTypePointer + 1);
191-
strncpy(fileType, fileTypePointer, fileTypeEndPointer - fileTypePointer);
190+
char* fileType = malloc((size_t) (fileTypeEndPointer - fileTypePointer + 1));
191+
strncpy(fileType, fileTypePointer, (size_t) (fileTypeEndPointer - fileTypePointer));
192192
fileType[fileTypeEndPointer - fileTypePointer] = '\0';
193193

194194
char* icon_sdr_path = asprintf_hd( "%s/icon.%s", sdr_path, fileType);
@@ -204,15 +204,15 @@ void index_file(char *path, char* filename, bool new) {
204204
if (header.icon[i] >= 'A' && header.icon[i] <= 'Z') {
205205
value = header.icon[i] - 'A';
206206
} else if (header.icon[i] >= 'a' && header.icon[i] <= 'z') {
207-
value = (header.icon[i] - 'a') + 26;
207+
value = (char) (header.icon[i] - 'a') + 26;
208208
} else if (header.icon[i] >= '0' && header.icon[i] <= '9') {
209-
value = (header.icon[i] - '0') + 52;
209+
value = (char) (header.icon[i] - '0') + 52;
210210
} else if (header.icon[i] == '+') {
211211
value = 62;
212212
} else if (header.icon[i] == '/') {
213213
value = 63;
214214
} else if (header.icon[i] != '=') {
215-
Log("Invalid B64 at position %i", i); // Warn
215+
Log("Invalid B64 at position %zu", i); // Warn
216216
}
217217

218218
// Add data to the currentByte
@@ -231,7 +231,7 @@ void index_file(char *path, char* filename, bool new) {
231231

232232
// Set new currentByte to leftover bits
233233
currentByte = 0;
234-
currentByte |= value << (2 + consumedBits);
234+
currentByte |= (char) value << (2 + consumedBits);
235235
processedBits = 6 - consumedBits;
236236
}
237237
}
@@ -348,7 +348,7 @@ void remove_file(const char* path, const char* filename, char* uuid) {
348348
const int pid = fork();
349349
if (pid == 0) {
350350
Log("Hello from fork!");
351-
char* command = buildCommand("source \"%s\"; on_remove;", escapedPath);
351+
char* command = asprintf_hd("source \"%s\"; on_remove;", escapedPath);
352352
Log("Executing command: %s", command);
353353
free(escapedPath);
354354
execl("/var/local/mkk/su", command, NULL);
@@ -367,7 +367,7 @@ void remove_file(const char* path, const char* filename, char* uuid) {
367367
if (access(sdrPath, R_OK|W_OK) == F_OK)
368368
{
369369
Log("SDR exists - deleting");
370-
recursiveDelete(sdrPath);
370+
rmdir_r(sdrPath);
371371
}
372372

373373
free(sdrPath);

launcher/main.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ bool shouldExit = false;
3434
LIPCcode stub(LIPC *lipc, const char *property, void *value, void*) {
3535
Log("Stub called for \"%s\" with value \"%s\"", property,
3636
(char *)value);
37-
char* mutValue = strdup(value);
37+
char* mutValue = strdup((char*) value);
3838
char *id = strtok((char *)mutValue, ":");
3939
char *response = asprintf_hd("%s:0:", id);
4040
Log("Replying with %s", response);
@@ -69,7 +69,7 @@ LIPCcode unload_callback(LIPC* lipc, const char* property, void* value, void* da
6969
return result;
7070
}
7171

72-
char* getScriptCommand(char* scriptPath)
72+
char* getScriptCommand(const char* scriptPath)
7373
{
7474
Log("Loading script file");
7575
FILE* file = fopen(scriptPath, "r");
@@ -94,18 +94,18 @@ char* getScriptCommand(char* scriptPath)
9494
escapedPath[escapedPathLength] = '\0';
9595

9696
Log("Building command");
97-
char* command = buildCommand("sh -l \"%s\"", escapedPath);
97+
char* command = asprintf_hd("sh -l \"%s\"", escapedPath);
9898

9999
if (header.useHooks) { // useHooks script - source it and use `on_run`
100100
Log("Script uses hooks!");
101101
free(command);
102-
command = buildCommand("sh -l -c \"source \\\"%s\\\"; on_run;\"", escapedPath);
102+
command = asprintf_hd("sh -l -c \"source \\\"%s\\\"; on_run;\"", escapedPath);
103103
}
104104
if (header.useFBInk) {
105105
Log("Script uses FBInk!");
106106
char* old_command = strdup(command);
107107
free(command);
108-
command = buildCommand("/mnt/us/libkh/bin/fbink -k; %s 2>&1 | /mnt/us/libkh/bin/fbink -y 5 -r", old_command);
108+
command = asprintf_hd("/mnt/us/libkh/bin/fbink -k; %s 2>&1 | /mnt/us/libkh/bin/fbink -y 5 -r", old_command);
109109
free(old_command);
110110
}
111111

@@ -117,7 +117,7 @@ char* getScriptCommand(char* scriptPath)
117117

118118
LIPCcode go_callback(LIPC* lipc, const char* property, void* value, void* data) {
119119
Log("go_callback");
120-
char* rawFilePath = strchr((const char*)value, ':') + 6 + strlen(SERVICE_NAME) + 1;
120+
char* rawFilePath = strchr((char*)value, ':') + 6 + strlen(SERVICE_NAME) + 1;
121121
char* query = strchr(rawFilePath, '?');
122122
if (query != NULL) {
123123
query[0] = 0;

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
project('sh_integration', 'c', version : '4.0.0', default_options: ['warning_level=everything'])
1+
project('sh_integration', 'c', version : '4.0.0', default_options: ['warning_level=everything', 'c_std=gnu23'])
22

33
arch = meson.get_external_property('arch', 'armhf')
44
if arch == 'armhf'

tests/launcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
LIPCcode stub(LIPC* lipc, const char* property, void* value, void* data);
1111
LIPCcode pause_callback(LIPC* lipc, const char* property, void* value, void* data);
12-
char* getScriptCommand(char* scriptPath);
12+
char* getScriptCommand(const char* scriptPath);
1313
LIPCcode go_callback(LIPC* lipc, const char* property, void* value, void* data);
1414
LIPCcode unload_callback(LIPC* lipc, const char* property, void* value, void* data);

tests/utils_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int main()
2828
assert(testURLDecode("Testing", "Testing"));
2929

3030

31-
char* command = buildCommand("test %s testing", "hello");
31+
char* command = asprintf_hd("test %s testing", "hello");
3232
assert(strcmp(command, "test hello testing") == 0);
3333

3434
FILE* file = fopen("./tests/test.sh", "r+");

utils/utils.c

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#include <stddef.h>
55
#include <stdlib.h>
66
#include <string.h>
7+
#include <unistd.h>
8+
9+
#define __USE_XOPEN_EXTENDED /* See feature_test_macros(7) */
10+
#include <ftw.h>
711

812
/**
913
* @brief vasprintf implementation
@@ -16,8 +20,8 @@ char* vasprintf_hd(const char * format, va_list args)
1620
{
1721
va_list args2;
1822
va_copy (args2, args);
19-
int size = vsnprintf(NULL, 0, format, args) + 1;
20-
char* str = malloc(size);
23+
size_t size = vsnprintf(NULL, 0, format, args) + 1;
24+
char* str = (char*) malloc(size);
2125
vsnprintf(str, size, format, args2);
2226
va_end(args2);
2327
return str;
@@ -38,7 +42,7 @@ char* asprintf_hd(const char * format, ...)
3842
va_end(args);
3943
}
4044

41-
int hexDecode(char c)
45+
int hexDecode(const char c)
4246
{
4347
if (c >= '0' && c <= '9')
4448
{
@@ -84,32 +88,32 @@ void strip(char** string)
8488
*string = finalString;
8589
}
8690

87-
char* buildCommand(const char* command, const char* sub)
91+
int internal_delete(const char* fpath, const struct stat*, int typeflag, struct FTW*)
8892
{
89-
char* builtCommand = asprintf_hd(command, sub);
90-
return builtCommand;
93+
switch (typeflag)
94+
{
95+
case FTW_F:
96+
remove(fpath);
97+
break;
98+
case FTW_D:
99+
case FTW_DP:
100+
rmdir(fpath);
101+
break;
102+
default:
103+
break;
104+
}
105+
return 0;
91106
}
92107

93-
void recursiveDelete(char* path)
108+
/**
109+
* @brief Deletes a folder recursively, equivalent to "rm -rf"
110+
*
111+
* @param path
112+
*/
113+
void rmdir_r(char* path)
94114
{
95-
DIR* dir = opendir(path);
96-
struct dirent* item;
97-
while ((item = readdir(dir)) != NULL)
98-
{
99-
if (strcmp(item->d_name, ".") == 0 || strcmp(item->d_name, "..") == 0)
100-
{
101-
continue;
102-
}
103-
char* itemPath = asprintf_hd("%s/%s", path, item->d_name);
104-
if (item->d_type == DT_DIR)
105-
{
106-
recursiveDelete(itemPath);
107-
}
108-
remove(itemPath);
109-
free(itemPath);
110-
}
111-
remove(path);
112-
closedir(dir);
115+
nftw(path, &internal_delete, 256, FTW_DEPTH);
116+
rmdir(path);
113117
}
114118

115119
void freeScriptHeader(struct ScriptHeader* header)

utils/utils.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ int hexDecode(char c);
1212
char* urlDecode(char* raw);
1313
void strip(char** string);
1414

15-
void recursiveDelete(char* path);
16-
17-
char* buildCommand(const char* command, const char* sub);
15+
void rmdir_r(char* path);
1816

1917
struct ScriptHeader
2018
{

0 commit comments

Comments
 (0)