2025-01-02 19:25:00 +00:00
|
|
|
/*
|
|
|
|
youtubeUnblock - https://github.com/Waujito/youtubeUnblock
|
|
|
|
|
|
|
|
Copyright (C) 2024-2025 Vadim Vetrov <vetrovvd@gmail.com>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2024-09-07 06:13:50 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "types.h"
|
|
|
|
#include <linux/moduleparam.h>
|
2024-09-28 19:45:35 +00:00
|
|
|
#include "types.h"
|
2024-12-08 13:06:50 +00:00
|
|
|
#include "args.h"
|
|
|
|
#include "logging.h"
|
2024-09-28 19:45:35 +00:00
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
#define MAX_ARGC 1024
|
2024-12-08 19:35:29 +00:00
|
|
|
static char *argv[MAX_ARGC];
|
2024-09-07 06:13:50 +00:00
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
static int params_set(const char *cval, const struct kernel_param *kp) {
|
|
|
|
int ret = 0;
|
2024-10-13 20:31:26 +00:00
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
int cv_len = strlen(cval);
|
|
|
|
if (cv_len >= 1 && cval[cv_len - 1] == '\n') {
|
|
|
|
cv_len--;
|
2024-09-15 19:02:04 +00:00
|
|
|
}
|
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
const char *ytb_prefix = "youtubeUnblock ";
|
|
|
|
int ytbp_len = strlen(ytb_prefix);
|
|
|
|
int len = cv_len + ytbp_len;
|
2024-09-07 06:13:50 +00:00
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
char *val = kmalloc(len + 1, GFP_KERNEL); // 1 for null-terminator
|
|
|
|
strncpy(val, ytb_prefix, ytbp_len);
|
|
|
|
strncpy(val + ytbp_len, cval, cv_len);
|
|
|
|
val[len] = '\0';
|
2024-09-07 06:13:50 +00:00
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
int argc = 0;
|
|
|
|
argv[argc++] = val;
|
|
|
|
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
if (val[i] == ' ') {
|
|
|
|
val[i] = '\0';
|
2024-09-15 19:02:04 +00:00
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
// safe because of null-terminator
|
|
|
|
if (val[i + 1] != ' ' && val[i + 1] != '\0') {
|
|
|
|
argv[argc++] = val + i + 1;
|
|
|
|
}
|
2024-09-07 06:13:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
ret = yparse_args(argc, argv);
|
|
|
|
kfree(val);
|
2024-09-07 06:13:50 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
static int params_get(char *buffer, const struct kernel_param *kp) {
|
|
|
|
size_t len = print_config(buffer, 4000);
|
|
|
|
return len;
|
2024-10-12 16:08:49 +00:00
|
|
|
}
|
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
static const struct kernel_param_ops params_ops = {
|
|
|
|
.set = params_set,
|
|
|
|
.get = params_get,
|
2024-10-12 16:08:49 +00:00
|
|
|
};
|
|
|
|
|
2024-12-08 13:06:50 +00:00
|
|
|
module_param_cb(parameters, ¶ms_ops, NULL, 0664);
|