using namespace clang;
namespace rspamd {
- struct PrintfArgChecker;
+struct PrintfArgChecker;
- static bool cstring_arg_handler (const Expr *arg,
- struct PrintfArgChecker *ctx);
+static bool cstring_arg_handler(const Expr *arg,
+ struct PrintfArgChecker *ctx);
- static bool int_arg_handler (const Expr *arg,
- struct PrintfArgChecker *ctx);
+static bool int_arg_handler(const Expr *arg,
+ struct PrintfArgChecker *ctx);
- static bool long_arg_handler (const Expr *arg,
- struct PrintfArgChecker *ctx);
+static bool long_arg_handler(const Expr *arg,
+ struct PrintfArgChecker *ctx);
- static bool size_arg_handler (const Expr *arg,
- struct PrintfArgChecker *ctx);
+static bool size_arg_handler(const Expr *arg,
+ struct PrintfArgChecker *ctx);
- static bool char_arg_handler (const Expr *arg,
- struct PrintfArgChecker *ctx);
+static bool char_arg_handler(const Expr *arg,
+ struct PrintfArgChecker *ctx);
- static bool double_arg_handler (const Expr *arg,
- struct PrintfArgChecker *ctx);
+static bool double_arg_handler(const Expr *arg,
+ struct PrintfArgChecker *ctx);
- static bool long_double_arg_handler (const Expr *arg,
- struct PrintfArgChecker *ctx);
+static bool long_double_arg_handler(const Expr *arg,
+ struct PrintfArgChecker *ctx);
- static bool pointer_arg_handler (const Expr *arg,
- struct PrintfArgChecker *ctx);
+static bool pointer_arg_handler(const Expr *arg,
+ struct PrintfArgChecker *ctx);
- static bool pid_arg_handler (const Expr *arg,
- struct PrintfArgChecker *ctx);
+static bool pid_arg_handler(const Expr *arg,
+ struct PrintfArgChecker *ctx);
- static bool time_arg_handler (const Expr *arg,
- struct PrintfArgChecker *ctx);
+static bool time_arg_handler(const Expr *arg,
+ struct PrintfArgChecker *ctx);
- static bool int64_arg_handler (const Expr *arg,
- struct PrintfArgChecker *ctx);
+static bool int64_arg_handler(const Expr *arg,
+ struct PrintfArgChecker *ctx);
- static bool int32_arg_handler (const Expr *arg,
- struct PrintfArgChecker *ctx);
+static bool int32_arg_handler(const Expr *arg,
+ struct PrintfArgChecker *ctx);
- static bool tok_arg_handler (const Expr *arg,
- struct PrintfArgChecker *ctx);
+static bool tok_arg_handler(const Expr *arg,
+ struct PrintfArgChecker *ctx);
- static bool fstring_arg_handler (const Expr *arg,
- struct PrintfArgChecker *ctx);
+static bool fstring_arg_handler(const Expr *arg,
+ struct PrintfArgChecker *ctx);
- static bool gstring_arg_handler (const Expr *arg,
- struct PrintfArgChecker *ctx);
+static bool gstring_arg_handler(const Expr *arg,
+ struct PrintfArgChecker *ctx);
- static bool gerr_arg_handler (const Expr *arg,
- struct PrintfArgChecker *ctx);
+static bool gerr_arg_handler(const Expr *arg,
+ struct PrintfArgChecker *ctx);
- using arg_parser_t = bool (*) (const Expr *, struct PrintfArgChecker *);
+using arg_parser_t = bool (*)(const Expr *, struct PrintfArgChecker *);
- static void
- print_error (const char *err, const Expr *e, const ASTContext *ast,
+static void
+print_error(const char *err, const Expr *e, const ASTContext *ast,
CompilerInstance *ci)
+{
+ auto loc = e->getExprLoc();
+ auto &diag = ci->getDiagnostics();
+ auto id = diag.getCustomDiagID(DiagnosticsEngine::Error,
+ "format query error: %0");
+ diag.Report(loc, id) << err;
+}
+
+static void
+print_warning(const char *err, const Expr *e, const ASTContext *ast,
+ CompilerInstance *ci)
+{
+ auto loc = e->getExprLoc();
+ auto &diag = ci->getDiagnostics();
+ auto id = diag.getCustomDiagID(DiagnosticsEngine::Warning,
+ "format query warning: %0");
+ diag.Report(loc, id) << err;
+}
+
+static void
+print_remark(const char *err, const Expr *e, const ASTContext *ast,
+ CompilerInstance *ci)
+{
+ auto loc = e->getExprLoc();
+ auto &diag = ci->getDiagnostics();
+ auto id = diag.getCustomDiagID(DiagnosticsEngine::Remark,
+ "format query warning: %0");
+ diag.Report(loc, id) << err;
+}
+
+struct PrintfArgChecker {
+private:
+ arg_parser_t parser;
+
+public:
+ int width;
+ int precision;
+ bool is_unsigned;
+ ASTContext *past;
+ CompilerInstance *pci;
+
+ PrintfArgChecker(arg_parser_t _p, ASTContext *_ast, CompilerInstance *_ci)
+ : parser(_p), past(_ast), pci(_ci)
{
- auto loc = e->getExprLoc ();
- auto &diag = ci->getDiagnostics ();
- auto id = diag.getCustomDiagID (DiagnosticsEngine::Error,
- "format query error: %0");
- diag.Report (loc, id) << err;
+ width = 0;
+ precision = 0;
+ is_unsigned = false;
}
- static void
- print_warning (const char *err, const Expr *e, const ASTContext *ast,
- CompilerInstance *ci)
+ virtual ~PrintfArgChecker()
{
- auto loc = e->getExprLoc ();
- auto &diag = ci->getDiagnostics ();
- auto id = diag.getCustomDiagID (DiagnosticsEngine::Warning,
- "format query warning: %0");
- diag.Report (loc, id) << err;
}
- static void
- print_remark (const char *err, const Expr *e, const ASTContext *ast,
- CompilerInstance *ci)
+ bool operator()(const Expr *e)
{
- auto loc = e->getExprLoc ();
- auto &diag = ci->getDiagnostics ();
- auto id = diag.getCustomDiagID (DiagnosticsEngine::Remark,
- "format query warning: %0");
- diag.Report (loc, id) << err;
+ return parser(e, this);
}
+};
- struct PrintfArgChecker {
- private:
- arg_parser_t parser;
- public:
- int width;
- int precision;
- bool is_unsigned;
- ASTContext *past;
- CompilerInstance *pci;
-
- PrintfArgChecker (arg_parser_t _p, ASTContext *_ast, CompilerInstance *_ci) :
- parser (_p), past (_ast), pci(_ci)
- {
- width = 0;
- precision = 0;
- is_unsigned = false;
- }
+class PrintfCheckVisitor::impl {
+ std::unordered_map<std::string, unsigned int> printf_functions;
+ std::unordered_set<char> format_specs;
+ ASTContext *pcontext;
+ CompilerInstance *ci;
- virtual ~PrintfArgChecker ()
- {
+ std::unique_ptr<PrintfArgChecker> parseFlags(const std::string &flags,
+ const Expr *e)
+ {
+ auto type = flags.back();
+
+ switch (type) {
+ case 's':
+ return std::make_unique<PrintfArgChecker>(cstring_arg_handler,
+ this->pcontext, this->ci);
+ case 'd':
+ return std::make_unique<PrintfArgChecker>(int_arg_handler,
+ this->pcontext, this->ci);
+ case 'z':
+ return std::make_unique<PrintfArgChecker>(size_arg_handler,
+ this->pcontext, this->ci);
+ case 'l':
+ return std::make_unique<PrintfArgChecker>(long_arg_handler,
+ this->pcontext, this->ci);
+ case 'f':
+ case 'g':
+ return std::make_unique<PrintfArgChecker>(double_arg_handler,
+ this->pcontext, this->ci);
+ case 'F':
+ case 'G':
+ return std::make_unique<PrintfArgChecker>(
+ long_double_arg_handler,
+ this->pcontext, this->ci);
+ case 'c':
+ return std::make_unique<PrintfArgChecker>(char_arg_handler,
+ this->pcontext, this->ci);
+ case 'p':
+ return std::make_unique<PrintfArgChecker>(pointer_arg_handler,
+ this->pcontext, this->ci);
+ case 'P':
+ return std::make_unique<PrintfArgChecker>(pid_arg_handler,
+ this->pcontext, this->ci);
+ case 't':
+ return std::make_unique<PrintfArgChecker>(time_arg_handler,
+ this->pcontext, this->ci);
+ case 'L':
+ return std::make_unique<PrintfArgChecker>(int64_arg_handler,
+ this->pcontext, this->ci);
+ case 'D':
+ return std::make_unique<PrintfArgChecker>(int32_arg_handler,
+ this->pcontext, this->ci);
+ case 'T':
+ return std::make_unique<PrintfArgChecker>(tok_arg_handler,
+ this->pcontext, this->ci);
+ case 'V':
+ return std::make_unique<PrintfArgChecker>(fstring_arg_handler,
+ this->pcontext, this->ci);
+ case 'v':
+ return std::make_unique<PrintfArgChecker>(gstring_arg_handler,
+ this->pcontext, this->ci);
+ case 'e':
+ return std::make_unique<PrintfArgChecker>(gerr_arg_handler,
+ this->pcontext, this->ci);
+ default: {
+ auto err_msg = std::string("unknown parser flag: ") + type;
+ print_warning(err_msg.c_str(),
+ e, this->pcontext, this->ci);
+ break;
}
-
- bool operator() (const Expr *e)
- {
- return parser (e, this);
}
- };
- class PrintfCheckVisitor::impl {
- std::unordered_map<std::string, unsigned int> printf_functions;
- std::unordered_set<char> format_specs;
- ASTContext *pcontext;
- CompilerInstance *ci;
-
- std::unique_ptr <PrintfArgChecker> parseFlags (const std::string &flags,
- const Expr *e)
- {
- auto type = flags.back ();
-
- switch (type) {
- case 's':
- return std::make_unique<PrintfArgChecker> (cstring_arg_handler,
- this->pcontext, this->ci);
- case 'd':
- return std::make_unique<PrintfArgChecker> (int_arg_handler,
- this->pcontext, this->ci);
- case 'z':
- return std::make_unique<PrintfArgChecker> (size_arg_handler,
- this->pcontext, this->ci);
- case 'l':
- return std::make_unique<PrintfArgChecker> (long_arg_handler,
- this->pcontext, this->ci);
- case 'f':
- case 'g':
- return std::make_unique<PrintfArgChecker> (double_arg_handler,
- this->pcontext, this->ci);
- case 'F':
- case 'G':
- return std::make_unique<PrintfArgChecker> (
- long_double_arg_handler,
- this->pcontext, this->ci);
- case 'c':
- return std::make_unique<PrintfArgChecker> (char_arg_handler,
- this->pcontext, this->ci);
- case 'p':
- return std::make_unique<PrintfArgChecker> (pointer_arg_handler,
- this->pcontext, this->ci);
- case 'P':
- return std::make_unique<PrintfArgChecker> (pid_arg_handler,
- this->pcontext, this->ci);
- case 't':
- return std::make_unique<PrintfArgChecker> (time_arg_handler,
- this->pcontext, this->ci);
- case 'L':
- return std::make_unique<PrintfArgChecker> (int64_arg_handler,
- this->pcontext, this->ci);
- case 'D':
- return std::make_unique<PrintfArgChecker> (int32_arg_handler,
- this->pcontext, this->ci);
- case 'T':
- return std::make_unique<PrintfArgChecker> (tok_arg_handler,
- this->pcontext, this->ci);
- case 'V':
- return std::make_unique<PrintfArgChecker> (fstring_arg_handler,
- this->pcontext, this->ci);
- case 'v':
- return std::make_unique<PrintfArgChecker> (gstring_arg_handler,
- this->pcontext, this->ci);
- case 'e':
- return std::make_unique<PrintfArgChecker> (gerr_arg_handler,
- this->pcontext, this->ci);
- default: {
- auto err_msg = std::string ("unknown parser flag: ") + type;
- print_warning (err_msg.c_str(),
- e, this->pcontext, this->ci);
+ return nullptr;
+ }
+
+ std::shared_ptr<std::vector<PrintfArgChecker>>
+ genParsers(const StringRef query, const Expr *e)
+ {
+ enum {
+ ignore_chars = 0,
+ read_percent,
+ read_width,
+ read_precision,
+ read_arg
+ } state = ignore_chars;
+ int width, precision;
+ std::string flags;
+
+ auto res = std::make_shared<std::vector<PrintfArgChecker>>();
+
+ for (auto citer = query.begin(); citer != query.end(); ++citer) {
+ auto c = *citer;
+
+ switch (state) {
+ case ignore_chars:
+ if (c == '%') {
+ state = read_percent;
+ flags.clear();
+ width = precision = 0;
+ }
break;
+ case read_percent:
+ if (isdigit(c)) {
+ state = read_width;
+ width = c - '0';
}
- }
-
- return nullptr;
- }
+ else if (c == '.') {
+ state = read_precision;
+ precision = c - '0';
+ }
+ else if (c == '*') {
+ /* %*s - need integer argument */
+ res->emplace_back(int_arg_handler, this->pcontext,
+ this->ci);
- std::shared_ptr <std::vector<PrintfArgChecker>>
- genParsers (const StringRef query, const Expr *e)
- {
- enum {
- ignore_chars = 0,
- read_percent,
- read_width,
- read_precision,
- read_arg
- } state = ignore_chars;
- int width, precision;
- std::string flags;
-
- auto res = std::make_shared<std::vector<PrintfArgChecker> > ();
-
- for (auto citer = query.begin(); citer != query.end(); ++citer) {
- auto c = *citer;
-
- switch (state) {
- case ignore_chars:
- if (c == '%') {
- state = read_percent;
- flags.clear ();
- width = precision = 0;
- }
- break;
- case read_percent:
- if (isdigit (c)) {
- state = read_width;
- width = c - '0';
- }
- else if (c == '.') {
- state = read_precision;
- precision = c - '0';
- }
- else if (c == '*') {
- /* %*s - need integer argument */
- res->emplace_back (int_arg_handler, this->pcontext,
- this->ci);
-
- if (*std::next (citer) == '.') {
- ++citer;
- state = read_precision;
- }
- else {
- state = read_arg;
- }
- }
- else if (c == '%') {
- /* Percent character, ignore */
- state = ignore_chars;
- }
- else {
- // Rewind iter
- --citer;
- state = read_arg;
- }
- break;
- case read_width:
- if (isdigit (c)) {
- width *= 10;
- width += c - '0';
- }
- else if (c == '.') {
+ if (*std::next(citer) == '.') {
+ ++citer;
state = read_precision;
- precision = c - '0';
}
else {
- // Rewind iter
- --citer;
state = read_arg;
}
- break;
- case read_precision:
- if (isdigit (c)) {
- precision *= 10;
- precision += c - '0';
+ }
+ else if (c == '%') {
+ /* Percent character, ignore */
+ state = ignore_chars;
+ }
+ else {
+ // Rewind iter
+ --citer;
+ state = read_arg;
+ }
+ break;
+ case read_width:
+ if (isdigit(c)) {
+ width *= 10;
+ width += c - '0';
+ }
+ else if (c == '.') {
+ state = read_precision;
+ precision = c - '0';
+ }
+ else {
+ // Rewind iter
+ --citer;
+ state = read_arg;
+ }
+ break;
+ case read_precision:
+ if (isdigit(c)) {
+ precision *= 10;
+ precision += c - '0';
+ }
+ else if (c == '*') {
+ res->emplace_back(int_arg_handler, this->pcontext,
+ this->ci);
+ state = read_arg;
+ }
+ else {
+ // Rewind iter
+ --citer;
+ state = read_arg;
+ }
+ break;
+ case read_arg:
+ auto found = format_specs.find(c);
+ if (found != format_specs.end() || !isalpha(c)) {
+
+ if (isalpha(c)) {
+ flags.push_back(c);
}
- else if (c == '*') {
- res->emplace_back (int_arg_handler, this->pcontext,
- this->ci);
- state = read_arg;
+
+ auto handler = parseFlags(flags, e);
+
+ if (handler) {
+ auto handler_copy = *handler;
+ handler_copy.precision = precision;
+ handler_copy.width = width;
+ res->emplace_back(std::move(handler_copy));
}
else {
- // Rewind iter
- --citer;
- state = read_arg;
+ return nullptr;
}
- break;
- case read_arg:
- auto found = format_specs.find (c);
- if (found != format_specs.end () || !isalpha (c)) {
-
- if (isalpha (c)) {
- flags.push_back (c);
- }
- auto handler = parseFlags (flags, e);
-
- if (handler) {
- auto handler_copy = *handler;
- handler_copy.precision = precision;
- handler_copy.width = width;
- res->emplace_back (std::move (handler_copy));
- }
- else {
- return nullptr;
- }
-
- if (c == '%') {
- state = read_percent;
- }
- else {
- state = ignore_chars;
- }
- flags.clear ();
- width = precision = 0;
+ if (c == '%') {
+ state = read_percent;
}
else {
- flags.push_back (c);
+ state = ignore_chars;
}
- break;
- }
- }
-
- if (state == read_arg) {
- auto handler = parseFlags (flags, e);
-
- if (handler) {
- auto handler_copy = *handler;
- handler_copy.precision = precision;
- handler_copy.width = width;
- res->emplace_back (std::move (handler_copy));
+ flags.clear();
+ width = precision = 0;
}
else {
- return nullptr;
+ flags.push_back(c);
}
+ break;
}
+ }
- return res;
+ if (state == read_arg) {
+ auto handler = parseFlags(flags, e);
+
+ if (handler) {
+ auto handler_copy = *handler;
+ handler_copy.precision = precision;
+ handler_copy.width = width;
+ res->emplace_back(std::move(handler_copy));
+ }
+ else {
+ return nullptr;
+ }
}
- public:
- impl (ASTContext *_ctx, clang::CompilerInstance &_ci)
- : pcontext (_ctx), ci(&_ci)
- {
- /* name -> format string position */
- printf_functions = {
- {"rspamd_printf", 0},
- {"rspamd_default_log_function", 4},
- {"rspamd_snprintf", 2},
- {"rspamd_fprintf", 1},
- {"rspamd_printf_gstring", 1},
- {"rspamd_printf_fstring", 1},
- {"rspamd_conditional_debug_fast", 6},
- };
-
- format_specs = {
- 's', 'd', 'l', 'L', 'v', 'V', 'f', 'F', 'g', 'G',
- 'T', 'z', 'D', 'c', 'p', 'P', 'e'
- };
+ return res;
+ }
+
+public:
+ impl(ASTContext *_ctx, clang::CompilerInstance &_ci)
+ : pcontext(_ctx), ci(&_ci)
+ {
+ /* name -> format string position */
+ printf_functions = {
+ {"rspamd_printf", 0},
+ {"rspamd_default_log_function", 4},
+ {"rspamd_snprintf", 2},
+ {"rspamd_fprintf", 1},
+ {"rspamd_printf_gstring", 1},
+ {"rspamd_printf_fstring", 1},
+ {"rspamd_conditional_debug_fast", 6},
};
- bool VisitCallExpr (CallExpr *E)
- {
- if (E->getCalleeDecl () == nullptr) {
- print_remark ("cannot get callee decl",
- E, this->pcontext, this->ci);
- return true;
- }
- auto callee = dyn_cast<NamedDecl> (E->getCalleeDecl ());
- if (callee == NULL) {
- print_remark ("cannot get named callee decl",
- E, this->pcontext, this->ci);
+ format_specs = {
+ 's', 'd', 'l', 'L', 'v', 'V', 'f', 'F', 'g', 'G',
+ 'T', 'z', 'D', 'c', 'p', 'P', 'e'};
+ };
+
+ bool VisitCallExpr(CallExpr *E)
+ {
+ if (E->getCalleeDecl() == nullptr) {
+ print_remark("cannot get callee decl",
+ E, this->pcontext, this->ci);
+ return true;
+ }
+ auto callee = dyn_cast<NamedDecl>(E->getCalleeDecl());
+ if (callee == NULL) {
+ print_remark("cannot get named callee decl",
+ E, this->pcontext, this->ci);
+ return true;
+ }
+
+ auto fname = callee->getNameAsString();
+
+ auto pos_it = printf_functions.find(fname);
+
+ if (pos_it != printf_functions.end()) {
+ const auto args = E->getArgs();
+ auto pos = pos_it->second;
+ auto query = args[pos];
+
+ if (!query->isEvaluatable(*pcontext)) {
+ print_remark("cannot evaluate query",
+ E, this->pcontext, this->ci);
+ /* It is not assumed to be an error */
return true;
}
- auto fname = callee->getNameAsString ();
+ clang::Expr::EvalResult r;
- auto pos_it = printf_functions.find (fname);
-
- if (pos_it != printf_functions.end ()) {
- const auto args = E->getArgs ();
- auto pos = pos_it->second;
- auto query = args[pos];
+ if (!query->EvaluateAsRValue(r, *pcontext)) {
+ print_warning("cannot evaluate rvalue of query",
+ E, this->pcontext, this->ci);
+ return false;
+ }
- if (!query->isEvaluatable (*pcontext)) {
- print_remark ("cannot evaluate query",
- E, this->pcontext, this->ci);
- /* It is not assumed to be an error */
- return true;
- }
+ auto qval = dyn_cast<StringLiteral>(
+ r.Val.getLValueBase().get<const Expr *>());
+ if (!qval) {
+ print_warning("bad or absent query string",
+ E, this->pcontext, this->ci);
+ return false;
+ }
- clang::Expr::EvalResult r;
+ auto parsers = genParsers(qval->getString(), E);
- if (!query->EvaluateAsRValue (r, *pcontext)) {
- print_warning ("cannot evaluate rvalue of query",
- E, this->pcontext, this->ci);
- return false;
- }
+ if (parsers) {
+ if (parsers->size() != E->getNumArgs() - (pos + 1)) {
+ std::ostringstream err_buf;
+ err_buf << "number of arguments for " << fname
+ << " mismatches query string '" << qval->getString().str()
+ << "', expected " << parsers->size() << " args"
+ << ", got " << (E->getNumArgs() - (pos + 1))
+ << " args";
+ print_error(err_buf.str().c_str(), E, this->pcontext, this->ci);
- auto qval = dyn_cast<StringLiteral> (
- r.Val.getLValueBase ().get<const Expr *> ());
- if (!qval) {
- print_warning ("bad or absent query string",
- E, this->pcontext, this->ci);
return false;
}
+ else {
+ for (auto i = pos + 1; i < E->getNumArgs(); i++) {
+ auto arg = args[i];
- auto parsers = genParsers (qval->getString (), E);
-
- if (parsers) {
- if (parsers->size () != E->getNumArgs () - (pos + 1)) {
- std::ostringstream err_buf;
- err_buf << "number of arguments for " << fname
- << " mismatches query string '" <<
- qval->getString ().str ()
- << "', expected " << parsers->size () <<
- " args"
- << ", got " <<
- (E->getNumArgs () - (pos + 1))
- << " args";
- print_error (err_buf.str().c_str(), E, this->pcontext, this->ci);
-
- return false;
- }
- else {
- for (auto i = pos + 1; i < E->getNumArgs (); i++) {
- auto arg = args[i];
-
- if (arg) {
- if (!parsers->at (i - (pos + 1)) (arg)) {
- return false;
- }
+ if (arg) {
+ if (!parsers->at(i - (pos + 1))(arg)) {
+ return false;
}
}
}
}
}
-
- return true;
}
- };
- PrintfCheckVisitor::PrintfCheckVisitor (ASTContext *ctx,
- clang::CompilerInstance &ci) :
- pimpl{new impl (ctx, ci)}
- {
+ return true;
}
+};
- PrintfCheckVisitor::~PrintfCheckVisitor ()
- {
- }
+PrintfCheckVisitor::PrintfCheckVisitor(ASTContext *ctx,
+ clang::CompilerInstance &ci)
+ : pimpl{new impl(ctx, ci)}
+{
+}
- bool PrintfCheckVisitor::VisitCallExpr (clang::CallExpr *E)
- {
- return pimpl->VisitCallExpr (E);
- }
+PrintfCheckVisitor::~PrintfCheckVisitor()
+{
+}
- /* Type handlers */
- static bool
- cstring_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
- {
- auto type = arg->getType ().split ().Ty;
+bool PrintfCheckVisitor::VisitCallExpr(clang::CallExpr *E)
+{
+ return pimpl->VisitCallExpr(E);
+}
- if (!type->isPointerType ()) {
- auto err_msg = std::string ("bad string argument for %s: ") +
- arg->getType ().getAsString ();
- print_error (err_msg.c_str(),
+/* Type handlers */
+static bool
+cstring_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx)
+{
+ auto type = arg->getType().split().Ty;
+
+ if (!type->isPointerType()) {
+ auto err_msg = std::string("bad string argument for %s: ") +
+ arg->getType().getAsString();
+ print_error(err_msg.c_str(),
arg, ctx->past, ctx->pci);
- return false;
- }
+ return false;
+ }
- auto ptr_type = type->getPointeeType ().split ().Ty;
+ auto ptr_type = type->getPointeeType().split().Ty;
- if (!ptr_type->isCharType ()) {
- /* We might have gchar * here */
- auto desugared_type = ptr_type->getUnqualifiedDesugaredType ();
- auto desugared_ptr_type = type->getUnqualifiedDesugaredType ();
+ if (!ptr_type->isCharType()) {
+ /* We might have char * here */
+ auto desugared_type = ptr_type->getUnqualifiedDesugaredType();
+ auto desugared_ptr_type = type->getUnqualifiedDesugaredType();
- if (!desugared_type || (!desugared_type->isCharType () &&
- !desugared_ptr_type->isVoidPointerType ())) {
- if (desugared_type) {
- desugared_type->dump ();
- }
- auto err_msg = std::string ("bad string argument for %s: ") +
- arg->getType ().getAsString ();
- print_error (err_msg.c_str(),
- arg, ctx->past, ctx->pci);
- return false;
+ if (!desugared_type || (!desugared_type->isCharType() &&
+ !desugared_ptr_type->isVoidPointerType())) {
+ if (desugared_type) {
+ desugared_type->dump();
}
+ auto err_msg = std::string("bad string argument for %s: ") +
+ arg->getType().getAsString();
+ print_error(err_msg.c_str(),
+ arg, ctx->past, ctx->pci);
+ return false;
}
-
- return true;
}
- static bool
- check_builtin_type (const Expr *arg, struct PrintfArgChecker *ctx,
- const std::vector <BuiltinType::Kind> &k, const std::string &fmt)
- {
- auto type = arg->getType ().split ().Ty;
+ return true;
+}
- auto desugared_type = type->getUnqualifiedDesugaredType ();
+static bool
+check_builtin_type(const Expr *arg, struct PrintfArgChecker *ctx,
+ const std::vector<BuiltinType::Kind> &k, const std::string &fmt)
+{
+ auto type = arg->getType().split().Ty;
- if (!desugared_type->isBuiltinType ()) {
- auto err_msg = std::string ("not a builtin type for ") + fmt + " arg: " +
- arg->getType ().getAsString ();
- print_error (err_msg.c_str(),
+ auto desugared_type = type->getUnqualifiedDesugaredType();
+
+ if (!desugared_type->isBuiltinType()) {
+ auto err_msg = std::string("not a builtin type for ") + fmt + " arg: " +
+ arg->getType().getAsString();
+ print_error(err_msg.c_str(),
arg, ctx->past, ctx->pci);
- return false;
- }
+ return false;
+ }
- auto builtin_type = dyn_cast<BuiltinType> (desugared_type);
- auto kind = builtin_type->getKind ();
- auto found = false;
+ auto builtin_type = dyn_cast<BuiltinType>(desugared_type);
+ auto kind = builtin_type->getKind();
+ auto found = false;
- for (auto kk : k) {
- if (kind == kk) {
- found = true;
- break;
- }
+ for (auto kk: k) {
+ if (kind == kk) {
+ found = true;
+ break;
}
+ }
- if (!found) {
- auto err_msg = std::string ("bad argument for ") +
- fmt + " arg: " +
- arg->getType ().getAsString () +
- ", resolved as: " +
- builtin_type->getNameAsCString (ctx->past->getPrintingPolicy ());
- print_error (err_msg.c_str(),
+ if (!found) {
+ auto err_msg = std::string("bad argument for ") +
+ fmt + " arg: " +
+ arg->getType().getAsString() +
+ ", resolved as: " +
+ builtin_type->getNameAsCString(ctx->past->getPrintingPolicy());
+ print_error(err_msg.c_str(),
arg, ctx->past, ctx->pci);
- return false;
- }
-
- return true;
+ return false;
}
- static bool
- int_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
- {
- return check_builtin_type (arg,
- ctx,
- {BuiltinType::Kind::UInt,
- BuiltinType::Kind::Int},
- "%d or *");
- }
+ return true;
+}
- static bool
- long_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
- {
- return check_builtin_type (arg,
- ctx,
- {BuiltinType::Kind::ULong,
- BuiltinType::Kind::Long},
- "%l");
- }
+static bool
+int_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx)
+{
+ return check_builtin_type(arg,
+ ctx,
+ {BuiltinType::Kind::UInt,
+ BuiltinType::Kind::Int},
+ "%d or *");
+}
- static bool
- char_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
- {
- return check_builtin_type (arg,
- ctx,
- {BuiltinType::Kind::UChar,
- BuiltinType::Kind::SChar,
- BuiltinType::Kind::Int}, // Because of char -> int propagation
- "%c");
- }
+static bool
+long_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx)
+{
+ return check_builtin_type(arg,
+ ctx,
+ {BuiltinType::Kind::ULong,
+ BuiltinType::Kind::Long},
+ "%l");
+}
- static bool
- size_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
- {
- if (sizeof (size_t) == sizeof (long)) {
- if (sizeof (long long) == sizeof (long)) {
- return check_builtin_type (arg,
- ctx,
- {BuiltinType::Kind::ULong,
- BuiltinType::Kind::Long,
- BuiltinType::Kind::LongLong,
- BuiltinType::Kind::ULongLong},
- "%z");
- }
- else {
- return check_builtin_type (arg,
- ctx,
- {BuiltinType::Kind::ULong,
- BuiltinType::Kind::Long},
- "%z");
- }
- }
- else if (sizeof (size_t) == sizeof (int)) {
- return check_builtin_type (arg,
- ctx,
- {BuiltinType::Kind::UInt,
- BuiltinType::Kind::Int},
- "%z");
+static bool
+char_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx)
+{
+ return check_builtin_type(arg,
+ ctx,
+ {BuiltinType::Kind::UChar,
+ BuiltinType::Kind::SChar,
+ BuiltinType::Kind::Int},// Because of char -> int propagation
+ "%c");
+}
+
+static bool
+size_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx)
+{
+ if (sizeof(size_t) == sizeof(long)) {
+ if (sizeof(long long) == sizeof(long)) {
+ return check_builtin_type(arg,
+ ctx,
+ {BuiltinType::Kind::ULong,
+ BuiltinType::Kind::Long,
+ BuiltinType::Kind::LongLong,
+ BuiltinType::Kind::ULongLong},
+ "%z");
}
else {
- assert (0);
+ return check_builtin_type(arg,
+ ctx,
+ {BuiltinType::Kind::ULong,
+ BuiltinType::Kind::Long},
+ "%z");
}
-
- return true;
}
-
- static bool
- double_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
- {
- return check_builtin_type (arg,
- ctx,
- {BuiltinType::Kind::Double},
- "%f or %g");
+ else if (sizeof(size_t) == sizeof(int)) {
+ return check_builtin_type(arg,
+ ctx,
+ {BuiltinType::Kind::UInt,
+ BuiltinType::Kind::Int},
+ "%z");
}
-
- static bool
- long_double_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
- {
- return check_builtin_type (arg,
- ctx,
- {BuiltinType::Kind::LongDouble},
- "%F or %G");
+ else {
+ assert(0);
}
- static bool
- pid_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
- {
- if (sizeof (pid_t) == sizeof (long)) {
- return check_builtin_type (arg,
- ctx,
- {BuiltinType::Kind::ULong,
- BuiltinType::Kind::Long},
- "%P");
- }
- else if (sizeof (pid_t) == sizeof (int)) {
- return check_builtin_type (arg,
- ctx,
- {BuiltinType::Kind::UInt,
- BuiltinType::Kind::Int},
- "%P");
- }
- else {
- assert (0);
- }
+ return true;
+}
+
+static bool
+double_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx)
+{
+ return check_builtin_type(arg,
+ ctx,
+ {BuiltinType::Kind::Double},
+ "%f or %g");
+}
+
+static bool
+long_double_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx)
+{
+ return check_builtin_type(arg,
+ ctx,
+ {BuiltinType::Kind::LongDouble},
+ "%F or %G");
+}
+
+static bool
+pid_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx)
+{
+ if (sizeof(pid_t) == sizeof(long)) {
+ return check_builtin_type(arg,
+ ctx,
+ {BuiltinType::Kind::ULong,
+ BuiltinType::Kind::Long},
+ "%P");
+ }
+ else if (sizeof(pid_t) == sizeof(int)) {
+ return check_builtin_type(arg,
+ ctx,
+ {BuiltinType::Kind::UInt,
+ BuiltinType::Kind::Int},
+ "%P");
}
+ else {
+ assert(0);
+ }
+}
- static bool
- time_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
- {
- if (sizeof (time_t) == sizeof (long)) {
- return check_builtin_type (arg,
- ctx,
- {BuiltinType::Kind::ULong,
- BuiltinType::Kind::Long},
- "%t");
- }
- else if (sizeof (time_t) == sizeof (int)) {
- return check_builtin_type (arg,
- ctx,
- {BuiltinType::Kind::UInt,
- BuiltinType::Kind::Int},
- "%t");
- }
- else {
- assert (0);
- }
+static bool
+time_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx)
+{
+ if (sizeof(time_t) == sizeof(long)) {
+ return check_builtin_type(arg,
+ ctx,
+ {BuiltinType::Kind::ULong,
+ BuiltinType::Kind::Long},
+ "%t");
+ }
+ else if (sizeof(time_t) == sizeof(int)) {
+ return check_builtin_type(arg,
+ ctx,
+ {BuiltinType::Kind::UInt,
+ BuiltinType::Kind::Int},
+ "%t");
}
+ else {
+ assert(0);
+ }
+}
- static bool
- pointer_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
- {
- auto type = arg->getType ().split ().Ty;
+static bool
+pointer_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx)
+{
+ auto type = arg->getType().split().Ty;
- if (!type->isPointerType ()) {
- auto err_msg = std::string ("bad pointer argument for %p: ") +
- arg->getType ().getAsString ();
- print_error (err_msg.c_str(),
+ if (!type->isPointerType()) {
+ auto err_msg = std::string("bad pointer argument for %p: ") +
+ arg->getType().getAsString();
+ print_error(err_msg.c_str(),
arg, ctx->past, ctx->pci);
- return false;
- }
-
- return true;
+ return false;
}
- static bool
- int64_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
- {
- std::vector <BuiltinType::Kind> check;
-
- if (sizeof (int64_t) == sizeof (long long)) {
- check.push_back (BuiltinType::Kind::ULongLong);
- check.push_back (BuiltinType::Kind::LongLong);
- }
- if (sizeof (int64_t) == sizeof (long)) {
- check.push_back (BuiltinType::Kind::ULong);
- check.push_back (BuiltinType::Kind::Long);
- }
+ return true;
+}
- return check_builtin_type (arg,
- ctx,
- check,
- "%L");
+static bool
+int64_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx)
+{
+ std::vector<BuiltinType::Kind> check;
- return true;
+ if (sizeof(int64_t) == sizeof(long long)) {
+ check.push_back(BuiltinType::Kind::ULongLong);
+ check.push_back(BuiltinType::Kind::LongLong);
+ }
+ if (sizeof(int64_t) == sizeof(long)) {
+ check.push_back(BuiltinType::Kind::ULong);
+ check.push_back(BuiltinType::Kind::Long);
}
- static bool
- int32_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
- {
- std::vector < BuiltinType::Kind> check;
+ return check_builtin_type(arg,
+ ctx,
+ check,
+ "%L");
- if (sizeof (int32_t) == sizeof (long)) {
- check.push_back (BuiltinType::Kind::ULong);
- check.push_back (BuiltinType::Kind::Long);
- }
- if (sizeof (int32_t) == sizeof (int)) {
- check.push_back (BuiltinType::Kind::UInt);
- check.push_back (BuiltinType::Kind::Int);
- }
+ return true;
+}
- return check_builtin_type (arg,
- ctx,
- check,
- "%D");
+static bool
+int32_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx)
+{
+ std::vector<BuiltinType::Kind> check;
- return true;
+ if (sizeof(int32_t) == sizeof(long)) {
+ check.push_back(BuiltinType::Kind::ULong);
+ check.push_back(BuiltinType::Kind::Long);
+ }
+ if (sizeof(int32_t) == sizeof(int)) {
+ check.push_back(BuiltinType::Kind::UInt);
+ check.push_back(BuiltinType::Kind::Int);
}
- static bool
- check_struct_type (const Expr *arg, struct PrintfArgChecker *ctx,
- const std::string &sname, const std::string &fmt)
- {
- auto type = arg->getType ().split ().Ty;
+ return check_builtin_type(arg,
+ ctx,
+ check,
+ "%D");
- if (!type->isPointerType ()) {
- auto err_msg = std::string ("non pointer argument for %s: ") +
- arg->getType ().getAsString ();
- print_error (err_msg.c_str(),
- arg, ctx->past, ctx->pci);
- return false;
- }
+ return true;
+}
- auto ptr_type = type->getPointeeType ().split ().Ty;
- auto desugared_type = ptr_type->getUnqualifiedDesugaredType ();
+static bool
+check_struct_type(const Expr *arg, struct PrintfArgChecker *ctx,
+ const std::string &sname, const std::string &fmt)
+{
+ auto type = arg->getType().split().Ty;
- if (!desugared_type->isRecordType ()) {
- auto err_msg = std::string ("not a record type for ") + fmt + " arg: " +
- arg->getType ().getAsString ();
- print_error (err_msg.c_str(),
+ if (!type->isPointerType()) {
+ auto err_msg = std::string("non pointer argument for %s: ") +
+ arg->getType().getAsString();
+ print_error(err_msg.c_str(),
arg, ctx->past, ctx->pci);
- return false;
- }
+ return false;
+ }
- auto struct_type = desugared_type->getAsStructureType ();
- auto struct_decl = struct_type->getDecl ();
- auto struct_def = struct_decl->getNameAsString ();
+ auto ptr_type = type->getPointeeType().split().Ty;
+ auto desugared_type = ptr_type->getUnqualifiedDesugaredType();
- if (struct_def != sname) {
- auto err_msg = std::string ("bad argument '") + struct_def + "' for "
- + fmt + " arg: " +
- arg->getType ().getAsString ();
- print_error (err_msg.c_str(),
+ if (!desugared_type->isRecordType()) {
+ auto err_msg = std::string("not a record type for ") + fmt + " arg: " +
+ arg->getType().getAsString();
+ print_error(err_msg.c_str(),
arg, ctx->past, ctx->pci);
- return false;
- }
-
- return true;
+ return false;
}
- static bool
- tok_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
- {
- return check_struct_type (arg,
- ctx,
- "f_str_tok",
- "%T");
- }
+ auto struct_type = desugared_type->getAsStructureType();
+ auto struct_decl = struct_type->getDecl();
+ auto struct_def = struct_decl->getNameAsString();
- static bool
- fstring_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
- {
- return check_struct_type (arg,
- ctx,
- "f_str_s",
- "%V");
+ if (struct_def != sname) {
+ auto err_msg = std::string("bad argument '") + struct_def + "' for " + fmt + " arg: " +
+ arg->getType().getAsString();
+ print_error(err_msg.c_str(),
+ arg, ctx->past, ctx->pci);
+ return false;
}
- static bool
- gstring_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
- {
- return check_struct_type (arg,
- ctx,
- "_GString",
- "%v");
- }
+ return true;
+}
- static bool
- gerr_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
- {
- return check_struct_type (arg,
- ctx,
- "_GError",
- "%e");
- }
+static bool
+tok_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx)
+{
+ return check_struct_type(arg,
+ ctx,
+ "f_str_tok",
+ "%T");
+}
+
+static bool
+fstring_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx)
+{
+ return check_struct_type(arg,
+ ctx,
+ "f_str_s",
+ "%V");
+}
+
+static bool
+gstring_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx)
+{
+ return check_struct_type(arg,
+ ctx,
+ "_GString",
+ "%v");
+}
+
+static bool
+gerr_arg_handler(const Expr *arg, struct PrintfArgChecker *ctx)
+{
+ return check_struct_type(arg,
+ ctx,
+ "_GError",
+ "%e");
}
+}// namespace rspamd
+/*
+ * Copyright 2024 Vsevolod Stakhov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
/*
** Copyright (C) 2009-2014 Mischa Sandberg <mischasan@gmail.com>
**
#include "_acism.h"
#include "unix-std.h"
-#define BACK ((SYMBOL)0)
+#define BACK ((SYMBOL) 0)
#define ROOT ((STATE) 0)
-extern const guchar lc_map[256];
+extern const unsigned char lc_map[256];
-int
-acism_lookup(ac_trie_t const *psp, const char *text, size_t len,
- ACISM_ACTION *cb, void *context, int *statep, bool caseless)
+int acism_lookup(ac_trie_t const *psp, const char *text, size_t len,
+ ACISM_ACTION *cb, void *context, int *statep, bool caseless)
{
- char const *cp = text, *endp = cp + len;
- uint8_t s;
- STATE state = *statep;
- int ret = 0;
-
- while (cp < endp) {
- s = caseless ? lc_map[(guint8)*cp++] : *cp++;
- _SYMBOL sym = psp->symv[s];
- if (!sym) {
- // Input byte is not in any pattern string.
- state = ROOT;
- continue;
- }
-
- // Search for a valid transition from this (state, sym),
- // following the backref chain.
-
- TRAN next;
- while (!t_valid(psp, next = p_tran(psp, state, sym)) && state != ROOT) {
- TRAN back = p_tran(psp, state, BACK);
- state = t_valid(psp, back) ? t_next(psp, back) : ROOT;
- }
-
- if (!t_valid(psp, next))
- continue;
-
- if (!(next & (IS_MATCH | IS_SUFFIX))) {
- // No complete match yet; keep going.
- state = t_next(psp, next);
- continue;
- }
-
- // At this point, one or more patterns have matched.
- // Find all matches by following the backref chain.
- // A valid node for (sym) with no SUFFIX flag marks the
- // end of the suffix chain.
- // In the same backref traversal, find a new (state),
- // if the original transition is to a leaf.
-
- STATE s = state;
-
- // Initially state is ROOT. The chain search saves the
- // first state from which the next char has a transition.
- state = t_isleaf(psp, next) ? 0 : t_next(psp, next);
-
- while (1) {
-
- if (t_valid(psp, next)) {
-
- if (next & IS_MATCH) {
- unsigned strno, ss = s + sym, i;
- if (t_isleaf(psp, psp->tranv[ss])) {
- strno = t_strno(psp, psp->tranv[ss]);
- } else {
- for (i = p_hash(psp, ss); psp->hashv[i].state != ss; ++i);
- strno = psp->hashv[i].strno;
- }
-
- if ((ret = cb(strno, cp - text, context)))
- goto EXIT;
- }
-
- if (!state && !t_isleaf(psp, next))
- state = t_next(psp, next);
- if ( state && !(next & IS_SUFFIX))
- break;
- }
-
- if (s == ROOT)
- break;
-
- TRAN b = p_tran(psp, s, BACK);
- s = t_valid(psp, b) ? t_next(psp, b) : ROOT;
- next = p_tran(psp, s, sym);
- }
- }
+ char const *cp = text, *endp = cp + len;
+ uint8_t s;
+ STATE state = *statep;
+ int ret = 0;
+
+ while (cp < endp) {
+ s = caseless ? lc_map[(uint8_t) *cp++] : *cp++;
+ _SYMBOL sym = psp->symv[s];
+ if (!sym) {
+ // Input byte is not in any pattern string.
+ state = ROOT;
+ continue;
+ }
+
+ // Search for a valid transition from this (state, sym),
+ // following the backref chain.
+
+ TRAN next;
+ while (!t_valid(psp, next = p_tran(psp, state, sym)) && state != ROOT) {
+ TRAN back = p_tran(psp, state, BACK);
+ state = t_valid(psp, back) ? t_next(psp, back) : ROOT;
+ }
+
+ if (!t_valid(psp, next))
+ continue;
+
+ if (!(next & (IS_MATCH | IS_SUFFIX))) {
+ // No complete match yet; keep going.
+ state = t_next(psp, next);
+ continue;
+ }
+
+ // At this point, one or more patterns have matched.
+ // Find all matches by following the backref chain.
+ // A valid node for (sym) with no SUFFIX flag marks the
+ // end of the suffix chain.
+ // In the same backref traversal, find a new (state),
+ // if the original transition is to a leaf.
+
+ STATE s = state;
+
+ // Initially state is ROOT. The chain search saves the
+ // first state from which the next char has a transition.
+ state = t_isleaf(psp, next) ? 0 : t_next(psp, next);
+
+ while (1) {
+
+ if (t_valid(psp, next)) {
+
+ if (next & IS_MATCH) {
+ unsigned strno, ss = s + sym, i;
+ if (t_isleaf(psp, psp->tranv[ss])) {
+ strno = t_strno(psp, psp->tranv[ss]);
+ }
+ else {
+ for (i = p_hash(psp, ss); psp->hashv[i].state != ss; ++i)
+ ;
+ strno = psp->hashv[i].strno;
+ }
+
+ if ((ret = cb(strno, cp - text, context)))
+ goto EXIT;
+ }
+
+ if (!state && !t_isleaf(psp, next))
+ state = t_next(psp, next);
+ if (state && !(next & IS_SUFFIX))
+ break;
+ }
+
+ if (s == ROOT)
+ break;
+
+ TRAN b = p_tran(psp, s, BACK);
+ s = t_valid(psp, b) ? t_next(psp, b) : ROOT;
+ next = p_tran(psp, s, sym);
+ }
+ }
EXIT:
*statep = state;
- return ret;
+ return ret;
}
-void
-acism_destroy(ac_trie_t *psp)
+void acism_destroy(ac_trie_t *psp)
{
if (!psp) return;
if (psp->flags & IS_MMAP)
- munmap((char*)psp->tranv - sizeof(ac_trie_t),
- sizeof(ac_trie_t) + p_size(psp));
- else g_free(psp->tranv);
+ munmap((char *) psp->tranv - sizeof(ac_trie_t),
+ sizeof(ac_trie_t) + p_size(psp));
+ else
+ g_free(psp->tranv);
g_free(psp);
}
//EOF
return hash;
}
-int
-cdb_init(struct cdb *cdbp, int fd)
+int cdb_init(struct cdb *cdbp, int fd)
{
struct stat st;
unsigned char *mem;
#endif
/* get file size */
- if (fstat (fd, &st) < 0)
+ if (fstat(fd, &st) < 0)
return -1;
/* trivial sanity check: at least toc should be here */
if (st.st_size < 2048)
#ifdef _WIN32
hFile = (HANDLE) _get_osfhandle(fd);
if (hFile == (HANDLE) -1)
- return -1;
+ return -1;
hMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
if (!hMapping)
- return -1;
- mem = (unsigned char *)MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0);
+ return -1;
+ mem = (unsigned char *) MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0);
CloseHandle(hMapping);
if (!mem)
- return -1;
+ return -1;
#else
- mem = (unsigned char*) mmap (NULL, fsize, PROT_READ, MAP_SHARED, fd, 0);
+ mem = (unsigned char *) mmap(NULL, fsize, PROT_READ, MAP_SHARED, fd, 0);
if (mem == MAP_FAILED)
return -1;
#endif /* _WIN32 */
cdbp->cdb_vpos = cdbp->cdb_vlen = 0;
cdbp->cdb_kpos = cdbp->cdb_klen = 0;
- dend = cdb_unpack (mem);
+ dend = cdb_unpack(mem);
if (dend < 2048)
dend = 2048;
else if (dend >= fsize)
return 0;
}
-void
-cdb_free(struct cdb *cdbp)
+void cdb_free(struct cdb *cdbp)
{
if (cdbp->cdb_mem) {
#ifdef _WIN32
- UnmapViewOfFile((void*) cdbp->cdb_mem);
+ UnmapViewOfFile((void *) cdbp->cdb_mem);
#else
- munmap ((void*) cdbp->cdb_mem, cdbp->cdb_fsize);
+ munmap((void *) cdbp->cdb_mem, cdbp->cdb_fsize);
#endif /* _WIN32 */
cdbp->cdb_mem = NULL;
}
cdbp->cdb_fsize = 0;
if (cdbp->loop) {
- ev_stat_stop (cdbp->loop, &cdbp->stat_ev);
+ ev_stat_stop(cdbp->loop, &cdbp->stat_ev);
}
}
return cdbp->cdb_mem + pos;
}
-int
-cdb_read(const struct cdb *cdbp, void *buf, unsigned len, unsigned pos)
+int cdb_read(const struct cdb *cdbp, void *buf, unsigned len, unsigned pos)
{
- const void *data = cdb_get (cdbp, len, pos);
+ const void *data = cdb_get(cdbp, len, pos);
if (!data)
return -1;
- memcpy (buf, data, len);
+ memcpy(buf, data, len);
return 0;
}
static void
-cdb_timer_callback (EV_P_ ev_stat *w, int revents)
+cdb_timer_callback(EV_P_ ev_stat *w, int revents)
{
struct cdb *cdbp = w->data;
- gint nfd;
+ int nfd;
/* Check cdb file for modifications */
- if ((nfd = open (cdbp->filename, O_RDONLY)) != -1) {
+ if ((nfd = open(cdbp->filename, O_RDONLY)) != -1) {
if (cdbp->cdb_mem) {
#ifdef _WIN32
- UnmapViewOfFile((void*) cdbp->cdb_mem);
+ UnmapViewOfFile((void *) cdbp->cdb_mem);
#else
- munmap ((void*) cdbp->cdb_mem, cdbp->cdb_fsize);
+ munmap((void *) cdbp->cdb_mem, cdbp->cdb_fsize);
#endif /* _WIN32 */
cdbp->cdb_mem = NULL;
}
- (void)close (cdbp->cdb_fd);
+ (void) close(cdbp->cdb_fd);
cdbp->cdb_fsize = 0;
- (void)cdb_init (cdbp, nfd);
+ (void) cdb_init(cdbp, nfd);
}
}
-void
-cdb_add_timer (struct cdb *cdbp, EV_P_ ev_tstamp seconds)
+void cdb_add_timer(struct cdb *cdbp, EV_P_ ev_tstamp seconds)
{
cdbp->loop = loop;
- ev_stat_init (&cdbp->stat_ev, cdb_timer_callback, cdbp->filename, seconds);
+ ev_stat_init(&cdbp->stat_ev, cdb_timer_callback, cdbp->filename, seconds);
cdbp->stat_ev.data = cdbp;
- ev_stat_start (EV_A_ &cdbp->stat_ev);
+ ev_stat_start(EV_A_ & cdbp->stat_ev);
}
#include <string.h>
#include <setjmp.h>
#if defined(TEST) && defined(NDEBUG)
-# warning undefining NDEBUG for TEST build
-# undef NDEBUG
+#warning undefining NDEBUG for TEST build
+#undef NDEBUG
#endif
#include <assert.h>
#define SIZEOF_VOID_P __SIZEOF_POINTER__
#else
#if defined(__ILP32__) || defined(__ILP32) || defined(_ILP32)
-# define SIZEOF_VOID_P 4
+#define SIZEOF_VOID_P 4
#elif defined(__ILP64__) || defined(__ILP64) || defined(_ILP64)
-# define SIZEOF_VOID_P 8
+#define SIZEOF_VOID_P 8
#elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64)
-# define SIZEOF_VOID_P 8
+#define SIZEOF_VOID_P 8
#elif defined(__LP64__) || defined(__LP64) || defined(_LP64)
-# define SIZEOF_VOID_P 8
+#define SIZEOF_VOID_P 8
#elif defined(UINTPTR_MAX) && defined(UINT64_MAX) && (UINTPTR_MAX == UINT64_MAX)
-# define SIZEOF_VOID_P 8
+#define SIZEOF_VOID_P 8
#else
-# define SIZEOF_VOID_P 4
+#define SIZEOF_VOID_P 4
#endif
#endif
#if SIZEOF_VOID_P == 4
-# define TBM_STRIDE 4
+#define TBM_STRIDE 4
#elif SIZEOF_VOID_P == 8
-# define TBM_STRIDE 5
+#define TBM_STRIDE 5
#else
-# error "Unsupported word size"
+#error "Unsupported word size"
#endif
#ifndef NO_STDINT_H
-# if TBM_STRIDE == 4
+#if TBM_STRIDE == 4
typedef uint16_t tbm_bitmap_t;
-# else
+#else
typedef uint32_t tbm_bitmap_t;
-# endif
+#endif
#else /* NO_STDINT_H */
-# if TBM_STRIDE == 4
-# if SIZEOF_SHORT == 2
+#if TBM_STRIDE == 4
+#if SIZEOF_SHORT == 2
typedef short unsigned tbm_bitmap_t;
-# else
-# error "can not determine type for 16 bit unsigned int"
-# endif
-# else /* TBM_STRIDE == 5 */
-# if SIZEOF_INT == 4
+#else
+#error "can not determine type for 16 bit unsigned int"
+#endif
+#else /* TBM_STRIDE == 5 */
+#if SIZEOF_INT == 4
typedef unsigned tbm_bitmap_t;
-# elif SIZEOF_LONG == 4
+#elif SIZEOF_LONG == 4
typedef long unsigned tbm_bitmap_t;
-# else
-# error "can not determine type for 32 bit unsigned int"
-# endif
-# endif
+#else
+#error "can not determine type for 32 bit unsigned int"
+#endif
+#endif
#endif
-#define TBM_FANOUT (1U << TBM_STRIDE)
-#define LC_BYTES_PER_NODE (SIZEOF_VOID_P - 1)
+#define TBM_FANOUT (1U << TBM_STRIDE)
+#define LC_BYTES_PER_NODE (SIZEOF_VOID_P - 1)
typedef union node_u node_t;
* lc_node.)
*/
-struct tbm_node
-{
+struct tbm_node {
#ifdef WORDS_BIGENDIAN
tbm_bitmap_t int_bm; /* the internal bitmap */
tbm_bitmap_t ext_bm; /* extending path ("external") bitmap */
tbm_bitmap_t ext_bm; /* extending path ("external") bitmap */
tbm_bitmap_t int_bm; /* the internal bitmap */
#endif
- union
- {
- node_t *children; /* pointer to array of children */
+ union {
+ node_t *children; /* pointer to array of children */
const void **data_end; /* one past end of internal prefix data array */
} ptr;
};
-struct lc_node
-{
+struct lc_node {
/* lc_flags contains the LC prefix length and a couple of bit flags
* (apparently char-sized bit fields are a gcc extension)
*/
-# define LC_FLAGS_IS_LC 0x80
-# define LC_FLAGS_IS_TERMINAL 0x40
-# define LC_FLAGS_LEN_MASK 0x3f
+#define LC_FLAGS_IS_LC 0x80
+#define LC_FLAGS_IS_TERMINAL 0x40
+#define LC_FLAGS_LEN_MASK 0x3f
#ifdef WORDS_BIGENDIAN
btrie_oct_t lc_flags;
btrie_oct_t prefix[LC_BYTES_PER_NODE];
btrie_oct_t prefix[LC_BYTES_PER_NODE];
btrie_oct_t lc_flags;
#endif
- union
- {
- node_t *child; /* pointer to child (if !is_terminal) */
+ union {
+ node_t *child; /* pointer to child (if !is_terminal) */
const void *data; /* the prefix data (if is_terminal) */
} ptr;
};
-union node_u
-{
+union node_u {
struct tbm_node tbm_node;
struct lc_node lc_node;
};
-struct free_hunk
-{
+struct free_hunk {
struct free_hunk *next;
};
#define MAX_CHILD_ARRAY_LEN (TBM_FANOUT + TBM_FANOUT / 2)
-struct btrie
-{
+struct btrie {
node_t root;
rspamd_mempool_t *mp;
jmp_buf exception;
/* mem mgmt stats */
size_t alloc_total; /* total bytes allocated from mempool */
- size_t alloc_data; /* bytes allocated for TBM node int. prefix data */
+ size_t alloc_data; /* bytes allocated for TBM node int. prefix data */
size_t alloc_waste; /* bytes wasted by rounding of data array size */
#ifdef BTRIE_DEBUG_ALLOC
size_t alloc_hist[MAX_CHILD_ARRAY_LEN * 2]; /* histogram of alloc sizes */
#endif
/* trie stats */
- size_t n_entries; /* number of entries */
+ size_t n_entries; /* number of entries */
size_t n_tbm_nodes; /* total number of TBM nodes in tree */
- size_t n_lc_nodes; /* total number of LC nodes in tree */
+ size_t n_lc_nodes; /* total number of LC nodes in tree */
};
/****************************************************************
assert(n_nodes > 0 && n_nodes <= MAX_CHILD_ARRAY_LEN);
- hunk = _get_hunk (btrie, n_nodes);
+ hunk = _get_hunk(btrie, n_nodes);
if (hunk == NULL) {
/* Do not have free hunk of exactly the requested size, look for a
* larger hunk. (The funny order in which we scan the buckets is
*/
size_t n, skip = n_nodes > 4 ? 4 : n_nodes;
for (n = n_nodes + skip; n <= MAX_CHILD_ARRAY_LEN; n++) {
- if ((hunk = _get_hunk (btrie, n)) != NULL) {
- _free_hunk (btrie, hunk + n_nodes, n - n_nodes);
+ if ((hunk = _get_hunk(btrie, n)) != NULL) {
+ _free_hunk(btrie, hunk + n_nodes, n - n_nodes);
goto DONE;
}
}
for (n = n_nodes + 1; n < n_nodes + skip && n <= MAX_CHILD_ARRAY_LEN;
- n++) {
- if ((hunk = _get_hunk (btrie, n)) != NULL) {
- _free_hunk (btrie, hunk + n_nodes, n - n_nodes);
+ n++) {
+ if ((hunk = _get_hunk(btrie, n)) != NULL) {
+ _free_hunk(btrie, hunk + n_nodes, n - n_nodes);
goto DONE;
}
}
/* failed to find free hunk, allocate a fresh one */
- hunk = rspamd_mempool_alloc0 (btrie->mp, n_nodes * sizeof(node_t));
+ hunk = rspamd_mempool_alloc0(btrie->mp, n_nodes * sizeof(node_t));
if (hunk == NULL)
- longjmp (btrie->exception, BTRIE_ALLOC_FAILED);
+ longjmp(btrie->exception, BTRIE_ALLOC_FAILED);
btrie->alloc_total += n_nodes * sizeof(node_t);
}
- DONE: btrie->alloc_data += ndata * sizeof(void *);
+DONE:
+ btrie->alloc_data += ndata * sizeof(void *);
btrie->alloc_waste += (ndata % 2) * sizeof(void *);
#ifdef BTRIE_DEBUG_ALLOC
btrie->alloc_hist[2 * nchildren + ndata]++;
/* Free memory allocated by alloc_nodes */
static void free_nodes(struct btrie *btrie, node_t *buf, unsigned nchildren,
- unsigned ndata)
+ unsigned ndata)
{
size_t n_nodes = nchildren + (ndata + 1) / 2;
assert(n_nodes > 0 && n_nodes <= MAX_CHILD_ARRAY_LEN);
- _free_hunk (btrie, buf - (ndata + 1) / 2, n_nodes);
+ _free_hunk(btrie, buf - (ndata + 1) / 2, n_nodes);
btrie->alloc_data -= ndata * sizeof(void *);
btrie->alloc_waste -= (ndata % 2) * sizeof(void *);
if (bin % 2 == 0) {
const struct free_hunk *hunk;
for (hunk = btrie->free_list[bin / 2 - 1]; hunk; hunk = hunk->next)
- n_free++;
+ n_free++;
}
free_bytes = n_free * bin * sizeof(void *);
printf("%3zu: %6zu %6zu %8zu %8zu %8zu\n", bin * sizeof(void *),
- n_alloc, n_free, bytes, waste_bytes, free_bytes);
+ n_alloc, n_free, bytes, waste_bytes, free_bytes);
total_alloc += n_alloc;
total_free += n_free;
}
puts("---- ------ ------ -------- -------- --------");
printf("SUM: %6zu %6zu %8zu %8zu %8zu\n",
- total_alloc, total_free, total_bytes, total_waste, total_free_bytes);
+ total_alloc, total_free, total_bytes, total_waste, total_free_bytes);
}
#endif
static inline unsigned count_bits_before(tbm_bitmap_t bm, int b)
{
- return b ? count_bits (bm >> ((1 << TBM_STRIDE) - b)) : 0;
+ return b ? count_bits(bm >> ((1 << TBM_STRIDE) - b)) : 0;
}
static inline unsigned count_bits_from(tbm_bitmap_t bm, int b)
{
- return count_bits (bm << b);
+ return count_bits(bm << b);
}
/* extracts a few bits from bitstring, returning them as an integer */
static inline btrie_oct_t RSPAMD_NO_SANITIZE extract_bits(const btrie_oct_t *prefix, unsigned pos,
- unsigned nbits)
+ unsigned nbits)
{
if (nbits == 0)
return 0;
/* get mask for high n bits of a byte */
static inline btrie_oct_t high_bits(unsigned n)
{
- return (btrie_oct_t) -(1U << (8 - n));
+ return (btrie_oct_t) - (1U << (8 - n));
}
/* determine whether two prefixes are equal */
static inline int prefixes_equal(const btrie_oct_t *pfx1,
- const btrie_oct_t *pfx2, unsigned len)
+ const btrie_oct_t *pfx2, unsigned len)
{
- return (memcmp (pfx1, pfx2, len / 8) == 0
- && (len % 8 == 0 ||
- ((pfx1[len / 8] ^ pfx2[len / 8]) & high_bits (len % 8)) == 0));
+ return (memcmp(pfx1, pfx2, len / 8) == 0 && (len % 8 == 0 ||
+ ((pfx1[len / 8] ^ pfx2[len / 8]) & high_bits(len % 8)) == 0));
}
/* determine length of longest common subprefix */
static inline unsigned common_prefix(const btrie_oct_t *pfx1,
- const btrie_oct_t *pfx2, unsigned len)
+ const btrie_oct_t *pfx2, unsigned len)
{
/* algorithm adapted from
* http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogLookup
*/
static btrie_oct_t leading_zeros[] =
- { 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, };
+ {
+ 8,
+ 7,
+ 6,
+ 6,
+ 5,
+ 5,
+ 5,
+ 5,
+ 4,
+ 4,
+ 4,
+ 4,
+ 4,
+ 4,
+ 4,
+ 4,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 3,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 2,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ };
unsigned nb;
for (nb = 0; nb < len / 8; nb++) {
static inline int is_tbm_node(const node_t *node)
{
- return !is_lc_node (node);
+ return !is_lc_node(node);
}
/* is node a TBM node with internal data? */
static inline int has_data(const node_t *node)
{
- return is_tbm_node (node) && node->tbm_node.int_bm != 0;
+ return is_tbm_node(node) && node->tbm_node.int_bm != 0;
}
static inline unsigned base_index(unsigned pfx, unsigned plen)
static inline const void **
tbm_data_p(const struct tbm_node *node, unsigned pfx, unsigned plen)
{
- unsigned bi = base_index (pfx, plen);
+ unsigned bi = base_index(pfx, plen);
- if ((node->int_bm & bit (bi)) == 0)
+ if ((node->int_bm & bit(bi)) == 0)
return NULL; /* no data */
else {
- return &node->ptr.data_end[-(int) count_bits_from (node->int_bm, bi)];
+ return &node->ptr.data_end[-(int) count_bits_from(node->int_bm, bi)];
}
}
/* add an element to the internal data array */
static void tbm_insert_data(struct btrie *btrie, struct tbm_node *node,
- unsigned pfx, unsigned plen, const void *data)
+ unsigned pfx, unsigned plen, const void *data)
{
/* XXX: don't realloc if already big enough? */
- unsigned bi = base_index (pfx, plen);
- unsigned nchildren = count_bits (node->ext_bm);
- int ndata = count_bits (node->int_bm);
- unsigned di = count_bits_before (node->int_bm, bi);
+ unsigned bi = base_index(pfx, plen);
+ unsigned nchildren = count_bits(node->ext_bm);
+ int ndata = count_bits(node->int_bm);
+ unsigned di = count_bits_before(node->int_bm, bi);
node_t *old_children = node->ptr.children;
const void **old_data_beg = node->ptr.data_end - ndata;
const void **data_beg;
- assert((node->int_bm & bit (bi)) == 0);
+ assert((node->int_bm & bit(bi)) == 0);
- node->ptr.children = alloc_nodes (btrie, nchildren, ndata + 1);
+ node->ptr.children = alloc_nodes(btrie, nchildren, ndata + 1);
data_beg = node->ptr.data_end - (ndata + 1);
data_beg[di] = data;
- node->int_bm |= bit (bi);
+ node->int_bm |= bit(bi);
if (nchildren != 0 || ndata != 0) {
memcpy(data_beg, old_data_beg, di * sizeof(data_beg[0]));
memcpy(&data_beg[di + 1], &old_data_beg[di],
- (ndata - di) * sizeof(data_beg[0])
- + nchildren * sizeof(node_t));
- free_nodes (btrie, old_children, nchildren, ndata);
+ (ndata - di) * sizeof(data_beg[0]) + nchildren * sizeof(node_t));
+ free_nodes(btrie, old_children, nchildren, ndata);
}
}
/* determine whether TBM has internal prefix data for pfx/plen or ancestors */
static inline int has_internal_data(const struct tbm_node *node, unsigned pfx,
- unsigned plen)
+ unsigned plen)
{
-# define BIT(n) (1U << ((1 << TBM_STRIDE) - 1 - (n)))
-# define B0() BIT(1) /* the bit for 0/0 */
-# define B1(n) (BIT((n) + 2) | B0()) /* the bits for n/1 and its ancestors */
-# define B2(n) (BIT((n) + 4) | B1(n >> 1)) /* the bits for n/2 and ancestors */
-# define B3(n) (BIT((n) + 8) | B2(n >> 1)) /* the bits for n/3 and ancestors */
-# define B4(n) (BIT((n) + 16) | B3(n >> 1)) /* the bits for n/4 and ancestors */
+#define BIT(n) (1U << ((1 << TBM_STRIDE) - 1 - (n)))
+#define B0() BIT(1) /* the bit for 0/0 */
+#define B1(n) (BIT((n) + 2) | B0()) /* the bits for n/1 and its ancestors */
+#define B2(n) (BIT((n) + 4) | B1(n >> 1)) /* the bits for n/2 and ancestors */
+#define B3(n) (BIT((n) + 8) | B2(n >> 1)) /* the bits for n/3 and ancestors */
+#define B4(n) (BIT((n) + 16) | B3(n >> 1)) /* the bits for n/4 and ancestors */
static tbm_bitmap_t ancestors[] =
- { 0, B0(), B1(0), B1(1), B2(0), B2(1), B2(2), B2(3), B3(0), B3(1), B3(2),
- B3(3), B3(4), B3(5), B3(6), B3(7),
-# if TBM_STRIDE == 5
- B4(0), B4(1), B4(2), B4(3), B4(4), B4(5), B4(6), B4(7), B4(8), B4(
- 9), B4(10), B4(11), B4(12), B4(13), B4(14), B4(15),
-# elif TBM_STRIDE != 4
-# error "unsupported TBM_STRIDE"
-# endif
- };
-# undef B4
-# undef B3
-# undef B2
-# undef B1
-# undef B0
-# undef BIT
-
- return (node->int_bm & ancestors[base_index (pfx, plen)]) != 0;
+ { 0,
+ B0(),
+ B1(0),
+ B1(1),
+ B2(0),
+ B2(1),
+ B2(2),
+ B2(3),
+ B3(0),
+ B3(1),
+ B3(2),
+ B3(3),
+ B3(4),
+ B3(5),
+ B3(6),
+ B3(7),
+#if TBM_STRIDE == 5
+ B4(0),
+ B4(1),
+ B4(2),
+ B4(3),
+ B4(4),
+ B4(5),
+ B4(6),
+ B4(7),
+ B4(8),
+ B4(
+ 9),
+ B4(10),
+ B4(11),
+ B4(12),
+ B4(13),
+ B4(14),
+ B4(15),
+#elif TBM_STRIDE != 4
+#error "unsupported TBM_STRIDE"
+#endif
+ };
+#undef B4
+#undef B3
+#undef B2
+#undef B1
+#undef B0
+#undef BIT
+
+ return (node->int_bm & ancestors[base_index(pfx, plen)]) != 0;
}
/* get pointer to TBM extending path */
static inline node_t *
tbm_ext_path(const struct tbm_node *node, unsigned pfx)
{
- if ((node->ext_bm & bit (pfx)) == 0)
+ if ((node->ext_bm & bit(pfx)) == 0)
return NULL;
else
- return &node->ptr.children[count_bits_before (node->ext_bm, pfx)];
+ return &node->ptr.children[count_bits_before(node->ext_bm, pfx)];
}
/* resize TBM node child array to make space for new child node */
static node_t *
tbm_insert_ext_path(struct btrie *btrie, struct tbm_node *node, unsigned pfx)
{
- unsigned nchildren = count_bits (node->ext_bm);
- unsigned ci = count_bits_before (node->ext_bm, pfx);
- int ndata = count_bits (node->int_bm);
+ unsigned nchildren = count_bits(node->ext_bm);
+ unsigned ci = count_bits_before(node->ext_bm, pfx);
+ int ndata = count_bits(node->int_bm);
node_t *old_children = node->ptr.children;
const void **old_data_beg = node->ptr.data_end - ndata;
- assert((node->ext_bm & bit (pfx)) == 0);
+ assert((node->ext_bm & bit(pfx)) == 0);
- node->ptr.children = alloc_nodes (btrie, nchildren + 1, ndata);
- init_empty_node (btrie, &node->ptr.children[ci]);
- node->ext_bm |= bit (pfx);
+ node->ptr.children = alloc_nodes(btrie, nchildren + 1, ndata);
+ init_empty_node(btrie, &node->ptr.children[ci]);
+ node->ext_bm |= bit(pfx);
if (nchildren != 0 || ndata != 0) {
const void **data_beg = node->ptr.data_end - ndata;
memcpy(data_beg, old_data_beg,
- ndata * sizeof(data_beg[0]) + ci * sizeof(node_t));
+ ndata * sizeof(data_beg[0]) + ci * sizeof(node_t));
memcpy(&node->ptr.children[ci + 1], &old_children[ci],
- (nchildren - ci) * sizeof(old_children[0]));
- free_nodes (btrie, old_children, nchildren, ndata);
+ (nchildren - ci) * sizeof(old_children[0]));
+ free_nodes(btrie, old_children, nchildren, ndata);
}
return &node->ptr.children[ci];
}
static inline void lc_init_flags(struct lc_node *node, int is_terminal,
- unsigned len)
+ unsigned len)
{
assert((len & ~LC_FLAGS_LEN_MASK) == 0);
node->lc_flags = LC_FLAGS_IS_LC | len;
static inline void lc_add_to_len(struct lc_node *node, int increment)
{
- unsigned new_len = lc_len (node) + increment;
+ unsigned new_len = lc_len(node) + increment;
assert((new_len & ~LC_FLAGS_LEN_MASK) == 0);
node->lc_flags = (node->lc_flags & ~LC_FLAGS_LEN_MASK) | new_len;
}
static inline unsigned lc_base(unsigned pos)
{
- return 8 * lc_shift (pos);
+ return 8 * lc_shift(pos);
}
static inline unsigned lc_bits(const struct lc_node *node, unsigned pos)
{
- return pos % 8 + lc_len (node);
+ return pos % 8 + lc_len(node);
}
static inline unsigned lc_bytes(const struct lc_node *node, unsigned pos)
{
- return (lc_bits (node, pos) + 7) / 8;
+ return (lc_bits(node, pos) + 7) / 8;
}
static inline unsigned lc_leading_bits(const struct lc_node *node, unsigned pos,
- unsigned nbits)
+ unsigned nbits)
{
- return extract_bits (node->prefix, pos % 8, nbits);
+ return extract_bits(node->prefix, pos % 8, nbits);
}
/* Initialize a new terminal LC node
* of LC nodes will be created.
*/
static void init_terminal_node(struct btrie *btrie, node_t *dst, unsigned pos,
- const btrie_oct_t *prefix, unsigned len, const void *data)
+ const btrie_oct_t *prefix, unsigned len, const void *data)
{
struct lc_node *node = &dst->lc_node;
unsigned nbytes = (len + 7) / 8;
- while (nbytes - lc_shift (pos) > LC_BYTES_PER_NODE) {
- memcpy(node->prefix, prefix + lc_shift (pos), LC_BYTES_PER_NODE);
- lc_init_flags (node, 0, 8 * LC_BYTES_PER_NODE - pos % 8);
- node->ptr.child = alloc_nodes (btrie, 1, 0);
- pos += lc_len (node);
+ while (nbytes - lc_shift(pos) > LC_BYTES_PER_NODE) {
+ memcpy(node->prefix, prefix + lc_shift(pos), LC_BYTES_PER_NODE);
+ lc_init_flags(node, 0, 8 * LC_BYTES_PER_NODE - pos % 8);
+ node->ptr.child = alloc_nodes(btrie, 1, 0);
+ pos += lc_len(node);
node = &node->ptr.child->lc_node;
btrie->n_lc_nodes++;
}
- memcpy(node->prefix, prefix + lc_shift (pos), nbytes - lc_shift (pos));
- lc_init_flags (node, 1, len - pos);
+ memcpy(node->prefix, prefix + lc_shift(pos), nbytes - lc_shift(pos));
+ lc_init_flags(node, 1, len - pos);
node->ptr.data = data;
btrie->n_lc_nodes++;
}
* also ensure that the leading nodes in the LC chain have maximum length.
*/
static void coalesce_lc_node(struct btrie *btrie, struct lc_node *node,
- unsigned pos)
+ unsigned pos)
{
- while (!lc_is_terminal (node) && lc_bits (node, pos) < 8 * LC_BYTES_PER_NODE
- && is_lc_node (node->ptr.child)) {
+ while (!lc_is_terminal(node) && lc_bits(node, pos) < 8 * LC_BYTES_PER_NODE && is_lc_node(node->ptr.child)) {
struct lc_node *child = &node->ptr.child->lc_node;
- unsigned spare_bits = 8 * LC_BYTES_PER_NODE - lc_bits (node, pos);
- unsigned end = pos + lc_len (node);
- unsigned shift = lc_shift (end) - lc_shift (pos);
- if (lc_len (child) <= spare_bits) {
+ unsigned spare_bits = 8 * LC_BYTES_PER_NODE - lc_bits(node, pos);
+ unsigned end = pos + lc_len(node);
+ unsigned shift = lc_shift(end) - lc_shift(pos);
+ if (lc_len(child) <= spare_bits) {
/* node plus child will fit in single node - merge */
- memcpy(node->prefix + shift, child->prefix, lc_bytes (child, end));
- lc_init_flags (node, lc_is_terminal (child),
- lc_len (node) + lc_len (child));
+ memcpy(node->prefix + shift, child->prefix, lc_bytes(child, end));
+ lc_init_flags(node, lc_is_terminal(child),
+ lc_len(node) + lc_len(child));
node->ptr = child->ptr;
- free_nodes (btrie, (node_t *) child, 1, 0);
+ free_nodes(btrie, (node_t *) child, 1, 0);
btrie->n_lc_nodes--;
}
else {
/* can't merge, but can take some of children bits */
- unsigned cshift = lc_shift (end + spare_bits) - lc_shift (end);
+ unsigned cshift = lc_shift(end + spare_bits) - lc_shift(end);
memcpy(node->prefix + shift, child->prefix,
- LC_BYTES_PER_NODE - shift);
- lc_add_to_len (node, spare_bits);
+ LC_BYTES_PER_NODE - shift);
+ lc_add_to_len(node, spare_bits);
if (cshift)
memmove(child->prefix, child->prefix + cshift,
- lc_bytes (child, end) - cshift);
- assert(lc_len (child) > spare_bits);
- lc_add_to_len (child, -spare_bits);
+ lc_bytes(child, end) - cshift);
+ assert(lc_len(child) > spare_bits);
+ lc_add_to_len(child, -spare_bits);
- pos += lc_len (node);
+ pos += lc_len(node);
node = child;
}
}
}
static void init_tbm_node(struct btrie *btrie, node_t *node, unsigned pos,
- const btrie_oct_t pbyte, const void **root_data_p, node_t *left,
- node_t *right);
+ const btrie_oct_t pbyte, const void **root_data_p, node_t *left,
+ node_t *right);
/* given an LC node at orig_pos, create a new (shorter) node at pos */
static void shorten_lc_node(struct btrie *btrie, node_t *dst, unsigned pos,
- struct lc_node *src, unsigned orig_pos)
+ struct lc_node *src, unsigned orig_pos)
{
assert(orig_pos < pos);
- assert(lc_len (src) >= pos - orig_pos);
- assert(dst != (node_t * )src);
+ assert(lc_len(src) >= pos - orig_pos);
+ assert(dst != (node_t *) src);
- if (lc_len (src) == pos - orig_pos && !lc_is_terminal (src)) {
+ if (lc_len(src) == pos - orig_pos && !lc_is_terminal(src)) {
/* just steal the child */
node_t *child = src->ptr.child;
*dst = *child;
- free_nodes (btrie, child, 1, 0);
+ free_nodes(btrie, child, 1, 0);
btrie->n_lc_nodes--;
}
else {
struct lc_node *node = &dst->lc_node;
- unsigned shift = lc_shift (pos) - lc_shift (orig_pos);
+ unsigned shift = lc_shift(pos) - lc_shift(orig_pos);
if (shift) {
memmove(node->prefix, src->prefix + shift,
- lc_bytes (src, orig_pos) - shift);
+ lc_bytes(src, orig_pos) - shift);
node->lc_flags = src->lc_flags;
node->ptr = src->ptr;
}
else {
*node = *src;
}
- lc_add_to_len (node, -(pos - orig_pos));
- coalesce_lc_node (btrie, node, pos);
+ lc_add_to_len(node, -(pos - orig_pos));
+ coalesce_lc_node(btrie, node, pos);
}
}
* on entry, node must have length at least len
*/
static void split_lc_node(struct btrie *btrie, struct lc_node *node,
- unsigned pos, unsigned len)
+ unsigned pos, unsigned len)
{
- node_t *child = alloc_nodes (btrie, 1, 0);
+ node_t *child = alloc_nodes(btrie, 1, 0);
- assert(lc_len (node) >= len);
- shorten_lc_node (btrie, child, pos + len, node, pos);
+ assert(lc_len(node) >= len);
+ shorten_lc_node(btrie, child, pos + len, node, pos);
- lc_init_flags (node, 0, len);
+ lc_init_flags(node, 0, len);
node->ptr.child = child;
btrie->n_lc_nodes++;
}
/* convert non-terminal LC node of length one to a TBM node *in place* */
static void convert_lc_node_1(struct btrie *btrie, struct lc_node *node,
- unsigned pos)
+ unsigned pos)
{
btrie_oct_t pbyte = node->prefix[0];
node_t *child = node->ptr.child;
node_t *left, *right;
- assert(lc_len (node) == 1);
- assert(!lc_is_terminal (node));
+ assert(lc_len(node) == 1);
+ assert(!lc_is_terminal(node));
- if (extract_bit (node->prefix, pos % 8))
+ if (extract_bit(node->prefix, pos % 8))
left = NULL, right = child;
else
left = child, right = NULL;
- init_tbm_node (btrie, (node_t *) node, pos, pbyte, NULL, left, right);
- free_nodes (btrie, child, 1, 0);
+ init_tbm_node(btrie, (node_t *) node, pos, pbyte, NULL, left, right);
+ free_nodes(btrie, child, 1, 0);
btrie->n_lc_nodes--;
}
/* convert an LC node to TBM node *in place* */
static void convert_lc_node(struct btrie *btrie, struct lc_node *node,
- unsigned pos)
+ unsigned pos)
{
- unsigned len = lc_len (node);
+ unsigned len = lc_len(node);
if (len >= TBM_STRIDE) {
- unsigned pfx = lc_leading_bits (node, pos, TBM_STRIDE);
+ unsigned pfx = lc_leading_bits(node, pos, TBM_STRIDE);
struct tbm_node *result = (struct tbm_node *) node;
/* split to LC of len TBM_STRIDE followed by child (extending path) */
- split_lc_node (btrie, node, pos, TBM_STRIDE);
+ split_lc_node(btrie, node, pos, TBM_STRIDE);
/* then convert leading LC node to TBM node */
result->int_bm = 0;
- result->ext_bm = bit (pfx);
+ result->ext_bm = bit(pfx);
btrie->n_lc_nodes--;
btrie->n_tbm_nodes++;
}
- else if (lc_is_terminal (node)) {
+ else if (lc_is_terminal(node)) {
/* convert short terminal LC to TBM (with internal data) */
- unsigned pfx = lc_leading_bits (node, pos, len);
+ unsigned pfx = lc_leading_bits(node, pos, len);
const void *data = node->ptr.data;
node_t *result = (node_t *) node;
- init_empty_node (btrie, result);
- tbm_insert_data (btrie, &result->tbm_node, pfx, len, data);
+ init_empty_node(btrie, result);
+ tbm_insert_data(btrie, &result->tbm_node, pfx, len, data);
btrie->n_lc_nodes--;
}
else {
assert(len > 0);
for (; len > 1; len--) {
- split_lc_node (btrie, node, pos, len - 1);
- convert_lc_node_1 (btrie, &node->ptr.child->lc_node, pos + len - 1);
+ split_lc_node(btrie, node, pos, len - 1);
+ convert_lc_node_1(btrie, &node->ptr.child->lc_node, pos + len - 1);
}
- convert_lc_node_1 (btrie, node, pos);
+ convert_lc_node_1(btrie, node, pos);
}
}
static void insert_lc_node(struct btrie *btrie, node_t *dst, unsigned pos,
- btrie_oct_t pbyte, unsigned last_bit, node_t *tail)
+ btrie_oct_t pbyte, unsigned last_bit, node_t *tail)
{
struct lc_node *node = &dst->lc_node;
btrie_oct_t mask = 1 << (7 - (pos % 8));
btrie_oct_t bit = last_bit ? mask : 0;
- if (mask != 0x01 && is_lc_node (tail)) {
+ if (mask != 0x01 && is_lc_node(tail)) {
/* optimization: LC tail has room for the extra bit (without shifting) */
assert((tail->lc_node.prefix[0] & mask) == bit);
*node = tail->lc_node;
- lc_add_to_len (node, 1);
+ lc_add_to_len(node, 1);
return;
}
/* add new leading LC node of len 1 */
node->prefix[0] = pbyte | bit;
- lc_init_flags (node, 0, 1);
- node->ptr.child = alloc_nodes (btrie, 1, 0);
+ lc_init_flags(node, 0, 1);
+ node->ptr.child = alloc_nodes(btrie, 1, 0);
node->ptr.child[0] = *tail;
btrie->n_lc_nodes++;
- if (is_lc_node (tail))
- coalesce_lc_node (btrie, node, pos);
+ if (is_lc_node(tail))
+ coalesce_lc_node(btrie, node, pos);
}
/* given:
* the bits in the prefix between lc_base(pos + plen) and pos + plen
*/
static inline btrie_oct_t next_pbyte(btrie_oct_t pbyte, unsigned pos,
- unsigned pfx)
+ unsigned pfx)
{
unsigned end = pos + TBM_STRIDE;
if (end % 8 != 0) {
btrie_oct_t nbyte = (btrie_oct_t) pfx << (8 - end % 8);
if (end % 8 > TBM_STRIDE)
- nbyte |= pbyte & high_bits (pos % 8);
+ nbyte |= pbyte & high_bits(pos % 8);
return nbyte;
}
return 0;
* root prefix of the new node.
*/
static void init_tbm_node(struct btrie *btrie, node_t *dst, unsigned pos,
- const btrie_oct_t pbyte, const void **root_data_p, node_t *left,
- node_t *right)
+ const btrie_oct_t pbyte, const void **root_data_p, node_t *left,
+ node_t *right)
{
struct tbm_node *node = &dst->tbm_node;
unsigned nchildren = 0;
tbm_bitmap_t int_bm = 0;
unsigned i, d, pfx_base;
- if (left && is_lc_node (left) && lc_len (&left->lc_node) < TBM_STRIDE)
- convert_lc_node (btrie, &left->lc_node, pos + 1);
- if (right && is_lc_node (right) && lc_len (&right->lc_node) < TBM_STRIDE)
- convert_lc_node (btrie, &right->lc_node, pos + 1);
+ if (left && is_lc_node(left) && lc_len(&left->lc_node) < TBM_STRIDE)
+ convert_lc_node(btrie, &left->lc_node, pos + 1);
+ if (right && is_lc_node(right) && lc_len(&right->lc_node) < TBM_STRIDE)
+ convert_lc_node(btrie, &right->lc_node, pos + 1);
/* set internal data for root prefix */
if (root_data_p) {
data[ndata++] = *root_data_p;
- int_bm |= bit (base_index (0, 0));
+ int_bm |= bit(base_index(0, 0));
}
/* copy internal data from children */
for (d = 0; d < TBM_STRIDE - 1; d++) {
- if (left && has_data (left)) {
+ if (left && has_data(left)) {
for (i = 0; i < 1U << d; i++) {
- const void **data_p = tbm_data_p (&left->tbm_node, i, d);
+ const void **data_p = tbm_data_p(&left->tbm_node, i, d);
if (data_p) {
data[ndata++] = *data_p;
- int_bm |= bit (base_index (i, d + 1));
+ int_bm |= bit(base_index(i, d + 1));
}
}
}
- if (right && has_data (right)) {
+ if (right && has_data(right)) {
for (i = 0; i < 1U << d; i++) {
- const void **data_p = tbm_data_p (&right->tbm_node, i, d);
+ const void **data_p = tbm_data_p(&right->tbm_node, i, d);
if (data_p) {
data[ndata++] = *data_p;
- int_bm |= bit (base_index (i + (1 << d), d + 1));
+ int_bm |= bit(base_index(i + (1 << d), d + 1));
}
}
}
if (child == NULL) {
continue;
}
- else if (is_lc_node (child)) {
- unsigned pfx = pfx_base + lc_leading_bits (&child->lc_node, pos + 1,
- TBM_STRIDE - 1);
+ else if (is_lc_node(child)) {
+ unsigned pfx = pfx_base + lc_leading_bits(&child->lc_node, pos + 1,
+ TBM_STRIDE - 1);
/* child is LC node, just shorten it by TBM_STRIDE - 1 */
- shorten_lc_node (btrie, &children[nchildren++], pos + TBM_STRIDE,
- &child->lc_node, pos + 1);
- ext_bm |= bit (pfx);
+ shorten_lc_node(btrie, &children[nchildren++], pos + TBM_STRIDE,
+ &child->lc_node, pos + 1);
+ ext_bm |= bit(pfx);
}
- else if (!is_empty_node (child)) {
+ else if (!is_empty_node(child)) {
/* convert deepest internal prefixes of child to extending paths
* of the new node
*/
for (i = 0; i < TBM_FANOUT / 2; i++) {
- const void **data_p = tbm_data_p (&child->tbm_node, i,
- TBM_STRIDE - 1);
- node_t *left_ext = tbm_ext_path (&child->tbm_node, 2 * i);
- node_t *right_ext = tbm_ext_path (&child->tbm_node, 2 * i + 1);
+ const void **data_p = tbm_data_p(&child->tbm_node, i,
+ TBM_STRIDE - 1);
+ node_t *left_ext = tbm_ext_path(&child->tbm_node, 2 * i);
+ node_t *right_ext = tbm_ext_path(&child->tbm_node, 2 * i + 1);
if (data_p || left_ext || right_ext) {
node_t *ext_path = &children[nchildren++];
unsigned pfx = pfx_base + i;
- btrie_oct_t npbyte = next_pbyte (pbyte, pos, pfx);
+ btrie_oct_t npbyte = next_pbyte(pbyte, pos, pfx);
- ext_bm |= bit (pfx);
+ ext_bm |= bit(pfx);
if (left_ext == NULL && right_ext == NULL) {
/* only have data - set ext_path to zero-length terminal LC node */
- lc_init_flags (&ext_path->lc_node, 1, 0);
+ lc_init_flags(&ext_path->lc_node, 1, 0);
ext_path->lc_node.prefix[0] = npbyte;
ext_path->lc_node.ptr.data = *data_p;
btrie->n_lc_nodes++;
else if (data_p || (left_ext && right_ext)) {
/* have at least two of data, left_ext, right_ext
* ext_path must be a full TBM node */
- init_tbm_node (btrie, ext_path, pos + TBM_STRIDE,
- npbyte, data_p, left_ext, right_ext);
+ init_tbm_node(btrie, ext_path, pos + TBM_STRIDE,
+ npbyte, data_p, left_ext, right_ext);
}
else if (left_ext) {
/* have only left_ext, insert length-one LC node */
- insert_lc_node (btrie, ext_path, pos + TBM_STRIDE,
- npbyte, 0, left_ext);
+ insert_lc_node(btrie, ext_path, pos + TBM_STRIDE,
+ npbyte, 0, left_ext);
}
else {
/* have only right_ext, insert length-one LC node */
- insert_lc_node (btrie, ext_path, pos + TBM_STRIDE,
- npbyte, 1, right_ext);
+ insert_lc_node(btrie, ext_path, pos + TBM_STRIDE,
+ npbyte, 1, right_ext);
}
}
}
btrie->n_tbm_nodes--;
- free_nodes (btrie, child->tbm_node.ptr.children,
- count_bits (child->tbm_node.ext_bm),
- count_bits (child->tbm_node.int_bm));
+ free_nodes(btrie, child->tbm_node.ptr.children,
+ count_bits(child->tbm_node.ext_bm),
+ count_bits(child->tbm_node.int_bm));
}
}
- assert(count_bits (int_bm) == ndata);
- assert(count_bits (ext_bm) == nchildren);
+ assert(count_bits(int_bm) == ndata);
+ assert(count_bits(ext_bm) == nchildren);
- node->ptr.children = alloc_nodes (btrie, nchildren, ndata);
- memcpy(node->ptr.data_end - (int )ndata, data, ndata * sizeof(data[0]));
+ node->ptr.children = alloc_nodes(btrie, nchildren, ndata);
+ memcpy(node->ptr.data_end - (int) ndata, data, ndata * sizeof(data[0]));
memcpy(node->ptr.children, children, nchildren * sizeof(children[0]));
node->ext_bm = ext_bm;
node->int_bm = int_bm;
}
static enum btrie_result add_to_trie(struct btrie *btrie, node_t *node,
- unsigned pos, const btrie_oct_t *prefix, unsigned len, const void *data)
+ unsigned pos, const btrie_oct_t *prefix, unsigned len, const void *data)
{
for (;;) {
- if (is_lc_node (node)) {
+ if (is_lc_node(node)) {
struct lc_node *lc_node = &node->lc_node;
- unsigned end = pos + lc_len (lc_node);
- unsigned cbits = common_prefix (prefix + lc_shift (pos),
- lc_node->prefix, (len < end ? len : end) - lc_base (pos));
- unsigned clen = lc_base (pos) + cbits; /* position of first mismatch */
+ unsigned end = pos + lc_len(lc_node);
+ unsigned cbits = common_prefix(prefix + lc_shift(pos),
+ lc_node->prefix, (len < end ? len : end) - lc_base(pos));
+ unsigned clen = lc_base(pos) + cbits; /* position of first mismatch */
- if (clen == end && !lc_is_terminal (lc_node)) {
+ if (clen == end && !lc_is_terminal(lc_node)) {
/* matched entire prefix of LC node, proceed to child */
- assert(lc_len (lc_node) > 0);
+ assert(lc_len(lc_node) > 0);
node = lc_node->ptr.child;
pos = end;
}
- else if (clen == end && len == end && lc_is_terminal (lc_node)) {
+ else if (clen == end && len == end && lc_is_terminal(lc_node)) {
/* exact match for terminal node - already have data for prefix */
return BTRIE_DUPLICATE_PREFIX;
}
else {
- assert(clen < end || (lc_is_terminal (lc_node) && len > end));
+ assert(clen < end || (lc_is_terminal(lc_node) && len > end));
/* Need to insert new TBM node at clen */
if (clen > pos) {
- split_lc_node (btrie, lc_node, pos, clen - pos);
+ split_lc_node(btrie, lc_node, pos, clen - pos);
node = lc_node->ptr.child;
- assert(is_lc_node (node));
+ assert(is_lc_node(node));
pos = clen;
}
- convert_lc_node (btrie, &node->lc_node, pos);
+ convert_lc_node(btrie, &node->lc_node, pos);
}
}
- else if (is_empty_node (node)) {
+ else if (is_empty_node(node)) {
/* at empty TBM node - just replace with terminal LC node */
- init_terminal_node (btrie, node, pos, prefix, len, data);
+ init_terminal_node(btrie, node, pos, prefix, len, data);
btrie->n_entries++;
btrie->n_tbm_nodes--;
return BTRIE_OKAY;
if (len < end) {
unsigned plen = len - pos;
- unsigned pfx = extract_bits (prefix, pos, plen);
+ unsigned pfx = extract_bits(prefix, pos, plen);
- if (tbm_data_p (tbm_node, pfx, plen) != NULL)
+ if (tbm_data_p(tbm_node, pfx, plen) != NULL)
return BTRIE_DUPLICATE_PREFIX; /* prefix already has data */
else {
- tbm_insert_data (btrie, tbm_node, pfx, plen, data);
+ tbm_insert_data(btrie, tbm_node, pfx, plen, data);
btrie->n_entries++;
return BTRIE_OKAY;
}
}
else {
- unsigned pfx = extract_bits (prefix, pos, TBM_STRIDE);
+ unsigned pfx = extract_bits(prefix, pos, TBM_STRIDE);
/* follow extending path */
- node = tbm_ext_path (tbm_node, pfx);
+ node = tbm_ext_path(tbm_node, pfx);
if (node == NULL)
- node = tbm_insert_ext_path (btrie, tbm_node, pfx);
+ node = tbm_insert_ext_path(btrie, tbm_node, pfx);
pos = end;
}
}
static const void *
search_trie(const node_t *node, unsigned pos, const btrie_oct_t *prefix,
- unsigned len)
+ unsigned len)
{
/* remember last TBM node seen with internal data */
const struct tbm_node *int_node = 0;
unsigned int_pfx = 0, int_plen = 0;
while (node) {
- if (is_lc_node (node)) {
+ if (is_lc_node(node)) {
const struct lc_node *lc_node = &node->lc_node;
- unsigned end = pos + lc_len (lc_node);
+ unsigned end = pos + lc_len(lc_node);
if (len < end)
break;
- if (!prefixes_equal (prefix + lc_shift (pos), lc_node->prefix,
- end - lc_base (pos)))
+ if (!prefixes_equal(prefix + lc_shift(pos), lc_node->prefix,
+ end - lc_base(pos)))
break;
- if (lc_is_terminal (lc_node))
+ if (lc_is_terminal(lc_node))
return lc_node->ptr.data; /* found terminal node */
pos = end;
unsigned end = pos + TBM_STRIDE;
if (len < end) {
unsigned plen = len - pos;
- unsigned pfx = extract_bits (prefix, pos, plen);
- if (has_internal_data (tbm_node, pfx, plen)) {
+ unsigned pfx = extract_bits(prefix, pos, plen);
+ if (has_internal_data(tbm_node, pfx, plen)) {
int_node = tbm_node;
int_pfx = pfx;
int_plen = plen;
break;
}
else {
- unsigned pfx = extract_bits (prefix, pos, TBM_STRIDE);
- if (has_internal_data (tbm_node, pfx >> 1, TBM_STRIDE - 1)) {
+ unsigned pfx = extract_bits(prefix, pos, TBM_STRIDE);
+ if (has_internal_data(tbm_node, pfx >> 1, TBM_STRIDE - 1)) {
int_node = tbm_node;
int_pfx = pfx >> 1;
int_plen = TBM_STRIDE - 1;
}
pos = end;
- node = tbm_ext_path (tbm_node, pfx);
+ node = tbm_ext_path(tbm_node, pfx);
}
}
}
if (int_node) {
- const void **data_p = tbm_data_p (int_node, int_pfx, int_plen);
+ const void **data_p = tbm_data_p(int_node, int_pfx, int_plen);
while (data_p == NULL) {
assert(int_plen > 0);
int_pfx >>= 1;
int_plen--;
- data_p = tbm_data_p (int_node, int_pfx, int_plen);
+ data_p = tbm_data_p(int_node, int_pfx, int_plen);
}
return *data_p;
}
{
struct btrie *btrie;
- if (!(btrie = rspamd_mempool_alloc0 (mp, sizeof(*btrie)))) {
+ if (!(btrie = rspamd_mempool_alloc0(mp, sizeof(*btrie)))) {
return NULL;
}
}
enum btrie_result btrie_add_prefix(struct btrie *btrie,
- const btrie_oct_t *prefix, unsigned len, const void *data)
+ const btrie_oct_t *prefix, unsigned len, const void *data)
{
enum btrie_result rv;
- if ((rv = setjmp (btrie->exception)) != 0)
+ if ((rv = setjmp(btrie->exception)) != 0)
return rv; /* out of memory */
- return add_to_trie (btrie, &btrie->root, 0, prefix, len, data);
+ return add_to_trie(btrie, &btrie->root, 0, prefix, len, data);
}
const void *
btrie_lookup(const struct btrie *btrie, const btrie_oct_t *prefix, unsigned len)
{
- return search_trie (&btrie->root, 0, prefix, len);
+ return search_trie(&btrie->root, 0, prefix, len);
}
/****************************************************************
node_stats(const node_t *node, size_t depth, struct stats *stats)
{
if (depth > stats->max_depth)
- stats->max_depth = depth;
+ stats->max_depth = depth;
stats->total_depth += depth;
if (is_lc_node(node)) {
stats->n_lc_nodes++;
#endif
if (!lc_is_terminal(&node->lc_node))
- node_stats(node->lc_node.ptr.child, depth + 1, stats);
+ node_stats(node->lc_node.ptr.child, depth + 1, stats);
#ifndef NDEBUG
else
- stats->n_entries++;
+ stats->n_entries++;
#endif
}
else {
stats->alloc_waste += (ndata % 2) * sizeof(void *);
#endif
for (i = 0; i < nchildren; i++)
- node_stats(&node->tbm_node.ptr.children[i], depth + 1, stats);
+ node_stats(&node->tbm_node.ptr.children[i], depth + 1, stats);
}
}
#endif /* BTRIE_EXTENDED_STATS */
#endif /* not NDEBUG */
const char *
-btrie_stats(const struct btrie *btrie, guint duplicates)
+btrie_stats(const struct btrie *btrie, unsigned int duplicates)
{
static char buf[128];
size_t n_nodes = btrie->n_lc_nodes + btrie->n_tbm_nodes;
size_t alloc_free = (btrie->alloc_total + sizeof(node_t) /* do not double-count the root node */
- - n_nodes * sizeof(node_t) - btrie->alloc_data - btrie->alloc_waste
- - sizeof(*btrie));
+ - n_nodes * sizeof(node_t) - btrie->alloc_data - btrie->alloc_waste - sizeof(*btrie));
#ifdef BTRIE_EXTENDED_STATS
struct stats stats;
double average_depth;
memset(&stats, 0, sizeof(stats));
node_stats(&btrie->root, 0, &stats);
- average_depth = (double)stats.total_depth / n_nodes;
+ average_depth = (double) stats.total_depth / n_nodes;
#ifndef NDEBUG
/* check the node counts */
#ifndef NDEBUG
/* check that we haven't lost any memory */
- assert(alloc_free == count_free (btrie));
+ assert(alloc_free == count_free(btrie));
#endif
#ifdef BTRIE_DEBUG_ALLOC
#ifdef BTRIE_EXTENDED_STATS
snprintf(buf, sizeof(buf),
- "ents=%lu tbm=%lu lc=%lu mem=%.0fk free=%lu waste=%lu"
- " depth=%.1f/%lu"
- ,(long unsigned)btrie->n_entries, (long unsigned)btrie->n_tbm_nodes,
- (long unsigned)btrie->n_lc_nodes, (double)btrie->alloc_total / 1024,
- (long unsigned)alloc_free, (long unsigned)btrie->alloc_waste
- , average_depth, (long unsigned)stats.max_depth);
+ "ents=%lu tbm=%lu lc=%lu mem=%.0fk free=%lu waste=%lu"
+ " depth=%.1f/%lu",
+ (long unsigned) btrie->n_entries, (long unsigned) btrie->n_tbm_nodes,
+ (long unsigned) btrie->n_lc_nodes, (double) btrie->alloc_total / 1024,
+ (long unsigned) alloc_free, (long unsigned) btrie->alloc_waste, average_depth, (long unsigned) stats.max_depth);
#else
snprintf(buf, sizeof(buf),
- "ents=%lu dup=%u tbm=%lu lc=%lu mem=%.0fk free=%lu waste=%lu",
- (long unsigned)btrie->n_entries,
- duplicates,
- (long unsigned)btrie->n_tbm_nodes,
- (long unsigned)btrie->n_lc_nodes, (double)btrie->alloc_total / 1024,
- (long unsigned)alloc_free, (long unsigned)btrie->alloc_waste
- );
+ "ents=%lu dup=%u tbm=%lu lc=%lu mem=%.0fk free=%lu waste=%lu",
+ (long unsigned) btrie->n_entries,
+ duplicates,
+ (long unsigned) btrie->n_tbm_nodes,
+ (long unsigned) btrie->n_lc_nodes, (double) btrie->alloc_total / 1024,
+ (long unsigned) alloc_free, (long unsigned) btrie->alloc_waste);
#endif
buf[sizeof(buf) - 1] = '\0';
return buf;
#ifndef NO_MASTER_DUMP
-struct walk_context
-{
+struct walk_context {
btrie_walk_cb_t *callback;
void *user_data;
walk_node(const node_t *node, unsigned pos, struct walk_context *ctx);
static void walk_tbm_node(const struct tbm_node *node, unsigned pos,
- unsigned pfx, unsigned plen, struct walk_context *ctx)
+ unsigned pfx, unsigned plen, struct walk_context *ctx)
{
btrie_oct_t *prefix = ctx->prefix;
int pbyte = pos / 8;
btrie_oct_t pbit = 0x80 >> (pos % 8);
- const void **data_p = tbm_data_p (node, pfx, plen);
+ const void **data_p = tbm_data_p(node, pfx, plen);
if (pos >= BTRIE_MAX_PREFIX) {
/* This can/should not happen, but don't overwrite buffers if it does. */
}
if (data_p)
- ctx->callback (prefix, pos, *data_p, 0, ctx->user_data);
+ ctx->callback(prefix, pos, *data_p, 0, ctx->user_data);
/* walk children */
if (plen < TBM_STRIDE - 1) {
/* children are internal prefixes in same node */
- walk_tbm_node (node, pos + 1, pfx << 1, plen + 1, ctx);
+ walk_tbm_node(node, pos + 1, pfx << 1, plen + 1, ctx);
prefix[pbyte] |= pbit;
- walk_tbm_node (node, pos + 1, (pfx << 1) + 1, plen + 1, ctx);
+ walk_tbm_node(node, pos + 1, (pfx << 1) + 1, plen + 1, ctx);
prefix[pbyte] &= ~pbit;
}
else {
/* children are extending paths */
const node_t *ext_path;
- if ((ext_path = tbm_ext_path (node, pfx << 1)) != NULL)
- walk_node (ext_path, pos + 1, ctx);
- if ((ext_path = tbm_ext_path (node, (pfx << 1) + 1)) != NULL) {
+ if ((ext_path = tbm_ext_path(node, pfx << 1)) != NULL)
+ walk_node(ext_path, pos + 1, ctx);
+ if ((ext_path = tbm_ext_path(node, (pfx << 1) + 1)) != NULL) {
prefix[pbyte] |= pbit;
- walk_node (ext_path, pos + 1, ctx);
+ walk_node(ext_path, pos + 1, ctx);
prefix[pbyte] &= ~pbit;
}
}
if (data_p)
- ctx->callback (prefix, pos, *data_p, 1, ctx->user_data);
+ ctx->callback(prefix, pos, *data_p, 1, ctx->user_data);
}
static void walk_lc_node(const struct lc_node *node, unsigned pos,
- struct walk_context *ctx)
+ struct walk_context *ctx)
{
btrie_oct_t *prefix = ctx->prefix;
- unsigned end = pos + lc_len (node);
- btrie_oct_t save_prefix = prefix[lc_shift (pos)];
+ unsigned end = pos + lc_len(node);
+ btrie_oct_t save_prefix = prefix[lc_shift(pos)];
if (end > BTRIE_MAX_PREFIX) {
/* This can/should not happen, but don't overwrite buffers if it does. */
}
/* construct full prefix to node */
- memcpy(&prefix[lc_shift (pos)], node->prefix, lc_bytes (node, pos));
+ memcpy(&prefix[lc_shift(pos)], node->prefix, lc_bytes(node, pos));
if (end % 8)
- prefix[end / 8] &= high_bits (end % 8);
+ prefix[end / 8] &= high_bits(end % 8);
- if (lc_is_terminal (node)) {
- ctx->callback (prefix, end, node->ptr.data, 0, ctx->user_data);
- ctx->callback (prefix, end, node->ptr.data, 1, ctx->user_data);
+ if (lc_is_terminal(node)) {
+ ctx->callback(prefix, end, node->ptr.data, 0, ctx->user_data);
+ ctx->callback(prefix, end, node->ptr.data, 1, ctx->user_data);
}
else
- walk_node (node->ptr.child, end, ctx);
+ walk_node(node->ptr.child, end, ctx);
- prefix[lc_shift (pos)] = save_prefix; /* restore parents prefix */
- if (lc_bytes (node, pos) > 1)
- memset(&prefix[lc_shift (pos) + 1], 0, lc_bytes (node, pos) - 1);
+ prefix[lc_shift(pos)] = save_prefix; /* restore parents prefix */
+ if (lc_bytes(node, pos) > 1)
+ memset(&prefix[lc_shift(pos) + 1], 0, lc_bytes(node, pos) - 1);
}
static void walk_node(const node_t *node, unsigned pos,
- struct walk_context *ctx)
+ struct walk_context *ctx)
{
- if (is_lc_node (node))
- walk_lc_node (&node->lc_node, pos, ctx);
+ if (is_lc_node(node))
+ walk_lc_node(&node->lc_node, pos, ctx);
else
- walk_tbm_node (&node->tbm_node, pos, 0, 0, ctx);
+ walk_tbm_node(&node->tbm_node, pos, 0, 0, ctx);
}
/* walk trie in lexicographical order
* calls callback twice (once preorder, once postorder) at each prefix
*/
void btrie_walk(const struct btrie *btrie, btrie_walk_cb_t *callback,
- void *user_data)
+ void *user_data)
{
struct walk_context ctx;
ctx.callback = callback;
ctx.user_data = user_data;
- walk_node (&btrie->root, 0, &ctx);
+ walk_node(&btrie->root, 0, &ctx);
}
#endif /* not NO_MASTER_DUMP */
#include <stdio.h>
#ifndef UNUSED
-# define UNUSED __attribute__((unused))
+#define UNUSED __attribute__((unused))
#endif
/* bogus replacements mp_alloc for running self-tests */
}
#if 0
-# define PASS(name) puts("OK " name)
+#define PASS(name) puts("OK " name)
#else
-# define PASS(name) fputs(".", stdout); fflush(stdout)
+#define PASS(name) \
+ fputs(".", stdout); \
+ fflush(stdout)
#endif
-const char * pgm_name = "???";
+const char *pgm_name = "???";
static void
test_struct_node_packing()
static void
test_bit()
{
- tbm_bitmap_t ones = ~(tbm_bitmap_t)0;
+ tbm_bitmap_t ones = ~(tbm_bitmap_t) 0;
tbm_bitmap_t high_bit = ones ^ (ones >> 1);
assert(bit(0) == high_bit);
test_count_bits()
{
unsigned max_bits = sizeof(tbm_bitmap_t) * 8;
- tbm_bitmap_t ones = ~(tbm_bitmap_t)0;
+ tbm_bitmap_t ones = ~(tbm_bitmap_t) 0;
assert(count_bits(0) == 0);
assert(count_bits(1) == 1);
test_count_bits_before()
{
unsigned max_bits = sizeof(tbm_bitmap_t) * 8;
- tbm_bitmap_t ones = ~(tbm_bitmap_t)0;
+ tbm_bitmap_t ones = ~(tbm_bitmap_t) 0;
unsigned i;
for (i = 0; i < max_bits; i++) {
test_count_bits_from()
{
unsigned max_bits = sizeof(tbm_bitmap_t) * 8;
- tbm_bitmap_t ones = ~(tbm_bitmap_t)0;
+ tbm_bitmap_t ones = ~(tbm_bitmap_t) 0;
unsigned i;
for (i = 0; i < max_bits; i++) {
unsigned i;
for (i = 0; i < 32; i++)
- assert(extract_bits(prefix, i, 0) == 0);
+ assert(extract_bits(prefix, i, 0) == 0);
for (i = 0; i < 8; i++)
- assert(extract_bits(prefix, i, 1) == 1);
+ assert(extract_bits(prefix, i, 1) == 1);
for (i = 8; i < 16; i++)
- assert(extract_bits(prefix, i, 1) == i % 2);
+ assert(extract_bits(prefix, i, 1) == i % 2);
for (i = 16; i < 24; i++)
- assert(extract_bits(prefix, i, 1) == (i + 1) % 2);
+ assert(extract_bits(prefix, i, 1) == (i + 1) % 2);
for (i = 24; i < 32; i++)
- assert(extract_bits(prefix, i, 1) == 0);
+ assert(extract_bits(prefix, i, 1) == 0);
assert(extract_bits(prefix, 2, 6) == 0x3f);
assert(extract_bits(prefix, 3, 6) == 0x3e);
assert(!prefixes_equal(prefix1, prefix2, 8 * LC_BYTES_PER_NODE));
assert(prefixes_equal(prefix1, prefix2, i));
if (i + 1 < 8 * LC_BYTES_PER_NODE)
- assert(!prefixes_equal(prefix1, prefix2, i + 1));
+ assert(!prefixes_equal(prefix1, prefix2, i + 1));
prefix1[i / 8] ^= 1 << (7 - i % 8);
}
PASS("test_prefixes_equal");
prefix1[i / 8] ^= 1 << (7 - i % 8);
assert(common_prefix(prefix1, prefix2, 8 * LC_BYTES_PER_NODE) == i);
if (i + 1 < 8 * LC_BYTES_PER_NODE)
- assert(common_prefix(prefix1, prefix2, i+1) == i);
+ assert(common_prefix(prefix1, prefix2, i + 1) == i);
prefix1[i / 8] ^= 1 << (7 - i % 8);
}
PASS("test_common_prefix");
static void
test_base_index()
{
- assert(base_index(0,0) == 1);
- assert(base_index(0,1) == 2);
- assert(base_index(1,1) == 3);
- assert(base_index(0,2) == 4);
- assert(base_index(1,2) == 5);
- assert(base_index(2,2) == 6);
- assert(base_index(3,2) == 7);
+ assert(base_index(0, 0) == 1);
+ assert(base_index(0, 1) == 2);
+ assert(base_index(1, 1) == 3);
+ assert(base_index(0, 2) == 4);
+ assert(base_index(1, 2) == 5);
+ assert(base_index(2, 2) == 6);
+ assert(base_index(3, 2) == 7);
PASS("test_base_index");
}
/****************************************************************/
static const btrie_oct_t numbered_bytes[] = {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
- 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
- 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
- 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
- 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
- 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+ 0x00,
+ 0x01,
+ 0x02,
+ 0x03,
+ 0x04,
+ 0x05,
+ 0x06,
+ 0x07,
+ 0x08,
+ 0x09,
+ 0x0a,
+ 0x0b,
+ 0x0c,
+ 0x0d,
+ 0x0e,
+ 0x0f,
+ 0x10,
+ 0x11,
+ 0x12,
+ 0x13,
+ 0x14,
+ 0x15,
+ 0x16,
+ 0x17,
+ 0x18,
+ 0x19,
+ 0x1a,
+ 0x1b,
+ 0x1c,
+ 0x1d,
+ 0x1e,
+ 0x1f,
+ 0x20,
+ 0x21,
+ 0x22,
+ 0x23,
+ 0x24,
+ 0x25,
+ 0x26,
+ 0x27,
+ 0x28,
+ 0x29,
+ 0x2a,
+ 0x2b,
+ 0x2c,
+ 0x2d,
+ 0x2e,
+ 0x2f,
+ 0x30,
+ 0x31,
+ 0x32,
+ 0x33,
+ 0x34,
+ 0x35,
+ 0x36,
+ 0x37,
+ 0x38,
+ 0x39,
+ 0x3a,
+ 0x3b,
+ 0x3c,
+ 0x3d,
+ 0x3e,
+ 0x3f,
};
static void
check_non_terminal_lc_node(struct lc_node *node, unsigned len)
{
- assert(is_lc_node((node_t *)node));
+ assert(is_lc_node((node_t *) node));
assert(!lc_is_terminal(node));
assert(lc_len(node) == len);
}
static void
check_terminal_lc_node(struct lc_node *node, unsigned len, const void *data)
{
- assert(is_lc_node((node_t *)node));
+ assert(is_lc_node((node_t *) node));
assert(lc_is_terminal(node));
assert(lc_len(node) == len);
assert(node->ptr.data == data);
test_init_terminal_node()
{
struct btrie *btrie = btrie_init(NULL);
- const void *data = (void *)0xdeadbeef;
+ const void *data = (void *) 0xdeadbeef;
node_t node;
struct lc_node *head = &node.lc_node;
init_terminal_node(btrie, &node, 0,
- numbered_bytes, 8 * LC_BYTES_PER_NODE, data);
+ numbered_bytes, 8 * LC_BYTES_PER_NODE, data);
check_terminal_lc_node(head, 8 * LC_BYTES_PER_NODE, data);
assert(memcmp(head->prefix, numbered_bytes, LC_BYTES_PER_NODE) == 0);
init_terminal_node(btrie, &node, 7,
- numbered_bytes, 8 * LC_BYTES_PER_NODE, data);
+ numbered_bytes, 8 * LC_BYTES_PER_NODE, data);
check_terminal_lc_node(head, 8 * LC_BYTES_PER_NODE - 7, data);
assert(memcmp(head->prefix, numbered_bytes, LC_BYTES_PER_NODE) == 0);
init_terminal_node(btrie, &node, 0,
- numbered_bytes, 2 * 8 * LC_BYTES_PER_NODE, data);
+ numbered_bytes, 2 * 8 * LC_BYTES_PER_NODE, data);
check_non_terminal_lc_node(head, 8 * LC_BYTES_PER_NODE);
assert(memcmp(head->prefix, numbered_bytes, LC_BYTES_PER_NODE) == 0);
{
struct lc_node *child = &head->ptr.child->lc_node;
check_terminal_lc_node(child, 8 * LC_BYTES_PER_NODE, data);
assert(memcmp(child->prefix, &numbered_bytes[LC_BYTES_PER_NODE],
- LC_BYTES_PER_NODE) == 0);
+ LC_BYTES_PER_NODE) == 0);
}
init_terminal_node(btrie, &node, 15,
- numbered_bytes, 8 * LC_BYTES_PER_NODE + 15, data);
+ numbered_bytes, 8 * LC_BYTES_PER_NODE + 15, data);
check_non_terminal_lc_node(head, 8 * LC_BYTES_PER_NODE - 7);
assert(memcmp(head->prefix, &numbered_bytes[1], LC_BYTES_PER_NODE) == 0);
{
test_coalesce_lc_node()
{
struct btrie *btrie = btrie_init(NULL);
- const void *data = (void *)0xdeadbeef;
+ const void *data = (void *) 0xdeadbeef;
node_t node;
struct lc_node *head = &node.lc_node;
/* test merging */
init_terminal_node(btrie, &node, 0,
- numbered_bytes, 8 * (LC_BYTES_PER_NODE + 1), data);
+ numbered_bytes, 8 * (LC_BYTES_PER_NODE + 1), data);
check_non_terminal_lc_node(head, LC_BYTES_PER_NODE * 8);
lc_add_to_len(head, -8);
coalesce_lc_node(btrie, head, 8);
check_terminal_lc_node(head, LC_BYTES_PER_NODE * 8, data);
- assert(head->prefix[LC_BYTES_PER_NODE - 1]
- == numbered_bytes[LC_BYTES_PER_NODE]);
+ assert(head->prefix[LC_BYTES_PER_NODE - 1] == numbered_bytes[LC_BYTES_PER_NODE]);
/* test bit stealing */
init_terminal_node(btrie, &node, 0,
- numbered_bytes, 8 * (2 * LC_BYTES_PER_NODE), data);
+ numbered_bytes, 8 * (2 * LC_BYTES_PER_NODE), data);
check_non_terminal_lc_node(head, LC_BYTES_PER_NODE * 8);
lc_add_to_len(head, -15);
coalesce_lc_node(btrie, head, 15);
check_non_terminal_lc_node(head, LC_BYTES_PER_NODE * 8 - 7);
assert(memcmp(head->prefix, numbered_bytes, LC_BYTES_PER_NODE - 1) == 0);
- assert(head->prefix[LC_BYTES_PER_NODE - 1]
- == numbered_bytes[LC_BYTES_PER_NODE]);
+ assert(head->prefix[LC_BYTES_PER_NODE - 1] == numbered_bytes[LC_BYTES_PER_NODE]);
{
struct lc_node *child = &head->ptr.child->lc_node;
check_terminal_lc_node(child, 8 * (LC_BYTES_PER_NODE - 1), data);
assert(memcmp(child->prefix, &numbered_bytes[LC_BYTES_PER_NODE + 1],
- LC_BYTES_PER_NODE - 1) == 0);
+ LC_BYTES_PER_NODE - 1) == 0);
}
PASS("test_coalesce_lc_node");
test_shorten_lc_node()
{
struct btrie *btrie = btrie_init(NULL);
- const void *data = (void *)0xdeadbeef;
+ const void *data = (void *) 0xdeadbeef;
node_t node, shorter;
/* test shorten without shift */
init_terminal_node(btrie, &node, 0,
- numbered_bytes, 8 * LC_BYTES_PER_NODE, data);
+ numbered_bytes, 8 * LC_BYTES_PER_NODE, data);
memset(shorter.lc_node.prefix, 0xff, LC_BYTES_PER_NODE);
shorten_lc_node(btrie, &shorter, 7, &node.lc_node, 0);
check_terminal_lc_node(&shorter.lc_node, LC_BYTES_PER_NODE * 8 - 7, data);
- assert(memcmp(shorter.lc_node.prefix, numbered_bytes, LC_BYTES_PER_NODE)
- == 0);
+ assert(memcmp(shorter.lc_node.prefix, numbered_bytes, LC_BYTES_PER_NODE) == 0);
/* test shorten with shift */
init_terminal_node(btrie, &node, 7,
- numbered_bytes, 8 * LC_BYTES_PER_NODE, data);
+ numbered_bytes, 8 * LC_BYTES_PER_NODE, data);
memset(shorter.lc_node.prefix, 0xff, LC_BYTES_PER_NODE);
shorten_lc_node(btrie, &shorter, 9, &node.lc_node, 7);
check_terminal_lc_node(&shorter.lc_node, LC_BYTES_PER_NODE * 8 - 9, data);
assert(memcmp(shorter.lc_node.prefix, &numbered_bytes[1],
- LC_BYTES_PER_NODE - 1) == 0);
+ LC_BYTES_PER_NODE - 1) == 0);
{
/* test child stealing */
test_split_lc_node()
{
struct btrie *btrie = btrie_init(NULL);
- const void *data = (void *)0xdeadbeef;
+ const void *data = (void *) 0xdeadbeef;
struct lc_node node;
- init_terminal_node(btrie, (node_t *)&node, 1, numbered_bytes, 25, data);
+ init_terminal_node(btrie, (node_t *) &node, 1, numbered_bytes, 25, data);
split_lc_node(btrie, &node, 1, 8);
check_non_terminal_lc_node(&node, 8);
check_terminal_lc_node(&node.ptr.child->lc_node, 16, data);
/* test conversion of terminal to non-terminal */
- init_terminal_node(btrie, (node_t *)&node, 7, numbered_bytes, 10, data);
+ init_terminal_node(btrie, (node_t *) &node, 7, numbered_bytes, 10, data);
split_lc_node(btrie, &node, 7, 3);
check_non_terminal_lc_node(&node, 3);
check_terminal_lc_node(&node.ptr.child->lc_node, 0, data);
test_convert_lc_node_1()
{
struct btrie *btrie = btrie_init(NULL);
- const void *data = (void *)0xdeadbeef;
+ const void *data = (void *) 0xdeadbeef;
struct lc_node head;
/* test tail is left */
init_terminal_node(btrie, head.ptr.child, 1, numbered_bytes, 1, data);
convert_lc_node_1(btrie, &head, 0);
{
- node_t *result = (node_t *)&head;
+ node_t *result = (node_t *) &head;
assert(is_tbm_node(result));
assert(result->tbm_node.ext_bm == 0);
assert(result->tbm_node.int_bm == bit(base_index(0, 1)));
init_terminal_node(btrie, head.ptr.child, 8, numbered_bytes, 10, data);
convert_lc_node_1(btrie, &head, 7);
{
- node_t *result = (node_t *)&head;
+ node_t *result = (node_t *) &head;
assert(is_tbm_node(result));
assert(result->tbm_node.ext_bm == 0);
assert(result->tbm_node.int_bm == bit(base_index(4, 3)));
test_convert_lc_node()
{
struct btrie *btrie = btrie_init(NULL);
- const void *data = (void *)0xdeadbeef;
+ const void *data = (void *) 0xdeadbeef;
node_t node;
/* if (len >= TBM_STRIDE) */
test_insert_lc_node()
{
struct btrie *btrie = btrie_init(NULL);
- const void *data = (void *)0xdeadbeef;
+ const void *data = (void *) 0xdeadbeef;
node_t node, tail;
/* test optimized case, last_bit == 0 */
test_init_tbm_node()
{
struct btrie *btrie = btrie_init(NULL);
- const void *data = (void *)0xdeadbeef;
+ const void *data = (void *) 0xdeadbeef;
unsigned lr;
node_t node;
assert(node.tbm_node.ext_bm == bit(base));
assert(node.tbm_node.int_bm == 0);
check_terminal_lc_node(&tbm_ext_path(&node.tbm_node, base)->lc_node,
- 1, data);
+ 1, data);
/* test with short LC node children */
init_terminal_node(btrie, &child, 1, numbered_bytes, TBM_STRIDE - 1, data);
init_tbm_node(btrie, &node, 0, 0, NULL, left, right);
assert(is_tbm_node(&node));
assert(node.tbm_node.ext_bm == 0);
- assert(node.tbm_node.int_bm == bit(base_index(base >> 1, TBM_STRIDE-1)));
- assert(*tbm_data_p(&node.tbm_node, base >> 1, TBM_STRIDE-1) == data);
+ assert(node.tbm_node.int_bm == bit(base_index(base >> 1, TBM_STRIDE - 1)));
+ assert(*tbm_data_p(&node.tbm_node, base >> 1, TBM_STRIDE - 1) == data);
/* construct TBM node with all eight combinations of having data,
* left_ext and/or right_ext in its extending paths */
init_empty_node(btrie, &child);
for (pfx = 0; pfx < 8; pfx++) {
if (pfx & 1)
- tbm_insert_data(btrie, &child.tbm_node, pfx, TBM_STRIDE - 1, data);
+ tbm_insert_data(btrie, &child.tbm_node, pfx, TBM_STRIDE - 1, data);
if (pfx & 2) {
btrie_oct_t prefix0 = 0;
init_terminal_node(btrie,
- tbm_insert_ext_path(btrie, &child.tbm_node, 2*pfx),
- TBM_STRIDE + 1,
- &prefix0, TBM_STRIDE + 2, data);
+ tbm_insert_ext_path(btrie, &child.tbm_node, 2 * pfx),
+ TBM_STRIDE + 1,
+ &prefix0, TBM_STRIDE + 2, data);
}
if (pfx & 4) {
btrie_oct_t prefix0 = 0x80 >> TBM_STRIDE;
init_terminal_node(btrie,
- tbm_insert_ext_path(btrie, &child.tbm_node, 2*pfx+1),
- TBM_STRIDE + 1,
- &prefix0, TBM_STRIDE + 3, data);
+ tbm_insert_ext_path(btrie, &child.tbm_node, 2 * pfx + 1),
+ TBM_STRIDE + 1,
+ &prefix0, TBM_STRIDE + 3, data);
}
}
init_tbm_node(btrie, &node, 0, 0, NULL, left, right);
unsigned base = lr ? (1U << (TBM_STRIDE - 1)) : 0;
node_t *ext_path = tbm_ext_path(&node.tbm_node, base + pfx);
if (pfx == 0)
- assert(ext_path == NULL);
+ assert(ext_path == NULL);
else if (pfx == 1)
- check_terminal_lc_node(&ext_path->lc_node, 0, data);
+ check_terminal_lc_node(&ext_path->lc_node, 0, data);
else if (pfx == 2) {
check_terminal_lc_node(&ext_path->lc_node, 2, data);
assert(ext_path->lc_node.prefix[0] == 0);
test_add_to_trie()
{
struct btrie *btrie = btrie_init(NULL);
- const void *data = (void *)0xdeadbeef;
+ const void *data = (void *) 0xdeadbeef;
enum btrie_result result;
unsigned pfx, plen;
node_t root;
/* test initial insertion */
init_empty_node(btrie, &root);
result = add_to_trie(btrie, &root, 0,
- numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE, data);
+ numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE, data);
assert(result == BTRIE_OKAY);
check_non_terminal_lc_node(&root.lc_node, 8 * LC_BYTES_PER_NODE);
check_terminal_lc_node(&root.lc_node.ptr.child->lc_node,
- 8 * LC_BYTES_PER_NODE, data);
+ 8 * LC_BYTES_PER_NODE, data);
/* test can follow LC node to tail, and then detect duplicate prefix */
result = add_to_trie(btrie, &root, 0,
- numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE, data);
+ numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE, data);
assert(result == BTRIE_DUPLICATE_PREFIX);
/* test can insert new TBM node within existing LC node */
result = add_to_trie(btrie, &root, 0,
- &numbered_bytes[1], 16, data);
+ &numbered_bytes[1], 16, data);
assert(result == BTRIE_OKAY);
check_non_terminal_lc_node(&root.lc_node, 7);
assert(is_tbm_node(root.lc_node.ptr.child));
btrie_oct_t prefix0 = plen ? pfx << (8 - plen) : 0;
init_empty_node(btrie, &root);
init_terminal_node(btrie, tbm_insert_ext_path(btrie, &root.tbm_node, 0),
- TBM_STRIDE,
- numbered_bytes, 8, data);
+ TBM_STRIDE,
+ numbered_bytes, 8, data);
result = add_to_trie(btrie, &root, 0, &prefix0, plen, data);
assert(result == BTRIE_OKAY);
assert(is_tbm_node(&root));
assert(root.tbm_node.ext_bm == bit(pfx));
assert(root.tbm_node.int_bm == bit(base_index(0, 0)));
check_terminal_lc_node(&tbm_ext_path(&root.tbm_node, pfx)->lc_node,
- 8 - TBM_STRIDE, data);
+ 8 - TBM_STRIDE, data);
result = add_to_trie(btrie, &root, 0, &prefix0, 8, data);
assert(result == BTRIE_DUPLICATE_PREFIX);
/* test can follow extending path */
init_empty_node(btrie, &root);
init_terminal_node(btrie,
- tbm_insert_ext_path(btrie, &root.tbm_node, 0), TBM_STRIDE,
- numbered_bytes, 8, data);
+ tbm_insert_ext_path(btrie, &root.tbm_node, 0), TBM_STRIDE,
+ numbered_bytes, 8, data);
result = add_to_trie(btrie, &root, 0, numbered_bytes, 7, data);
assert(result == BTRIE_OKAY);
assert(root.tbm_node.ext_bm == bit(0));
assert(root.tbm_node.int_bm == 0);
check_non_terminal_lc_node(&root.tbm_node.ptr.children[0].lc_node,
- 7 - TBM_STRIDE);
+ 7 - TBM_STRIDE);
PASS("test_add_to_trie");
}
test_search_trie()
{
struct btrie *btrie = btrie_init(NULL);
- const void *data01 = (void *)0xdead0001;
- const void *data11 = (void *)0xdead0101;
- const void *data = (void *)0xdeadbeef;
+ const void *data01 = (void *) 0xdead0001;
+ const void *data11 = (void *) 0xdead0101;
+ const void *data = (void *) 0xdeadbeef;
unsigned plen, pfx;
node_t root;
/* test can follow chain of LC nodes to an exact match */
init_empty_node(btrie, &root);
add_to_trie(btrie, &root, 0,
- numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE, data);
+ numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE, data);
- assert(search_trie(&root, 0, numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE)
- == data);
- assert(search_trie(&root, 0, numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE + 1)
- == data);
- assert(search_trie(&root, 0, numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE - 1)
- == NULL);
- assert(search_trie(&root, 0, &numbered_bytes[1], 8 * 2 * LC_BYTES_PER_NODE)
- == NULL);
+ assert(search_trie(&root, 0, numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE) == data);
+ assert(search_trie(&root, 0, numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE + 1) == data);
+ assert(search_trie(&root, 0, numbered_bytes, 8 * 2 * LC_BYTES_PER_NODE - 1) == NULL);
+ assert(search_trie(&root, 0, &numbered_bytes[1], 8 * 2 * LC_BYTES_PER_NODE) == NULL);
/* test can follow extending path to an exact match */
for (pfx = 0; pfx < (1U << TBM_STRIDE); pfx++) {
assert(search_trie(&root, 0, &prefix0, 8) == data);
/* test that last matching TBM internal prefix gets picked up */
if (prefix0 & 0x80)
- assert(search_trie(&root, 0, &prefix0, 7) == data11);
+ assert(search_trie(&root, 0, &prefix0, 7) == data11);
else
- assert(search_trie(&root, 0, &prefix0, 7) == data01);
+ assert(search_trie(&root, 0, &prefix0, 7) == data01);
prefix0 ^= 1 << (8 - TBM_STRIDE);
if (prefix0 & 0x80)
- assert(search_trie(&root, 0, &prefix0, 8) == data11);
+ assert(search_trie(&root, 0, &prefix0, 8) == data11);
else
- assert(search_trie(&root, 0, &prefix0, 8) == data01);
+ assert(search_trie(&root, 0, &prefix0, 8) == data01);
}
/* test finding of TBM internal prefixes */
for (pfx = 0; pfx < (1U << TBM_STRIDE); pfx++) {
btrie_oct_t prefix0 = pfx << (8 - plen);
if (prefix0 & 0x80)
- assert(search_trie(&root, 0, &prefix0, plen) == data11);
+ assert(search_trie(&root, 0, &prefix0, plen) == data11);
else
- assert(search_trie(&root, 0, &prefix0, plen) == data01);
+ assert(search_trie(&root, 0, &prefix0, plen) == data01);
}
}
#define INDENT_FILL "....:....|....:....|....:....|....:....|"
static void dump_node(const node_t *node, unsigned pos, btrie_oct_t *prefix,
- int indent);
+ int indent);
static void
dump_prefix(btrie_oct_t *prefix, unsigned len, int indent, const char *tail)
printf("%*.*s0x", indent, indent, INDENT_FILL);
for (i = 0; i < len / 8; i++)
- printf("%02x", prefix[i]);
+ printf("%02x", prefix[i]);
if (len % 8)
- printf("%02x", prefix[len / 8] & high_bits(len % 8));
+ printf("%02x", prefix[len / 8] & high_bits(len % 8));
printf("/%u%s", len, tail);
}
unsigned shift = 16 - (pos % 8) - nbits;
v = (v & ~(mask << shift)) | (pfx << shift);
prefix[pos / 8] = v >> 8;
- prefix[pos / 8 + 1] = (btrie_oct_t)v;
+ prefix[pos / 8 + 1] = (btrie_oct_t) v;
}
}
static void
dump_tbm_node(const struct tbm_node *node, unsigned pos,
- btrie_oct_t *prefix, int indent)
+ btrie_oct_t *prefix, int indent)
{
unsigned pfx = 0, plen = 0;
if (data_p) {
insert_bits(prefix, pos, pfx, plen);
dump_prefix(prefix, pos + plen, indent, "");
- printf(" [%u/%u] (%s)\n", pfx, plen, (const char *)*data_p);
+ printf(" [%u/%u] (%s)\n", pfx, plen, (const char *) *data_p);
}
plen++;
pfx <<= 1;
}
while (pfx & 1) {
if (--plen == 0)
- return;
+ return;
pfx >>= 1;
}
pfx++;
static void
dump_lc_node(const struct lc_node *node, unsigned pos,
- btrie_oct_t *prefix, int indent)
+ btrie_oct_t *prefix, int indent)
{
unsigned end = pos + lc_len(node);
btrie_oct_t save_prefix = prefix[lc_shift(pos)];
if (lc_is_terminal(node)) {
dump_prefix(prefix, end, indent, "");
- printf(" (%s)\n", (const char *)node->ptr.data);
+ printf(" (%s)\n", (const char *) node->ptr.data);
}
else {
dump_prefix(prefix, end, indent, "\n");
prefix[lc_shift(pos)] = save_prefix;
if (lc_bytes(node, pos) > 1)
- memset(&prefix[lc_shift(pos) + 1], 0, lc_bytes(node, pos) - 1);
+ memset(&prefix[lc_shift(pos) + 1], 0, lc_bytes(node, pos) - 1);
}
static void
dump_node(const node_t *node, unsigned pos, btrie_oct_t *prefix, int indent)
{
if (is_lc_node(node))
- dump_lc_node(&node->lc_node, pos, prefix, indent);
+ dump_lc_node(&node->lc_node, pos, prefix, indent);
else
- dump_tbm_node(&node->tbm_node, pos, prefix, indent);
+ dump_tbm_node(&node->tbm_node, pos, prefix, indent);
}
static void
parse_prefix(const char *arg, btrie_oct_t prefix[16], unsigned *len)
{
char addrbuf[128];
- return sscanf(arg, "%127[0-9a-fA-F:]/%u", addrbuf, len) == 2
- && inet_pton(AF_INET6, addrbuf, prefix) == 1;
+ return sscanf(arg, "%127[0-9a-fA-F:]/%u", addrbuf, len) == 2 && inet_pton(AF_INET6, addrbuf, prefix) == 1;
}
static int
btrie_oct_t prefix[16];
unsigned len;
- for (i = 1; i < argc-1; i++) {
+ for (i = 1; i < argc - 1; i++) {
if (!parse_prefix(argv[i], prefix, &len)) {
fprintf(stderr, "Can not parse arg '%s'\n", argv[i]);
return 1;
if (argc > 1) {
const void *data;
- if (!parse_prefix(argv[argc-1], prefix, &len)) {
- fprintf(stderr, "Can not parse arg '%s'\n", argv[argc-1]);
+ if (!parse_prefix(argv[argc - 1], prefix, &len)) {
+ fprintf(stderr, "Can not parse arg '%s'\n", argv[argc - 1]);
return 1;
}
data = btrie_lookup(btrie, prefix, 128);
- printf("lookup(%s) => %s\n", argv[argc-1], (const char *)data);
+ printf("lookup(%s) => %s\n", argv[argc - 1], (const char *) data);
}
return 0;
}
-int
-main(int argc, char *argv[])
+int main(int argc, char *argv[])
{
if ((pgm_name = strrchr(argv[0], '/')) != NULL)
- pgm_name++;
+ pgm_name++;
else
- pgm_name = argv[0];
+ pgm_name = argv[0];
if (argc > 1)
- return test_btrie(argc, argv);
+ return test_btrie(argc, argv);
else
- return unit_tests();
+ return unit_tests();
}
#endif /* TEST */
* in btrie_walk() --- btrie_add_prefix() and btrie_lookup() impose no
* limit on the length of bitstrings
*/
-#define BTRIE_MAX_PREFIX 128
+#define BTRIE_MAX_PREFIX 128
struct btrie;
struct memory_pool_s;
-struct btrie * btrie_init(struct memory_pool_s *mp);
+struct btrie *btrie_init(struct memory_pool_s *mp);
-enum btrie_result
-{
+enum btrie_result {
BTRIE_OKAY = 0,
BTRIE_ALLOC_FAILED = -1,
BTRIE_DUPLICATE_PREFIX = 1
};
enum btrie_result btrie_add_prefix(struct btrie *btrie,
- const btrie_oct_t *prefix, unsigned len, const void *data);
+ const btrie_oct_t *prefix, unsigned len, const void *data);
const void *btrie_lookup(const struct btrie *btrie, const btrie_oct_t *pfx,
- unsigned len);
+ unsigned len);
-const char *btrie_stats(const struct btrie *btrie, guint duplicates);
+const char *btrie_stats(const struct btrie *btrie, unsigned int duplicates);
#ifndef NO_MASTER_DUMP
typedef void btrie_walk_cb_t(const btrie_oct_t *prefix, unsigned len,
- const void *data, int post, void *user_data);
+ const void *data, int post, void *user_data);
void btrie_walk(const struct btrie *btrie, btrie_walk_cb_t *callback,
- void *user_data);
+ void *user_data);
#endif /* not NO_MASTER_DUMP */
#endif /* _BTRIE_H_INCLUDED */
+/*
+ * Copyright 2024 Vsevolod Stakhov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
/*
* Copyright (c) 2014, Vsevolod Stakhov
*
#include "compression.h"
__KHASH_IMPL(rdns_requests_hash, kh_inline, int, struct rdns_request *, true,
- kh_int_hash_func, kh_int_hash_equal);
+ kh_int_hash_func, kh_int_hash_equal);
static int
-rdns_send_request (struct rdns_request *req, int fd, bool new_req)
+rdns_send_request(struct rdns_request *req, int fd, bool new_req)
{
ssize_t r;
struct rdns_server *serv = req->io->srv;
if (resolver->curve_plugin == NULL) {
if (!IS_CHANNEL_CONNECTED(req->io)) {
- r = sendto (fd, req->packet, req->pos, 0,
- req->io->saddr,
- req->io->slen);
+ r = sendto(fd, req->packet, req->pos, 0,
+ req->io->saddr,
+ req->io->slen);
}
else {
- r = send (fd, req->packet, req->pos, 0);
+ r = send(fd, req->packet, req->pos, 0);
}
}
else {
if (!IS_CHANNEL_CONNECTED(req->io)) {
- r = resolver->curve_plugin->cb.curve_plugin.send_cb (req,
- resolver->curve_plugin->data,
- req->io->saddr,
- req->io->slen);
+ r = resolver->curve_plugin->cb.curve_plugin.send_cb(req,
+ resolver->curve_plugin->data,
+ req->io->saddr,
+ req->io->slen);
}
else {
- r = resolver->curve_plugin->cb.curve_plugin.send_cb (req,
- resolver->curve_plugin->data,
- NULL,
- 0);
+ r = resolver->curve_plugin->cb.curve_plugin.send_cb(req,
+ resolver->curve_plugin->data,
+ NULL,
+ 0);
}
}
if (r == -1) {
k = kh_put(rdns_requests_hash, req->io->requests, req->id, &pr);
kh_value(req->io->requests, k) = req;
- req->async_event = resolver->async->add_write (resolver->async->data,
- fd, req);
+ req->async_event = resolver->async->add_write(resolver->async->data,
+ fd, req);
req->state = RDNS_REQUEST_WAIT_SEND;
}
/*
return 0;
}
else {
- rdns_debug ("send failed: %s for server %s", strerror (errno), serv->name);
+ rdns_debug("send failed: %s for server %s", strerror(errno), serv->name);
return -1;
}
}
else if (!IS_CHANNEL_CONNECTED(req->io)) {
/* Connect socket */
- r = connect (fd, req->io->saddr, req->io->slen);
+ r = connect(fd, req->io->saddr, req->io->slen);
if (r == -1) {
- rdns_err ("cannot connect after sending request: %s for server %s",
- strerror (errno), serv->name);
+ rdns_err("cannot connect after sending request: %s for server %s",
+ strerror(errno), serv->name);
}
else {
req->io->flags |= RDNS_CHANNEL_CONNECTED;
k = kh_put(rdns_requests_hash, req->io->requests, req->id, &pr);
kh_value(req->io->requests, k) = req;
/* Fill timeout */
- req->async_event = resolver->async->add_timer (resolver->async->data,
- req->timeout, req);
+ req->async_event = resolver->async->add_timer(resolver->async->data,
+ req->timeout, req);
req->state = RDNS_REQUEST_WAIT_REPLY;
}
static struct rdns_request *
-rdns_find_dns_request (uint8_t *in, struct rdns_io_channel *ioc)
+rdns_find_dns_request(uint8_t *in, struct rdns_io_channel *ioc)
{
struct dns_header header;
int id;
struct rdns_resolver *resolver = ioc->resolver;
- memcpy (&header, in, sizeof(header));
+ memcpy(&header, in, sizeof(header));
id = header.qid;
khiter_t k = kh_get(rdns_requests_hash, ioc->requests, id);
if (k == kh_end(ioc->requests)) {
/* No such requests found */
- rdns_debug ("DNS request with id %d has not been found for IO channel", id);
+ rdns_debug("DNS request with id %d has not been found for IO channel", id);
return NULL;
}
}
static bool
-rdns_parse_reply (uint8_t *in, int r, struct rdns_request *req,
- struct rdns_reply **_rep)
+rdns_parse_reply(uint8_t *in, int r, struct rdns_request *req,
+ struct rdns_reply **_rep)
{
- struct dns_header *header = (struct dns_header *)in;
+ struct dns_header *header = (struct dns_header *) in;
struct rdns_reply *rep;
struct rdns_reply_entry *elt;
uint8_t *pos, *npos;
/* First check header fields */
if (header->qr == 0) {
- rdns_info ("got request while waiting for reply");
+ rdns_info("got request while waiting for reply");
return false;
}
- qdcount = ntohs (header->qdcount);
+ qdcount = ntohs(header->qdcount);
if (qdcount != req->qcount) {
- rdns_info ("request has %d queries, reply has %d queries", (int)req->qcount, (int)header->qdcount);
+ rdns_info("request has %d queries, reply has %d queries", (int) req->qcount, (int) header->qdcount);
return false;
}
* Now we have request and query data is now at the end of header, so compare
* request QR section and reply QR section
*/
- req->pos = sizeof (struct dns_header);
- pos = in + sizeof (struct dns_header);
- t = r - sizeof (struct dns_header);
- for (i = 0; i < (int)qdcount; i ++) {
- if ((npos = rdns_request_reply_cmp (req, pos,t)) == NULL) {
- rdns_info ("DNS request with id %d is for different query, ignoring", (int)req->id);
+ req->pos = sizeof(struct dns_header);
+ pos = in + sizeof(struct dns_header);
+ t = r - sizeof(struct dns_header);
+ for (i = 0; i < (int) qdcount; i++) {
+ if ((npos = rdns_request_reply_cmp(req, pos, t)) == NULL) {
+ rdns_info("DNS request with id %d is for different query, ignoring", (int) req->id);
return false;
}
t -= npos - pos;
/*
* Now pos is in answer section, so we should extract data and form reply
*/
- rep = rdns_make_reply (req, header->rcode);
+ rep = rdns_make_reply(req, header->rcode);
if (header->ad) {
rep->flags |= RDNS_AUTH;
}
if (rep == NULL) {
- rdns_warn ("Cannot allocate memory for reply");
+ rdns_warn("Cannot allocate memory for reply");
return false;
}
if (rep->code == RDNS_RC_NOERROR) {
r -= pos - in;
/* Extract RR records */
- for (i = 0; i < ntohs (header->ancount); i ++) {
- elt = malloc (sizeof (struct rdns_reply_entry));
- t = rdns_parse_rr (resolver, in, elt, &pos, rep, &r);
+ for (i = 0; i < ntohs(header->ancount); i++) {
+ elt = malloc(sizeof(struct rdns_reply_entry));
+ t = rdns_parse_rr(resolver, in, elt, &pos, rep, &r);
if (t == -1) {
- free (elt);
- rdns_debug ("incomplete reply");
+ free(elt);
+ rdns_debug("incomplete reply");
break;
}
else if (t == 1) {
- DL_APPEND (rep->entries, elt);
+ DL_APPEND(rep->entries, elt);
if (elt->type == type) {
found = true;
}
}
else {
- rdns_debug ("no matching reply for %s",
- req->requested_names[0].name);
- free (elt);
+ rdns_debug("no matching reply for %s",
+ req->requested_names[0].name);
+ free(elt);
}
}
}
}
static bool
-rdns_tcp_maybe_realloc_read_buf (struct rdns_io_channel *ioc)
+rdns_tcp_maybe_realloc_read_buf(struct rdns_io_channel *ioc)
{
if (ioc->tcp->read_buf_allocated == 0 && ioc->tcp->next_read_size > 0) {
ioc->tcp->cur_read_buf = malloc(ioc->tcp->next_read_size);
void *next_buf = realloc(ioc->tcp->cur_read_buf, next_shift);
if (next_buf == NULL) {
- free (ioc->tcp->cur_read_buf);
+ free(ioc->tcp->cur_read_buf);
ioc->tcp->cur_read_buf = NULL;
return false;
}
}
static void
-rdns_process_tcp_read (int fd, struct rdns_io_channel *ioc)
+rdns_process_tcp_read(int fd, struct rdns_io_channel *ioc)
{
ssize_t r;
struct rdns_resolver *resolver = ioc->resolver;
/* We have read the size, so we can try read one more time */
if (!rdns_tcp_maybe_realloc_read_buf(ioc)) {
rdns_err("failed to allocate %d bytes: %s",
- (int)ioc->tcp->next_read_size, strerror(errno));
+ (int) ioc->tcp->next_read_size, strerror(errno));
r = -1;
goto err;
}
}
}
else if (ioc->tcp->cur_read == 1) {
- r = read(fd, ((unsigned char *)&ioc->tcp->next_read_size) + 1, 1);
+ r = read(fd, ((unsigned char *) &ioc->tcp->next_read_size) + 1, 1);
if (r == -1 || r == 0) {
goto err;
/* We have read the size, so we can try read one more time */
if (!rdns_tcp_maybe_realloc_read_buf(ioc)) {
rdns_err("failed to allocate %d bytes: %s",
- (int)ioc->tcp->next_read_size, strerror(errno));
+ (int) ioc->tcp->next_read_size, strerror(errno));
r = -1;
goto err;
}
if ((ioc->tcp->cur_read - 2) == ioc->tcp->next_read_size) {
/* We have a full packet ready, process it */
- struct rdns_request *req = rdns_find_dns_request (ioc->tcp->cur_read_buf, ioc);
+ struct rdns_request *req = rdns_find_dns_request(ioc->tcp->cur_read_buf, ioc);
if (req != NULL) {
struct rdns_reply *rep;
- if (rdns_parse_reply (ioc->tcp->cur_read_buf,
- ioc->tcp->next_read_size, req, &rep)) {
- UPSTREAM_OK (req->io->srv);
+ if (rdns_parse_reply(ioc->tcp->cur_read_buf,
+ ioc->tcp->next_read_size, req, &rep)) {
+ UPSTREAM_OK(req->io->srv);
if (req->resolver->ups && req->io->srv->ups_elt) {
- req->resolver->ups->ok (req->io->srv->ups_elt,
- req->resolver->ups->data);
+ req->resolver->ups->ok(req->io->srv->ups_elt,
+ req->resolver->ups->data);
}
- req->func (rep, req->arg);
- REF_RELEASE (req);
+ req->func(rep, req->arg);
+ REF_RELEASE(req);
}
}
else {
ioc->tcp->cur_read = 0;
/* Retry read the next packet to avoid unnecessary polling */
- rdns_process_tcp_read (fd, ioc);
+ rdns_process_tcp_read(fd, ioc);
}
return;
err:
if (r == 0) {
/* Got EOF, just close the socket */
- rdns_debug ("closing TCP channel due to EOF");
- rdns_ioc_tcp_reset (ioc);
+ rdns_debug("closing TCP channel due to EOF");
+ rdns_ioc_tcp_reset(ioc);
}
else if (errno == EINTR || errno == EAGAIN) {
/* We just retry later as there is no real error */
return;
}
else {
- rdns_debug ("closing TCP channel due to IO error: %s", strerror(errno));
- rdns_ioc_tcp_reset (ioc);
+ rdns_debug("closing TCP channel due to IO error: %s", strerror(errno));
+ rdns_ioc_tcp_reset(ioc);
}
}
static void
-rdns_process_tcp_connect (int fd, struct rdns_io_channel *ioc)
+rdns_process_tcp_connect(int fd, struct rdns_io_channel *ioc)
{
- ioc->flags |= RDNS_CHANNEL_CONNECTED|RDNS_CHANNEL_ACTIVE;
+ ioc->flags |= RDNS_CHANNEL_CONNECTED | RDNS_CHANNEL_ACTIVE;
ioc->flags &= ~RDNS_CHANNEL_TCP_CONNECTING;
if (ioc->tcp->async_read == NULL) {
ioc->tcp->async_read = ioc->resolver->async->add_read(ioc->resolver->async->data,
- ioc->sock, ioc);
+ ioc->sock, ioc);
}
}
static bool
-rdns_reschedule_req_over_tcp (struct rdns_request *req, struct rdns_server *serv)
+rdns_reschedule_req_over_tcp(struct rdns_request *req, struct rdns_server *serv)
{
struct rdns_resolver *resolver;
struct rdns_io_channel *old_ioc = req->io,
- *ioc = serv->tcp_io_channels[ottery_rand_uint32 () % serv->tcp_io_cnt];
+ *ioc = serv->tcp_io_channels[ottery_rand_uint32() % serv->tcp_io_cnt];
resolver = req->resolver;
if (oc == NULL) {
rdns_err("failed to allocate output buffer for TCP ioc: %s",
- strerror(errno));
+ strerror(errno));
return false;
}
- oc->write_buf = ((unsigned char *)oc) + sizeof(*oc);
+ oc->write_buf = ((unsigned char *) oc) + sizeof(*oc);
memcpy(oc->write_buf, req->packet, req->packet_len);
oc->next_write_size = htons(req->packet_len);
DL_APPEND(ioc->tcp->output_chain, oc);
if (ioc->tcp->async_write == NULL) {
- ioc->tcp->async_write = resolver->async->add_write (
- resolver->async->data,
- ioc->sock, ioc);
+ ioc->tcp->async_write = resolver->async->add_write(
+ resolver->async->data,
+ ioc->sock, ioc);
}
req->state = RDNS_REQUEST_TCP;
/* Switch IO channel from UDP to TCP */
- rdns_request_remove_from_hash (req);
+ rdns_request_remove_from_hash(req);
req->io = ioc;
khiter_t k;
if (pr == 0) {
/* We have already a request with this id, so we have to regenerate ID */
- req->id = rdns_permutor_generate_id ();
+ req->id = rdns_permutor_generate_id();
/* Update packet as well */
uint16_t raw_id = req->id;
memcpy(req->packet, &raw_id, sizeof(raw_id));
}
}
- req->async_event = resolver->async->add_timer (resolver->async->data,
- req->timeout, req);
+ req->async_event = resolver->async->add_timer(resolver->async->data,
+ req->timeout, req);
kh_value(req->io->requests, k) = req;
REF_RELEASE(old_ioc);
}
static void
-rdns_process_udp_read (int fd, struct rdns_io_channel *ioc)
+rdns_process_udp_read(int fd, struct rdns_io_channel *ioc)
{
struct rdns_resolver *resolver;
struct rdns_request *req = NULL;
/* First read packet from socket */
if (resolver->curve_plugin == NULL) {
- r = recv (fd, in, sizeof (in), 0);
- if (r > (int)(sizeof (struct dns_header) + sizeof (struct dns_query))) {
- req = rdns_find_dns_request (in, ioc);
+ r = recv(fd, in, sizeof(in), 0);
+ if (r > (int) (sizeof(struct dns_header) + sizeof(struct dns_query))) {
+ req = rdns_find_dns_request(in, ioc);
}
}
else {
- r = resolver->curve_plugin->cb.curve_plugin.recv_cb (ioc, in,
- sizeof (in), resolver->curve_plugin->data, &req,
- ioc->saddr, ioc->slen);
+ r = resolver->curve_plugin->cb.curve_plugin.recv_cb(ioc, in,
+ sizeof(in), resolver->curve_plugin->data, &req,
+ ioc->saddr, ioc->slen);
if (req == NULL &&
- r > (int)(sizeof (struct dns_header) + sizeof (struct dns_query))) {
- req = rdns_find_dns_request (in, ioc);
+ r > (int) (sizeof(struct dns_header) + sizeof(struct dns_query))) {
+ req = rdns_find_dns_request(in, ioc);
}
}
if (req != NULL) {
- if (rdns_parse_reply (in, r, req, &rep)) {
- UPSTREAM_OK (req->io->srv);
+ if (rdns_parse_reply(in, r, req, &rep)) {
+ UPSTREAM_OK(req->io->srv);
if (req->resolver->ups && req->io->srv->ups_elt) {
- req->resolver->ups->ok (req->io->srv->ups_elt,
- req->resolver->ups->data);
+ req->resolver->ups->ok(req->io->srv->ups_elt,
+ req->resolver->ups->data);
}
- rdns_request_unschedule (req, true);
+ rdns_request_unschedule(req, true);
if (!(rep->flags & RDNS_TRUNCATED)) {
req->state = RDNS_REQUEST_REPLIED;
req->func(rep, req->arg);
/* This will free reply as well */
- REF_RELEASE (req);
+ REF_RELEASE(req);
}
else {
if (req->io->srv->tcp_io_cnt > 0) {
rdns_debug("truncated UDP reply for %s; schedule over TCP", req->requested_names[0].name);
/* Reschedule via TCP */
- if (!rdns_reschedule_req_over_tcp (req, req->io->srv)) {
+ if (!rdns_reschedule_req_over_tcp(req, req->io->srv)) {
/* Use truncated reply as we have no other options */
req->state = RDNS_REQUEST_REPLIED;
req->func(rep, req->arg);
- REF_RELEASE (req);
+ REF_RELEASE(req);
}
else {
/* Remove and free the truncated reply, as we have rescheduled the reply */
req->state = RDNS_REQUEST_REPLIED;
req->func(rep, req->arg);
/* This will free reply as well */
- REF_RELEASE (req);
+ REF_RELEASE(req);
}
}
}
}
else {
/* Still want to increase uses */
- ioc->uses ++;
+ ioc->uses++;
}
}
-void
-rdns_process_read (int fd, void *arg)
+void rdns_process_read(int fd, void *arg)
{
- struct rdns_io_channel *ioc = (struct rdns_io_channel *)arg;
+ struct rdns_io_channel *ioc = (struct rdns_io_channel *) arg;
struct rdns_resolver *resolver;
resolver = ioc->resolver;
if (IS_CHANNEL_TCP(ioc)) {
if (IS_CHANNEL_CONNECTED(ioc)) {
- rdns_process_tcp_read (fd, ioc);
+ rdns_process_tcp_read(fd, ioc);
}
else {
- rdns_err ("read readiness on non connected TCP channel!");
+ rdns_err("read readiness on non connected TCP channel!");
}
}
else {
- rdns_process_udp_read (fd, ioc);
+ rdns_process_udp_read(fd, ioc);
}
}
-void
-rdns_process_timer (void *arg)
+void rdns_process_timer(void *arg)
{
- struct rdns_request *req = (struct rdns_request *)arg;
+ struct rdns_request *req = (struct rdns_request *) arg;
struct rdns_reply *rep;
int r;
bool renew = false;
struct rdns_server *serv = NULL;
unsigned cnt;
- req->retransmits --;
+ req->retransmits--;
resolver = req->resolver;
if (req->resolver->ups && req->io->srv->ups_elt) {
- req->resolver->ups->fail (req->io->srv->ups_elt,
- req->resolver->ups->data, "timeout waiting reply");
+ req->resolver->ups->fail(req->io->srv->ups_elt,
+ req->resolver->ups->data, "timeout waiting reply");
}
else {
- UPSTREAM_FAIL (req->io->srv, time (NULL));
+ UPSTREAM_FAIL(req->io->srv, time(NULL));
}
if (req->state == RDNS_REQUEST_TCP) {
- rep = rdns_make_reply (req, RDNS_RC_TIMEOUT);
- rdns_request_unschedule (req, true);
+ rep = rdns_make_reply(req, RDNS_RC_TIMEOUT);
+ rdns_request_unschedule(req, true);
req->state = RDNS_REQUEST_REPLIED;
- req->func (rep, req->arg);
- REF_RELEASE (req);
+ req->func(rep, req->arg);
+ REF_RELEASE(req);
return;
}
if (req->retransmits == 0) {
- rep = rdns_make_reply (req, RDNS_RC_TIMEOUT);
- rdns_request_unschedule (req, true);
+ rep = rdns_make_reply(req, RDNS_RC_TIMEOUT);
+ rdns_request_unschedule(req, true);
req->state = RDNS_REQUEST_REPLIED;
- req->func (rep, req->arg);
- REF_RELEASE (req);
+ req->func(rep, req->arg);
+ REF_RELEASE(req);
return;
}
if (!IS_CHANNEL_ACTIVE(req->io) || req->retransmits == 1) {
if (resolver->ups) {
- cnt = resolver->ups->count (resolver->ups->data);
+ cnt = resolver->ups->count(resolver->ups->data);
}
else {
cnt = 0;
- UPSTREAM_FOREACH (resolver->servers, serv) {
- cnt ++;
+ UPSTREAM_FOREACH(resolver->servers, serv)
+ {
+ cnt++;
}
}
if (!IS_CHANNEL_ACTIVE(req->io) || cnt > 1) {
/* Do not reschedule IO requests on inactive sockets */
- rdns_debug ("reschedule request with id: %d", (int)req->id);
- rdns_request_unschedule (req, true);
- REF_RELEASE (req->io);
+ rdns_debug("reschedule request with id: %d", (int) req->id);
+ rdns_request_unschedule(req, true);
+ REF_RELEASE(req->io);
if (resolver->ups) {
struct rdns_upstream_elt *elt;
- elt = resolver->ups->select_retransmit (
- req->requested_names[0].name,
- req->requested_names[0].len,
- req->io->srv->ups_elt,
- resolver->ups->data);
+ elt = resolver->ups->select_retransmit(
+ req->requested_names[0].name,
+ req->requested_names[0].len,
+ req->io->srv->ups_elt,
+ resolver->ups->data);
if (elt) {
serv = elt->server;
serv->ups_elt = elt;
}
else {
- UPSTREAM_SELECT_ROUND_ROBIN (resolver->servers, serv);
+ UPSTREAM_SELECT_ROUND_ROBIN(resolver->servers, serv);
}
}
else {
- UPSTREAM_SELECT_ROUND_ROBIN (resolver->servers, serv);
+ UPSTREAM_SELECT_ROUND_ROBIN(resolver->servers, serv);
}
if (serv == NULL) {
- rdns_warn ("cannot find suitable server for request");
- rep = rdns_make_reply (req, RDNS_RC_SERVFAIL);
+ rdns_warn("cannot find suitable server for request");
+ rep = rdns_make_reply(req, RDNS_RC_SERVFAIL);
req->state = RDNS_REQUEST_REPLIED;
- req->func (rep, req->arg);
- REF_RELEASE (req);
+ req->func(rep, req->arg);
+ REF_RELEASE(req);
return;
}
/* Select random IO channel */
- req->io = serv->io_channels[ottery_rand_uint32 () % serv->io_cnt];
- req->io->uses ++;
- REF_RETAIN (req->io);
+ req->io = serv->io_channels[ottery_rand_uint32() % serv->io_cnt];
+ req->io->uses++;
+ REF_RETAIN(req->io);
renew = true;
}
}
* Note: when `renew` is true, then send_request deals with the
* timers and events itself
*/
- r = rdns_send_request (req, req->io->sock, renew);
+ r = rdns_send_request(req, req->io->sock, renew);
if (r == 0) {
/* Retransmit one more time */
if (!renew) {
- req->async->del_timer (req->async->data,
- req->async_event);
- req->async_event = req->async->add_write (req->async->data,
- req->io->sock, req);
+ req->async->del_timer(req->async->data,
+ req->async_event);
+ req->async_event = req->async->add_write(req->async->data,
+ req->io->sock, req);
}
req->state = RDNS_REQUEST_WAIT_SEND;
}
else if (r == -1) {
if (req->resolver->ups && req->io->srv->ups_elt) {
- req->resolver->ups->fail (req->io->srv->ups_elt,
- req->resolver->ups->data, "cannot send retransmit after timeout");
+ req->resolver->ups->fail(req->io->srv->ups_elt,
+ req->resolver->ups->data, "cannot send retransmit after timeout");
}
else {
- UPSTREAM_FAIL (req->io->srv, time (NULL));
+ UPSTREAM_FAIL(req->io->srv, time(NULL));
}
if (!renew) {
- req->async->del_timer (req->async->data,
- req->async_event);
+ req->async->del_timer(req->async->data,
+ req->async_event);
req->async_event = NULL;
rdns_request_remove_from_hash(req);
}
/* We have not scheduled timeout actually due to send error */
- rep = rdns_make_reply (req, RDNS_RC_NETERR);
+ rep = rdns_make_reply(req, RDNS_RC_NETERR);
req->state = RDNS_REQUEST_REPLIED;
- req->func (rep, req->arg);
- REF_RELEASE (req);
+ req->func(rep, req->arg);
+ REF_RELEASE(req);
}
else {
- req->async->repeat_timer (req->async->data, req->async_event);
+ req->async->repeat_timer(req->async->data, req->async_event);
req->state = RDNS_REQUEST_WAIT_REPLY;
}
}
static void
-rdns_process_periodic (void *arg)
+rdns_process_periodic(void *arg)
{
- struct rdns_resolver *resolver = (struct rdns_resolver*)arg;
+ struct rdns_resolver *resolver = (struct rdns_resolver *) arg;
struct rdns_server *serv;
- UPSTREAM_RESCAN (resolver->servers, time (NULL));
+ UPSTREAM_RESCAN(resolver->servers, time(NULL));
- UPSTREAM_FOREACH (resolver->servers, serv) {
- for (int i = 0; i < serv->tcp_io_cnt; i ++) {
+ UPSTREAM_FOREACH(resolver->servers, serv)
+ {
+ for (int i = 0; i < serv->tcp_io_cnt; i++) {
if (IS_CHANNEL_CONNECTED(serv->tcp_io_channels[i])) {
/* Disconnect channels with no requests in flight */
if (kh_size(serv->tcp_io_channels[i]->requests) == 0) {
- rdns_debug ("reset inactive TCP connection to %s", serv->name);
- rdns_ioc_tcp_reset (serv->tcp_io_channels[i]);
+ rdns_debug("reset inactive TCP connection to %s", serv->name);
+ rdns_ioc_tcp_reset(serv->tcp_io_channels[i]);
}
}
}
}
static void
-rdns_process_ioc_refresh (void *arg)
+rdns_process_ioc_refresh(void *arg)
{
- struct rdns_resolver *resolver = (struct rdns_resolver*)arg;
+ struct rdns_resolver *resolver = (struct rdns_resolver *) arg;
struct rdns_server *serv;
struct rdns_io_channel *ioc, *nioc;
unsigned int i;
if (resolver->max_ioc_uses > 0) {
- UPSTREAM_FOREACH (resolver->servers, serv) {
- for (i = 0; i < serv->io_cnt; i ++) {
+ UPSTREAM_FOREACH(resolver->servers, serv)
+ {
+ for (i = 0; i < serv->io_cnt; i++) {
ioc = serv->io_channels[i];
if (ioc->uses > resolver->max_ioc_uses) {
/* Schedule IOC removing */
- nioc = rdns_ioc_new (serv, resolver, false);
+ nioc = rdns_ioc_new(serv, resolver, false);
if (nioc == NULL) {
- rdns_err ("calloc fails to allocate rdns_io_channel");
+ rdns_err("calloc fails to allocate rdns_io_channel");
continue;
}
serv->io_channels[i] = nioc;
- rdns_debug ("scheduled io channel for server %s to be refreshed after "
- "%lu usages", serv->name, (unsigned long)ioc->uses);
+ rdns_debug("scheduled io channel for server %s to be refreshed after "
+ "%lu usages",
+ serv->name, (unsigned long) ioc->uses);
ioc->flags &= ~RDNS_CHANNEL_ACTIVE;
- REF_RELEASE (ioc);
+ REF_RELEASE(ioc);
}
}
}
}
static void
-rdns_process_udp_retransmit (int fd, struct rdns_request *req)
+rdns_process_udp_retransmit(int fd, struct rdns_request *req)
{
struct rdns_resolver *resolver;
struct rdns_reply *rep;
resolver = req->resolver;
- resolver->async->del_write (resolver->async->data,
- req->async_event);
+ resolver->async->del_write(resolver->async->data,
+ req->async_event);
req->async_event = NULL;
if (req->state == RDNS_REQUEST_FAKE) {
/* Reply is ready */
- req->func (req->reply, req->arg);
- REF_RELEASE (req);
+ req->func(req->reply, req->arg);
+ REF_RELEASE(req);
return;
}
- r = rdns_send_request (req, fd, false);
+ r = rdns_send_request(req, fd, false);
if (r == 0) {
/* Retransmit one more time */
- req->async_event = req->async->add_write (req->async->data,
- fd, req);
+ req->async_event = req->async->add_write(req->async->data,
+ fd, req);
req->state = RDNS_REQUEST_WAIT_SEND;
}
else if (r == -1) {
if (req->resolver->ups && req->io->srv->ups_elt) {
- req->resolver->ups->fail (req->io->srv->ups_elt,
- req->resolver->ups->data, "retransmit send failed");
+ req->resolver->ups->fail(req->io->srv->ups_elt,
+ req->resolver->ups->data, "retransmit send failed");
}
else {
- UPSTREAM_FAIL (req->io->srv, time (NULL));
+ UPSTREAM_FAIL(req->io->srv, time(NULL));
}
- rep = rdns_make_reply (req, RDNS_RC_NETERR);
+ rep = rdns_make_reply(req, RDNS_RC_NETERR);
req->state = RDNS_REQUEST_REPLIED;
- req->func (rep, req->arg);
- REF_RELEASE (req);
+ req->func(rep, req->arg);
+ REF_RELEASE(req);
}
else {
- req->async_event = req->async->add_timer (req->async->data,
- req->timeout, req);
+ req->async_event = req->async->add_timer(req->async->data,
+ req->timeout, req);
req->state = RDNS_REQUEST_WAIT_REPLY;
}
}
static ssize_t
-rdns_write_output_chain (struct rdns_io_channel *ioc, struct rdns_tcp_output_chain *oc)
+rdns_write_output_chain(struct rdns_io_channel *ioc, struct rdns_tcp_output_chain *oc)
{
ssize_t r;
struct iovec iov[2];
int niov, already_written;
- int packet_len = ntohs (oc->next_write_size);
+ int packet_len = ntohs(oc->next_write_size);
switch (oc->cur_write) {
case 0:
/* Size + DNS request in full */
iov[0].iov_base = &oc->next_write_size;
- iov[0].iov_len = sizeof (oc->next_write_size);
+ iov[0].iov_len = sizeof(oc->next_write_size);
iov[1].iov_base = oc->write_buf;
iov[1].iov_len = packet_len;
niov = 2;
break;
case 1:
/* Partial Size + DNS request in full */
- iov[0].iov_base = ((unsigned char *)&oc->next_write_size) + 1;
+ iov[0].iov_base = ((unsigned char *) &oc->next_write_size) + 1;
iov[0].iov_len = 1;
iov[1].iov_base = oc->write_buf;
iov[1].iov_len = packet_len;
}
static void
-rdns_process_tcp_write (int fd, struct rdns_io_channel *ioc)
+rdns_process_tcp_write(int fd, struct rdns_io_channel *ioc)
{
struct rdns_resolver *resolver = ioc->resolver;
/* Try to write as much as we can */
struct rdns_tcp_output_chain *oc, *tmp;
- DL_FOREACH_SAFE(ioc->tcp->output_chain, oc, tmp) {
- ssize_t r = rdns_write_output_chain (ioc, oc);
+ DL_FOREACH_SAFE(ioc->tcp->output_chain, oc, tmp)
+ {
+ ssize_t r = rdns_write_output_chain(ioc, oc);
if (r == -1) {
if (errno == EAGAIN || errno == EINTR) {
return;
}
else {
- rdns_err ("error when trying to write request to %s: %s",
- ioc->srv->name, strerror (errno));
- rdns_ioc_tcp_reset (ioc);
+ rdns_err("error when trying to write request to %s: %s",
+ ioc->srv->name, strerror(errno));
+ rdns_ioc_tcp_reset(ioc);
return;
}
}
else if (ntohs(oc->next_write_size) < oc->cur_write) {
/* Packet has been fully written, remove it */
DL_DELETE(ioc->tcp->output_chain, oc);
- free (oc); /* It also frees write buf */
- ioc->tcp->cur_output_chains --;
+ free(oc); /* It also frees write buf */
+ ioc->tcp->cur_output_chains--;
}
else {
/* Buffer is not yet processed, stop unless we can continue */
if (ioc->tcp->cur_output_chains == 0) {
/* Unregister write event */
- ioc->resolver->async->del_write (ioc->resolver->async->data,
- ioc->tcp->async_write);
+ ioc->resolver->async->del_write(ioc->resolver->async->data,
+ ioc->tcp->async_write);
ioc->tcp->async_write = NULL;
}
}
-void
-rdns_process_write (int fd, void *arg)
+void rdns_process_write(int fd, void *arg)
{
/*
* We first need to dispatch *arg to understand what has caused the write
*/
uint64_t tag;
- memcpy (&tag, arg, sizeof(tag));
+ memcpy(&tag, arg, sizeof(tag));
if (tag == RDNS_IO_CHANNEL_TAG) {
struct rdns_io_channel *ioc = (struct rdns_io_channel *) arg;
}
struct rdns_server *
-rdns_select_request_upstream (struct rdns_resolver *resolver,
- struct rdns_request *req,
- bool is_retransmit,
- struct rdns_server *prev_serv)
+rdns_select_request_upstream(struct rdns_resolver *resolver,
+ struct rdns_request *req,
+ bool is_retransmit,
+ struct rdns_server *prev_serv)
{
struct rdns_server *serv = NULL;
struct rdns_upstream_elt *elt;
if (is_retransmit && prev_serv) {
- elt = resolver->ups->select_retransmit (req->requested_names[0].name,
- req->requested_names[0].len,
- prev_serv->ups_elt,
- resolver->ups->data);
+ elt = resolver->ups->select_retransmit(req->requested_names[0].name,
+ req->requested_names[0].len,
+ prev_serv->ups_elt,
+ resolver->ups->data);
}
else {
- elt = resolver->ups->select (req->requested_names[0].name,
- req->requested_names[0].len, resolver->ups->data);
+ elt = resolver->ups->select(req->requested_names[0].name,
+ req->requested_names[0].len, resolver->ups->data);
}
if (elt) {
serv->ups_elt = elt;
}
else {
- UPSTREAM_SELECT_ROUND_ROBIN (resolver->servers, serv);
+ UPSTREAM_SELECT_ROUND_ROBIN(resolver->servers, serv);
}
}
else {
- UPSTREAM_SELECT_ROUND_ROBIN (resolver->servers, serv);
+ UPSTREAM_SELECT_ROUND_ROBIN(resolver->servers, serv);
}
return serv;
}
-#define align_ptr(p, a) \
- (guint8 *) (((uintptr_t) (p) + ((uintptr_t) a - 1)) & ~((uintptr_t) a - 1))
-
-struct rdns_request*
-rdns_make_request_full (
- struct rdns_resolver *resolver,
- dns_callback_type cb,
- void *cbdata,
- double timeout,
- unsigned int repeats,
- unsigned int queries,
- ...
- )
+#define align_ptr(p, a) \
+ (uint8_t *) (((uintptr_t) (p) + ((uintptr_t) a - 1)) & ~((uintptr_t) a - 1))
+
+struct rdns_request *
+rdns_make_request_full(
+ struct rdns_resolver *resolver,
+ dns_callback_type cb,
+ void *cbdata,
+ double timeout,
+ unsigned int repeats,
+ unsigned int queries,
+ ...)
{
va_list args;
struct rdns_request *req;
const char *cur_name, *last_name = NULL;
khash_t(rdns_compression_hash) *comp = NULL;
struct rdns_fake_reply *fake_rep = NULL;
- char fake_buf[MAX_FAKE_NAME + sizeof (struct rdns_fake_reply_idx) + 16];
+ char fake_buf[MAX_FAKE_NAME + sizeof(struct rdns_fake_reply_idx) + 16];
struct rdns_fake_reply_idx *idx;
if (resolver == NULL || !resolver->initialized) {
return NULL;
}
- rdns_err ("resolver is uninitialized");
+ rdns_err("resolver is uninitialized");
return NULL;
}
- req = malloc (sizeof (struct rdns_request));
+ req = malloc(sizeof(struct rdns_request));
if (req == NULL) {
- rdns_err ("failed to allocate memory for request: %s",
- strerror (errno));
+ rdns_err("failed to allocate memory for request: %s",
+ strerror(errno));
return NULL;
}
req->io = NULL;
req->state = RDNS_REQUEST_NEW;
req->packet = NULL;
- req->requested_names = calloc (queries, sizeof (struct rdns_request_name));
+ req->requested_names = calloc(queries, sizeof(struct rdns_request_name));
req->async_event = NULL;
if (req->requested_names == NULL) {
- free (req);
- rdns_err ("failed to allocate memory for request data: %s",
- strerror (errno));
+ free(req);
+ rdns_err("failed to allocate memory for request data: %s",
+ strerror(errno));
return NULL;
}
#ifdef TWEETNACL
req->curve_plugin_data = NULL;
#endif
- REF_INIT_RETAIN (req, rdns_request_free);
+ REF_INIT_RETAIN(req, rdns_request_free);
/* Calculate packet's total length based on records count */
- va_start (args, queries);
+ va_start(args, queries);
for (i = 0; i < queries * 2; i += 2) {
cur = i / 2;
- cur_name = va_arg (args, const char *);
- type = va_arg (args, int);
+ cur_name = va_arg(args, const char *);
+ type = va_arg(args, int);
if (cur_name != NULL) {
- clen = strlen (cur_name);
+ clen = strlen(cur_name);
if (clen == 0) {
- rdns_warn ("got empty name to resolve");
- rdns_request_free (req);
+ rdns_warn("got empty name to resolve");
+ rdns_request_free(req);
return NULL;
}
if (cur_name[0] == '.') {
/* Skip dots at the begin */
- unsigned int ndots = strspn (cur_name, ".");
+ unsigned int ndots = strspn(cur_name, ".");
cur_name += ndots;
clen -= ndots;
if (clen == 0) {
- rdns_warn ("got empty name to resolve");
- rdns_request_free (req);
+ rdns_warn("got empty name to resolve");
+ rdns_request_free(req);
return NULL;
}
}
if (cur_name[clen - 1] == '.') {
/* Skip trailing dots */
while (clen >= 1 && cur_name[clen - 1] == '.') {
- clen --;
+ clen--;
}
if (clen == 0) {
- rdns_warn ("got empty name to resolve");
- rdns_request_free (req);
+ rdns_warn("got empty name to resolve");
+ rdns_request_free(req);
return NULL;
}
}
if (last_name == NULL && queries == 1 && clen < MAX_FAKE_NAME) {
/* We allocate structure in the static space */
- idx = (struct rdns_fake_reply_idx *)align_ptr (fake_buf, 16);
+ idx = (struct rdns_fake_reply_idx *) align_ptr(fake_buf, 16);
idx->type = type;
idx->len = clen;
- memcpy (idx->request, cur_name, clen);
- HASH_FIND (hh, resolver->fake_elts, idx, sizeof (*idx) + clen,
- fake_rep);
+ memcpy(idx->request, cur_name, clen);
+ HASH_FIND(hh, resolver->fake_elts, idx, sizeof(*idx) + clen,
+ fake_rep);
if (fake_rep) {
/* We actually treat it as a short-circuit */
- req->reply = rdns_make_reply (req, fake_rep->rcode);
+ req->reply = rdns_make_reply(req, fake_rep->rcode);
req->reply->entries = fake_rep->result;
req->state = RDNS_REQUEST_FAKE;
}
tlen += clen;
}
else if (last_name == NULL) {
- rdns_err ("got NULL as the first name to resolve");
- rdns_request_free (req);
+ rdns_err("got NULL as the first name to resolve");
+ rdns_request_free(req);
return NULL;
}
if (req->state != RDNS_REQUEST_FAKE) {
- if (!rdns_format_dns_name (resolver, last_name, clen,
- &req->requested_names[cur].name, &olen)) {
- rdns_err ("cannot format %s", last_name);
- rdns_request_free (req);
+ if (!rdns_format_dns_name(resolver, last_name, clen,
+ &req->requested_names[cur].name, &olen)) {
+ rdns_err("cannot format %s", last_name);
+ rdns_request_free(req);
return NULL;
}
req->requested_names[cur].type = type;
}
- va_end (args);
+ va_end(args);
if (req->state != RDNS_REQUEST_FAKE) {
- rdns_allocate_packet (req, tlen);
- rdns_make_dns_header (req, queries);
+ rdns_allocate_packet(req, tlen);
+ rdns_make_dns_header(req, queries);
for (i = 0; i < queries; i++) {
cur_name = req->requested_names[i].name;
clen = req->requested_names[i].len;
type = req->requested_names[i].type;
if (queries > 1) {
- if (!rdns_add_rr (req, cur_name, clen, type, &comp)) {
- rdns_err ("cannot add rr");
- REF_RELEASE (req);
+ if (!rdns_add_rr(req, cur_name, clen, type, &comp)) {
+ rdns_err("cannot add rr");
+ REF_RELEASE(req);
rdns_compression_free(comp);
return NULL;
}
- } else {
- if (!rdns_add_rr (req, cur_name, clen, type, NULL)) {
- rdns_err ("cannot add rr");
- REF_RELEASE (req);
+ }
+ else {
+ if (!rdns_add_rr(req, cur_name, clen, type, NULL)) {
+ rdns_err("cannot add rr");
+ REF_RELEASE(req);
rdns_compression_free(comp);
return NULL;
}
rdns_compression_free(comp);
/* Add EDNS RR */
- rdns_add_edns0 (req);
+ rdns_add_edns0(req);
req->retransmits = repeats ? repeats : 1;
req->timeout = timeout;
req->async = resolver->async;
- serv = rdns_select_request_upstream (resolver, req, false, NULL);
+ serv = rdns_select_request_upstream(resolver, req, false, NULL);
if (serv == NULL) {
- rdns_warn ("cannot find suitable server for request");
- REF_RELEASE (req);
+ rdns_warn("cannot find suitable server for request");
+ REF_RELEASE(req);
return NULL;
}
/* Select random IO channel */
- req->io = serv->io_channels[ottery_rand_uint32 () % serv->io_cnt];
+ req->io = serv->io_channels[ottery_rand_uint32() % serv->io_cnt];
if (req->state == RDNS_REQUEST_FAKE) {
- req->async_event = resolver->async->add_write (resolver->async->data,
- req->io->sock, req);
+ req->async_event = resolver->async->add_write(resolver->async->data,
+ req->io->sock, req);
}
else {
/* Now send request to server */
do {
- r = rdns_send_request (req, req->io->sock, true);
+ r = rdns_send_request(req, req->io->sock, true);
if (r == -1) {
- req->retransmits --; /* It must be > 0 */
+ req->retransmits--; /* It must be > 0 */
if (req->retransmits > 0) {
if (resolver->ups && serv->ups_elt) {
- resolver->ups->fail (serv->ups_elt, resolver->ups->data,
- "send IO error");
+ resolver->ups->fail(serv->ups_elt, resolver->ups->data,
+ "send IO error");
}
else {
- UPSTREAM_FAIL (serv, time (NULL));
+ UPSTREAM_FAIL(serv, time(NULL));
}
- serv = rdns_select_request_upstream (resolver, req,
- true, serv);
+ serv = rdns_select_request_upstream(resolver, req,
+ true, serv);
if (serv == NULL) {
- rdns_warn ("cannot find suitable server for request");
- REF_RELEASE (req);
+ rdns_warn("cannot find suitable server for request");
+ REF_RELEASE(req);
return NULL;
}
- req->io = serv->io_channels[ottery_rand_uint32 () % serv->io_cnt];
+ req->io = serv->io_channels[ottery_rand_uint32() % serv->io_cnt];
}
else {
- rdns_info ("cannot send DNS request: %s", strerror (errno));
- REF_RELEASE (req);
+ rdns_info("cannot send DNS request: %s", strerror(errno));
+ REF_RELEASE(req);
if (resolver->ups && serv->ups_elt) {
- resolver->ups->fail (serv->ups_elt, resolver->ups->data,
- "send IO error");
+ resolver->ups->fail(serv->ups_elt, resolver->ups->data,
+ "send IO error");
}
else {
- UPSTREAM_FAIL (serv, time (NULL));
+ UPSTREAM_FAIL(serv, time(NULL));
}
return NULL;
} while (req->retransmits > 0);
}
- REF_RETAIN (req->io);
- REF_RETAIN (req->resolver);
+ REF_RETAIN(req->io);
+ REF_RETAIN(req->resolver);
return req;
}
-bool
-rdns_resolver_init (struct rdns_resolver *resolver)
+bool rdns_resolver_init(struct rdns_resolver *resolver)
{
unsigned int i;
struct rdns_server *serv;
struct rdns_io_channel *ioc;
if (!resolver->async_binded) {
- rdns_err ("no async backend specified");
+ rdns_err("no async backend specified");
return false;
}
if (resolver->servers == NULL) {
- rdns_err ("no DNS servers defined");
+ rdns_err("no DNS servers defined");
return false;
}
/* Now init io channels to all servers */
- UPSTREAM_FOREACH (resolver->servers, serv) {
- serv->io_channels = calloc (serv->io_cnt, sizeof (struct rdns_io_channel *));
+ UPSTREAM_FOREACH(resolver->servers, serv)
+ {
+ serv->io_channels = calloc(serv->io_cnt, sizeof(struct rdns_io_channel *));
if (serv->io_channels == NULL) {
- rdns_err ("cannot allocate memory for the resolver IO channels");
+ rdns_err("cannot allocate memory for the resolver IO channels");
return false;
}
- for (i = 0; i < serv->io_cnt; i ++) {
+ for (i = 0; i < serv->io_cnt; i++) {
ioc = rdns_ioc_new(serv, resolver, false);
if (ioc == NULL) {
- rdns_err ("cannot allocate memory or init the IO channel");
+ rdns_err("cannot allocate memory or init the IO channel");
return false;
}
* We are more forgiving for TCP IO channels: we can have zero of them
* if DNS is misconfigured and still be able to resolve stuff
*/
- serv->tcp_io_channels = calloc (serv->tcp_io_cnt, sizeof (struct rdns_io_channel *));
+ serv->tcp_io_channels = calloc(serv->tcp_io_cnt, sizeof(struct rdns_io_channel *));
if (serv->tcp_io_channels == NULL) {
- rdns_err ("cannot allocate memory for the resolver TCP IO channels");
+ rdns_err("cannot allocate memory for the resolver TCP IO channels");
return false;
}
- for (i = 0; i < serv->tcp_io_cnt; i ++) {
- ioc = rdns_ioc_new (serv, resolver, true);
+ for (i = 0; i < serv->tcp_io_cnt; i++) {
+ ioc = rdns_ioc_new(serv, resolver, true);
if (ioc == NULL) {
- rdns_err ("cannot allocate memory or init the TCP IO channel");
+ rdns_err("cannot allocate memory or init the TCP IO channel");
continue;
}
}
if (resolver->async->add_periodic) {
- resolver->periodic = resolver->async->add_periodic (resolver->async->data,
- UPSTREAM_REVIVE_TIME, rdns_process_periodic, resolver);
+ resolver->periodic = resolver->async->add_periodic(resolver->async->data,
+ UPSTREAM_REVIVE_TIME, rdns_process_periodic, resolver);
}
resolver->initialized = true;
return true;
}
-void
-rdns_resolver_register_plugin (struct rdns_resolver *resolver,
- struct rdns_plugin *plugin)
+void rdns_resolver_register_plugin(struct rdns_resolver *resolver,
+ struct rdns_plugin *plugin)
{
if (resolver != NULL && plugin != NULL) {
/* XXX: support only network plugin now, and only a single one */
}
void *
-rdns_resolver_add_server (struct rdns_resolver *resolver,
- const char *name, unsigned int port,
- int priority, unsigned int io_cnt)
+rdns_resolver_add_server(struct rdns_resolver *resolver,
+ const char *name, unsigned int port,
+ int priority, unsigned int io_cnt)
{
struct rdns_server *serv;
union {
struct in6_addr v6;
} addr;
- if (inet_pton (AF_INET, name, &addr) == 0 &&
- inet_pton (AF_INET6, name, &addr) == 0) {
+ if (inet_pton(AF_INET, name, &addr) == 0 &&
+ inet_pton(AF_INET6, name, &addr) == 0) {
/* Invalid IP */
return NULL;
}
return NULL;
}
- serv = calloc (1, sizeof (struct rdns_server));
+ serv = calloc(1, sizeof(struct rdns_server));
if (serv == NULL) {
return NULL;
}
- serv->name = strdup (name);
+ serv->name = strdup(name);
if (serv->name == NULL) {
- free (serv);
+ free(serv);
return NULL;
}
serv->tcp_io_cnt = default_tcp_io_cnt;
serv->port = port;
- UPSTREAM_ADD (resolver->servers, serv, priority);
+ UPSTREAM_ADD(resolver->servers, serv, priority);
return serv;
}
-void
-rdns_resolver_set_logger (struct rdns_resolver *resolver,
- rdns_log_function logger, void *log_data)
+void rdns_resolver_set_logger(struct rdns_resolver *resolver,
+ rdns_log_function logger, void *log_data)
{
resolver->logger = logger;
resolver->log_data = log_data;
}
-void
-rdns_resolver_set_log_level (struct rdns_resolver *resolver,
- enum rdns_log_level level)
+void rdns_resolver_set_log_level(struct rdns_resolver *resolver,
+ enum rdns_log_level level)
{
resolver->log_level = level;
}
-void
-rdns_resolver_set_upstream_lib (struct rdns_resolver *resolver,
- struct rdns_upstream_context *ups_ctx,
- void *ups_data)
+void rdns_resolver_set_upstream_lib(struct rdns_resolver *resolver,
+ struct rdns_upstream_context *ups_ctx,
+ void *ups_data)
{
resolver->ups = ups_ctx;
resolver->ups->data = ups_data;
}
-void
-rdns_resolver_set_max_io_uses (struct rdns_resolver *resolver,
- uint64_t max_ioc_uses, double check_time)
+void rdns_resolver_set_max_io_uses(struct rdns_resolver *resolver,
+ uint64_t max_ioc_uses, double check_time)
{
if (resolver->refresh_ioc_periodic != NULL) {
- resolver->async->del_periodic (resolver->async->data,
- resolver->refresh_ioc_periodic);
+ resolver->async->del_periodic(resolver->async->data,
+ resolver->refresh_ioc_periodic);
resolver->refresh_ioc_periodic = NULL;
}
resolver->max_ioc_uses = max_ioc_uses;
if (check_time > 0.0 && resolver->async->add_periodic) {
resolver->refresh_ioc_periodic =
- resolver->async->add_periodic (resolver->async->data,
- check_time, rdns_process_ioc_refresh, resolver);
+ resolver->async->add_periodic(resolver->async->data,
+ check_time, rdns_process_ioc_refresh, resolver);
}
}
static void
-rdns_resolver_free (struct rdns_resolver *resolver)
+rdns_resolver_free(struct rdns_resolver *resolver)
{
struct rdns_server *serv, *stmp;
struct rdns_io_channel *ioc;
if (resolver->initialized) {
if (resolver->periodic != NULL) {
- resolver->async->del_periodic (resolver->async->data, resolver->periodic);
+ resolver->async->del_periodic(resolver->async->data, resolver->periodic);
}
if (resolver->refresh_ioc_periodic != NULL) {
- resolver->async->del_periodic (resolver->async->data,
- resolver->refresh_ioc_periodic);
+ resolver->async->del_periodic(resolver->async->data,
+ resolver->refresh_ioc_periodic);
}
if (resolver->curve_plugin != NULL && resolver->curve_plugin->dtor != NULL) {
- resolver->curve_plugin->dtor (resolver, resolver->curve_plugin->data);
+ resolver->curve_plugin->dtor(resolver, resolver->curve_plugin->data);
}
/* Stop IO watch on all IO channels */
- UPSTREAM_FOREACH_SAFE (resolver->servers, serv, stmp) {
- for (i = 0; i < serv->io_cnt; i ++) {
+ UPSTREAM_FOREACH_SAFE(resolver->servers, serv, stmp)
+ {
+ for (i = 0; i < serv->io_cnt; i++) {
ioc = serv->io_channels[i];
- REF_RELEASE (ioc);
+ REF_RELEASE(ioc);
}
- for (i = 0; i < serv->tcp_io_cnt; i ++) {
+ for (i = 0; i < serv->tcp_io_cnt; i++) {
ioc = serv->tcp_io_channels[i];
- REF_RELEASE (ioc);
+ REF_RELEASE(ioc);
}
- UPSTREAM_DEL (resolver->servers, serv);
- free (serv->io_channels);
- free (serv->tcp_io_channels);
- free (serv->name);
- free (serv);
+ UPSTREAM_DEL(resolver->servers, serv);
+ free(serv->io_channels);
+ free(serv->tcp_io_channels);
+ free(serv->name);
+ free(serv);
}
}
- free (resolver->async);
- free (resolver);
+ free(resolver->async);
+ free(resolver);
}
struct rdns_resolver *
-rdns_resolver_new (int flags)
+rdns_resolver_new(int flags)
{
- struct rdns_resolver *new_resolver;
+ struct rdns_resolver *new_resolver;
- new_resolver = calloc (1, sizeof (struct rdns_resolver));
+ new_resolver = calloc(1, sizeof(struct rdns_resolver));
- REF_INIT_RETAIN (new_resolver, rdns_resolver_free);
+ REF_INIT_RETAIN(new_resolver, rdns_resolver_free);
new_resolver->logger = rdns_logger_internal;
new_resolver->log_data = new_resolver;
return new_resolver;
}
-void
-rdns_resolver_async_bind (struct rdns_resolver *resolver,
- struct rdns_async_context *ctx)
+void rdns_resolver_async_bind(struct rdns_resolver *resolver,
+ struct rdns_async_context *ctx)
{
if (resolver != NULL && ctx != NULL) {
resolver->async = ctx;
}
}
-void
-rdns_resolver_set_dnssec (struct rdns_resolver *resolver, bool enabled)
+void rdns_resolver_set_dnssec(struct rdns_resolver *resolver, bool enabled)
{
if (resolver) {
resolver->enable_dnssec = enabled;
}
-void rdns_resolver_set_fake_reply (struct rdns_resolver *resolver,
- const char *name,
- enum rdns_request_type type,
- enum dns_rcode rcode,
- struct rdns_reply_entry *reply)
+void rdns_resolver_set_fake_reply(struct rdns_resolver *resolver,
+ const char *name,
+ enum rdns_request_type type,
+ enum dns_rcode rcode,
+ struct rdns_reply_entry *reply)
{
struct rdns_fake_reply *fake_rep;
struct rdns_fake_reply_idx *srch;
- unsigned len = strlen (name);
+ unsigned len = strlen(name);
- assert (len < MAX_FAKE_NAME);
- srch = malloc (sizeof (*srch) + len);
+ assert(len < MAX_FAKE_NAME);
+ srch = malloc(sizeof(*srch) + len);
srch->len = len;
srch->type = type;
- memcpy (srch->request, name, len);
+ memcpy(srch->request, name, len);
- HASH_FIND (hh, resolver->fake_elts, srch, len + sizeof (*srch), fake_rep);
+ HASH_FIND(hh, resolver->fake_elts, srch, len + sizeof(*srch), fake_rep);
if (fake_rep) {
/* Append reply to the existing list */
fake_rep->rcode = rcode;
if (reply) {
- DL_CONCAT (fake_rep->result, reply);
+ DL_CONCAT(fake_rep->result, reply);
}
}
else {
- fake_rep = calloc (1, sizeof (*fake_rep) + len);
+ fake_rep = calloc(1, sizeof(*fake_rep) + len);
if (fake_rep == NULL) {
- abort ();
+ abort();
}
fake_rep->rcode = rcode;
- memcpy (&fake_rep->key, srch, sizeof (*srch) + len);
+ memcpy(&fake_rep->key, srch, sizeof(*srch) + len);
if (reply) {
- DL_CONCAT (fake_rep->result, reply);
+ DL_CONCAT(fake_rep->result, reply);
}
- HASH_ADD (hh, resolver->fake_elts, key, sizeof (*srch) + len, fake_rep);
+ HASH_ADD(hh, resolver->fake_elts, key, sizeof(*srch) + len, fake_rep);
}
- free (srch);
+ free(srch);
}
#define UCL_ARRAY_TYPE_META "ucl.type.array"
#define UCL_IMPL_ARRAY_TYPE_META "ucl.type.impl_array"
-static int ucl_object_lua_push_array (lua_State *L, const ucl_object_t *obj, int flags);
-static int ucl_object_lua_push_scalar (lua_State *L, const ucl_object_t *obj, int flags);
-static int ucl_object_push_lua_common (lua_State *L, const ucl_object_t *obj, int flags);
-static ucl_object_t* ucl_object_lua_fromtable (lua_State *L, int idx, ucl_string_flags_t flags);
-static ucl_object_t* ucl_object_lua_fromelt (lua_State *L, int idx, ucl_string_flags_t flags);
+static int ucl_object_lua_push_array(lua_State *L, const ucl_object_t *obj, int flags);
+static int ucl_object_lua_push_scalar(lua_State *L, const ucl_object_t *obj, int flags);
+static int ucl_object_push_lua_common(lua_State *L, const ucl_object_t *obj, int flags);
+static ucl_object_t *ucl_object_lua_fromtable(lua_State *L, int idx, ucl_string_flags_t flags);
+static ucl_object_t *ucl_object_lua_fromelt(lua_State *L, int idx, ucl_string_flags_t flags);
static void *ucl_null;
* @param obj
*/
static void
-ucl_object_lua_push_element (lua_State *L, const char *key,
- const ucl_object_t *obj, int flags)
+ucl_object_lua_push_element(lua_State *L, const char *key,
+ const ucl_object_t *obj, int flags)
{
- lua_pushstring (L, key);
- ucl_object_push_lua_common (L, obj, flags|LUA_UCL_ALLOW_ARRAY);
- lua_settable (L, -3);
+ lua_pushstring(L, key);
+ ucl_object_push_lua_common(L, obj, flags | LUA_UCL_ALLOW_ARRAY);
+ lua_settable(L, -3);
}
static void
-lua_ucl_userdata_dtor (void *ud)
+lua_ucl_userdata_dtor(void *ud)
{
- struct ucl_lua_funcdata *fd = (struct ucl_lua_funcdata *)ud;
+ struct ucl_lua_funcdata *fd = (struct ucl_lua_funcdata *) ud;
- luaL_unref (fd->L, LUA_REGISTRYINDEX, fd->idx);
+ luaL_unref(fd->L, LUA_REGISTRYINDEX, fd->idx);
if (fd->ret != NULL) {
- free (fd->ret);
+ free(fd->ret);
}
- free (fd);
+ free(fd);
}
static const char *
-lua_ucl_userdata_emitter (void *ud)
+lua_ucl_userdata_emitter(void *ud)
{
- struct ucl_lua_funcdata *fd = (struct ucl_lua_funcdata *)ud;
+ struct ucl_lua_funcdata *fd = (struct ucl_lua_funcdata *) ud;
const char *out = "";
- lua_rawgeti (fd->L, LUA_REGISTRYINDEX, fd->idx);
+ lua_rawgeti(fd->L, LUA_REGISTRYINDEX, fd->idx);
- lua_pcall (fd->L, 0, 1, 0);
- out = lua_tostring (fd->L, -1);
+ lua_pcall(fd->L, 0, 1, 0);
+ out = lua_tostring(fd->L, -1);
if (out != NULL) {
/* We need to store temporary string in a more appropriate place */
if (fd->ret) {
- free (fd->ret);
+ free(fd->ret);
}
- fd->ret = strdup (out);
+ fd->ret = strdup(out);
}
- lua_settop (fd->L, 0);
+ lua_settop(fd->L, 0);
return fd->ret;
}
* @return
*/
static int
-ucl_object_lua_push_object (lua_State *L, const ucl_object_t *obj,
- int flags)
+ucl_object_lua_push_object(lua_State *L, const ucl_object_t *obj,
+ int flags)
{
const ucl_object_t *cur;
ucl_object_iter_t it = NULL;
if ((flags & LUA_UCL_ALLOW_ARRAY) && obj->next != NULL) {
/* Actually we need to push this as an array */
- return ucl_object_lua_push_array (L, obj, flags);
+ return ucl_object_lua_push_array(L, obj, flags);
}
- lua_createtable (L, 0, obj->len);
+ lua_createtable(L, 0, obj->len);
it = NULL;
- while ((cur = ucl_object_iterate (obj, &it, true)) != NULL) {
- ucl_object_lua_push_element (L, ucl_object_key (cur), cur, flags);
+ while ((cur = ucl_object_iterate(obj, &it, true)) != NULL) {
+ ucl_object_lua_push_element(L, ucl_object_key(cur), cur, flags);
}
- luaL_getmetatable (L, UCL_OBJECT_TYPE_META);
- lua_setmetatable (L, -2);
+ luaL_getmetatable(L, UCL_OBJECT_TYPE_META);
+ lua_setmetatable(L, -2);
return 1;
}
* @return
*/
static int
-ucl_object_lua_push_array (lua_State *L, const ucl_object_t *obj, int flags)
+ucl_object_lua_push_array(lua_State *L, const ucl_object_t *obj, int flags)
{
const ucl_object_t *cur;
ucl_object_iter_t it;
if (obj->type == UCL_ARRAY) {
nelt = obj->len;
- it = ucl_object_iterate_new (obj);
- lua_createtable (L, nelt, 0);
+ it = ucl_object_iterate_new(obj);
+ lua_createtable(L, nelt, 0);
- while ((cur = ucl_object_iterate_safe (it, true))) {
- ucl_object_push_lua (L, cur, (flags & ~LUA_UCL_ALLOW_ARRAY));
- lua_rawseti (L, -2, i);
- i ++;
+ while ((cur = ucl_object_iterate_safe(it, true))) {
+ ucl_object_push_lua(L, cur, (flags & ~LUA_UCL_ALLOW_ARRAY));
+ lua_rawseti(L, -2, i);
+ i++;
}
- luaL_getmetatable (L, UCL_ARRAY_TYPE_META);
- lua_setmetatable (L, -2);
+ luaL_getmetatable(L, UCL_ARRAY_TYPE_META);
+ lua_setmetatable(L, -2);
- ucl_object_iterate_free (it);
+ ucl_object_iterate_free(it);
}
else {
/* Optimize allocation by preallocation of table */
- LL_FOREACH (obj, cur) {
- nelt ++;
+ LL_FOREACH(obj, cur)
+ {
+ nelt++;
}
- lua_createtable (L, nelt, 0);
+ lua_createtable(L, nelt, 0);
- LL_FOREACH (obj, cur) {
- ucl_object_push_lua (L, cur, (flags & ~LUA_UCL_ALLOW_ARRAY));
- lua_rawseti (L, -2, i);
- i ++;
+ LL_FOREACH(obj, cur)
+ {
+ ucl_object_push_lua(L, cur, (flags & ~LUA_UCL_ALLOW_ARRAY));
+ lua_rawseti(L, -2, i);
+ i++;
}
- luaL_getmetatable (L, UCL_IMPL_ARRAY_TYPE_META);
- lua_setmetatable (L, -2);
+ luaL_getmetatable(L, UCL_IMPL_ARRAY_TYPE_META);
+ lua_setmetatable(L, -2);
}
return 1;
* Push a simple object to lua depending on its actual type
*/
static int
-ucl_object_lua_push_scalar (lua_State *L, const ucl_object_t *obj,
- int flags)
+ucl_object_lua_push_scalar(lua_State *L, const ucl_object_t *obj,
+ int flags)
{
struct ucl_lua_funcdata *fd;
if ((flags & LUA_UCL_ALLOW_ARRAY) && obj->next != NULL) {
/* Actually we need to push this as an array */
- return ucl_object_lua_push_array (L, obj, flags);
+ return ucl_object_lua_push_array(L, obj, flags);
}
switch (obj->type) {
case UCL_BOOLEAN:
- lua_pushboolean (L, ucl_obj_toboolean (obj));
+ lua_pushboolean(L, ucl_obj_toboolean(obj));
break;
case UCL_STRING:
- lua_pushlstring (L, ucl_obj_tostring (obj), obj->len);
+ lua_pushlstring(L, ucl_obj_tostring(obj), obj->len);
break;
case UCL_INT:
#if LUA_VERSION_NUM >= 501
- lua_pushinteger (L, ucl_obj_toint (obj));
+ lua_pushinteger(L, ucl_obj_toint(obj));
#else
- lua_pushnumber (L, ucl_obj_toint (obj));
+ lua_pushnumber(L, ucl_obj_toint(obj));
#endif
break;
case UCL_FLOAT:
case UCL_TIME:
- lua_pushnumber (L, ucl_obj_todouble (obj));
+ lua_pushnumber(L, ucl_obj_todouble(obj));
break;
case UCL_NULL:
if (flags & LUA_UCL_CONVERT_NIL) {
- lua_pushboolean (L, false);
+ lua_pushboolean(L, false);
}
else {
- lua_getfield (L, LUA_REGISTRYINDEX, "ucl.null");
+ lua_getfield(L, LUA_REGISTRYINDEX, "ucl.null");
}
break;
case UCL_USERDATA:
- fd = (struct ucl_lua_funcdata *)obj->value.ud;
- lua_rawgeti (L, LUA_REGISTRYINDEX, fd->idx);
+ fd = (struct ucl_lua_funcdata *) obj->value.ud;
+ lua_rawgeti(L, LUA_REGISTRYINDEX, fd->idx);
break;
default:
- lua_pushnil (L);
+ lua_pushnil(L);
break;
}
}
static int
-ucl_object_push_lua_common (lua_State *L, const ucl_object_t *obj, int flags)
+ucl_object_push_lua_common(lua_State *L, const ucl_object_t *obj, int flags)
{
switch (obj->type) {
case UCL_OBJECT:
- return ucl_object_lua_push_object (L, obj, flags);
+ return ucl_object_lua_push_object(L, obj, flags);
case UCL_ARRAY:
- return ucl_object_lua_push_array (L, obj, flags);
+ return ucl_object_lua_push_array(L, obj, flags);
default:
- return ucl_object_lua_push_scalar (L, obj, flags);
+ return ucl_object_lua_push_scalar(L, obj, flags);
}
}
* @param {bool} allow_array expand implicit arrays (should be true for all but partial arrays)
* @return {int} `1` if an object is pushed to lua
*/
-int
-ucl_object_push_lua (lua_State *L, const ucl_object_t *obj, bool allow_array)
+int ucl_object_push_lua(lua_State *L, const ucl_object_t *obj, bool allow_array)
{
- return ucl_object_push_lua_common (L, obj,
- allow_array ? LUA_UCL_ALLOW_ARRAY : LUA_UCL_DEFAULT_FLAGS);
+ return ucl_object_push_lua_common(L, obj,
+ allow_array ? LUA_UCL_ALLOW_ARRAY : LUA_UCL_DEFAULT_FLAGS);
}
-int
-ucl_object_push_lua_filter_nil (lua_State *L, const ucl_object_t *obj, bool allow_array)
+int ucl_object_push_lua_filter_nil(lua_State *L, const ucl_object_t *obj, bool allow_array)
{
- return ucl_object_push_lua_common (L, obj,
- allow_array ? (LUA_UCL_ALLOW_ARRAY|LUA_UCL_CONVERT_NIL) :
- (LUA_UCL_DEFAULT_FLAGS|LUA_UCL_CONVERT_NIL));
+ return ucl_object_push_lua_common(L, obj,
+ allow_array ? (LUA_UCL_ALLOW_ARRAY | LUA_UCL_CONVERT_NIL) : (LUA_UCL_DEFAULT_FLAGS | LUA_UCL_CONVERT_NIL));
}
/**
* @param idx
*/
static ucl_object_t *
-ucl_object_lua_fromtable (lua_State *L, int idx, ucl_string_flags_t flags)
+ucl_object_lua_fromtable(lua_State *L, int idx, ucl_string_flags_t flags)
{
ucl_object_t *obj, *top = NULL, *cur;
size_t keylen;
if (idx < 0) {
/* For negative indicies we want to invert them */
- idx = lua_gettop (L) + idx + 1;
+ idx = lua_gettop(L) + idx + 1;
}
/* First, we check from metatable */
- if (luaL_getmetafield (L, idx, "class") != 0) {
+ if (luaL_getmetafield(L, idx, "class") != 0) {
- if (lua_type (L, -1) == LUA_TSTRING) {
- const char *classname = lua_tostring (L, -1);
+ if (lua_type(L, -1) == LUA_TSTRING) {
+ const char *classname = lua_tostring(L, -1);
- if (strcmp (classname, UCL_OBJECT_TYPE_META) == 0) {
+ if (strcmp(classname, UCL_OBJECT_TYPE_META) == 0) {
is_array = false;
found_mt = true;
- } else if (strcmp (classname, UCL_ARRAY_TYPE_META) == 0) {
+ }
+ else if (strcmp(classname, UCL_ARRAY_TYPE_META) == 0) {
is_array = true;
found_mt = true;
#if LUA_VERSION_NUM >= 502
- max = lua_rawlen (L, idx);
+ max = lua_rawlen(L, idx);
#else
- max = lua_objlen (L, idx);
+ max = lua_objlen(L, idx);
#endif
nelts = max;
- } else if (strcmp (classname, UCL_IMPL_ARRAY_TYPE_META) == 0) {
+ }
+ else if (strcmp(classname, UCL_IMPL_ARRAY_TYPE_META) == 0) {
is_array = true;
is_implicit = true;
found_mt = true;
#if LUA_VERSION_NUM >= 502
- max = lua_rawlen (L, idx);
+ max = lua_rawlen(L, idx);
#else
- max = lua_objlen (L, idx);
+ max = lua_objlen(L, idx);
#endif
nelts = max;
}
}
- lua_pop (L, 1);
+ lua_pop(L, 1);
}
if (!found_mt) {
/* Check for array (it is all inefficient) */
- lua_pushnil (L);
+ lua_pushnil(L);
- while (lua_next (L, idx) != 0) {
- lua_pushvalue (L, -2);
+ while (lua_next(L, idx) != 0) {
+ lua_pushvalue(L, -2);
- if (lua_type (L, -1) == LUA_TNUMBER) {
- double num = lua_tonumber (L, -1);
+ if (lua_type(L, -1) == LUA_TNUMBER) {
+ double num = lua_tonumber(L, -1);
if (num == (int) num) {
if (num > max) {
max = num;
is_array = false;
}
- lua_pop (L, 2);
- nelts ++;
+ lua_pop(L, 2);
+ nelts++;
}
}
int i;
if (!is_implicit) {
- top = ucl_object_typed_new (UCL_ARRAY);
- ucl_object_reserve (top, nelts);
+ top = ucl_object_typed_new(UCL_ARRAY);
+ ucl_object_reserve(top, nelts);
}
else {
top = NULL;
}
- for (i = 1; i <= max; i ++) {
- lua_pushinteger (L, i);
- lua_gettable (L, idx);
+ for (i = 1; i <= max; i++) {
+ lua_pushinteger(L, i);
+ lua_gettable(L, idx);
- obj = ucl_object_lua_fromelt (L, lua_gettop (L), flags);
+ obj = ucl_object_lua_fromelt(L, lua_gettop(L), flags);
if (obj != NULL) {
if (is_implicit) {
- DL_APPEND (top, obj);
+ DL_APPEND(top, obj);
}
else {
- ucl_array_append (top, obj);
+ ucl_array_append(top, obj);
}
}
- lua_pop (L, 1);
+ lua_pop(L, 1);
}
}
else {
- lua_pushnil (L);
- top = ucl_object_typed_new (UCL_OBJECT);
- ucl_object_reserve (top, nelts);
+ lua_pushnil(L);
+ top = ucl_object_typed_new(UCL_OBJECT);
+ ucl_object_reserve(top, nelts);
- while (lua_next (L, idx) != 0) {
+ while (lua_next(L, idx) != 0) {
/* copy key to avoid modifications */
- lua_pushvalue (L, -2);
- k = lua_tolstring (L, -1, &keylen);
- obj = ucl_object_lua_fromelt (L, lua_gettop (L) - 1, flags);
+ lua_pushvalue(L, -2);
+ k = lua_tolstring(L, -1, &keylen);
+ obj = ucl_object_lua_fromelt(L, lua_gettop(L) - 1, flags);
if (obj != NULL) {
- ucl_object_insert_key (top, obj, k, keylen, true);
+ ucl_object_insert_key(top, obj, k, keylen, true);
- DL_FOREACH (obj, cur) {
+ DL_FOREACH(obj, cur)
+ {
if (cur->keylen == 0) {
cur->keylen = obj->keylen;
cur->key = obj->key;
}
}
}
- lua_pop (L, 2);
+ lua_pop(L, 2);
}
}
* @param idx
*/
static ucl_object_t *
-ucl_object_lua_fromelt (lua_State *L, int idx, ucl_string_flags_t flags)
+ucl_object_lua_fromelt(lua_State *L, int idx, ucl_string_flags_t flags)
{
int type;
double num;
const char *str;
size_t sz;
- type = lua_type (L, idx);
+ type = lua_type(L, idx);
switch (type) {
case LUA_TSTRING:
- str = lua_tolstring (L, idx, &sz);
+ str = lua_tolstring(L, idx, &sz);
if (str) {
/*
}
}
else {
- obj = ucl_object_typed_new (UCL_NULL);
+ obj = ucl_object_typed_new(UCL_NULL);
}
break;
case LUA_TNUMBER:
- num = lua_tonumber (L, idx);
- if (num == (int64_t)num) {
- obj = ucl_object_fromint (num);
+ num = lua_tonumber(L, idx);
+ if (num == (int64_t) num) {
+ obj = ucl_object_fromint(num);
}
else {
- obj = ucl_object_fromdouble (num);
+ obj = ucl_object_fromdouble(num);
}
break;
case LUA_TBOOLEAN:
- obj = ucl_object_frombool (lua_toboolean (L, idx));
+ obj = ucl_object_frombool(lua_toboolean(L, idx));
break;
case LUA_TUSERDATA:
- if (lua_topointer (L, idx) == ucl_null) {
- obj = ucl_object_typed_new (UCL_NULL);
+ if (lua_topointer(L, idx) == ucl_null) {
+ obj = ucl_object_typed_new(UCL_NULL);
}
else {
/* Assume it is a text like object */
- struct _rspamd_lua_text *t = lua_touserdata (L, idx);
+ struct _rspamd_lua_text *t = lua_touserdata(L, idx);
if (t) {
- if (t->len >0) {
+ if (t->len > 0) {
obj = ucl_object_fromstring_common(t->start, t->len, 0);
}
else {
case LUA_TTABLE:
case LUA_TFUNCTION:
case LUA_TTHREAD:
- if (luaL_getmetafield (L, idx, "__gen_ucl")) {
- if (lua_isfunction (L, -1)) {
- lua_settop (L, 3); /* gen, obj, func */
- lua_insert (L, 1); /* func, gen, obj */
- lua_insert (L, 2); /* func, obj, gen */
+ if (luaL_getmetafield(L, idx, "__gen_ucl")) {
+ if (lua_isfunction(L, -1)) {
+ lua_settop(L, 3); /* gen, obj, func */
+ lua_insert(L, 1); /* func, gen, obj */
+ lua_insert(L, 2); /* func, obj, gen */
lua_call(L, 2, 1);
- obj = ucl_object_lua_fromelt (L, 1, flags);
+ obj = ucl_object_lua_fromelt(L, 1, flags);
}
- lua_pop (L, 2);
+ lua_pop(L, 2);
}
else {
if (type == LUA_TTABLE) {
- obj = ucl_object_lua_fromtable (L, idx, flags);
+ obj = ucl_object_lua_fromtable(L, idx, flags);
}
else if (type == LUA_TFUNCTION) {
- fd = malloc (sizeof (*fd));
+ fd = malloc(sizeof(*fd));
if (fd != NULL) {
- lua_pushvalue (L, idx);
+ lua_pushvalue(L, idx);
fd->L = L;
fd->ret = NULL;
- fd->idx = luaL_ref (L, LUA_REGISTRYINDEX);
+ fd->idx = luaL_ref(L, LUA_REGISTRYINDEX);
- obj = ucl_object_new_userdata (lua_ucl_userdata_dtor,
- lua_ucl_userdata_emitter, (void *)fd);
+ obj = ucl_object_new_userdata(lua_ucl_userdata_dtor,
+ lua_ucl_userdata_emitter, (void *) fd);
}
}
}
* this object thus needs to be unref'ed after usage.
*/
ucl_object_t *
-ucl_object_lua_import (lua_State *L, int idx)
+ucl_object_lua_import(lua_State *L, int idx)
{
ucl_object_t *obj;
int t;
- t = lua_type (L, idx);
+ t = lua_type(L, idx);
switch (t) {
case LUA_TTABLE:
- obj = ucl_object_lua_fromtable (L, idx, UCL_STRING_RAW);
+ obj = ucl_object_lua_fromtable(L, idx, UCL_STRING_RAW);
break;
default:
- obj = ucl_object_lua_fromelt (L, idx, UCL_STRING_RAW);
+ obj = ucl_object_lua_fromelt(L, idx, UCL_STRING_RAW);
break;
}
* this object thus needs to be unref'ed after usage.
*/
ucl_object_t *
-ucl_object_lua_import_escape (lua_State *L, int idx)
+ucl_object_lua_import_escape(lua_State *L, int idx)
{
ucl_object_t *obj;
int t;
- t = lua_type (L, idx);
+ t = lua_type(L, idx);
switch (t) {
case LUA_TTABLE:
- obj = ucl_object_lua_fromtable (L, idx, UCL_STRING_ESCAPE);
+ obj = ucl_object_lua_fromtable(L, idx, UCL_STRING_ESCAPE);
break;
default:
- obj = ucl_object_lua_fromelt (L, idx, UCL_STRING_ESCAPE);
+ obj = ucl_object_lua_fromelt(L, idx, UCL_STRING_ESCAPE);
break;
}
}
static int
-lua_ucl_to_string (lua_State *L, const ucl_object_t *obj, enum ucl_emitter type)
+lua_ucl_to_string(lua_State *L, const ucl_object_t *obj, enum ucl_emitter type)
{
unsigned char *result;
size_t outlen;
- result = ucl_object_emit_len (obj, type, &outlen);
+ result = ucl_object_emit_len(obj, type, &outlen);
if (result != NULL) {
- lua_pushlstring (L, (const char *)result, outlen);
- free (result);
+ lua_pushlstring(L, (const char *) result, outlen);
+ free(result);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
}
static int
-lua_ucl_parser_init (lua_State *L)
+lua_ucl_parser_init(lua_State *L)
{
struct ucl_parser *parser, **pparser;
int flags = UCL_PARSER_NO_FILEVARS;
- if (lua_gettop (L) >= 1) {
- flags = lua_tonumber (L, 1);
+ if (lua_gettop(L) >= 1) {
+ flags = lua_tonumber(L, 1);
}
- parser = ucl_parser_new (flags);
+ parser = ucl_parser_new(flags);
if (parser == NULL) {
- lua_pushnil (L);
+ lua_pushnil(L);
}
- pparser = lua_newuserdata (L, sizeof (parser));
+ pparser = lua_newuserdata(L, sizeof(parser));
*pparser = parser;
- luaL_getmetatable (L, PARSER_META);
- lua_setmetatable (L, -2);
+ luaL_getmetatable(L, PARSER_META);
+ lua_setmetatable(L, -2);
return 1;
}
static struct ucl_parser *
-lua_ucl_parser_get (lua_State *L, int index)
+lua_ucl_parser_get(lua_State *L, int index)
{
return *((struct ucl_parser **) luaL_checkudata(L, index, PARSER_META));
}
static ucl_object_t *
-lua_ucl_object_get (lua_State *L, int index)
+lua_ucl_object_get(lua_State *L, int index)
{
return *((ucl_object_t **) luaL_checkudata(L, index, OBJECT_META));
}
static void
-lua_ucl_push_opaque (lua_State *L, ucl_object_t *obj)
+lua_ucl_push_opaque(lua_State *L, ucl_object_t *obj)
{
ucl_object_t **pobj;
- pobj = lua_newuserdata (L, sizeof (*pobj));
+ pobj = lua_newuserdata(L, sizeof(*pobj));
*pobj = obj;
- luaL_getmetatable (L, OBJECT_META);
- lua_setmetatable (L, -2);
+ luaL_getmetatable(L, OBJECT_META);
+ lua_setmetatable(L, -2);
}
static inline enum ucl_parse_type
-lua_ucl_str_to_parse_type (const char *str)
+lua_ucl_str_to_parse_type(const char *str)
{
enum ucl_parse_type type = UCL_PARSE_UCL;
if (str != NULL) {
- if (strcasecmp (str, "msgpack") == 0) {
+ if (strcasecmp(str, "msgpack") == 0) {
type = UCL_PARSE_MSGPACK;
}
- else if (strcasecmp (str, "sexp") == 0 ||
- strcasecmp (str, "csexp") == 0) {
+ else if (strcasecmp(str, "sexp") == 0 ||
+ strcasecmp(str, "csexp") == 0) {
type = UCL_PARSE_CSEXP;
}
- else if (strcasecmp (str, "auto") == 0) {
+ else if (strcasecmp(str, "auto") == 0) {
type = UCL_PARSE_AUTO;
}
}
end
*/
static int
-lua_ucl_parser_parse_file (lua_State *L)
+lua_ucl_parser_parse_file(lua_State *L)
{
struct ucl_parser *parser;
const char *file;
int ret = 2;
- parser = lua_ucl_parser_get (L, 1);
- file = luaL_checkstring (L, 2);
+ parser = lua_ucl_parser_get(L, 1);
+ file = luaL_checkstring(L, 2);
if (parser != NULL && file != NULL) {
- if (ucl_parser_add_file (parser, file)) {
- lua_pushboolean (L, true);
+ if (ucl_parser_add_file(parser, file)) {
+ lua_pushboolean(L, true);
ret = 1;
}
else {
- lua_pushboolean (L, false);
- lua_pushstring (L, ucl_parser_get_error (parser));
+ lua_pushboolean(L, false);
+ lua_pushstring(L, ucl_parser_get_error(parser));
}
}
else {
- lua_pushboolean (L, false);
- lua_pushstring (L, "invalid arguments");
+ lua_pushboolean(L, false);
+ lua_pushstring(L, "invalid arguments");
}
return ret;
local res = parser:register_variable('CONFDIR', '/etc/foo')
*/
static int
-lua_ucl_parser_register_variable (lua_State *L)
+lua_ucl_parser_register_variable(lua_State *L)
{
struct ucl_parser *parser;
const char *name, *value;
int ret = 2;
- parser = lua_ucl_parser_get (L, 1);
- name = luaL_checkstring (L, 2);
- value = luaL_checkstring (L, 3);
+ parser = lua_ucl_parser_get(L, 1);
+ name = luaL_checkstring(L, 2);
+ value = luaL_checkstring(L, 3);
if (parser != NULL && name != NULL && value != NULL) {
- ucl_parser_register_variable (parser, name, value);
- lua_pushboolean (L, true);
+ ucl_parser_register_variable(parser, name, value);
+ lua_pushboolean(L, true);
ret = 1;
}
else {
- return luaL_error (L, "invalid arguments");
+ return luaL_error(L, "invalid arguments");
}
return ret;
local res = parser:register_variables({CONFDIR = '/etc/foo', VARDIR = '/var'})
*/
static int
-lua_ucl_parser_register_variables (lua_State *L)
+lua_ucl_parser_register_variables(lua_State *L)
{
struct ucl_parser *parser;
const char *name, *value;
int ret = 2;
- parser = lua_ucl_parser_get (L, 1);
+ parser = lua_ucl_parser_get(L, 1);
- if (parser != NULL && lua_type (L, 2) == LUA_TTABLE) {
- for (lua_pushnil (L); lua_next (L, 2); lua_pop (L, 1)) {
- lua_pushvalue (L, -2);
- name = luaL_checkstring (L, -1);
- value = luaL_checkstring (L, -2);
- ucl_parser_register_variable (parser, name, value);
- lua_pop (L, 1);
+ if (parser != NULL && lua_type(L, 2) == LUA_TTABLE) {
+ for (lua_pushnil(L); lua_next(L, 2); lua_pop(L, 1)) {
+ lua_pushvalue(L, -2);
+ name = luaL_checkstring(L, -1);
+ value = luaL_checkstring(L, -2);
+ ucl_parser_register_variable(parser, name, value);
+ lua_pop(L, 1);
}
- lua_pushboolean (L, true);
+ lua_pushboolean(L, true);
ret = 1;
}
else {
- return luaL_error (L, "invalid arguments");
+ return luaL_error(L, "invalid arguments");
}
return ret;
* @return {bool[, string]} if res is `true` then file has been parsed successfully, otherwise an error string is also returned
*/
static int
-lua_ucl_parser_parse_string (lua_State *L)
+lua_ucl_parser_parse_string(lua_State *L)
{
struct ucl_parser *parser;
const char *string;
enum ucl_parse_type type = UCL_PARSE_UCL;
int ret = 2;
- parser = lua_ucl_parser_get (L, 1);
- string = luaL_checklstring (L, 2, &llen);
+ parser = lua_ucl_parser_get(L, 1);
+ string = luaL_checklstring(L, 2, &llen);
- if (lua_type (L, 3) == LUA_TSTRING) {
- type = lua_ucl_str_to_parse_type (lua_tostring (L, 3));
+ if (lua_type(L, 3) == LUA_TSTRING) {
+ type = lua_ucl_str_to_parse_type(lua_tostring(L, 3));
}
if (parser != NULL && string != NULL) {
- if (ucl_parser_add_chunk_full (parser, (const unsigned char *)string,
- llen, 0, UCL_DUPLICATE_APPEND, type)) {
- lua_pushboolean (L, true);
+ if (ucl_parser_add_chunk_full(parser, (const unsigned char *) string,
+ llen, 0, UCL_DUPLICATE_APPEND, type)) {
+ lua_pushboolean(L, true);
ret = 1;
}
else {
- lua_pushboolean (L, false);
- lua_pushstring (L, ucl_parser_get_error (parser));
+ lua_pushboolean(L, false);
+ lua_pushstring(L, ucl_parser_get_error(parser));
}
}
else {
- lua_pushboolean (L, false);
- lua_pushstring (L, "invalid arguments");
+ lua_pushboolean(L, false);
+ lua_pushstring(L, "invalid arguments");
}
return ret;
* @return {bool[, string]} if res is `true` then file has been parsed successfully, otherwise an error string is also returned
*/
static int
-lua_ucl_parser_parse_text (lua_State *L)
+lua_ucl_parser_parse_text(lua_State *L)
{
struct ucl_parser *parser;
struct _rspamd_lua_text *t;
enum ucl_parse_type type = UCL_PARSE_UCL;
int ret = 2;
- parser = lua_ucl_parser_get (L, 1);
+ parser = lua_ucl_parser_get(L, 1);
- if (lua_type (L, 2) == LUA_TUSERDATA) {
- t = lua_touserdata (L, 2);
+ if (lua_type(L, 2) == LUA_TUSERDATA) {
+ t = lua_touserdata(L, 2);
}
- else if (lua_type (L, 2) == LUA_TSTRING) {
- const gchar *s;
+ else if (lua_type(L, 2) == LUA_TSTRING) {
+ const char *s;
gsize len;
static struct _rspamd_lua_text st_t;
- s = lua_tolstring (L, 2, &len);
+ s = lua_tolstring(L, 2, &len);
st_t.start = s;
st_t.len = len;
return luaL_error(L, "invalid argument as input, expected userdata or a string");
}
- if (lua_type (L, 3) == LUA_TSTRING) {
- type = lua_ucl_str_to_parse_type (lua_tostring (L, 3));
+ if (lua_type(L, 3) == LUA_TSTRING) {
+ type = lua_ucl_str_to_parse_type(lua_tostring(L, 3));
}
if (parser != NULL && t != NULL) {
- if (ucl_parser_add_chunk_full (parser, (const unsigned char *)t->start,
- t->len, 0, UCL_DUPLICATE_APPEND, type)) {
- lua_pushboolean (L, true);
+ if (ucl_parser_add_chunk_full(parser, (const unsigned char *) t->start,
+ t->len, 0, UCL_DUPLICATE_APPEND, type)) {
+ lua_pushboolean(L, true);
ret = 1;
}
else {
- lua_pushboolean (L, false);
- lua_pushstring (L, ucl_parser_get_error (parser));
+ lua_pushboolean(L, false);
+ lua_pushstring(L, ucl_parser_get_error(parser));
}
}
else {
- lua_pushboolean (L, false);
- lua_pushstring (L, "invalid arguments");
+ lua_pushboolean(L, false);
+ lua_pushstring(L, "invalid arguments");
}
return ret;
* @return {variant or nil} ucl object as lua native variable
*/
static int
-lua_ucl_parser_get_object (lua_State *L)
+lua_ucl_parser_get_object(lua_State *L)
{
struct ucl_parser *parser;
ucl_object_t *obj;
int ret = 1;
- parser = lua_ucl_parser_get (L, 1);
- obj = ucl_parser_get_object (parser);
+ parser = lua_ucl_parser_get(L, 1);
+ obj = ucl_parser_get_object(parser);
if (obj != NULL) {
- ret = ucl_object_push_lua (L, obj, false);
+ ret = ucl_object_push_lua(L, obj, false);
/* no need to keep reference */
- ucl_object_unref (obj);
+ ucl_object_unref(obj);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return ret;
* @return {ucl.object or nil} ucl object wrapped variable
*/
static int
-lua_ucl_parser_get_object_wrapped (lua_State *L)
+lua_ucl_parser_get_object_wrapped(lua_State *L)
{
struct ucl_parser *parser;
ucl_object_t *obj;
int ret = 1;
- parser = lua_ucl_parser_get (L, 1);
- obj = ucl_parser_get_object (parser);
+ parser = lua_ucl_parser_get(L, 1);
+ obj = ucl_parser_get_object(parser);
if (obj != NULL) {
- lua_ucl_push_opaque (L, obj);
+ lua_ucl_push_opaque(L, obj);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return ret;
*
*/
static int
-lua_ucl_parser_validate (lua_State *L)
+lua_ucl_parser_validate(lua_State *L)
{
struct ucl_parser *parser, *schema_parser;
ucl_object_t *schema;
const char *schema_file;
struct ucl_schema_error err;
- parser = lua_ucl_parser_get (L, 1);
+ parser = lua_ucl_parser_get(L, 1);
if (parser && parser->top_obj) {
- if (lua_type (L, 2) == LUA_TTABLE) {
- schema = ucl_object_lua_import (L, 2);
+ if (lua_type(L, 2) == LUA_TTABLE) {
+ schema = ucl_object_lua_import(L, 2);
if (schema == NULL) {
- lua_pushboolean (L, false);
- lua_pushstring (L, "cannot load schema from lua table");
+ lua_pushboolean(L, false);
+ lua_pushstring(L, "cannot load schema from lua table");
return 2;
}
}
- else if (lua_type (L, 2) == LUA_TSTRING) {
- schema_parser = ucl_parser_new (0);
- schema_file = luaL_checkstring (L, 2);
+ else if (lua_type(L, 2) == LUA_TSTRING) {
+ schema_parser = ucl_parser_new(0);
+ schema_file = luaL_checkstring(L, 2);
- if (!ucl_parser_add_file (schema_parser, schema_file)) {
- lua_pushboolean (L, false);
- lua_pushfstring (L, "cannot parse schema file \"%s\": "
- "%s", schema_file, ucl_parser_get_error (parser));
- ucl_parser_free (schema_parser);
+ if (!ucl_parser_add_file(schema_parser, schema_file)) {
+ lua_pushboolean(L, false);
+ lua_pushfstring(L, "cannot parse schema file \"%s\": "
+ "%s",
+ schema_file, ucl_parser_get_error(parser));
+ ucl_parser_free(schema_parser);
return 2;
}
- schema = ucl_parser_get_object (schema_parser);
- ucl_parser_free (schema_parser);
+ schema = ucl_parser_get_object(schema_parser);
+ ucl_parser_free(schema_parser);
}
else {
- lua_pushboolean (L, false);
- lua_pushstring (L, "invalid schema argument");
+ lua_pushboolean(L, false);
+ lua_pushstring(L, "invalid schema argument");
return 2;
}
- if (!ucl_object_validate (schema, parser->top_obj, &err)) {
- lua_pushboolean (L, false);
- lua_pushfstring (L, "validation error: "
- "%s", err.msg);
+ if (!ucl_object_validate(schema, parser->top_obj, &err)) {
+ lua_pushboolean(L, false);
+ lua_pushfstring(L, "validation error: "
+ "%s",
+ err.msg);
}
else {
- lua_pushboolean (L, true);
- lua_pushnil (L);
+ lua_pushboolean(L, true);
+ lua_pushnil(L);
}
- ucl_object_unref (schema);
+ ucl_object_unref(schema);
}
else {
- lua_pushboolean (L, false);
- lua_pushstring (L, "invalid parser or empty top object");
+ lua_pushboolean(L, false);
+ lua_pushstring(L, "invalid parser or empty top object");
}
return 2;
}
static int
-lua_ucl_parser_gc (lua_State *L)
+lua_ucl_parser_gc(lua_State *L)
{
struct ucl_parser *parser;
- parser = lua_ucl_parser_get (L, 1);
- ucl_parser_free (parser);
+ parser = lua_ucl_parser_get(L, 1);
+ ucl_parser_free(parser);
return 0;
}
* @return {variant} any lua object
*/
static int
-lua_ucl_object_unwrap (lua_State *L)
+lua_ucl_object_unwrap(lua_State *L)
{
ucl_object_t *obj;
- obj = lua_ucl_object_get (L, 1);
+ obj = lua_ucl_object_get(L, 1);
if (obj) {
- ucl_object_push_lua (L, obj, true);
+ ucl_object_push_lua(L, obj, true);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
}
static inline enum ucl_emitter
-lua_ucl_str_to_emit_type (const char *strtype)
+lua_ucl_str_to_emit_type(const char *strtype)
{
enum ucl_emitter format = UCL_EMIT_JSON_COMPACT;
- if (strcasecmp (strtype, "json") == 0) {
+ if (strcasecmp(strtype, "json") == 0) {
format = UCL_EMIT_JSON;
}
- else if (strcasecmp (strtype, "json-compact") == 0) {
+ else if (strcasecmp(strtype, "json-compact") == 0) {
format = UCL_EMIT_JSON_COMPACT;
}
- else if (strcasecmp (strtype, "yaml") == 0) {
+ else if (strcasecmp(strtype, "yaml") == 0) {
format = UCL_EMIT_YAML;
}
- else if (strcasecmp (strtype, "config") == 0 ||
- strcasecmp (strtype, "ucl") == 0) {
+ else if (strcasecmp(strtype, "config") == 0 ||
+ strcasecmp(strtype, "ucl") == 0) {
format = UCL_EMIT_CONFIG;
}
* @return {string} string representation of the opaque ucl object
*/
static int
-lua_ucl_object_tostring (lua_State *L)
+lua_ucl_object_tostring(lua_State *L)
{
ucl_object_t *obj;
enum ucl_emitter format = UCL_EMIT_JSON_COMPACT;
- obj = lua_ucl_object_get (L, 1);
+ obj = lua_ucl_object_get(L, 1);
if (obj) {
- if (lua_gettop (L) > 1) {
- if (lua_type (L, 2) == LUA_TSTRING) {
- const char *strtype = lua_tostring (L, 2);
+ if (lua_gettop(L) > 1) {
+ if (lua_type(L, 2) == LUA_TSTRING) {
+ const char *strtype = lua_tostring(L, 2);
- format = lua_ucl_str_to_emit_type (strtype);
+ format = lua_ucl_str_to_emit_type(strtype);
}
}
- return lua_ucl_to_string (L, obj, format);
+ return lua_ucl_to_string(L, obj, format);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
* ucl object as {result,err,ext_refs}
*/
static int
-lua_ucl_object_validate (lua_State *L)
+lua_ucl_object_validate(lua_State *L)
{
ucl_object_t *obj, *schema, *ext_refs = NULL;
const ucl_object_t *schema_elt;
struct ucl_schema_error err;
const char *path = NULL;
- obj = lua_ucl_object_get (L, 1);
- schema = lua_ucl_object_get (L, 2);
+ obj = lua_ucl_object_get(L, 1);
+ schema = lua_ucl_object_get(L, 2);
- if (schema && obj && ucl_object_type (schema) == UCL_OBJECT) {
- if (lua_gettop (L) > 2) {
- if (lua_type (L, 3) == LUA_TSTRING) {
- path = lua_tostring (L, 3);
+ if (schema && obj && ucl_object_type(schema) == UCL_OBJECT) {
+ if (lua_gettop(L) > 2) {
+ if (lua_type(L, 3) == LUA_TSTRING) {
+ path = lua_tostring(L, 3);
if (path[0] == '#') {
path++;
}
}
- else if (lua_type (L, 3) == LUA_TUSERDATA || lua_type (L, 3) ==
- LUA_TTABLE) {
+ else if (lua_type(L, 3) == LUA_TUSERDATA || lua_type(L, 3) ==
+ LUA_TTABLE) {
/* External refs */
- ext_refs = lua_ucl_object_get (L, 3);
+ ext_refs = lua_ucl_object_get(L, 3);
}
- if (lua_gettop (L) > 3) {
- if (lua_type (L, 4) == LUA_TUSERDATA || lua_type (L, 4) ==
- LUA_TTABLE) {
+ if (lua_gettop(L) > 3) {
+ if (lua_type(L, 4) == LUA_TUSERDATA || lua_type(L, 4) ==
+ LUA_TTABLE) {
/* External refs */
- ext_refs = lua_ucl_object_get (L, 4);
+ ext_refs = lua_ucl_object_get(L, 4);
}
}
}
if (path) {
- schema_elt = ucl_object_lookup_path_char (schema, path, '/');
+ schema_elt = ucl_object_lookup_path_char(schema, path, '/');
}
else {
/* Use the top object */
}
if (schema_elt) {
- res = ucl_object_validate_root_ext (schema_elt, obj, schema,
- ext_refs, &err);
+ res = ucl_object_validate_root_ext(schema_elt, obj, schema,
+ ext_refs, &err);
if (res) {
- lua_pushboolean (L, res);
- lua_pushnil (L);
+ lua_pushboolean(L, res);
+ lua_pushnil(L);
if (ext_refs) {
- lua_ucl_push_opaque (L, ext_refs);
+ lua_ucl_push_opaque(L, ext_refs);
}
}
else {
- lua_pushboolean (L, res);
- lua_pushfstring (L, "validation error: %s", err.msg);
+ lua_pushboolean(L, res);
+ lua_pushfstring(L, "validation error: %s", err.msg);
if (ext_refs) {
- lua_ucl_push_opaque (L, ext_refs);
+ lua_ucl_push_opaque(L, ext_refs);
}
}
}
else {
- lua_pushboolean (L, res);
+ lua_pushboolean(L, res);
- lua_pushfstring (L, "cannot find the requested path: %s", path);
+ lua_pushfstring(L, "cannot find the requested path: %s", path);
if (ext_refs) {
- lua_ucl_push_opaque (L, ext_refs);
+ lua_ucl_push_opaque(L, ext_refs);
}
}
}
else {
- lua_pushboolean (L, res);
- lua_pushstring (L, "invalid object or schema");
+ lua_pushboolean(L, res);
+ lua_pushstring(L, "invalid object or schema");
}
if (ext_refs) {
}
static int
-lua_ucl_object_gc (lua_State *L)
+lua_ucl_object_gc(lua_State *L)
{
ucl_object_t *obj;
- obj = lua_ucl_object_get (L, 1);
+ obj = lua_ucl_object_get(L, 1);
- ucl_object_unref (obj);
+ ucl_object_unref(obj);
return 0;
}
static void
-lua_ucl_parser_mt (lua_State *L)
+lua_ucl_parser_mt(lua_State *L)
{
- luaL_newmetatable (L, PARSER_META);
+ luaL_newmetatable(L, PARSER_META);
lua_pushvalue(L, -1);
lua_setfield(L, -2, "__index");
- lua_pushcfunction (L, lua_ucl_parser_gc);
- lua_setfield (L, -2, "__gc");
+ lua_pushcfunction(L, lua_ucl_parser_gc);
+ lua_setfield(L, -2, "__gc");
- lua_pushcfunction (L, lua_ucl_parser_parse_file);
- lua_setfield (L, -2, "parse_file");
+ lua_pushcfunction(L, lua_ucl_parser_parse_file);
+ lua_setfield(L, -2, "parse_file");
- lua_pushcfunction (L, lua_ucl_parser_parse_string);
- lua_setfield (L, -2, "parse_string");
+ lua_pushcfunction(L, lua_ucl_parser_parse_string);
+ lua_setfield(L, -2, "parse_string");
- lua_pushcfunction (L, lua_ucl_parser_parse_text);
- lua_setfield (L, -2, "parse_text");
+ lua_pushcfunction(L, lua_ucl_parser_parse_text);
+ lua_setfield(L, -2, "parse_text");
- lua_pushcfunction (L, lua_ucl_parser_register_variable);
- lua_setfield (L, -2, "register_variable");
+ lua_pushcfunction(L, lua_ucl_parser_register_variable);
+ lua_setfield(L, -2, "register_variable");
- lua_pushcfunction (L, lua_ucl_parser_register_variables);
- lua_setfield (L, -2, "register_variables");
+ lua_pushcfunction(L, lua_ucl_parser_register_variables);
+ lua_setfield(L, -2, "register_variables");
- lua_pushcfunction (L, lua_ucl_parser_get_object);
- lua_setfield (L, -2, "get_object");
+ lua_pushcfunction(L, lua_ucl_parser_get_object);
+ lua_setfield(L, -2, "get_object");
- lua_pushcfunction (L, lua_ucl_parser_get_object_wrapped);
- lua_setfield (L, -2, "get_object_wrapped");
+ lua_pushcfunction(L, lua_ucl_parser_get_object_wrapped);
+ lua_setfield(L, -2, "get_object_wrapped");
- lua_pushcfunction (L, lua_ucl_parser_validate);
- lua_setfield (L, -2, "validate");
+ lua_pushcfunction(L, lua_ucl_parser_validate);
+ lua_setfield(L, -2, "validate");
- lua_pop (L, 1);
+ lua_pop(L, 1);
}
static void
-lua_ucl_object_mt (lua_State *L)
+lua_ucl_object_mt(lua_State *L)
{
- luaL_newmetatable (L, OBJECT_META);
+ luaL_newmetatable(L, OBJECT_META);
lua_pushvalue(L, -1);
lua_setfield(L, -2, "__index");
- lua_pushcfunction (L, lua_ucl_object_gc);
- lua_setfield (L, -2, "__gc");
+ lua_pushcfunction(L, lua_ucl_object_gc);
+ lua_setfield(L, -2, "__gc");
- lua_pushcfunction (L, lua_ucl_object_tostring);
- lua_setfield (L, -2, "__tostring");
+ lua_pushcfunction(L, lua_ucl_object_tostring);
+ lua_setfield(L, -2, "__tostring");
- lua_pushcfunction (L, lua_ucl_object_tostring);
- lua_setfield (L, -2, "tostring");
+ lua_pushcfunction(L, lua_ucl_object_tostring);
+ lua_setfield(L, -2, "tostring");
- lua_pushcfunction (L, lua_ucl_object_unwrap);
- lua_setfield (L, -2, "unwrap");
+ lua_pushcfunction(L, lua_ucl_object_unwrap);
+ lua_setfield(L, -2, "unwrap");
- lua_pushcfunction (L, lua_ucl_object_unwrap);
- lua_setfield (L, -2, "tolua");
+ lua_pushcfunction(L, lua_ucl_object_unwrap);
+ lua_setfield(L, -2, "tolua");
- lua_pushcfunction (L, lua_ucl_object_validate);
- lua_setfield (L, -2, "validate");
+ lua_pushcfunction(L, lua_ucl_object_validate);
+ lua_setfield(L, -2, "validate");
- lua_pushstring (L, OBJECT_META);
- lua_setfield (L, -2, "class");
+ lua_pushstring(L, OBJECT_META);
+ lua_setfield(L, -2, "class");
- lua_pop (L, 1);
+ lua_pop(L, 1);
}
static void
-lua_ucl_types_mt (lua_State *L)
+lua_ucl_types_mt(lua_State *L)
{
- luaL_newmetatable (L, UCL_OBJECT_TYPE_META);
+ luaL_newmetatable(L, UCL_OBJECT_TYPE_META);
- lua_pushcfunction (L, lua_ucl_object_tostring);
- lua_setfield (L, -2, "__tostring");
+ lua_pushcfunction(L, lua_ucl_object_tostring);
+ lua_setfield(L, -2, "__tostring");
- lua_pushcfunction (L, lua_ucl_object_tostring);
- lua_setfield (L, -2, "tostring");
+ lua_pushcfunction(L, lua_ucl_object_tostring);
+ lua_setfield(L, -2, "tostring");
- lua_pushstring (L, UCL_OBJECT_TYPE_META);
- lua_setfield (L, -2, "class");
+ lua_pushstring(L, UCL_OBJECT_TYPE_META);
+ lua_setfield(L, -2, "class");
- lua_pop (L, 1);
+ lua_pop(L, 1);
- luaL_newmetatable (L, UCL_ARRAY_TYPE_META);
+ luaL_newmetatable(L, UCL_ARRAY_TYPE_META);
- lua_pushcfunction (L, lua_ucl_object_tostring);
- lua_setfield (L, -2, "__tostring");
+ lua_pushcfunction(L, lua_ucl_object_tostring);
+ lua_setfield(L, -2, "__tostring");
- lua_pushcfunction (L, lua_ucl_object_tostring);
- lua_setfield (L, -2, "tostring");
+ lua_pushcfunction(L, lua_ucl_object_tostring);
+ lua_setfield(L, -2, "tostring");
- lua_pushstring (L, UCL_ARRAY_TYPE_META);
- lua_setfield (L, -2, "class");
+ lua_pushstring(L, UCL_ARRAY_TYPE_META);
+ lua_setfield(L, -2, "class");
- lua_pop (L, 1);
+ lua_pop(L, 1);
- luaL_newmetatable (L, UCL_IMPL_ARRAY_TYPE_META);
+ luaL_newmetatable(L, UCL_IMPL_ARRAY_TYPE_META);
- lua_pushcfunction (L, lua_ucl_object_tostring);
- lua_setfield (L, -2, "__tostring");
+ lua_pushcfunction(L, lua_ucl_object_tostring);
+ lua_setfield(L, -2, "__tostring");
- lua_pushcfunction (L, lua_ucl_object_tostring);
- lua_setfield (L, -2, "tostring");
+ lua_pushcfunction(L, lua_ucl_object_tostring);
+ lua_setfield(L, -2, "tostring");
- lua_pushstring (L, UCL_IMPL_ARRAY_TYPE_META);
- lua_setfield (L, -2, "class");
+ lua_pushstring(L, UCL_IMPL_ARRAY_TYPE_META);
+ lua_setfield(L, -2, "class");
- lua_pop (L, 1);
+ lua_pop(L, 1);
}
static int
-lua_ucl_to_json (lua_State *L)
+lua_ucl_to_json(lua_State *L)
{
ucl_object_t *obj;
int format = UCL_EMIT_JSON;
- if (lua_gettop (L) > 1) {
- if (lua_toboolean (L, 2)) {
+ if (lua_gettop(L) > 1) {
+ if (lua_toboolean(L, 2)) {
format = UCL_EMIT_JSON_COMPACT;
}
}
- obj = ucl_object_lua_import (L, 1);
+ obj = ucl_object_lua_import(L, 1);
if (obj != NULL) {
- lua_ucl_to_string (L, obj, format);
- ucl_object_unref (obj);
+ lua_ucl_to_string(L, obj, format);
+ ucl_object_unref(obj);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
}
static int
-lua_ucl_to_config (lua_State *L)
+lua_ucl_to_config(lua_State *L)
{
ucl_object_t *obj;
- obj = ucl_object_lua_import (L, 1);
+ obj = ucl_object_lua_import(L, 1);
if (obj != NULL) {
- lua_ucl_to_string (L, obj, UCL_EMIT_CONFIG);
- ucl_object_unref (obj);
+ lua_ucl_to_string(L, obj, UCL_EMIT_CONFIG);
+ ucl_object_unref(obj);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
--]]
*/
static int
-lua_ucl_to_format (lua_State *L)
+lua_ucl_to_format(lua_State *L)
{
ucl_object_t *obj;
int format = UCL_EMIT_JSON;
bool sort = false;
- if (lua_gettop (L) > 1) {
- if (lua_type (L, 2) == LUA_TNUMBER) {
- format = lua_tonumber (L, 2);
+ if (lua_gettop(L) > 1) {
+ if (lua_type(L, 2) == LUA_TNUMBER) {
+ format = lua_tonumber(L, 2);
if (format < 0 || format >= UCL_EMIT_YAML) {
- lua_pushnil (L);
+ lua_pushnil(L);
return 1;
}
}
- else if (lua_type (L, 2) == LUA_TSTRING) {
- const char *strtype = lua_tostring (L, 2);
+ else if (lua_type(L, 2) == LUA_TSTRING) {
+ const char *strtype = lua_tostring(L, 2);
- if (strcasecmp (strtype, "json") == 0) {
+ if (strcasecmp(strtype, "json") == 0) {
format = UCL_EMIT_JSON;
}
- else if (strcasecmp (strtype, "json-compact") == 0) {
+ else if (strcasecmp(strtype, "json-compact") == 0) {
format = UCL_EMIT_JSON_COMPACT;
}
- else if (strcasecmp (strtype, "yaml") == 0) {
+ else if (strcasecmp(strtype, "yaml") == 0) {
format = UCL_EMIT_YAML;
}
- else if (strcasecmp (strtype, "config") == 0 ||
- strcasecmp (strtype, "ucl") == 0) {
+ else if (strcasecmp(strtype, "config") == 0 ||
+ strcasecmp(strtype, "ucl") == 0) {
format = UCL_EMIT_CONFIG;
}
- else if (strcasecmp (strtype, "msgpack") == 0 ||
- strcasecmp (strtype, "messagepack") == 0) {
+ else if (strcasecmp(strtype, "msgpack") == 0 ||
+ strcasecmp(strtype, "messagepack") == 0) {
format = UCL_EMIT_MSGPACK;
}
}
- if (lua_isboolean (L, 3)) {
- sort = lua_toboolean (L, 3);
+ if (lua_isboolean(L, 3)) {
+ sort = lua_toboolean(L, 3);
}
}
- obj = ucl_object_lua_import (L, 1);
+ obj = ucl_object_lua_import(L, 1);
if (obj != NULL) {
if (sort) {
- if (ucl_object_type (obj) == UCL_OBJECT) {
- ucl_object_sort_keys (obj, UCL_SORT_KEYS_RECURSIVE);
+ if (ucl_object_type(obj) == UCL_OBJECT) {
+ ucl_object_sort_keys(obj, UCL_SORT_KEYS_RECURSIVE);
}
}
- lua_ucl_to_string (L, obj, format);
- ucl_object_unref (obj);
+ lua_ucl_to_string(L, obj, format);
+ ucl_object_unref(obj);
}
else {
- lua_pushnil (L);
+ lua_pushnil(L);
}
return 1;
}
static int
-lua_ucl_null_tostring (lua_State* L)
+lua_ucl_null_tostring(lua_State *L)
{
- lua_pushstring (L, "null");
+ lua_pushstring(L, "null");
return 1;
}
static void
-lua_ucl_null_mt (lua_State *L)
+lua_ucl_null_mt(lua_State *L)
{
- luaL_newmetatable (L, NULL_META);
+ luaL_newmetatable(L, NULL_META);
- lua_pushcfunction (L, lua_ucl_null_tostring);
- lua_setfield (L, -2, "__tostring");
+ lua_pushcfunction(L, lua_ucl_null_tostring);
+ lua_setfield(L, -2, "__tostring");
- lua_pop (L, 1);
+ lua_pop(L, 1);
}
-int
-luaopen_ucl (lua_State *L)
+int luaopen_ucl(lua_State *L)
{
- lua_ucl_parser_mt (L);
- lua_ucl_null_mt (L);
- lua_ucl_object_mt (L);
- lua_ucl_types_mt (L);
+ lua_ucl_parser_mt(L);
+ lua_ucl_null_mt(L);
+ lua_ucl_object_mt(L);
+ lua_ucl_types_mt(L);
/* Create the refs weak table: */
- lua_createtable (L, 0, 2);
- lua_pushliteral (L, "v"); /* tbl, "v" */
- lua_setfield (L, -2, "__mode");
- lua_pushvalue (L, -1); /* tbl, tbl */
- lua_setmetatable (L, -2); /* tbl */
- lua_setfield (L, LUA_REGISTRYINDEX, "ucl.refs");
+ lua_createtable(L, 0, 2);
+ lua_pushliteral(L, "v"); /* tbl, "v" */
+ lua_setfield(L, -2, "__mode");
+ lua_pushvalue(L, -1); /* tbl, tbl */
+ lua_setmetatable(L, -2); /* tbl */
+ lua_setfield(L, LUA_REGISTRYINDEX, "ucl.refs");
- lua_newtable (L);
+ lua_newtable(L);
- lua_pushcfunction (L, lua_ucl_parser_init);
- lua_setfield (L, -2, "parser");
+ lua_pushcfunction(L, lua_ucl_parser_init);
+ lua_setfield(L, -2, "parser");
- lua_pushcfunction (L, lua_ucl_to_json);
- lua_setfield (L, -2, "to_json");
+ lua_pushcfunction(L, lua_ucl_to_json);
+ lua_setfield(L, -2, "to_json");
- lua_pushcfunction (L, lua_ucl_to_config);
- lua_setfield (L, -2, "to_config");
+ lua_pushcfunction(L, lua_ucl_to_config);
+ lua_setfield(L, -2, "to_config");
- lua_pushcfunction (L, lua_ucl_to_format);
- lua_setfield (L, -2, "to_format");
+ lua_pushcfunction(L, lua_ucl_to_format);
+ lua_setfield(L, -2, "to_format");
- ucl_null = lua_newuserdata (L, 0);
- luaL_getmetatable (L, NULL_META);
- lua_setmetatable (L, -2);
+ ucl_null = lua_newuserdata(L, 0);
+ luaL_getmetatable(L, NULL_META);
+ lua_setmetatable(L, -2);
- lua_pushvalue (L, -1);
- lua_setfield (L, LUA_REGISTRYINDEX, "ucl.null");
+ lua_pushvalue(L, -1);
+ lua_setfield(L, LUA_REGISTRYINDEX, "ucl.null");
- lua_setfield (L, -2, "null");
+ lua_setfield(L, -2, "null");
return 1;
}
-struct ucl_lua_funcdata*
-ucl_object_toclosure (const ucl_object_t *obj)
+struct ucl_lua_funcdata *
+ucl_object_toclosure(const ucl_object_t *obj)
{
if (obj == NULL || obj->type != UCL_USERDATA) {
return NULL;
}
- return (struct ucl_lua_funcdata*)obj->value.ud;
+ return (struct ucl_lua_funcdata *) obj->value.ud;
}
};
static uint64_t
-ucl_hash_seed (void)
+ucl_hash_seed(void)
{
static uint64_t seed;
if (seed == 0) {
seed = UCL_RANDOM_FUNCTION;
#else
/* Not very random but can be useful for our purposes */
- seed = time (NULL);
+ seed = time(NULL);
#endif
}
return seed;
}
-extern const guchar lc_map[256];
+extern const unsigned char lc_map[256];
static inline uint32_t
-ucl_hash_func (const ucl_object_t *o)
+ucl_hash_func(const ucl_object_t *o)
{
- return (uint32_t)rspamd_cryptobox_fast_hash (o->key, o->keylen, 0xb9a1ef83c4561c95ULL);
+ return (uint32_t) rspamd_cryptobox_fast_hash(o->key, o->keylen, 0xb9a1ef83c4561c95ULL);
}
static inline int
-ucl_hash_equal (const ucl_object_t *k1, const ucl_object_t *k2)
+ucl_hash_equal(const ucl_object_t *k1, const ucl_object_t *k2)
{
if (k1->keylen == k2->keylen) {
- return memcmp (k1->key, k2->key, k1->keylen) == 0;
+ return memcmp(k1->key, k2->key, k1->keylen) == 0;
}
return 0;
}
-KHASH_INIT (ucl_hash_node, const ucl_object_t *, struct ucl_hash_elt *, 1,
- ucl_hash_func, ucl_hash_equal)
+KHASH_INIT(ucl_hash_node, const ucl_object_t *, struct ucl_hash_elt *, 1,
+ ucl_hash_func, ucl_hash_equal)
static inline uint32_t
-ucl_hash_caseless_func (const ucl_object_t *o)
+ucl_hash_caseless_func(const ucl_object_t *o)
{
unsigned len = o->keylen;
unsigned leftover = o->keylen % 4;
unsigned fp, i;
- const uint8_t* s = (const uint8_t*)o->key;
+ const uint8_t *s = (const uint8_t *) o->key;
union {
struct {
unsigned char c1, c2, c3, c4;
rspamd_cryptobox_fast_hash_state_t hst;
fp = len - leftover;
- rspamd_cryptobox_fast_hash_init (&hst, h);
+ rspamd_cryptobox_fast_hash_init(&hst, h);
for (i = 0; i != fp; i += 4) {
u.c.c1 = s[i], u.c.c2 = s[i + 1], u.c.c3 = s[i + 2], u.c.c4 = s[i + 3];
u.c.c2 = lc_map[u.c.c2];
u.c.c3 = lc_map[u.c.c3];
u.c.c4 = lc_map[u.c.c4];
- rspamd_cryptobox_fast_hash_update (&hst, &u, sizeof (u));
+ rspamd_cryptobox_fast_hash_update(&hst, &u, sizeof(u));
}
u.pp = 0;
switch (leftover) {
case 3:
- u.c.c3 = lc_map[(unsigned char)s[i++]];
+ u.c.c3 = lc_map[(unsigned char) s[i++]];
case 2:
/* fallthrough */
- u.c.c2 = lc_map[(unsigned char)s[i++]];
+ u.c.c2 = lc_map[(unsigned char) s[i++]];
case 1:
/* fallthrough */
- u.c.c1 = lc_map[(unsigned char)s[i]];
- rspamd_cryptobox_fast_hash_update (&hst, &u, sizeof (u));
+ u.c.c1 = lc_map[(unsigned char) s[i]];
+ rspamd_cryptobox_fast_hash_update(&hst, &u, sizeof(u));
break;
}
- return (uint32_t)rspamd_cryptobox_fast_hash_final (&hst);
+ return (uint32_t) rspamd_cryptobox_fast_hash_final(&hst);
}
static inline bool
-ucl_hash_caseless_equal (const ucl_object_t *k1, const ucl_object_t *k2)
+ucl_hash_caseless_equal(const ucl_object_t *k1, const ucl_object_t *k2)
{
if (k1->keylen == k2->keylen) {
- return rspamd_lc_cmp (k1->key, k2->key, k1->keylen) == 0;
+ return rspamd_lc_cmp(k1->key, k2->key, k1->keylen) == 0;
}
return false;
}
-KHASH_INIT (ucl_hash_caseless_node, const ucl_object_t *, struct ucl_hash_elt *, 1,
- ucl_hash_caseless_func, ucl_hash_caseless_equal)
+KHASH_INIT(ucl_hash_caseless_node, const ucl_object_t *, struct ucl_hash_elt *, 1,
+ ucl_hash_caseless_func, ucl_hash_caseless_equal)
-ucl_hash_t*
-ucl_hash_create (bool ignore_case)
+ucl_hash_t *
+ucl_hash_create(bool ignore_case)
{
ucl_hash_t *new;
- new = UCL_ALLOC (sizeof (ucl_hash_t));
+ new = UCL_ALLOC(sizeof(ucl_hash_t));
if (new != NULL) {
void *h;
new->head = NULL;
new->caseless = ignore_case;
if (ignore_case) {
- h = (void *)kh_init (ucl_hash_caseless_node);
+ h = (void *) kh_init(ucl_hash_caseless_node);
}
else {
- h = (void *)kh_init (ucl_hash_node);
+ h = (void *) kh_init(ucl_hash_node);
}
if (h == NULL) {
- UCL_FREE (sizeof (ucl_hash_t), new);
+ UCL_FREE(sizeof(ucl_hash_t), new);
return NULL;
}
new->hash = h;
return new;
}
-void ucl_hash_destroy (ucl_hash_t* hashlin, ucl_hash_free_func func)
+void ucl_hash_destroy(ucl_hash_t *hashlin, ucl_hash_free_func func)
{
if (hashlin == NULL) {
if (func != NULL) {
/* Iterate over the hash first */
khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *)
- hashlin->hash;
+ hashlin->hash;
khiter_t k;
const ucl_object_t *cur, *tmp;
- for (k = kh_begin (h); k != kh_end (h); ++k) {
- if (kh_exist (h, k)) {
- cur = (kh_value (h, k))->obj;
+ for (k = kh_begin(h); k != kh_end(h); ++k) {
+ if (kh_exist(h, k)) {
+ cur = (kh_value(h, k))->obj;
while (cur != NULL) {
tmp = cur->next;
- func (__DECONST (ucl_object_t *, cur));
+ func(__DECONST(ucl_object_t *, cur));
cur = tmp;
}
}
if (hashlin->caseless) {
khash_t(ucl_hash_caseless_node) *h = (khash_t(ucl_hash_caseless_node) *)
- hashlin->hash;
- kh_destroy (ucl_hash_caseless_node, h);
+ hashlin->hash;
+ kh_destroy(ucl_hash_caseless_node, h);
}
else {
khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *)
- hashlin->hash;
- kh_destroy (ucl_hash_node, h);
+ hashlin->hash;
+ kh_destroy(ucl_hash_node, h);
}
struct ucl_hash_elt *cur, *tmp;
- DL_FOREACH_SAFE(hashlin->head, cur, tmp) {
+ DL_FOREACH_SAFE(hashlin->head, cur, tmp)
+ {
UCL_FREE(sizeof(*cur), cur);
}
- UCL_FREE (sizeof (*hashlin), hashlin);
+ UCL_FREE(sizeof(*hashlin), hashlin);
}
-bool
-ucl_hash_insert (ucl_hash_t* hashlin, const ucl_object_t *obj,
- const char *key, unsigned keylen)
+bool ucl_hash_insert(ucl_hash_t *hashlin, const ucl_object_t *obj,
+ const char *key, unsigned keylen)
{
khiter_t k;
int ret;
if (hashlin->caseless) {
khash_t(ucl_hash_caseless_node) *h = (khash_t(ucl_hash_caseless_node) *)
- hashlin->hash;
- k = kh_put (ucl_hash_caseless_node, h, obj, &ret);
+ hashlin->hash;
+ k = kh_put(ucl_hash_caseless_node, h, obj, &ret);
if (ret > 0) {
elt = UCL_ALLOC(sizeof(*elt));
- pelt = &kh_value (h, k);
+ pelt = &kh_value(h, k);
*pelt = elt;
DL_APPEND(hashlin->head, elt);
elt->obj = obj;
}
else {
khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *)
- hashlin->hash;
- k = kh_put (ucl_hash_node, h, obj, &ret);
+ hashlin->hash;
+ k = kh_put(ucl_hash_node, h, obj, &ret);
if (ret > 0) {
elt = UCL_ALLOC(sizeof(*elt));
- pelt = &kh_value (h, k);
+ pelt = &kh_value(h, k);
*pelt = elt;
DL_APPEND(hashlin->head, elt);
elt->obj = obj;
- } else if (ret < 0) {
+ }
+ else if (ret < 0) {
goto e0;
}
}
return true;
- e0:
+e0:
return false;
}
-void ucl_hash_replace (ucl_hash_t* hashlin, const ucl_object_t *old,
- const ucl_object_t *new)
+void ucl_hash_replace(ucl_hash_t *hashlin, const ucl_object_t *old,
+ const ucl_object_t *new)
{
khiter_t k;
int ret;
if (hashlin->caseless) {
khash_t(ucl_hash_caseless_node) *h = (khash_t(ucl_hash_caseless_node) *)
- hashlin->hash;
- k = kh_put (ucl_hash_caseless_node, h, old, &ret);
+ hashlin->hash;
+ k = kh_put(ucl_hash_caseless_node, h, old, &ret);
if (ret == 0) {
elt = kh_value(h, k);
- kh_del (ucl_hash_caseless_node, h, k);
- k = kh_put (ucl_hash_caseless_node, h, new, &ret);
+ kh_del(ucl_hash_caseless_node, h, k);
+ k = kh_put(ucl_hash_caseless_node, h, new, &ret);
nelt = UCL_ALLOC(sizeof(*nelt));
nelt->obj = new;
kh_value(h, k) = nelt;
}
else {
khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *)
- hashlin->hash;
- k = kh_put (ucl_hash_node, h, old, &ret);
+ hashlin->hash;
+ k = kh_put(ucl_hash_node, h, old, &ret);
if (ret == 0) {
- elt = kh_value (h, k);
- kh_del (ucl_hash_node, h, k);
- k = kh_put (ucl_hash_node, h, new, &ret);
+ elt = kh_value(h, k);
+ kh_del(ucl_hash_node, h, k);
+ k = kh_put(ucl_hash_node, h, new, &ret);
nelt = UCL_ALLOC(sizeof(*nelt));
nelt->obj = new;
kh_value(h, k) = nelt;
const struct ucl_hash_elt *cur;
};
-#define UHI_SETERR(ep, ern) {if (ep != NULL) *ep = (ern);}
+#define UHI_SETERR(ep, ern) \
+ { \
+ if (ep != NULL) *ep = (ern); \
+ }
-const void*
-ucl_hash_iterate2 (ucl_hash_t *hashlin, ucl_hash_iter_t *iter, int *ep)
+const void *
+ucl_hash_iterate2(ucl_hash_t *hashlin, ucl_hash_iter_t *iter, int *ep)
{
- struct ucl_hash_real_iter *it = (struct ucl_hash_real_iter *)(*iter);
+ struct ucl_hash_real_iter *it = (struct ucl_hash_real_iter *) (*iter);
const ucl_object_t *ret = NULL;
if (hashlin == NULL) {
}
if (it == NULL) {
- it = UCL_ALLOC (sizeof (*it));
+ it = UCL_ALLOC(sizeof(*it));
if (it == NULL) {
UHI_SETERR(ep, ENOMEM);
it->cur = it->cur->next;
}
else {
- UCL_FREE (sizeof (*it), it);
+ UCL_FREE(sizeof(*it), it);
*iter = NULL;
return NULL;
}
return ret;
}
-bool
-ucl_hash_iter_has_next (ucl_hash_t *hashlin, ucl_hash_iter_t iter)
+bool ucl_hash_iter_has_next(ucl_hash_t *hashlin, ucl_hash_iter_t iter)
{
- struct ucl_hash_real_iter *it = (struct ucl_hash_real_iter *)(iter);
+ struct ucl_hash_real_iter *it = (struct ucl_hash_real_iter *) (iter);
return it->cur != NULL;
}
-const ucl_object_t*
-ucl_hash_search (ucl_hash_t* hashlin, const char *key, unsigned keylen)
+const ucl_object_t *
+ucl_hash_search(ucl_hash_t *hashlin, const char *key, unsigned keylen)
{
khiter_t k;
const ucl_object_t *ret = NULL;
if (hashlin->caseless) {
khash_t(ucl_hash_caseless_node) *h = (khash_t(ucl_hash_caseless_node) *)
- hashlin->hash;
+ hashlin->hash;
- k = kh_get (ucl_hash_caseless_node, h, &search);
- if (k != kh_end (h)) {
- elt = kh_value (h, k);
+ k = kh_get(ucl_hash_caseless_node, h, &search);
+ if (k != kh_end(h)) {
+ elt = kh_value(h, k);
ret = elt->obj;
}
}
else {
khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *)
- hashlin->hash;
- k = kh_get (ucl_hash_node, h, &search);
- if (k != kh_end (h)) {
- elt = kh_value (h, k);
+ hashlin->hash;
+ k = kh_get(ucl_hash_node, h, &search);
+ if (k != kh_end(h)) {
+ elt = kh_value(h, k);
ret = elt->obj;
}
}
return ret;
}
-void
-ucl_hash_delete (ucl_hash_t* hashlin, const ucl_object_t *obj)
+void ucl_hash_delete(ucl_hash_t *hashlin, const ucl_object_t *obj)
{
khiter_t k;
struct ucl_hash_elt *elt;
if (hashlin->caseless) {
khash_t(ucl_hash_caseless_node) *h = (khash_t(ucl_hash_caseless_node) *)
- hashlin->hash;
+ hashlin->hash;
- k = kh_get (ucl_hash_caseless_node, h, obj);
- if (k != kh_end (h)) {
- elt = kh_value (h, k);
+ k = kh_get(ucl_hash_caseless_node, h, obj);
+ if (k != kh_end(h)) {
+ elt = kh_value(h, k);
DL_DELETE(hashlin->head, elt);
- kh_del (ucl_hash_caseless_node, h, k);
+ kh_del(ucl_hash_caseless_node, h, k);
UCL_FREE(sizeof(*elt), elt);
}
}
else {
khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *)
- hashlin->hash;
- k = kh_get (ucl_hash_node, h, obj);
- if (k != kh_end (h)) {
- elt = kh_value (h, k);
+ hashlin->hash;
+ k = kh_get(ucl_hash_node, h, obj);
+ if (k != kh_end(h)) {
+ elt = kh_value(h, k);
DL_DELETE(hashlin->head, elt);
- kh_del (ucl_hash_node, h, k);
+ kh_del(ucl_hash_node, h, k);
UCL_FREE(sizeof(*elt), elt);
}
}
}
-bool
-ucl_hash_reserve (ucl_hash_t *hashlin, size_t sz)
+bool ucl_hash_reserve(ucl_hash_t *hashlin, size_t sz)
{
if (hashlin == NULL) {
return false;
}
- if (sz > kh_size((khash_t(ucl_hash_node) *)hashlin->hash)) {
+ if (sz > kh_size((khash_t(ucl_hash_node) *) hashlin->hash)) {
if (hashlin->caseless) {
khash_t(ucl_hash_caseless_node) *h = (khash_t(
- ucl_hash_caseless_node) *)
- hashlin->hash;
- kh_resize (ucl_hash_caseless_node, h, sz * 2);
- } else {
+ ucl_hash_caseless_node) *)
+ hashlin->hash;
+ kh_resize(ucl_hash_caseless_node, h, sz * 2);
+ }
+ else {
khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *)
- hashlin->hash;
- kh_resize (ucl_hash_node, h, sz * 2);
+ hashlin->hash;
+ kh_resize(ucl_hash_node, h, sz * 2);
}
}
}
static int
-ucl_hash_cmp_icase (const void *a, const void *b)
+ucl_hash_cmp_icase(const void *a, const void *b)
{
- const struct ucl_hash_elt *oa = (const struct ucl_hash_elt *)a,
- *ob = (const struct ucl_hash_elt *)b;
+ const struct ucl_hash_elt *oa = (const struct ucl_hash_elt *) a,
+ *ob = (const struct ucl_hash_elt *) b;
if (oa->obj->keylen == ob->obj->keylen) {
- return rspamd_lc_cmp (oa->obj->key, ob->obj->key, oa->obj->keylen);
+ return rspamd_lc_cmp(oa->obj->key, ob->obj->key, oa->obj->keylen);
}
- return ((int)(oa->obj->keylen)) - ob->obj->keylen;
+ return ((int) (oa->obj->keylen)) - ob->obj->keylen;
}
static int
-ucl_hash_cmp_case_sens (const void *a, const void *b)
+ucl_hash_cmp_case_sens(const void *a, const void *b)
{
- const struct ucl_hash_elt *oa = (const struct ucl_hash_elt *)a,
- *ob = (const struct ucl_hash_elt *)b;
+ const struct ucl_hash_elt *oa = (const struct ucl_hash_elt *) a,
+ *ob = (const struct ucl_hash_elt *) b;
if (oa->obj->keylen == ob->obj->keylen) {
- return memcmp (oa->obj->key, ob->obj->key, oa->obj->keylen);
+ return memcmp(oa->obj->key, ob->obj->key, oa->obj->keylen);
}
- return ((int)(oa->obj->keylen)) - ob->obj->keylen;
+ return ((int) (oa->obj->keylen)) - ob->obj->keylen;
}
-void
-ucl_hash_sort (ucl_hash_t *hashlin, enum ucl_object_keys_sort_flags fl)
+void ucl_hash_sort(ucl_hash_t *hashlin, enum ucl_object_keys_sort_flags fl)
{
if (fl & UCL_SORT_KEYS_ICASE) {
if (fl & UCL_SORT_KEYS_RECURSIVE) {
struct ucl_hash_elt *elt;
- DL_FOREACH(hashlin->head, elt) {
- if (ucl_object_type (elt->obj) == UCL_OBJECT) {
- ucl_hash_sort (elt->obj->value.ov, fl);
+ DL_FOREACH(hashlin->head, elt)
+ {
+ if (ucl_object_type(elt->obj) == UCL_OBJECT) {
+ ucl_hash_sort(elt->obj->value.ov, fl);
}
}
}
static GPatternSpec **exclude_compiled = nullptr;
static struct rspamd_http_context *http_ctx;
-static gint retcode = EXIT_SUCCESS;
+static int retcode = EXIT_SUCCESS;
-static gboolean rspamc_password_callback(const gchar *option_name,
- const gchar *value,
+static gboolean rspamc_password_callback(const char *option_name,
+ const char *value,
gpointer data,
GError **error);
static gboolean
-rspamc_password_callback(const gchar *option_name,
- const gchar *value,
+rspamc_password_callback(const char *option_name,
+ const char *value,
gpointer data,
GError **error)
{
* Parse command line
*/
static void
-read_cmd_line(gint *argc, gchar ***argv)
+read_cmd_line(int *argc, char ***argv)
{
GError *error = nullptr;
GOptionContext *context;
static void
print_commands_list()
{
- guint cmd_len = 0;
+ unsigned int cmd_len = 0;
rspamc_print(stdout, "Rspamc commands summary:\n");
static void
rspamc_mime_output(FILE *out, ucl_object_t *result, GString *input,
- gdouble time, GError *err)
+ double time, GError *err)
{
- const gchar *action = "no action", *line_end = "\r\n", *p;
- gdouble score = 0.0, required_score = 0.0;
+ const char *action = "no action", *line_end = "\r\n", *p;
+ double score = 0.0, required_score = 0.0;
gboolean is_spam = FALSE;
auto nl_type = RSPAMD_TASK_NEWLINES_CRLF;
static void
rspamc_client_execute_cmd(const struct rspamc_command &cmd, ucl_object_t *result,
- GString *input, gdouble time, GError *err)
+ GString *input, double time, GError *err)
{
- gchar **eargv;
- gint eargc, infd, outfd, errfd;
+ char **eargv;
+ int eargc, infd, outfd, errfd;
GError *exec_err = nullptr;
GPid cld;
rspamc_client_cb(struct rspamd_client_connection *conn,
struct rspamd_http_message *msg,
const char *name, ucl_object_t *result, GString *input,
- gpointer ud, gdouble start_time, gdouble send_time,
+ gpointer ud, double start_time, double send_time,
const char *body, gsize bodylen,
GError *err)
{
struct rspamc_callback_data *cbdata = (struct rspamc_callback_data *) ud;
FILE *out = stdout;
- gdouble finish = rspamd_get_ticks(FALSE), diff;
+ double finish = rspamd_get_ticks(FALSE), diff;
auto &cmd = cbdata->cmd;
{
struct rspamd_client_connection *conn;
const char *p;
- guint16 port;
+ uint16_t port;
GError *err = nullptr;
std::string hostbuf;
* Since rspamd uses untagged HTTP we can pass a single message per socket
*/
struct rspamd_client_connection {
- gint fd;
+ int fd;
GString *server_name;
struct rspamd_cryptobox_pubkey *key;
struct rspamd_cryptobox_keypair *keypair;
ev_tstamp timeout;
struct rspamd_http_connection *http_conn;
gboolean req_sent;
- gdouble start_time;
- gdouble send_time;
+ double start_time;
+ double send_time;
struct rspamd_client_request *req;
struct rspamd_keypair_cache *keys_cache;
};
}
}
-static gint
+static int
rspamd_client_body_handler(struct rspamd_http_connection *conn,
struct rspamd_http_message *msg,
- const gchar *chunk, gsize len)
+ const char *chunk, gsize len)
{
/* Do nothing here */
return 0;
c->start_time, c->send_time, NULL, 0, err);
}
-static gint
+static int
rspamd_client_finish_handler(struct rspamd_http_connection *conn,
struct rspamd_http_message *msg)
{
struct ucl_parser *parser;
GError *err;
const rspamd_ftok_t *tok;
- const gchar *start, *body = NULL;
- guchar *out = NULL;
+ const char *start, *body = NULL;
+ unsigned char *out = NULL;
gsize len, bodylen = 0;
c = req->conn;
if (rspamd_http_message_get_body(msg, NULL) == NULL || msg->code / 100 != 2) {
err = g_error_new(RCLIENT_ERROR, msg->code, "HTTP error: %d, %.*s",
msg->code,
- (gint) msg->status->len, msg->status->str);
+ (int) msg->status->len, msg->status->str);
req->cb(c, msg, c->server_name->str, NULL, req->input, req->ud,
c->start_time, c->send_time, body, bodylen, err);
g_error_free(err);
struct rspamd_client_connection *
rspamd_client_init(struct rspamd_http_context *http_ctx,
- struct ev_loop *ev_base, const gchar *name,
- guint16 port, gdouble timeout, const gchar *key)
+ struct ev_loop *ev_base, const char *name,
+ uint16_t port, double timeout, const char *key)
{
struct rspamd_client_connection *conn;
- gint fd;
+ int fd;
fd = rspamd_socket(name, port, SOCK_STREAM, TRUE, FALSE, TRUE);
gboolean
rspamd_client_command(struct rspamd_client_connection *conn,
- const gchar *command, GQueue *attrs,
+ const char *command, GQueue *attrs,
FILE *in, rspamd_client_callback cb,
gpointer ud, gboolean compressed,
- const gchar *comp_dictionary,
- const gchar *filename,
+ const char *comp_dictionary,
+ const char *filename,
GError **err)
{
struct rspamd_client_request *req;
struct rspamd_http_client_header *nh;
- gchar *p;
+ char *p;
gsize remain, old_len;
GList *cur;
GString *input = NULL;
rspamd_fstring_t *body;
- guint dict_id = 0;
+ unsigned int dict_id = 0;
gsize dict_len = 0;
void *dict = NULL;
ZSTD_CCtx *zctx;
rspamd_http_message_add_header(req->msg, COMPRESSION_HEADER, "zstd");
if (dict_id != 0) {
- gchar dict_str[32];
+ char dict_str[32];
rspamd_snprintf(dict_str, sizeof(dict_str), "%ud", dict_id);
rspamd_http_message_add_header(req->msg, "Dictionary", dict_str);
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
struct rspamd_http_message;
struct rspamd_http_client_header {
- gchar *name;
- gchar *value;
+ char *name;
+ char *value;
};
/**
typedef void (*rspamd_client_callback)(
struct rspamd_client_connection *conn,
struct rspamd_http_message *msg,
- const gchar *name,
+ const char *name,
ucl_object_t *result,
GString *input,
gpointer ud,
- gdouble start_time,
- gdouble send_time,
- const gchar *body,
+ double start_time,
+ double send_time,
+ const char *body,
gsize body_len,
GError *err);
struct rspamd_client_connection *rspamd_client_init(
struct rspamd_http_context *http_ctx,
struct ev_loop *ev_base,
- const gchar *name,
- guint16 port,
- gdouble timeout,
- const gchar *key);
+ const char *name,
+ uint16_t port,
+ double timeout,
+ const char *key);
/**
*
*/
gboolean rspamd_client_command(
struct rspamd_client_connection *conn,
- const gchar *command,
+ const char *command,
GQueue *attrs,
FILE *in,
rspamd_client_callback cb,
gpointer ud,
gboolean compressed,
- const gchar *comp_dictionary,
- const gchar *filename,
+ const char *comp_dictionary,
+ const char *filename,
GError **err);
/**
/* Whether we use ssl for this server */
gboolean use_ssl;
/* Webui password */
- gchar *password;
+ char *password;
/* Privileged password */
- gchar *enable_password;
+ char *enable_password;
/* Cached versions of the passwords */
rspamd_ftok_t cached_password;
rspamd_ftok_t cached_enable_password;
/* Main server */
struct rspamd_main *srv;
/* SSL cert */
- gchar *ssl_cert;
+ char *ssl_cert;
/* SSL private key */
- gchar *ssl_key;
+ char *ssl_key;
/* A map of secure IP */
const ucl_object_t *secure_ip;
struct rspamd_radix_map_helper *secure_map;
/* Static files dir */
- gchar *static_files_dir;
+ char *static_files_dir;
/* Custom commands registered by plugins */
GHashTable *custom_commands;
struct rspamd_rrd_file *rrd;
struct rspamd_lang_detector *lang_det;
- gdouble task_timeout;
+ double task_timeout;
/* Health check stuff */
- guint workers_count;
- guint scanners_count;
- guint workers_hb_lost;
+ unsigned int workers_count;
+ unsigned int scanners_count;
+ unsigned int workers_hb_lost;
ev_timer health_check_timer;
};
struct rspamd_controller_plugin_cbdata {
lua_State *L;
struct rspamd_controller_worker_ctx *ctx;
- gchar *plugin;
+ char *plugin;
struct ucl_lua_funcdata *handler;
ucl_object_t *obj;
gboolean is_enable;
gboolean need_task;
- guint version;
+ unsigned int version;
};
static gboolean
-rspamd_is_encrypted_password(const gchar *password,
+rspamd_is_encrypted_password(const char *password,
struct rspamd_controller_pbkdf const **pbkdf)
{
- const gchar *start, *end;
+ const char *start, *end;
int64_t id;
gsize size, i;
gboolean ret = FALSE;
}
if (size > 0) {
- gchar *endptr;
+ char *endptr;
id = strtoul(start, &endptr, 10);
if ((endptr == NULL || *endptr == *end)) {
return ret;
}
-static const gchar *
-rspamd_encrypted_password_get_str(const gchar *password, gsize skip,
+static const char *
+rspamd_encrypted_password_get_str(const char *password, gsize skip,
gsize *length)
{
- const gchar *str, *start, *end;
+ const char *str, *start, *end;
gsize size;
start = password + skip;
static gboolean
rspamd_check_encrypted_password(struct rspamd_controller_worker_ctx *ctx,
- const rspamd_ftok_t *password, const gchar *check,
+ const rspamd_ftok_t *password, const char *check,
const struct rspamd_controller_pbkdf *pbkdf,
gboolean is_enable)
{
- const gchar *salt, *hash;
- gchar *salt_decoded, *key_decoded;
+ const char *salt, *hash;
+ char *salt_decoded, *key_decoded;
gsize salt_len = 0, key_len = 0;
gboolean ret = TRUE;
- guchar *local_key;
+ unsigned char *local_key;
rspamd_ftok_t *cache;
gpointer m;
* @return 0 if no forwarded found, 1 if forwarded found and it is yet trusted
* and -1 if forwarded is denied
*/
-static gint
+static int
rspamd_controller_check_forwarded(struct rspamd_controller_session *session,
struct rspamd_http_message *msg,
struct rspamd_controller_worker_ctx *ctx)
{
const rspamd_ftok_t *hdr;
- const gchar *comma;
+ const char *comma;
const char *hdr_name = "X-Forwarded-For", *alt_hdr_name = "X-Real-IP";
char ip_buf[INET6_ADDRSTRLEN + 1];
rspamd_inet_addr_t *addr = NULL;
- gint ret = 0;
+ int ret = 0;
hdr = rspamd_http_message_find_header(msg, hdr_name);
struct rspamd_controller_session *session,
struct rspamd_http_message *msg, gboolean is_enable)
{
- const gchar *check;
+ const char *check;
const rspamd_ftok_t *password;
rspamd_ftok_t lookup;
GHashTable *query_args = NULL;
/* Try to get password from query args */
query_args = rspamd_http_message_parse_query(msg);
- lookup.begin = (gchar *) "password";
+ lookup.begin = (char *) "password";
lookup.len = sizeof("password") - 1;
password = g_hash_table_lookup(query_args, &lookup);
group_symbols = ucl_object_typed_new(UCL_ARRAY);
while (g_hash_table_iter_next(&sit, &k, &v)) {
- gdouble tm = 0.0, freq = 0, freq_dev = 0;
+ double tm = 0.0, freq = 0, freq_dev = 0;
sym = v;
sym_obj = ucl_object_typed_new(UCL_OBJECT);
static gboolean
rspamd_controller_can_edit_map(struct rspamd_map_backend *bk)
{
- gchar *fpath;
+ char *fpath;
if (access(bk->uri, W_OK) == 0) {
return TRUE;
GList *cur;
struct rspamd_map *map;
struct rspamd_map_backend *bk;
- guint i;
+ unsigned int i;
gboolean editable;
ucl_object_t *obj, *top;
struct rspamd_map_backend *bk = NULL;
const rspamd_ftok_t *idstr;
struct stat st;
- gint fd;
+ int fd;
gulong id, i;
gboolean found = FALSE;
struct rspamd_http_message *reply;
static ucl_object_t *
rspamd_controller_pie_element(enum rspamd_action_type action,
- const char *label, gdouble data)
+ const char *label, double data)
{
ucl_object_t *res = ucl_object_typed_new(UCL_OBJECT);
const char *colors[METRIC_ACTION_MAX] = {
{
struct rspamd_controller_session *session = conn_ent->ud;
struct rspamd_controller_worker_ctx *ctx;
- gdouble data[5], total;
+ double data[5], total;
ucl_object_t *top;
ctx = session->ctx;
void rspamd_controller_graph_point(gulong t, gulong step,
struct rspamd_rrd_query_result *rrd_result,
- gdouble *acc,
+ double *acc,
ucl_object_t **elt)
{
- guint nan_cnt;
- gdouble sum = 0.0, yval;
+ unsigned int nan_cnt;
+ double sum = 0.0, yval;
ucl_object_t *data_elt;
- guint i, j;
+ unsigned int i, j;
for (i = 0; i < rrd_result->ds_count; i++) {
sum = 0.0;
}
else {
ucl_object_insert_key(data_elt,
- ucl_object_fromdouble(sum / (gdouble) step), "y", 1,
+ ucl_object_fromdouble(sum / (double) step), "y", 1,
false);
}
ucl_array_append(elt[i], data_elt);
rspamd_ftok_t srch, *value;
struct rspamd_rrd_query_result *rrd_result;
gulong i, k, start_row, cnt, t, ts, step;
- gdouble *acc;
+ double *acc;
ucl_object_t *res, *elt[METRIC_ACTION_MAX];
enum {
rra_day = 0,
rra_invalid
} rra_num = rra_invalid;
/* How many points are we going to send to display */
- static const guint desired_points = 500;
+ static const unsigned int desired_points = 500;
ctx = session->ctx;
}
query = rspamd_http_message_parse_query(msg);
- srch.begin = (gchar *) "type";
+ srch.begin = (char *) "type";
srch.len = 4;
if (query == NULL || (value = g_hash_table_lookup(query, &srch)) == NULL) {
k = 0;
/* Create window */
- step = ceil(((gdouble) rrd_result->rra_rows) / desired_points);
+ step = ceil(((double) rrd_result->rra_rows) / desired_points);
g_assert(step >= 1);
acc = g_malloc0(sizeof(double) * rrd_result->ds_count * step);
memcpy(&acc[k * rrd_result->ds_count],
&rrd_result->data[i * rrd_result->ds_count],
- sizeof(gdouble) * rrd_result->ds_count);
+ sizeof(double) * rrd_result->ds_count);
if (k < step - 1) {
k++;
struct rspamd_http_message *msg)
{
struct roll_history_row *row, *copied_rows;
- guint i, rows_proc, row_num;
+ unsigned int i, rows_proc, row_num;
struct tm tm;
- gchar timebuf[32], **syms;
+ char timebuf[32], **syms;
ucl_object_t *top, *obj;
top = ucl_object_typed_new(UCL_ARRAY);
syms = g_strsplit_set(row->symbols, ", ", -1);
if (syms) {
- guint nelts = g_strv_length(syms);
+ unsigned int nelts = g_strv_length(syms);
ucl_object_t *syms_obj = ucl_object_typed_new(UCL_OBJECT);
ucl_object_reserve(syms_obj, nelts);
- for (guint j = 0; j < nelts; j++) {
+ for (unsigned int j = 0; j < nelts; j++) {
g_strstrip(syms[j]);
if (strlen(syms[j]) == 0) {
struct rspamd_controller_session *session = conn_ent->ud;
struct rspamd_controller_worker_ctx *ctx;
struct roll_history_row *row;
- guint completed_rows, i, t;
+ unsigned int completed_rows, i, t;
lua_State *L;
ctx = session->ctx;
struct rspamd_task *task, **ptask;
struct rspamd_http_connection_entry **pconn;
struct rspamd_controller_worker_ctx *ctx;
- gchar filebuf[PATH_MAX], realbuf[PATH_MAX];
+ char filebuf[PATH_MAX], realbuf[PATH_MAX];
struct http_parser_url u;
rspamd_ftok_t lookup;
struct stat st;
ucl_object_t *obj;
const ucl_object_t *cur;
struct rspamd_controller_worker_ctx *ctx;
- const gchar *error;
- gdouble score;
- gint i, added = 0;
+ const char *error;
+ double score;
+ int i, added = 0;
enum rspamd_action_type act;
ucl_object_iter_t it = NULL;
const ucl_object_t *cur, *jname, *jvalue;
ucl_object_iter_t iter = NULL;
struct rspamd_controller_worker_ctx *ctx;
- const gchar *error;
- gdouble val;
+ const char *error;
+ double val;
struct rspamd_symbol *sym;
int added = 0;
const rspamd_ftok_t *idstr;
gulong id, i;
gboolean found = FALSE;
- gchar tempname[PATH_MAX];
- gint fd;
+ char tempname[PATH_MAX];
+ int fd;
ctx = session->ctx;
{
struct rspamd_controller_session *session = conn_ent->ud;
ucl_object_t *top, *sub;
- gint i;
+ int i;
int64_t uptime;
uint64_t spam = 0, ham = 0;
rspamd_mempool_stat_t mem_st;
ucl_object_t *top;
struct rspamd_fuzzy_stat_entry *entry;
rspamd_fstring_t *output;
- gint i;
+ int i;
conn_ent = cbdata->conn_ent;
top = cbdata->top;
{
struct rspamd_controller_session *session = conn_ent->ud;
ucl_object_t *top, *sub;
- gint i;
+ int i;
int64_t uptime;
uint64_t spam = 0, ham = 0;
rspamd_mempool_stat_t mem_st;
{
struct rspamd_controller_session *session = conn_ent->ud;
struct rspamd_custom_controller_command *cmd;
- gchar *url_str;
+ char *url_str;
struct http_parser_url u;
rspamd_ftok_t lookup;
lookup.begin = msg->url->str + u.field_data[UF_PATH].off;
lookup.len = u.field_data[UF_PATH].len;
- rspamd_normalize_path_inplace((gchar *) lookup.begin,
+ rspamd_normalize_path_inplace((char *) lookup.begin,
lookup.len,
&unnorm_len);
lookup.len = unnorm_len;
lookup.begin = msg->url->str + u.field_data[UF_PATH].off;
lookup.len = u.field_data[UF_PATH].len;
- rspamd_normalize_path_inplace((gchar *) lookup.begin,
+ rspamd_normalize_path_inplace((char *) lookup.begin,
lookup.len,
&unnorm_len);
lookup.len = unnorm_len;
struct rspamd_controller_worker_ctx *ctx;
struct rspamd_controller_session *session;
rspamd_inet_addr_t *addr = NULL;
- gint nfd;
+ int nfd;
ctx = worker->ctx;
static void
rspamd_controller_password_sane(struct rspamd_controller_worker_ctx *ctx,
- const gchar *password, const gchar *type)
+ const char *password, const char *type)
{
const struct rspamd_controller_pbkdf *pbkdf = &pbkdf_list[0];
}
struct rspamd_http_connection_entry *
-lua_check_controller_entry(lua_State *L, gint pos)
+lua_check_controller_entry(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_csession_classname);
luaL_argcheck(L, ud != NULL, pos, "'csession' expected");
lua_csession_send_error(lua_State *L)
{
struct rspamd_http_connection_entry *c = lua_check_controller_entry(L, 1);
- guint err_code = lua_tonumber(L, 2);
- const gchar *err_str = lua_tostring(L, 3);
+ unsigned int err_code = lua_tonumber(L, 2);
+ const char *err_str = lua_tostring(L, 3);
if (c) {
rspamd_controller_send_error(c, err_code, "%s", err_str);
lua_csession_send_string(lua_State *L)
{
struct rspamd_http_connection_entry *c = lua_check_controller_entry(L, 1);
- const gchar *str = lua_tostring(L, 2);
+ const char *str = lua_tostring(L, 2);
if (c) {
rspamd_controller_send_string(c, str);
struct rspamd_controller_worker_ctx *ctx,
const ucl_object_t *webui_data,
const ucl_object_t *handler,
- const gchar *path,
- const gchar *plugin_name)
+ const char *path,
+ const char *plugin_name)
{
struct rspamd_controller_plugin_cbdata *cbd;
const ucl_object_t *elt;
static void
rspamd_controller_health_rep(struct rspamd_worker *worker,
- struct rspamd_srv_reply *rep, gint rep_fd,
+ struct rspamd_srv_reply *rep, int rep_fd,
gpointer ud)
{
struct rspamd_controller_worker_ctx *ctx = (struct rspamd_controller_worker_ctx *) ud;
struct module_ctx *mctx;
GHashTableIter iter;
gpointer key, value;
- guint i;
+ unsigned int i;
gpointer m;
g_assert(rspamd_worker_check_context(worker->ctx, rspamd_controller_ctx_magic));
/* Update stats on keys each 1 hour */
#define KEY_STAT_INTERVAL 3600.0
-static const gchar *local_db_name = "local";
+static const char *local_db_name = "local";
/* Init functions */
gpointer init_fuzzy(struct rspamd_config *cfg);
/* Store averages for checked/matched per minute */
struct rspamd_counter_data checked_ctr;
struct rspamd_counter_data matched_ctr;
- gdouble last_checked_time;
+ double last_checked_time;
uint64_t last_checked_count;
uint64_t last_matched_count;
struct rspamd_cryptobox_keypair *keypair;
struct rspamd_leaky_bucket_elt {
rspamd_inet_addr_t *addr;
- gdouble last;
- gdouble cur;
+ double last;
+ double cur;
};
static const uint64_t rspamd_fuzzy_storage_magic = 0x291a3253eb1b3ea5ULL;
static bool
fuzzy_kp_equal(gconstpointer a, gconstpointer b)
{
- const guchar *pa = a, *pb = b;
+ const unsigned char *pa = a, *pb = b;
return (memcmp(pa, pb, RSPAMD_FUZZY_KEYLEN) == 0);
}
struct rspamd_config *cfg;
/* END OF COMMON PART */
struct fuzzy_global_stat stat;
- gdouble expire;
- gdouble sync_timeout;
- gdouble delay;
+ double expire;
+ double sync_timeout;
+ double delay;
struct rspamd_radix_map_helper *update_ips;
struct rspamd_hash_map_helper *update_keys;
struct rspamd_radix_map_helper *blocked_ips;
const ucl_object_t *ratelimit_whitelist_map;
const ucl_object_t *dynamic_keys_map;
- guint keypair_cache_size;
+ unsigned int keypair_cache_size;
ev_timer stat_ev;
ev_io peer_ev;
rspamd_lru_hash_t *ratelimit_buckets;
struct rspamd_fuzzy_backend *backend;
GArray *updates_pending;
- guint updates_failed;
- guint updates_maxfail;
+ unsigned int updates_failed;
+ unsigned int updates_maxfail;
/* Used to send data between workers */
- gint peer_fd;
+ int peer_fd;
/* Ratelimits */
- guint leaky_bucket_ttl;
- guint leaky_bucket_mask;
- guint max_buckets;
+ unsigned int leaky_bucket_ttl;
+ unsigned int leaky_bucket_mask;
+ unsigned int max_buckets;
gboolean ratelimit_log_only;
- gdouble leaky_bucket_burst;
- gdouble leaky_bucket_rate;
+ double leaky_bucket_burst;
+ double leaky_bucket_rate;
struct rspamd_worker *worker;
const ucl_object_t *skip_map;
struct rspamd_hash_map_helper *skip_hashes;
- gint lua_pre_handler_cbref;
- gint lua_post_handler_cbref;
- gint lua_blacklist_cbref;
+ int lua_pre_handler_cbref;
+ int lua_post_handler_cbref;
+ int lua_blacklist_cbref;
khash_t(fuzzy_key_ids_set) * default_forbidden_ids;
/* Ids that should not override other ids */
khash_t(fuzzy_key_ids_set) * weak_ids;
enum rspamd_fuzzy_epoch epoch;
enum fuzzy_cmd_type cmd_type;
- gint fd;
+ int fd;
ev_tstamp timestamp;
struct ev_io io;
ref_entry_t ref;
struct fuzzy_key *key;
struct rspamd_fuzzy_cmd_extension *extensions;
- guchar nm[rspamd_cryptobox_MAX_NMBYTES];
+ unsigned char nm[rspamd_cryptobox_MAX_NMBYTES];
};
struct fuzzy_peer_request {
struct rspamd_updates_cbdata {
GArray *updates_pending;
struct rspamd_fuzzy_storage_ctx *ctx;
- gchar *source;
+ char *source;
gboolean final;
};
static void rspamd_fuzzy_write_reply(struct fuzzy_session *session);
static gboolean rspamd_fuzzy_process_updates_queue(struct rspamd_fuzzy_storage_ctx *ctx,
- const gchar *source, gboolean final);
+ const char *source, gboolean final);
static gboolean rspamd_fuzzy_check_client(struct rspamd_fuzzy_storage_ctx *ctx,
rspamd_inet_addr_t *addr);
static void rspamd_fuzzy_maybe_call_blacklisted(struct rspamd_fuzzy_storage_ctx *ctx,
rspamd_inet_addr_t *addr,
- const gchar *reason);
+ const char *reason);
static struct fuzzy_key *fuzzy_add_keypair_from_ucl(const ucl_object_t *obj,
khash_t(rspamd_fuzzy_keys_hash) * target);
};
/* Callbacks for reading json dynamic rules */
-static gchar *
-ucl_keymap_read_cb(gchar *chunk,
- gint len,
+static char *
+ucl_keymap_read_cb(char *chunk,
+ int len,
struct map_cb_data *data,
gboolean final)
{
static void
rspamd_fuzzy_maybe_call_blacklisted(struct rspamd_fuzzy_storage_ctx *ctx,
rspamd_inet_addr_t *addr,
- const gchar *reason)
+ const char *reason)
{
if (ctx->lua_blacklist_cbref != -1) {
lua_State *L = ctx->cfg->lua_state;
- gint err_idx, ret;
+ int err_idx, ret;
lua_pushcfunction(L, &rspamd_lua_traceback);
err_idx = lua_gettop(L);
}
if (session->ctx->update_keys != NULL && session->key->stat && session->key->key) {
- static gchar base32_buf[rspamd_cryptobox_HASHBYTES * 2 + 1];
- guint raw_len;
- const guchar *pk_raw = rspamd_keypair_component(session->key->key,
- RSPAMD_KEYPAIR_COMPONENT_ID, &raw_len);
- gint encoded_len = rspamd_encode_base32_buf(pk_raw, raw_len,
- base32_buf, sizeof(base32_buf),
- RSPAMD_BASE32_DEFAULT);
+ static char base32_buf[rspamd_cryptobox_HASHBYTES * 2 + 1];
+ unsigned int raw_len;
+ const unsigned char *pk_raw = rspamd_keypair_component(session->key->key,
+ RSPAMD_KEYPAIR_COMPONENT_ID, &raw_len);
+ int encoded_len = rspamd_encode_base32_buf(pk_raw, raw_len,
+ base32_buf, sizeof(base32_buf),
+ RSPAMD_BASE32_DEFAULT);
if (rspamd_match_hash_map(session->ctx->update_keys, base32_buf, encoded_len)) {
return TRUE;
static void
rspamd_fuzzy_updates_cb(gboolean success,
- guint nadded,
- guint ndeleted,
- guint nextended,
- guint nignored,
+ unsigned int nadded,
+ unsigned int ndeleted,
+ unsigned int nextended,
+ unsigned int nignored,
void *ud)
{
struct rspamd_updates_cbdata *cbdata = ud;
struct rspamd_fuzzy_storage_ctx *ctx;
- const gchar *source;
+ const char *source;
ctx = cbdata->ctx;
source = cbdata->source;
static gboolean
rspamd_fuzzy_process_updates_queue(struct rspamd_fuzzy_storage_ctx *ctx,
- const gchar *source, gboolean final)
+ const char *source, gboolean final)
{
struct rspamd_updates_cbdata *cbdata;
static void
rspamd_fuzzy_update_key_stat(gboolean matched,
struct fuzzy_key_stat *key_stat,
- guint cmd,
+ unsigned int cmd,
struct rspamd_fuzzy_reply *res,
ev_tstamp timestamp)
{
gboolean is_delayed,
struct fuzzy_key *key,
struct fuzzy_key_stat *ip_stat,
- guint cmd,
+ unsigned int cmd,
struct rspamd_fuzzy_reply *res,
ev_tstamp timestamp)
{
rspamd_fuzzy_make_reply(struct rspamd_fuzzy_cmd *cmd,
struct rspamd_fuzzy_reply *result,
struct fuzzy_session *session,
- gint flags)
+ int flags)
{
gsize len;
session->timestamp);
}
- rspamd_cryptobox_encrypt_nm_inplace((guchar *) &session->reply.rep,
+ rspamd_cryptobox_encrypt_nm_inplace((unsigned char *) &session->reply.rep,
len,
session->reply.hdr.nonce,
session->nm,
}
static gboolean
-fuzzy_peer_try_send(gint fd, struct fuzzy_peer_request *up_req)
+fuzzy_peer_try_send(int fd, struct fuzzy_peer_request *up_req)
{
gssize r;
struct rspamd_fuzzy_cmd *cmd = NULL;
const struct rspamd_shingle *shingle = NULL;
struct rspamd_shingle sgl_cpy;
- gint send_flags = 0;
+ int send_flags = 0;
switch (session->cmd_type) {
case CMD_ENCRYPTED_NORMAL:
if (session->ctx->lua_post_handler_cbref != -1) {
/* Start lua post handler */
lua_State *L = session->ctx->cfg->lua_state;
- gint err_idx, ret;
+ int err_idx, ret;
lua_pushcfunction(L, &rspamd_lua_traceback);
err_idx = lua_gettop(L);
if (!isnan(session->ctx->delay) &&
rspamd_match_radix_map_addr(session->ctx->delay_whitelist,
session->addr) == NULL) {
- gdouble hash_age = rspamd_get_calendar_ticks() - result->ts;
- gdouble jittered_age = rspamd_time_jitter(session->ctx->delay,
- session->ctx->delay / 2.0);
+ double hash_age = rspamd_get_calendar_ticks() - result->ts;
+ double jittered_age = rspamd_time_jitter(session->ctx->delay,
+ session->ctx->delay / 2.0);
if (hash_age < jittered_age) {
send_flags |= RSPAMD_FUZZY_REPLY_DELAY;
struct fuzzy_peer_cmd up_cmd;
struct fuzzy_peer_request *up_req;
struct fuzzy_key_stat *ip_stat = NULL;
- gchar hexbuf[rspamd_cryptobox_HASHBYTES * 2 + 1];
+ char hexbuf[rspamd_cryptobox_HASHBYTES * 2 + 1];
rspamd_inet_addr_t *naddr;
gpointer ptr;
gsize up_len = 0;
- gint send_flags = 0;
+ int send_flags = 0;
cmd = &session->cmd.basic;
if (session->ctx->lua_pre_handler_cbref != -1) {
/* Start lua pre handler */
lua_State *L = session->ctx->cfg->lua_state;
- gint err_idx, ret;
+ int err_idx, ret;
lua_pushcfunction(L, &rspamd_lua_traceback);
err_idx = lua_gettop(L);
static enum rspamd_fuzzy_epoch
-rspamd_fuzzy_command_valid(struct rspamd_fuzzy_cmd *cmd, gint r)
+rspamd_fuzzy_command_valid(struct rspamd_fuzzy_cmd *cmd, int r)
{
enum rspamd_fuzzy_epoch ret = RSPAMD_FUZZY_EPOCH_MAX;
}
static gboolean
-rspamd_fuzzy_decrypt_command(struct fuzzy_session *s, guchar *buf, gsize buflen)
+rspamd_fuzzy_decrypt_command(struct fuzzy_session *s, unsigned char *buf, gsize buflen)
{
struct rspamd_fuzzy_encrypted_req_hdr hdr;
struct rspamd_cryptobox_pubkey *rk;
static gboolean
-rspamd_fuzzy_extensions_from_wire(struct fuzzy_session *s, guchar *buf, gsize buflen)
+rspamd_fuzzy_extensions_from_wire(struct fuzzy_session *s, unsigned char *buf, gsize buflen)
{
struct rspamd_fuzzy_cmd_extension *ext, *prev_ext;
- guchar *storage, *p = buf, *end = buf + buflen;
+ unsigned char *storage, *p = buf, *end = buf + buflen;
gsize st_len = 0, n_ext = 0;
/* Read number of extensions to allocate array */
while (p < end) {
- guchar cmd = *p++;
+ unsigned char cmd = *p++;
if (p < end) {
if (cmd == RSPAMD_FUZZY_EXT_SOURCE_DOMAIN) {
/* Next byte is buf length */
- guchar dom_len = *p++;
+ unsigned char dom_len = *p++;
if (dom_len <= (end - p)) {
st_len += dom_len;
storage = g_malloc(n_ext * sizeof(struct rspamd_fuzzy_cmd_extension) +
st_len);
- guchar *data_buf = storage +
- n_ext * sizeof(struct rspamd_fuzzy_cmd_extension);
+ unsigned char *data_buf = storage +
+ n_ext * sizeof(struct rspamd_fuzzy_cmd_extension);
ext = (struct rspamd_fuzzy_cmd_extension *) storage;
/* All validation has been done, so we can just go further */
while (p < end) {
prev_ext = ext;
- guchar cmd = *p++;
+ unsigned char cmd = *p++;
if (cmd == RSPAMD_FUZZY_EXT_SOURCE_DOMAIN) {
/* Next byte is buf length */
- guchar dom_len = *p++;
- guchar *dest = data_buf;
+ unsigned char dom_len = *p++;
+ unsigned char *dest = data_buf;
ext->ext = RSPAMD_FUZZY_EXT_SOURCE_DOMAIN;
ext->next = ext + 1;
ext = ext->next;
}
else if (cmd == RSPAMD_FUZZY_EXT_SOURCE_IP4) {
- guchar *dest = data_buf;
+ unsigned char *dest = data_buf;
ext->ext = RSPAMD_FUZZY_EXT_SOURCE_IP4;
ext->next = ext + 1;
ext = ext->next;
}
else if (cmd == RSPAMD_FUZZY_EXT_SOURCE_IP6) {
- guchar *dest = data_buf;
+ unsigned char *dest = data_buf;
ext->ext = RSPAMD_FUZZY_EXT_SOURCE_IP6;
ext->next = ext + 1;
}
static gboolean
-rspamd_fuzzy_cmd_from_wire(guchar *buf, guint buflen, struct fuzzy_session *s)
+rspamd_fuzzy_cmd_from_wire(unsigned char *buf, unsigned int buflen, struct fuzzy_session *s)
{
enum rspamd_fuzzy_epoch epoch;
gboolean encrypted = FALSE;
gssize r, msg_len;
uint64_t *nerrors;
struct iovec iovs[MSGVEC_LEN];
- guint8 bufs[MSGVEC_LEN][FUZZY_INPUT_BUFLEN];
+ uint8_t bufs[MSGVEC_LEN][FUZZY_INPUT_BUFLEN];
union sa_union peer_sa[MSGVEC_LEN];
socklen_t salen = sizeof(peer_sa[0]);
#ifdef HAVE_RECVMMSG
static gboolean
rspamd_fuzzy_storage_sync(struct rspamd_main *rspamd_main,
- struct rspamd_worker *worker, gint fd,
- gint attached_fd,
+ struct rspamd_worker *worker, int fd,
+ int attached_fd,
struct rspamd_control_command *cmd,
gpointer ud)
{
static gboolean
rspamd_fuzzy_control_blocked(struct rspamd_main *rspamd_main,
- struct rspamd_worker *worker, gint fd,
- gint attached_fd,
+ struct rspamd_worker *worker, int fd,
+ int attached_fd,
struct rspamd_control_command *cmd,
gpointer ud)
{
static gboolean
rspamd_fuzzy_storage_reload(struct rspamd_main *rspamd_main,
- struct rspamd_worker *worker, gint fd,
- gint attached_fd,
+ struct rspamd_worker *worker, int fd,
+ int attached_fd,
struct rspamd_control_command *cmd,
gpointer ud)
{
rspamd_fuzzy_key_stat_iter(const unsigned char *pk_iter, struct fuzzy_key *fuzzy_key, ucl_object_t *keys_obj, gboolean ip_stat)
{
struct fuzzy_key_stat *key_stat = fuzzy_key->stat;
- gchar keyname[17];
+ char keyname[17];
if (key_stat) {
rspamd_snprintf(keyname, sizeof(keyname), "%8bs", pk_iter);
while ((cur = ucl_object_iterate(obj, &it, true)) != NULL) {
const ucl_object_t *ip, *value, *last;
- const gchar *ip_str;
+ const char *ip_str;
double limit_val, last_val;
ip = ucl_object_find_key(cur, "ip");
static gboolean
rspamd_fuzzy_storage_stat(struct rspamd_main *rspamd_main,
- struct rspamd_worker *worker, gint fd,
- gint attached_fd,
+ struct rspamd_worker *worker, int fd,
+ int attached_fd,
struct rspamd_control_command *cmd,
gpointer ud)
{
struct rspamd_control_reply rep;
ucl_object_t *obj;
struct ucl_emitter_functions *emit_subr;
- guchar fdspace[CMSG_SPACE(sizeof(int))];
+ unsigned char fdspace[CMSG_SPACE(sizeof(int))];
struct iovec iov;
struct msghdr msg;
struct cmsghdr *cmsg;
- gint outfd = -1;
- gchar tmppath[PATH_MAX];
+ int outfd = -1;
+ char tmppath[PATH_MAX];
memset(&rep, 0, sizeof(rep));
rep.type = RSPAMD_CONTROL_FUZZY_STAT;
struct rspamd_rcl_struct_parser *pd = (struct rspamd_rcl_struct_parser *) ud;
khash_t(fuzzy_key_ids_set) * target;
- target = *(khash_t(fuzzy_key_ids_set) **) ((gchar *) pd->user_struct + pd->offset);
+ target = *(khash_t(fuzzy_key_ids_set) **) ((char *) pd->user_struct + pd->offset);
if (ucl_object_type(obj) == UCL_ARRAY) {
const ucl_object_t *cur;
key->flags_stat = kh_init(fuzzy_key_flag_stat);
/* Preallocate some space for flags */
kh_resize(fuzzy_key_flag_stat, key->flags_stat, 8);
- const guchar *pk = rspamd_keypair_component(kp, RSPAMD_KEYPAIR_COMPONENT_PK,
- NULL);
+ const unsigned char *pk = rspamd_keypair_component(kp, RSPAMD_KEYPAIR_COMPONENT_PK,
+ NULL);
keystat->keypair = rspamd_keypair_ref(kp);
/* We map entries by pubkey in binary form for faster lookup */
khiter_t k;
static void
fuzzy_peer_rep(struct rspamd_worker *worker,
- struct rspamd_srv_reply *rep, gint rep_fd,
+ struct rspamd_srv_reply *rep, int rep_fd,
gpointer ud)
{
struct rspamd_fuzzy_storage_ctx *ctx = ud;
RSPAMD_WORKER_VER /* Version info */
};
-static const gdouble default_max_time = 1.0;
-static const gdouble default_recompile_time = 60.0;
+static const double default_max_time = 1.0;
+static const double default_recompile_time = 60.0;
static const uint64_t rspamd_hs_helper_magic = 0x22d310157a2288a0ULL;
/*
/* Config */
struct rspamd_config *cfg;
/* END OF COMMON PART */
- gchar *hs_dir;
+ char *hs_dir;
gboolean loaded;
- gdouble max_time;
- gdouble recompile_time;
+ double max_time;
+ double recompile_time;
ev_timer recompile_timer;
};
{
struct stat st;
glob_t globbuf;
- guint len, i;
- gint rc;
- gchar *pattern;
+ unsigned int len, i;
+ int rc;
+ char *pattern;
gboolean ret = TRUE;
pid_t our_pid = getpid();
if ((rc = glob(pattern, 0, NULL, &globbuf)) == 0) {
for (i = 0; i < globbuf.gl_pathc; i++) {
/* Check if we have a pid in the filename */
- const gchar *end_num = globbuf.gl_pathv[i] +
- strlen(globbuf.gl_pathv[i]) - (sizeof(".hs.new") - 1);
- const gchar *p = end_num - 1;
+ const char *end_num = globbuf.gl_pathv[i] +
+ strlen(globbuf.gl_pathv[i]) - (sizeof(".hs.new") - 1);
+ const char *p = end_num - 1;
pid_t foreign_pid = -1;
while (p > globbuf.gl_pathv[i]) {
}
static void
-rspamd_rs_compile_cb(guint ncompiled, GError *err, void *cbd)
+rspamd_rs_compile_cb(unsigned int ncompiled, GError *err, void *cbd)
{
struct rspamd_worker *worker = (struct rspamd_worker *) cbd;
ev_timer *tm;
static gboolean
rspamd_hs_helper_reload(struct rspamd_main *rspamd_main,
- struct rspamd_worker *worker, gint fd,
- gint attached_fd,
+ struct rspamd_worker *worker, int fd,
+ int attached_fd,
struct rspamd_control_command *cmd,
gpointer ud)
{
const char *
base64_load(void)
{
- guint i;
+ unsigned int i;
const base64_impl_t *opt_impl = base64_ref;
/* Enable reference */
}
gboolean
-rspamd_cryptobox_base64_decode(const gchar *in, gsize inlen,
- guchar *out, gsize *outlen)
+rspamd_cryptobox_base64_decode(const char *in, gsize inlen,
+ unsigned char *out, gsize *outlen)
{
const base64_impl_t *opt_impl = base64_ref;
- for (gint i = G_N_ELEMENTS(base64_list) - 1; i > 0; i--) {
+ for (int i = G_N_ELEMENTS(base64_list) - 1; i > 0; i--) {
if (base64_list[i].enabled && base64_list[i].min_len <= inlen) {
opt_impl = &base64_list[i];
break;
base64_test(bool generic, size_t niters, size_t len, size_t str_len)
{
size_t cycles;
- guchar *in, *out, *tmp;
- gdouble t1, t2, total = 0;
+ unsigned char *in, *out, *tmp;
+ double t1, t2, total = 0;
gsize outlen;
g_assert(len > 0);
gboolean
-rspamd_cryptobox_base64_is_valid(const gchar *in, gsize inlen)
+rspamd_cryptobox_base64_is_valid(const char *in, gsize inlen)
{
- const guchar *p, *end;
+ const unsigned char *p, *end;
if (inlen == 0) {
return FALSE;
-/*-
- * Copyright 2016 Vsevolod Stakhov
- * Copyright (c) 2014 cforler
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
#include "config.h"
int catena_test(void)
{
/* From catena-v3.1 spec */
- guint8 pw[] = {0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64};
- guint8 salt[] = {0x73, 0x61, 0x6c, 0x74};
- guint8 ad[] = {0x64, 0x61, 0x74, 0x61};
- guint8 expected[] = {
+ uint8_t pw[] = {0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64};
+ uint8_t salt[] = {0x73, 0x61, 0x6c, 0x74};
+ uint8_t ad[] = {0x64, 0x61, 0x74, 0x61};
+ uint8_t expected[] = {
0x20, 0xc5, 0x91, 0x93, 0x8f, 0xc3, 0xaf, 0xcc, 0x3b, 0xba, 0x91, 0xd2, 0xfb,
0x84, 0xbf, 0x7b, 0x44, 0x04, 0xf9, 0x4c, 0x45, 0xed, 0x4d, 0x11, 0xa7, 0xe2,
0xb4, 0x12, 0x3e, 0xab, 0x0b, 0x77, 0x4a, 0x12, 0xb4, 0x22, 0xd0, 0xda, 0xb5,
0x25, 0x29, 0x02, 0xfc, 0x54, 0x47, 0xea, 0x82, 0x63, 0x8c, 0x1a, 0xfb, 0xa7,
0xa9, 0x94, 0x24, 0x13, 0x0e, 0x44, 0x36, 0x3b, 0x9d, 0x9f, 0xc9, 0x60};
- guint8 real[H_LEN];
+ uint8_t real[H_LEN];
if (catena(pw, sizeof(pw), salt, sizeof(salt), ad, sizeof(ad),
4, 10, 10, H_LEN, real) != 0) {
const char *
chacha_load(void)
{
- guint i;
+ unsigned int i;
if (cpu_config != 0) {
for (i = 0; i < G_N_ELEMENTS(chacha_list); i++) {
static gboolean cryptobox_loaded = FALSE;
-static const guchar n0[16] = {0};
+static const unsigned char n0[16] = {0};
#define CRYPTOBOX_ALIGNMENT 16
#define cryptobox_align_ptr(p, a) \
(void *) (((uintptr_t) (p) + ((uintptr_t) a - 1)) & ~((uintptr_t) a - 1))
static void
-rspamd_cryptobox_cpuid(gint cpu[4], gint info)
+rspamd_cryptobox_cpuid(int cpu[4], int info)
{
uint32_t __attribute__((unused)) eax, __attribute__((unused)) ecx = 0, __attribute__((unused)) ebx = 0, __attribute__((unused)) edx = 0;
cpu[2] = ecx;
cpu[3] = edx;
#else
- memset(cpu, 0, sizeof(gint) * 4);
+ memset(cpu, 0, sizeof(int) * 4);
#endif
}
}
static gboolean
-rspamd_cryptobox_test_instr(gint instr)
+rspamd_cryptobox_test_instr(int instr)
{
void (*old_handler)(int);
uint32_t rd;
struct rspamd_cryptobox_library_ctx *
rspamd_cryptobox_init(void)
{
- gint cpu[4], nid;
+ int cpu[4], nid;
const uint32_t osxsave_mask = (1 << 27);
const uint32_t fma_movbe_osxsave_mask = ((1 << 12) | (1 << 22) | (1 << 27));
const uint32_t avx2_bmi12_mask = (1 << 5) | (1 << 3) | (1 << 8);
unsigned char *buf = NULL; /* Thanks openssl for this API (no) */
len = EC_POINT_point2buf(EC_KEY_get0_group(ec_sec), ec_pub,
POINT_CONVERSION_UNCOMPRESSED, &buf, NULL);
- g_assert(len <= (gint) rspamd_cryptobox_pk_bytes(mode));
+ g_assert(len <= (int) rspamd_cryptobox_pk_bytes(mode));
memcpy(pk, buf, len);
OPENSSL_free(buf);
#else
bn_pub = EC_POINT_point2bn(EC_KEY_get0_group(ec_sec),
ec_pub, POINT_CONVERSION_UNCOMPRESSED, NULL, NULL);
len = BN_num_bytes(bn_pub);
- g_assert(len <= (gint) rspamd_cryptobox_pk_bytes(mode));
+ g_assert(len <= (int) rspamd_cryptobox_pk_bytes(mode));
BN_bn2bin(bn_pub, pk);
BN_free(bn_pub);
#endif
len = BN_num_bytes(bn_sec);
- g_assert(len <= (gint) sizeof(rspamd_sk_t));
+ g_assert(len <= (int) sizeof(rspamd_sk_t));
BN_bn2bin(bn_sec, sk);
EC_KEY_free(ec_sec);
unsigned char *buf = NULL; /* Thanks openssl for this API (no) */
len = EC_POINT_point2buf(EC_KEY_get0_group(ec_sec), ec_pub,
POINT_CONVERSION_UNCOMPRESSED, &buf, NULL);
- g_assert(len <= (gint) rspamd_cryptobox_pk_bytes(mode));
+ g_assert(len <= (int) rspamd_cryptobox_pk_bytes(mode));
memcpy(pk, buf, len);
OPENSSL_free(buf);
#else
bn_pub = EC_POINT_point2bn(EC_KEY_get0_group(ec_sec),
ec_pub, POINT_CONVERSION_UNCOMPRESSED, NULL, NULL);
len = BN_num_bytes(bn_pub);
- g_assert(len <= (gint) rspamd_cryptobox_pk_bytes(mode));
+ g_assert(len <= (int) rspamd_cryptobox_pk_bytes(mode));
BN_bn2bin(bn_pub, pk);
BN_free(bn_pub);
#endif
len = BN_num_bytes(bn_sec);
- g_assert(len <= (gint) sizeof(rspamd_sk_t));
+ g_assert(len <= (int) sizeof(rspamd_sk_t));
BN_bn2bin(bn_sec, sk);
EC_KEY_free(ec_sec);
#endif
enum rspamd_cryptobox_mode mode)
{
if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) {
- guchar s[32];
- guchar e[32];
+ unsigned char s[32];
+ unsigned char e[32];
memcpy(e, sk, 32);
e[0] &= 248;
EC_KEY *lk;
EC_POINT *ec_pub;
BIGNUM *bn_pub, *bn_sec;
- gint len;
- guchar s[32];
+ int len;
+ unsigned char s[32];
lk = EC_KEY_new_by_curve_name(CRYPTOBOX_CURVE_NID);
g_assert(lk != NULL);
}
}
-void rspamd_cryptobox_sign(guchar *sig, unsigned long long *siglen_p,
- const guchar *m, gsize mlen,
+void rspamd_cryptobox_sign(unsigned char *sig, unsigned long long *siglen_p,
+ const unsigned char *m, gsize mlen,
const rspamd_sk_t sk,
enum rspamd_cryptobox_mode mode)
{
BIGNUM *bn_sec;
EVP_MD_CTX *sha_ctx;
unsigned char h[64];
- guint diglen = rspamd_cryptobox_signature_bytes(mode);
+ unsigned int diglen = rspamd_cryptobox_signature_bytes(mode);
/* Prehash */
sha_ctx = EVP_MD_CTX_create();
}
}
-bool rspamd_cryptobox_verify(const guchar *sig,
+bool rspamd_cryptobox_verify(const unsigned char *sig,
gsize siglen,
- const guchar *m,
+ const unsigned char *m,
gsize mlen,
const rspamd_pk_t pk,
enum rspamd_cryptobox_mode mode)
{
if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) {
crypto_onetimeauth_state *mac_ctx;
- guchar RSPAMD_ALIGNED(32) subkey[CHACHA_BLOCKBYTES];
+ unsigned char RSPAMD_ALIGNED(32) subkey[CHACHA_BLOCKBYTES];
mac_ctx = cryptobox_align_ptr(auth_ctx, CRYPTOBOX_ALIGNMENT);
memset(subkey, 0, sizeof(subkey));
}
static gboolean
-rspamd_cryptobox_encrypt_update(void *enc_ctx, const guchar *in, gsize inlen,
- guchar *out, gsize *outlen,
+rspamd_cryptobox_encrypt_update(void *enc_ctx, const unsigned char *in, gsize inlen,
+ unsigned char *out, gsize *outlen,
enum rspamd_cryptobox_mode mode)
{
if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) {
g_assert(0);
#else
EVP_CIPHER_CTX **s = enc_ctx;
- gint r;
+ int r;
r = inlen;
g_assert(EVP_EncryptUpdate(*s, out, &r, in, inlen) == 1);
}
static gboolean
-rspamd_cryptobox_auth_update(void *auth_ctx, const guchar *in, gsize inlen,
+rspamd_cryptobox_auth_update(void *auth_ctx, const unsigned char *in, gsize inlen,
enum rspamd_cryptobox_mode mode)
{
if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) {
}
static gsize
-rspamd_cryptobox_encrypt_final(void *enc_ctx, guchar *out, gsize remain,
+rspamd_cryptobox_encrypt_final(void *enc_ctx, unsigned char *out, gsize remain,
enum rspamd_cryptobox_mode mode)
{
if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) {
g_assert(0);
#else
EVP_CIPHER_CTX **s = enc_ctx;
- gint r = remain;
+ int r = remain;
g_assert(EVP_EncryptFinal_ex(*s, out, &r) == 1);
{
if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) {
crypto_onetimeauth_state *mac_ctx;
- guchar RSPAMD_ALIGNED(32) subkey[CHACHA_BLOCKBYTES];
+ unsigned char RSPAMD_ALIGNED(32) subkey[CHACHA_BLOCKBYTES];
mac_ctx = cryptobox_align_ptr(auth_ctx, CRYPTOBOX_ALIGNMENT);
memset(subkey, 0, sizeof(subkey));
}
static gboolean
-rspamd_cryptobox_decrypt_update(void *enc_ctx, const guchar *in, gsize inlen,
- guchar *out, gsize *outlen,
+rspamd_cryptobox_decrypt_update(void *enc_ctx, const unsigned char *in, gsize inlen,
+ unsigned char *out, gsize *outlen,
enum rspamd_cryptobox_mode mode)
{
if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) {
g_assert(0);
#else
EVP_CIPHER_CTX **s = enc_ctx;
- gint r;
+ int r;
r = outlen ? *outlen : inlen;
g_assert(EVP_DecryptUpdate(*s, out, &r, in, inlen) == 1);
static gboolean
rspamd_cryptobox_auth_verify_update(void *auth_ctx,
- const guchar *in, gsize inlen,
+ const unsigned char *in, gsize inlen,
enum rspamd_cryptobox_mode mode)
{
if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) {
}
static gboolean
-rspamd_cryptobox_decrypt_final(void *enc_ctx, guchar *out, gsize remain,
+rspamd_cryptobox_decrypt_final(void *enc_ctx, unsigned char *out, gsize remain,
enum rspamd_cryptobox_mode mode)
{
if (G_LIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) {
g_assert(0);
#else
EVP_CIPHER_CTX **s = enc_ctx;
- gint r = remain;
+ int r = remain;
if (EVP_DecryptFinal_ex(*s, out, &r) < 0) {
return FALSE;
#else
EVP_CIPHER_CTX **s = auth_ctx;
- if (EVP_CIPHER_CTX_ctrl(*s, EVP_CTRL_GCM_SET_TAG, 16, (guchar *) sig) != 1) {
+ if (EVP_CIPHER_CTX_ctrl(*s, EVP_CTRL_GCM_SET_TAG, 16, (unsigned char *) sig) != 1) {
return FALSE;
}
}
}
-void rspamd_cryptobox_encrypt_nm_inplace(guchar *data, gsize len,
+void rspamd_cryptobox_encrypt_nm_inplace(unsigned char *data, gsize len,
const rspamd_nonce_t nonce,
const rspamd_nm_t nm,
rspamd_mac_t sig,
static void
rspamd_cryptobox_flush_outbuf(struct rspamd_cryptobox_segment *st,
- const guchar *buf, gsize len, gsize offset)
+ const unsigned char *buf, gsize len, gsize offset)
{
gsize cpy_len;
enum rspamd_cryptobox_mode mode)
{
struct rspamd_cryptobox_segment *cur = segments, *start_seg = segments;
- guchar outbuf[CHACHA_BLOCKBYTES * 16];
+ unsigned char outbuf[CHACHA_BLOCKBYTES * 16];
void *enc_ctx, *auth_ctx;
- guchar *out, *in;
+ unsigned char *out, *in;
gsize r, remain, inremain, seg_offset;
enc_ctx = g_alloca(rspamd_cryptobox_encrypt_ctx_len(mode));
seg_offset = 0;
for (;;) {
- if (cur - segments == (gint) cnt) {
+ if (cur - segments == (int) cnt) {
break;
}
}
gboolean
-rspamd_cryptobox_decrypt_nm_inplace(guchar *data, gsize len,
+rspamd_cryptobox_decrypt_nm_inplace(unsigned char *data, gsize len,
const rspamd_nonce_t nonce, const rspamd_nm_t nm,
const rspamd_mac_t sig, enum rspamd_cryptobox_mode mode)
{
}
gboolean
-rspamd_cryptobox_decrypt_inplace(guchar *data, gsize len,
+rspamd_cryptobox_decrypt_inplace(unsigned char *data, gsize len,
const rspamd_nonce_t nonce,
const rspamd_pk_t pk, const rspamd_sk_t sk,
const rspamd_mac_t sig,
enum rspamd_cryptobox_mode mode)
{
- guchar nm[rspamd_cryptobox_MAX_NMBYTES];
+ unsigned char nm[rspamd_cryptobox_MAX_NMBYTES];
gboolean ret;
rspamd_cryptobox_nm(nm, pk, sk, mode);
return ret;
}
-void rspamd_cryptobox_encrypt_inplace(guchar *data, gsize len,
+void rspamd_cryptobox_encrypt_inplace(unsigned char *data, gsize len,
const rspamd_nonce_t nonce,
const rspamd_pk_t pk, const rspamd_sk_t sk,
rspamd_mac_t sig,
enum rspamd_cryptobox_mode mode)
{
- guchar nm[rspamd_cryptobox_MAX_NMBYTES];
+ unsigned char nm[rspamd_cryptobox_MAX_NMBYTES];
rspamd_cryptobox_nm(nm, pk, sk, mode);
rspamd_cryptobox_encrypt_nm_inplace(data, len, nonce, nm, sig, mode);
rspamd_mac_t sig,
enum rspamd_cryptobox_mode mode)
{
- guchar nm[rspamd_cryptobox_MAX_NMBYTES];
+ unsigned char nm[rspamd_cryptobox_MAX_NMBYTES];
rspamd_cryptobox_nm(nm, pk, sk, mode);
rspamd_cryptobox_encryptv_nm_inplace(segments, cnt, nonce, nm, sig, mode);
*/
static gboolean
rspamd_cryptobox_pbkdf2(const char *pass, gsize pass_len,
- const guint8 *salt, gsize salt_len, guint8 *key, gsize key_len,
+ const uint8_t *salt, gsize salt_len, uint8_t *key, gsize key_len,
unsigned int rounds)
{
- guint8 *asalt, obuf[crypto_generichash_blake2b_BYTES_MAX];
- guint8 d1[crypto_generichash_blake2b_BYTES_MAX],
+ uint8_t *asalt, obuf[crypto_generichash_blake2b_BYTES_MAX];
+ uint8_t d1[crypto_generichash_blake2b_BYTES_MAX],
d2[crypto_generichash_blake2b_BYTES_MAX];
unsigned int i, j;
unsigned int count;
pass, pass_len);
}
else {
- guint8 k[crypto_generichash_blake2b_BYTES_MAX];
+ uint8_t k[crypto_generichash_blake2b_BYTES_MAX];
/*
* We use additional blake2 iteration to store large key
pass, pass_len);
}
else {
- guint8 k[crypto_generichash_blake2b_BYTES_MAX];
+ uint8_t k[crypto_generichash_blake2b_BYTES_MAX];
/*
* We use additional blake2 iteration to store large key
gboolean
rspamd_cryptobox_pbkdf(const char *pass, gsize pass_len,
- const guint8 *salt, gsize salt_len, guint8 *key, gsize key_len,
+ const uint8_t *salt, gsize salt_len, uint8_t *key, gsize key_len,
unsigned int complexity, enum rspamd_cryptobox_pbkdf_type type)
{
gboolean ret = FALSE;
return ret;
}
-guint rspamd_cryptobox_pk_bytes(enum rspamd_cryptobox_mode mode)
+unsigned int rspamd_cryptobox_pk_bytes(enum rspamd_cryptobox_mode mode)
{
if (G_UNLIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) {
return 32;
}
}
-guint rspamd_cryptobox_pk_sig_bytes(enum rspamd_cryptobox_mode mode)
+unsigned int rspamd_cryptobox_pk_sig_bytes(enum rspamd_cryptobox_mode mode)
{
if (G_UNLIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) {
return 32;
}
}
-guint rspamd_cryptobox_nonce_bytes(enum rspamd_cryptobox_mode mode)
+unsigned int rspamd_cryptobox_nonce_bytes(enum rspamd_cryptobox_mode mode)
{
if (G_UNLIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) {
return 24;
}
-guint rspamd_cryptobox_sk_bytes(enum rspamd_cryptobox_mode mode)
+unsigned int rspamd_cryptobox_sk_bytes(enum rspamd_cryptobox_mode mode)
{
return 32;
}
-guint rspamd_cryptobox_sk_sig_bytes(enum rspamd_cryptobox_mode mode)
+unsigned int rspamd_cryptobox_sk_sig_bytes(enum rspamd_cryptobox_mode mode)
{
if (G_UNLIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) {
return 64;
}
}
-guint rspamd_cryptobox_signature_bytes(enum rspamd_cryptobox_mode mode)
+unsigned int rspamd_cryptobox_signature_bytes(enum rspamd_cryptobox_mode mode)
{
- static guint ssl_keylen;
+ static unsigned int ssl_keylen;
if (G_UNLIKELY(mode == RSPAMD_CRYPTOBOX_MODE_25519)) {
return 64;
}
}
-guint rspamd_cryptobox_nm_bytes(enum rspamd_cryptobox_mode mode)
+unsigned int rspamd_cryptobox_nm_bytes(enum rspamd_cryptobox_mode mode)
{
return 32;
}
-guint rspamd_cryptobox_mac_bytes(enum rspamd_cryptobox_mode mode)
+unsigned int rspamd_cryptobox_mac_bytes(enum rspamd_cryptobox_mode mode)
{
return 16;
}
-void rspamd_cryptobox_hash_init(rspamd_cryptobox_hash_state_t *p, const guchar *key, gsize keylen)
+void rspamd_cryptobox_hash_init(rspamd_cryptobox_hash_state_t *p, const unsigned char *key, gsize keylen)
{
crypto_generichash_blake2b_state *st = cryptobox_align_ptr(p,
RSPAMD_ALIGNOF(crypto_generichash_blake2b_state));
/**
* Update hash with data portion
*/
-void rspamd_cryptobox_hash_update(rspamd_cryptobox_hash_state_t *p, const guchar *data, gsize len)
+void rspamd_cryptobox_hash_update(rspamd_cryptobox_hash_state_t *p, const unsigned char *data, gsize len)
{
crypto_generichash_blake2b_state *st = cryptobox_align_ptr(p,
RSPAMD_ALIGNOF(crypto_generichash_blake2b_state));
/**
* Output hash to the buffer of rspamd_cryptobox_HASHBYTES length
*/
-void rspamd_cryptobox_hash_final(rspamd_cryptobox_hash_state_t *p, guchar *out)
+void rspamd_cryptobox_hash_final(rspamd_cryptobox_hash_state_t *p, unsigned char *out)
{
crypto_generichash_blake2b_state *st = cryptobox_align_ptr(p,
RSPAMD_ALIGNOF(crypto_generichash_blake2b_state));
/**
* One in all function
*/
-void rspamd_cryptobox_hash(guchar *out,
- const guchar *data,
+void rspamd_cryptobox_hash(unsigned char *out,
+ const unsigned char *data,
gsize len,
- const guchar *key,
+ const unsigned char *key,
gsize keylen)
{
crypto_generichash_blake2b(out, crypto_generichash_blake2b_BYTES_MAX,
case RSPAMD_CRYPTOBOX_MUMHASH: {
struct _mum_iuf *iuf = (struct _mum_iuf *) st->opaque;
gsize drem = len;
- const guchar *p = data;
+ const unsigned char *p = data;
if (iuf->rem > 0) {
/* Process remainder */
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
#endif
struct rspamd_cryptobox_segment {
- guchar *data;
+ unsigned char *data;
gsize len;
};
#define CPUID_SSE42 0x40
#define CPUID_RDRAND 0x80
-typedef guchar rspamd_pk_t[rspamd_cryptobox_MAX_PKBYTES];
-typedef guchar rspamd_sk_t[rspamd_cryptobox_MAX_SKBYTES];
-typedef guchar rspamd_mac_t[rspamd_cryptobox_MAX_MACBYTES];
-typedef guchar rspamd_nm_t[rspamd_cryptobox_MAX_NMBYTES];
-typedef guchar rspamd_nonce_t[rspamd_cryptobox_MAX_NONCEBYTES];
-typedef guchar rspamd_sipkey_t[rspamd_cryptobox_SIPKEYBYTES];
-typedef guchar rspamd_signature_t[rspamd_cryptobox_MAX_SIGBYTES];
-typedef guchar rspamd_sig_pk_t[rspamd_cryptobox_MAX_SIGPKBYTES];
-typedef guchar rspamd_sig_sk_t[rspamd_cryptobox_MAX_SIGSKBYTES];
+typedef unsigned char rspamd_pk_t[rspamd_cryptobox_MAX_PKBYTES];
+typedef unsigned char rspamd_sk_t[rspamd_cryptobox_MAX_SKBYTES];
+typedef unsigned char rspamd_mac_t[rspamd_cryptobox_MAX_MACBYTES];
+typedef unsigned char rspamd_nm_t[rspamd_cryptobox_MAX_NMBYTES];
+typedef unsigned char rspamd_nonce_t[rspamd_cryptobox_MAX_NONCEBYTES];
+typedef unsigned char rspamd_sipkey_t[rspamd_cryptobox_SIPKEYBYTES];
+typedef unsigned char rspamd_signature_t[rspamd_cryptobox_MAX_SIGBYTES];
+typedef unsigned char rspamd_sig_pk_t[rspamd_cryptobox_MAX_SIGPKBYTES];
+typedef unsigned char rspamd_sig_sk_t[rspamd_cryptobox_MAX_SIGSKBYTES];
enum rspamd_cryptobox_mode {
RSPAMD_CRYPTOBOX_MODE_25519 = 0,
};
struct rspamd_cryptobox_library_ctx {
- gchar *cpu_extensions;
- const gchar *chacha20_impl;
- const gchar *base64_impl;
+ char *cpu_extensions;
+ const char *chacha20_impl;
+ const char *base64_impl;
unsigned long cpu_config;
};
* @param sk local secret key
* @param sig output signature
*/
-void rspamd_cryptobox_encrypt_inplace(guchar *data, gsize len,
+void rspamd_cryptobox_encrypt_inplace(unsigned char *data, gsize len,
const rspamd_nonce_t nonce,
const rspamd_pk_t pk, const rspamd_sk_t sk, rspamd_mac_t sig,
enum rspamd_cryptobox_mode mode);
* @param sig signature input
* @return TRUE if input has been verified successfully
*/
-gboolean rspamd_cryptobox_decrypt_inplace(guchar *data, gsize len,
+gboolean rspamd_cryptobox_decrypt_inplace(unsigned char *data, gsize len,
const rspamd_nonce_t nonce,
const rspamd_pk_t pk, const rspamd_sk_t sk, const rspamd_mac_t sig,
enum rspamd_cryptobox_mode mode);
* @param sk local secret key
* @param sig output signature
*/
-void rspamd_cryptobox_encrypt_nm_inplace(guchar *data, gsize len,
+void rspamd_cryptobox_encrypt_nm_inplace(unsigned char *data, gsize len,
const rspamd_nonce_t nonce,
const rspamd_nm_t nm, rspamd_mac_t sig,
enum rspamd_cryptobox_mode mode);
* @param sig signature input
* @return TRUE if input has been verified successfully
*/
-gboolean rspamd_cryptobox_decrypt_nm_inplace(guchar *data, gsize len,
+gboolean rspamd_cryptobox_decrypt_nm_inplace(unsigned char *data, gsize len,
const rspamd_nonce_t nonce,
const rspamd_nm_t nm, const rspamd_mac_t sig,
enum rspamd_cryptobox_mode mode);
* @param mlen input length
* @param sk secret key
*/
-void rspamd_cryptobox_sign(guchar *sig, unsigned long long *siglen_p,
- const guchar *m, gsize mlen,
+void rspamd_cryptobox_sign(unsigned char *sig, unsigned long long *siglen_p,
+ const unsigned char *m, gsize mlen,
const rspamd_sk_t sk,
enum rspamd_cryptobox_mode mode);
* @param pk public key for verification
* @return true if signature is valid, false otherwise
*/
-bool rspamd_cryptobox_verify(const guchar *sig,
+bool rspamd_cryptobox_verify(const unsigned char *sig,
gsize siglen,
- const guchar *m,
+ const unsigned char *m,
gsize mlen,
const rspamd_pk_t pk,
enum rspamd_cryptobox_mode mode);
* @return TRUE in case of success and FALSE if failed
*/
gboolean rspamd_cryptobox_pbkdf(const char *pass, gsize pass_len,
- const guint8 *salt, gsize salt_len,
- guint8 *key, gsize key_len,
+ const uint8_t *salt, gsize salt_len,
+ uint8_t *key, gsize key_len,
unsigned int complexity,
enum rspamd_cryptobox_pbkdf_type type);
/**
* Real size of rspamd cryptobox public key
*/
-guint rspamd_cryptobox_pk_bytes(enum rspamd_cryptobox_mode mode);
+unsigned int rspamd_cryptobox_pk_bytes(enum rspamd_cryptobox_mode mode);
/**
* Real size of rspamd cryptobox signing public key
*/
-guint rspamd_cryptobox_pk_sig_bytes(enum rspamd_cryptobox_mode mode);
+unsigned int rspamd_cryptobox_pk_sig_bytes(enum rspamd_cryptobox_mode mode);
/**
* Real size of crypto nonce
*/
-guint rspamd_cryptobox_nonce_bytes(enum rspamd_cryptobox_mode mode);
+unsigned int rspamd_cryptobox_nonce_bytes(enum rspamd_cryptobox_mode mode);
/**
* Real size of rspamd cryptobox secret key
*/
-guint rspamd_cryptobox_sk_bytes(enum rspamd_cryptobox_mode mode);
+unsigned int rspamd_cryptobox_sk_bytes(enum rspamd_cryptobox_mode mode);
/**
* Real size of rspamd cryptobox signing secret key
*/
-guint rspamd_cryptobox_sk_sig_bytes(enum rspamd_cryptobox_mode mode);
+unsigned int rspamd_cryptobox_sk_sig_bytes(enum rspamd_cryptobox_mode mode);
/**
* Real size of rspamd cryptobox shared key
*/
-guint rspamd_cryptobox_nm_bytes(enum rspamd_cryptobox_mode mode);
+unsigned int rspamd_cryptobox_nm_bytes(enum rspamd_cryptobox_mode mode);
/**
* Real size of rspamd cryptobox MAC signature
*/
-guint rspamd_cryptobox_mac_bytes(enum rspamd_cryptobox_mode mode);
+unsigned int rspamd_cryptobox_mac_bytes(enum rspamd_cryptobox_mode mode);
/**
* Real size of rspamd cryptobox digital signature
*/
-guint rspamd_cryptobox_signature_bytes(enum rspamd_cryptobox_mode mode);
+unsigned int rspamd_cryptobox_signature_bytes(enum rspamd_cryptobox_mode mode);
/* Hash IUF interface */
typedef crypto_generichash_blake2b_state rspamd_cryptobox_hash_state_t;
* non-keyed hash is generated
*/
void rspamd_cryptobox_hash_init(rspamd_cryptobox_hash_state_t *st,
- const guchar *key, gsize keylen);
+ const unsigned char *key, gsize keylen);
/**
* Update hash with data portion
*/
void rspamd_cryptobox_hash_update(rspamd_cryptobox_hash_state_t *st,
- const guchar *data, gsize len);
+ const unsigned char *data, gsize len);
/**
* Output hash to the buffer of rspamd_cryptobox_HASHBYTES length
*/
-void rspamd_cryptobox_hash_final(rspamd_cryptobox_hash_state_t *st, guchar *out);
+void rspamd_cryptobox_hash_final(rspamd_cryptobox_hash_state_t *st, unsigned char *out);
/**
* One in all function
*/
-void rspamd_cryptobox_hash(guchar *out,
- const guchar *data,
+void rspamd_cryptobox_hash(unsigned char *out,
+ const unsigned char *data,
gsize len,
- const guchar *key,
+ const unsigned char *key,
gsize keylen);
enum rspamd_cryptobox_fast_hash_type {
/* Non crypto hash IUF interface */
typedef struct CRYPTO_ALIGN(64) rspamd_cryptobox_fast_hash_state_s {
- guchar opaque[576]; /* Required for xxhash3 */
+ unsigned char opaque[576]; /* Required for xxhash3 */
enum rspamd_cryptobox_fast_hash_type type;
} rspamd_cryptobox_fast_hash_state_t;
* @param outlen
* @return
*/
-gboolean rspamd_cryptobox_base64_decode(const gchar *in, gsize inlen,
- guchar *out, gsize *outlen);
+gboolean rspamd_cryptobox_base64_decode(const char *in, gsize inlen,
+ unsigned char *out, gsize *outlen);
/**
* Returns TRUE if data looks like a valid base64 string
* @param inlen
* @return
*/
-gboolean rspamd_cryptobox_base64_is_valid(const gchar *in, gsize inlen);
+gboolean rspamd_cryptobox_base64_is_valid(const char *in, gsize inlen);
#ifdef __cplusplus
}
#include "libutil/printf.h"
#include "contrib/libottery/ottery.h"
-const guchar encrypted_magic[7] = {'r', 'u', 'c', 'l', 'e', 'v', '1'};
+const unsigned char encrypted_magic[7] = {'r', 'u', 'c', 'l', 'e', 'v', '1'};
static GQuark
rspamd_keypair_quark(void)
*/
static void *
rspamd_cryptobox_keypair_sk(struct rspamd_cryptobox_keypair *kp,
- guint *len)
+ unsigned int *len)
{
g_assert(kp != NULL);
static void *
rspamd_cryptobox_keypair_pk(struct rspamd_cryptobox_keypair *kp,
- guint *len)
+ unsigned int *len)
{
g_assert(kp != NULL);
static void *
rspamd_cryptobox_pubkey_pk(const struct rspamd_cryptobox_pubkey *kp,
- guint *len)
+ unsigned int *len)
{
g_assert(kp != NULL);
enum rspamd_cryptobox_mode alg)
{
struct rspamd_cryptobox_keypair *kp;
- guint size = 0;
+ unsigned int size = 0;
if (alg == RSPAMD_CRYPTOBOX_MODE_25519) {
if (type == RSPAMD_KEYPAIR_KEX) {
enum rspamd_cryptobox_mode alg)
{
struct rspamd_cryptobox_pubkey *pk;
- guint size = 0;
+ unsigned int size = 0;
if (alg == RSPAMD_CRYPTOBOX_MODE_25519) {
if (type == RSPAMD_KEYPAIR_KEX) {
void rspamd_cryptobox_keypair_dtor(struct rspamd_cryptobox_keypair *kp)
{
void *sk;
- guint len = 0;
+ unsigned int len = 0;
sk = rspamd_cryptobox_keypair_sk(kp, &len);
g_assert(sk != NULL && len > 0);
{
struct rspamd_cryptobox_keypair *kp;
void *pk, *sk;
- guint size;
+ unsigned int size;
kp = rspamd_cryptobox_keypair_alloc(type, alg);
kp->alg = alg;
}
struct rspamd_cryptobox_pubkey *
-rspamd_pubkey_from_base32(const gchar *b32,
+rspamd_pubkey_from_base32(const char *b32,
gsize len,
enum rspamd_cryptobox_keypair_type type,
enum rspamd_cryptobox_mode alg)
{
- guchar *decoded;
+ unsigned char *decoded;
gsize dlen, expected_len;
- guint pklen;
+ unsigned int pklen;
struct rspamd_cryptobox_pubkey *pk;
- guchar *pk_data;
+ unsigned char *pk_data;
g_assert(b32 != NULL);
}
struct rspamd_cryptobox_pubkey *
-rspamd_pubkey_from_hex(const gchar *hex,
+rspamd_pubkey_from_hex(const char *hex,
gsize len,
enum rspamd_cryptobox_keypair_type type,
enum rspamd_cryptobox_mode alg)
{
- guchar *decoded;
+ unsigned char *decoded;
gsize dlen, expected_len;
- guint pklen;
+ unsigned int pklen;
struct rspamd_cryptobox_pubkey *pk;
- guchar *pk_data;
+ unsigned char *pk_data;
g_assert(hex != NULL);
}
struct rspamd_cryptobox_pubkey *
-rspamd_pubkey_from_bin(const guchar *raw,
+rspamd_pubkey_from_bin(const unsigned char *raw,
gsize len,
enum rspamd_cryptobox_keypair_type type,
enum rspamd_cryptobox_mode alg)
{
gsize expected_len;
- guint pklen;
+ unsigned int pklen;
struct rspamd_cryptobox_pubkey *pk;
- guchar *pk_data;
+ unsigned char *pk_data;
g_assert(raw != NULL && len > 0);
}
-const guchar *
+const unsigned char *
rspamd_pubkey_get_nm(struct rspamd_cryptobox_pubkey *p,
struct rspamd_cryptobox_keypair *kp)
{
g_assert(p != NULL);
if (p->nm) {
- if (memcmp(kp->id, (const guchar *) &p->nm->sk_id, sizeof(uint64_t)) == 0) {
+ if (memcmp(kp->id, (const unsigned char *) &p->nm->sk_id, sizeof(uint64_t)) == 0) {
return p->nm->nm;
}
return NULL;
}
-const guchar *
+const unsigned char *
rspamd_pubkey_calculate_nm(struct rspamd_cryptobox_pubkey *p,
struct rspamd_cryptobox_keypair *kp)
{
return p->nm->nm;
}
-const guchar *
+const unsigned char *
rspamd_keypair_get_id(struct rspamd_cryptobox_keypair *kp)
{
g_assert(kp != NULL);
return kp->extensions;
}
-const guchar *
+const unsigned char *
rspamd_pubkey_get_id(struct rspamd_cryptobox_pubkey *pk)
{
g_assert(pk != NULL);
return pk->id;
}
-const guchar *
+const unsigned char *
rspamd_pubkey_get_pk(struct rspamd_cryptobox_pubkey *pk,
- guint *len)
+ unsigned int *len)
{
- guchar *ret = NULL;
- guint rlen;
+ unsigned char *ret = NULL;
+ unsigned int rlen;
ret = rspamd_cryptobox_pubkey_pk(pk, &rlen);
}
static void
-rspamd_keypair_print_component(guchar *data, gsize datalen,
- GString *res, guint how, const gchar *description)
+rspamd_keypair_print_component(unsigned char *data, gsize datalen,
+ GString *res, unsigned int how, const char *description)
{
- gint olen, b32_len;
+ int olen, b32_len;
if (how & RSPAMD_KEYPAIR_HUMAN) {
rspamd_printf_gstring(res, "%s: ", description);
}
}
else if (how & RSPAMD_KEYPAIR_HEX) {
- rspamd_printf_gstring(res, "%*xs", (gint) datalen, data);
+ rspamd_printf_gstring(res, "%*xs", (int) datalen, data);
}
else {
g_string_append_len(res, data, datalen);
}
GString *
-rspamd_keypair_print(struct rspamd_cryptobox_keypair *kp, guint how)
+rspamd_keypair_print(struct rspamd_cryptobox_keypair *kp, unsigned int how)
{
GString *res;
- guint len;
+ unsigned int len;
gpointer p;
g_assert(kp != NULL);
}
GString *
-rspamd_pubkey_print(struct rspamd_cryptobox_pubkey *pk, guint how)
+rspamd_pubkey_print(struct rspamd_cryptobox_pubkey *pk, unsigned int how)
{
GString *res;
- guint len;
+ unsigned int len;
gpointer p;
g_assert(pk != NULL);
return res;
}
-const guchar *
+const unsigned char *
rspamd_keypair_component(struct rspamd_cryptobox_keypair *kp,
- guint ncomp, guint *len)
+ unsigned int ncomp, unsigned int *len)
{
- guint rlen = 0;
- const guchar *ret = NULL;
+ unsigned int rlen = 0;
+ const unsigned char *ret = NULL;
g_assert(kp != NULL);
rspamd_keypair_from_ucl(const ucl_object_t *obj)
{
const ucl_object_t *privkey, *pubkey, *elt;
- const gchar *str;
+ const char *str;
enum rspamd_cryptobox_keypair_type type = RSPAMD_KEYPAIR_KEX;
enum rspamd_cryptobox_mode mode = RSPAMD_CRYPTOBOX_MODE_25519;
gboolean is_hex = FALSE;
struct rspamd_cryptobox_keypair *kp;
- guint len;
+ unsigned int len;
gsize ucl_len;
- gint dec_len;
+ int dec_len;
gpointer target;
if (ucl_object_type(obj) != UCL_OBJECT) {
dec_len = rspamd_decode_base32_buf(str, ucl_len, target, len, RSPAMD_BASE32_DEFAULT);
}
- if (dec_len != (gint) len) {
+ if (dec_len != (int) len) {
rspamd_keypair_unref(kp);
return NULL;
dec_len = rspamd_decode_base32_buf(str, ucl_len, target, len, RSPAMD_BASE32_DEFAULT);
}
- if (dec_len != (gint) len) {
+ if (dec_len != (int) len) {
rspamd_keypair_unref(kp);
return NULL;
enum rspamd_keypair_dump_flags flags)
{
ucl_object_t *ucl_out, *elt;
- gint how = 0;
+ int how = 0;
GString *keypair_out;
- const gchar *encoding;
+ const char *encoding;
g_assert(kp != NULL);
gboolean
rspamd_keypair_decrypt(struct rspamd_cryptobox_keypair *kp,
- const guchar *in, gsize inlen,
- guchar **out, gsize *outlen,
+ const unsigned char *in, gsize inlen,
+ unsigned char **out, gsize *outlen,
GError **err)
{
- const guchar *nonce, *mac, *data, *pubkey;
+ const unsigned char *nonce, *mac, *data, *pubkey;
g_assert(kp != NULL);
g_assert(in != NULL);
gboolean
rspamd_keypair_encrypt(struct rspamd_cryptobox_keypair *kp,
- const guchar *in, gsize inlen,
- guchar **out, gsize *outlen,
+ const unsigned char *in, gsize inlen,
+ unsigned char **out, gsize *outlen,
GError **err)
{
- guchar *nonce, *mac, *data, *pubkey;
+ unsigned char *nonce, *mac, *data, *pubkey;
struct rspamd_cryptobox_keypair *local;
gsize olen;
gboolean
rspamd_pubkey_encrypt(struct rspamd_cryptobox_pubkey *pk,
- const guchar *in, gsize inlen,
- guchar **out, gsize *outlen,
+ const unsigned char *in, gsize inlen,
+ unsigned char **out, gsize *outlen,
GError **err)
{
- guchar *nonce, *mac, *data, *pubkey;
+ unsigned char *nonce, *mac, *data, *pubkey;
struct rspamd_cryptobox_keypair *local;
gsize olen;
RSPAMD_KEYPAIR_SIGN
};
-extern const guchar encrypted_magic[7];
+extern const unsigned char encrypted_magic[7];
/**
* Opaque structure for the full (public + private) keypair
* @param alg algorithm of the key (nist or curve25519)
* @return new pubkey or NULL in case of error
*/
-struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_base32(const gchar *b32,
+struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_base32(const char *b32,
gsize len,
enum rspamd_cryptobox_keypair_type type,
enum rspamd_cryptobox_mode alg);
* @param alg algorithm of the key (nist or curve25519)
* @return new pubkey or NULL in case of error
*/
-struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_hex(const gchar *hex,
+struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_hex(const char *hex,
gsize len,
enum rspamd_cryptobox_keypair_type type,
enum rspamd_cryptobox_mode alg);
* @param alg algorithm of the key (nist or curve25519)
* @return new pubkey or NULL in case of error
*/
-struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_bin(const guchar *raw,
+struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_bin(const unsigned char *raw,
gsize len,
enum rspamd_cryptobox_keypair_type type,
enum rspamd_cryptobox_mode alg);
* @param p
* @return
*/
-const guchar *rspamd_pubkey_get_nm(struct rspamd_cryptobox_pubkey *p,
- struct rspamd_cryptobox_keypair *kp);
+const unsigned char *rspamd_pubkey_get_nm(struct rspamd_cryptobox_pubkey *p,
+ struct rspamd_cryptobox_keypair *kp);
/**
* Calculate and store nm value for the specified local key (performs ECDH)
* @param p
* @return
*/
-const guchar *rspamd_pubkey_calculate_nm(struct rspamd_cryptobox_pubkey *p,
- struct rspamd_cryptobox_keypair *kp);
+const unsigned char *rspamd_pubkey_calculate_nm(struct rspamd_cryptobox_pubkey *p,
+ struct rspamd_cryptobox_keypair *kp);
/**
* Get raw public key id for a specified keypair (rspamd_cryptobox_HASHBYTES)
* @param kp
* @return
*/
-const guchar *rspamd_keypair_get_id(struct rspamd_cryptobox_keypair *kp);
+const unsigned char *rspamd_keypair_get_id(struct rspamd_cryptobox_keypair *kp);
/**
* Returns keypair extensions if any
* @param kp
* @return
*/
-const guchar *rspamd_pubkey_get_id(struct rspamd_cryptobox_pubkey *pk);
+const unsigned char *rspamd_pubkey_get_id(struct rspamd_cryptobox_pubkey *pk);
/**
* Get raw public key from pubkey opaque structure
* @param len
* @return
*/
-const guchar *rspamd_pubkey_get_pk(struct rspamd_cryptobox_pubkey *pk,
- guint *len);
+const unsigned char *rspamd_pubkey_get_pk(struct rspamd_cryptobox_pubkey *pk,
+ unsigned int *len);
/** Short ID characters count */
#define RSPAMD_KEYPAIR_SHORT_ID_LEN 5
* @return newly allocated string with keypair
*/
GString *rspamd_keypair_print(struct rspamd_cryptobox_keypair *kp,
- guint how);
+ unsigned int how);
/**
* Print pubkey encoding it if needed
* @return newly allocated string with keypair
*/
GString *rspamd_pubkey_print(struct rspamd_cryptobox_pubkey *pk,
- guint how);
+ unsigned int how);
/** Get keypair pubkey ID */
#define RSPAMD_KEYPAIR_COMPONENT_ID 0
* @param len length of input
* @return raw content of the component
*/
-const guchar *rspamd_keypair_component(struct rspamd_cryptobox_keypair *kp,
- guint ncomp, guint *len);
+const unsigned char *rspamd_keypair_component(struct rspamd_cryptobox_keypair *kp,
+ unsigned int ncomp, unsigned int *len);
/**
* Create a new keypair from ucl object
* @return TRUE if decryption is completed, out must be freed in this case
*/
gboolean rspamd_keypair_decrypt(struct rspamd_cryptobox_keypair *kp,
- const guchar *in, gsize inlen,
- guchar **out, gsize *outlen,
+ const unsigned char *in, gsize inlen,
+ unsigned char **out, gsize *outlen,
GError **err);
/**
* @return TRUE if encryption has been completed, out must be freed in this case
*/
gboolean rspamd_keypair_encrypt(struct rspamd_cryptobox_keypair *kp,
- const guchar *in, gsize inlen,
- guchar **out, gsize *outlen,
+ const unsigned char *in, gsize inlen,
+ unsigned char **out, gsize *outlen,
GError **err);
/**
* @return TRUE if encryption has been completed, out must be freed in this case
*/
gboolean rspamd_pubkey_encrypt(struct rspamd_cryptobox_pubkey *pk,
- const guchar *in, gsize inlen,
- guchar **out, gsize *outlen,
+ const unsigned char *in, gsize inlen,
+ unsigned char **out, gsize *outlen,
GError **err);
#ifdef __cplusplus
* KEX cached data
*/
struct rspamd_cryptobox_nm {
- guchar nm[rspamd_cryptobox_MAX_NMBYTES];
+ unsigned char nm[rspamd_cryptobox_MAX_NMBYTES];
uint64_t sk_id; /* Used to store secret key id */
ref_entry_t ref;
};
* Generic keypair
*/
struct rspamd_cryptobox_keypair {
- guchar id[rspamd_cryptobox_HASHBYTES];
+ unsigned char id[rspamd_cryptobox_HASHBYTES];
enum rspamd_cryptobox_keypair_type type;
enum rspamd_cryptobox_mode alg;
ucl_object_t *extensions;
#define RSPAMD_CRYPTOBOX_KEYPAIR_NIST(x) ((struct rspamd_cryptobox_keypair_nist *) (x))
struct rspamd_cryptobox_keypair_nist {
struct rspamd_cryptobox_keypair parent;
- guchar sk[32];
- guchar pk[65];
+ unsigned char sk[32];
+ unsigned char pk[65];
};
/*
#define RSPAMD_CRYPTOBOX_KEYPAIR_25519(x) ((struct rspamd_cryptobox_keypair_25519 *) (x))
struct rspamd_cryptobox_keypair_25519 {
struct rspamd_cryptobox_keypair parent;
- guchar sk[32];
- guchar pk[32];
+ unsigned char sk[32];
+ unsigned char pk[32];
};
/*
#define RSPAMD_CRYPTOBOX_KEYPAIR_SIG_NIST(x) ((struct rspamd_cryptobox_keypair_sig_nist *) (x))
struct rspamd_cryptobox_keypair_sig_nist {
struct rspamd_cryptobox_keypair parent;
- guchar sk[32];
- guchar pk[65];
+ unsigned char sk[32];
+ unsigned char pk[65];
};
/*
#define RSPAMD_CRYPTOBOX_KEYPAIR_SIG_25519(x) ((struct rspamd_cryptobox_keypair_sig_25519 *) (x))
struct rspamd_cryptobox_keypair_sig_25519 {
struct rspamd_cryptobox_keypair parent;
- guchar sk[64];
- guchar pk[32];
+ unsigned char sk[64];
+ unsigned char pk[32];
};
/*
* Public component of the keypair
*/
struct rspamd_cryptobox_pubkey {
- guchar id[rspamd_cryptobox_HASHBYTES];
+ unsigned char id[rspamd_cryptobox_HASHBYTES];
struct rspamd_cryptobox_nm *nm;
enum rspamd_cryptobox_keypair_type type;
enum rspamd_cryptobox_mode alg;
#define RSPAMD_CRYPTOBOX_PUBKEY_NIST(x) ((struct rspamd_cryptobox_pubkey_nist *) (x))
struct rspamd_cryptobox_pubkey_nist {
struct rspamd_cryptobox_pubkey parent;
- guchar pk[65];
+ unsigned char pk[65];
};
/*
#define RSPAMD_CRYPTOBOX_PUBKEY_25519(x) ((struct rspamd_cryptobox_pubkey_25519 *) (x))
struct rspamd_cryptobox_pubkey_25519 {
struct rspamd_cryptobox_pubkey parent;
- guchar pk[32];
+ unsigned char pk[32];
};
/*
#define RSPAMD_CRYPTOBOX_PUBKEY_SIG_NIST(x) ((struct rspamd_cryptobox_pubkey_sig_nist *) (x))
struct rspamd_cryptobox_pubkey_sig_nist {
struct rspamd_cryptobox_pubkey parent;
- guchar pk[65];
+ unsigned char pk[65];
};
/*
#define RSPAMD_CRYPTOBOX_PUBKEY_SIG_25519(x) ((struct rspamd_cryptobox_pubkey_sig_25519 *) (x))
struct rspamd_cryptobox_pubkey_sig_25519 {
struct rspamd_cryptobox_pubkey parent;
- guchar pk[32];
+ unsigned char pk[32];
};
void rspamd_cryptobox_nm_dtor(struct rspamd_cryptobox_nm *nm);
struct rspamd_keypair_elt {
struct rspamd_cryptobox_nm *nm;
- guchar pair[rspamd_cryptobox_HASHBYTES * 2];
+ unsigned char pair[rspamd_cryptobox_HASHBYTES * 2];
};
struct rspamd_keypair_cache {
g_free(elt);
}
-static guint
+static unsigned int
rspamd_keypair_hash(gconstpointer ptr)
{
struct rspamd_keypair_elt *elt = (struct rspamd_keypair_elt *) ptr;
}
struct rspamd_keypair_cache *
-rspamd_keypair_cache_new(guint max_items)
+rspamd_keypair_cache_new(unsigned int max_items)
{
struct rspamd_keypair_cache *c;
* @param max_items defines maximum count of elements in the cache
* @return new cache
*/
-struct rspamd_keypair_cache *rspamd_keypair_cache_new(guint max_items);
+struct rspamd_keypair_cache *rspamd_keypair_cache_new(unsigned int max_items);
/**
{
struct rspamd_archive *arch = p;
struct rspamd_archive_file *f;
- guint i;
+ unsigned int i;
for (i = 0; i < arch->files->len; i++) {
f = g_ptr_array_index(arch->files, i);
rspamd_archive_file_try_utf(struct rspamd_task *task,
struct rspamd_archive *arch,
struct rspamd_archive_file *fentry,
- const gchar *in, gsize inlen)
+ const char *in, gsize inlen)
{
- const gchar *charset = NULL, *p, *end;
+ const char *charset = NULL, *p, *end;
GString *res;
charset = rspamd_mime_charset_find_by_content(in, inlen, TRUE);
rspamd_archive_process_zip(struct rspamd_task *task,
struct rspamd_mime_part *part)
{
- const guchar *p, *start, *end, *eocd = NULL, *cd;
+ const unsigned char *p, *start, *end, *eocd = NULL, *cd;
const uint32_t eocd_magic = 0x06054b50, cd_basic_len = 46;
- const guchar cd_magic[] = {0x50, 0x4b, 0x01, 0x02};
- const guint max_processed = 1024;
+ const unsigned char cd_magic[] = {0x50, 0x4b, 0x01, 0x02};
+ const unsigned int max_processed = 1024;
uint32_t cd_offset, cd_size, comp_size, uncomp_size, processed = 0;
- guint16 extra_len, fname_len, comment_len;
+ uint16_t extra_len, fname_len, comment_len;
struct rspamd_archive *arch;
struct rspamd_archive_file *f = NULL;
cd_offset = GUINT32_FROM_LE(cd_offset);
/* We need to check sanity as well */
- if (cd_offset + cd_size > (guint) (eocd - start)) {
+ if (cd_offset + cd_size > (unsigned int) (eocd - start)) {
msg_info_task("zip archive is invalid (bad size/offset for CD)");
return;
arch);
while (cd < start + cd_offset + cd_size) {
- guint16 flags;
+ uint16_t flags;
/* Read central directory record */
if (eocd - cd < cd_basic_len ||
return;
}
- memcpy(&flags, cd + 8, sizeof(guint16));
+ memcpy(&flags, cd + 8, sizeof(uint16_t));
flags = GUINT16_FROM_LE(flags);
memcpy(&comp_size, cd + 20, sizeof(uint32_t));
comp_size = GUINT32_FROM_LE(comp_size);
}
/* Process extra fields */
- const guchar *extra = cd + fname_len + cd_basic_len;
+ const unsigned char *extra = cd + fname_len + cd_basic_len;
p = extra;
- while (p + sizeof(guint16) * 2 < extra + extra_len) {
- guint16 hid, hlen;
+ while (p + sizeof(uint16_t) * 2 < extra + extra_len) {
+ uint16_t hid, hlen;
- memcpy(&hid, p, sizeof(guint16));
+ memcpy(&hid, p, sizeof(uint16_t));
hid = GUINT16_FROM_LE(hid);
- memcpy(&hlen, p + sizeof(guint16), sizeof(guint16));
+ memcpy(&hlen, p + sizeof(uint16_t), sizeof(uint16_t));
hlen = GUINT16_FROM_LE(hlen);
if (hid == 0x0017) {
f->flags |= RSPAMD_ARCHIVE_FILE_ENCRYPTED;
}
- p += hlen + sizeof(guint16) * 2;
+ p += hlen + sizeof(uint16_t) * 2;
}
cd += fname_len + comment_len + extra_len + cd_basic_len;
arch->size = part->parsed_data.len;
}
-static inline gint
-rspamd_archive_rar_read_vint(const guchar *start, gsize remain, uint64_t *res)
+static inline int
+rspamd_archive_rar_read_vint(const unsigned char *start, gsize remain, uint64_t *res)
{
/*
* From http://www.rarlab.com/technote.htm:
* continuation flag. Second byte, if present, contains next 7 bits and so on.
*/
uint64_t t = 0;
- guint shift = 0;
- const guchar *p = start;
+ unsigned int shift = 0;
+ const unsigned char *p = start;
while (remain > 0 && shift <= 57) {
if (*p & 0x80) {
#define RAR_READ_UINT16(n) \
do { \
- if (end - p < (glong) sizeof(guint16)) { \
+ if (end - p < (glong) sizeof(uint16_t)) { \
msg_debug_archive("rar archive is invalid (bad int16)"); \
return; \
} \
n = p[0] + (p[1] << 8); \
- p += sizeof(guint16); \
+ p += sizeof(uint16_t); \
} while (0)
-#define RAR_READ_UINT32(n) \
- do { \
- if (end - p < (glong) sizeof(uint32_t)) { \
- msg_debug_archive("rar archive is invalid (bad int32)"); \
- return; \
- } \
- n = (guint) p[0] + ((guint) p[1] << 8) + ((guint) p[2] << 16) + ((guint) p[3] << 24); \
- p += sizeof(uint32_t); \
+#define RAR_READ_UINT32(n) \
+ do { \
+ if (end - p < (glong) sizeof(uint32_t)) { \
+ msg_debug_archive("rar archive is invalid (bad int32)"); \
+ return; \
+ } \
+ n = (unsigned int) p[0] + ((unsigned int) p[1] << 8) + ((unsigned int) p[2] << 16) + ((unsigned int) p[3] << 24); \
+ p += sizeof(uint32_t); \
} while (0)
static void
-rspamd_archive_process_rar_v4(struct rspamd_task *task, const guchar *start,
- const guchar *end, struct rspamd_mime_part *part)
+rspamd_archive_process_rar_v4(struct rspamd_task *task, const unsigned char *start,
+ const unsigned char *end, struct rspamd_mime_part *part)
{
- const guchar *p = start, *start_section;
- guint8 type;
- guint flags;
+ const unsigned char *p = start, *start_section;
+ uint8_t type;
+ unsigned int flags;
uint64_t sz, comp_sz = 0, uncomp_sz = 0;
struct rspamd_archive *arch;
struct rspamd_archive_file *f;
while (p < end) {
/* Crc16 */
start_section = p;
- RAR_SKIP_BYTES(sizeof(guint16));
+ RAR_SKIP_BYTES(sizeof(uint16_t));
type = *p;
p++;
RAR_READ_UINT16(flags);
}
if (type == 0x74) {
- guint fname_len;
+ unsigned int fname_len;
/* File header */
/* Uncompressed size */
if (flags & 0x200) {
/* We have unicode + normal version */
- guchar *tmp;
+ unsigned char *tmp;
tmp = memchr(p, '\0', fname_len);
rspamd_archive_process_rar(struct rspamd_task *task,
struct rspamd_mime_part *part)
{
- const guchar *p, *end, *section_start;
- const guchar rar_v5_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x01, 0x00},
- rar_v4_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x00};
- const guint rar_encrypted_header = 4, rar_main_header = 1,
- rar_file_header = 2;
+ const unsigned char *p, *end, *section_start;
+ const unsigned char rar_v5_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x01, 0x00},
+ rar_v4_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x00};
+ const unsigned int rar_encrypted_header = 4, rar_main_header = 1,
+ rar_file_header = 2;
uint64_t vint, sz, comp_sz = 0, uncomp_sz = 0, flags = 0, type = 0,
extra_sz = 0;
struct rspamd_archive *arch;
struct rspamd_archive_file *f;
- gint r;
+ int r;
p = part->parsed_data.begin;
end = p + part->parsed_data.len;
if (f && has_extra && extra_sz > 0 &&
p + fname_len + extra_sz < end) {
/* Try to find encryption record in extra field */
- const guchar *ex = p + fname_len;
+ const unsigned char *ex = p + fname_len;
while (ex < p + extra_sz) {
- const guchar *t;
+ const unsigned char *t;
int64_t cur_sz = 0, sec_type = 0;
r = rspamd_archive_rar_read_vint(ex, extra_sz, &cur_sz);
arch->size = part->parsed_data.len;
}
-static inline gint
-rspamd_archive_7zip_read_vint(const guchar *start, gsize remain, uint64_t *res)
+static inline int
+rspamd_archive_7zip_read_vint(const unsigned char *start, gsize remain, uint64_t *res)
{
/*
* REAL_UINT64 means real UINT64.
* 11111110 BYTE y[7] : y
* 11111111 BYTE y[8] : y
*/
- guchar t;
+ unsigned char t;
if (remain == 0) {
return -1;
}
}
else {
- gint cur_bit = 6, intlen = 1;
- const guchar bmask = 0xFF;
+ int cur_bit = 6, intlen = 1;
+ const unsigned char bmask = 0xFF;
uint64_t tgt;
while (cur_bit > 0) {
n = GUINT64_FROM_LE(n); \
p += sizeof(uint64_t); \
} while (0)
-#define SZ_SKIP_BYTES(n) \
- do { \
- if (end - p >= (n)) { \
- p += (n); \
- } \
- else { \
- msg_debug_archive("7zip archive is invalid (truncated); wanted to read %d bytes, %d avail: %s", (gint) (n), (gint) (end - p), G_STRLOC); \
- return NULL; \
- } \
+#define SZ_SKIP_BYTES(n) \
+ do { \
+ if (end - p >= (n)) { \
+ p += (n); \
+ } \
+ else { \
+ msg_debug_archive("7zip archive is invalid (truncated); wanted to read %d bytes, %d avail: %s", (int) (n), (int) (end - p), G_STRLOC); \
+ return NULL; \
+ } \
} while (0)
enum rspamd_7zip_header_mark {
((codec_id) == _7Z_CRYPTO_RAR_29) || \
((codec_id) == _7Z_CRYPTO_AES_256_SHA_256))
-static const guchar *
+static const unsigned char *
rspamd_7zip_read_bits(struct rspamd_task *task,
- const guchar *p, const guchar *end,
- struct rspamd_archive *arch, guint nbits,
- guint *pbits_set)
+ const unsigned char *p, const unsigned char *end,
+ struct rspamd_archive *arch, unsigned int nbits,
+ unsigned int *pbits_set)
{
unsigned mask = 0, avail = 0, i;
gboolean bit_set = 0;
return p;
}
-static const guchar *
+static const unsigned char *
rspamd_7zip_read_digest(struct rspamd_task *task,
- const guchar *p, const guchar *end,
+ const unsigned char *p, const unsigned char *end,
struct rspamd_archive *arch,
uint64_t num_streams,
- guint *pdigest_read)
+ unsigned int *pdigest_read)
{
- guchar all_defined = *p;
+ unsigned char all_defined = *p;
uint64_t i;
- guint num_defined = 0;
+ unsigned int num_defined = 0;
/*
* BYTE AllAreDefined
* if (AllAreDefined == 0)
return p;
}
-static const guchar *
+static const unsigned char *
rspamd_7zip_read_pack_info(struct rspamd_task *task,
- const guchar *p, const guchar *end,
+ const unsigned char *p, const unsigned char *end,
struct rspamd_archive *arch)
{
uint64_t pack_pos = 0, pack_streams = 0, i, cur_sz;
- guint num_digests = 0;
- guchar t;
+ unsigned int num_digests = 0;
+ unsigned char t;
/*
* UINT64 PackPos
* UINT64 NumPackStreams
return p;
}
-static const guchar *
+static const unsigned char *
rspamd_7zip_read_folder(struct rspamd_task *task,
- const guchar *p, const guchar *end,
- struct rspamd_archive *arch, guint *pnstreams, guint *ndigests)
+ const unsigned char *p, const unsigned char *end,
+ struct rspamd_archive *arch, unsigned int *pnstreams, unsigned int *ndigests)
{
uint64_t ncoders = 0, i, j, noutstreams = 0, ninstreams = 0;
for (i = 0; i < ncoders && p != NULL && p < end; i++) {
uint64_t sz, tmp;
- guchar t;
+ unsigned char t;
/*
* BYTE
* {
return p;
}
-static const guchar *
+static const unsigned char *
rspamd_7zip_read_coders_info(struct rspamd_task *task,
- const guchar *p, const guchar *end,
+ const unsigned char *p, const unsigned char *end,
struct rspamd_archive *arch,
- guint *pnum_folders, guint *pnum_nodigest)
+ unsigned int *pnum_folders, unsigned int *pnum_nodigest)
{
uint64_t num_folders = 0, i, tmp;
- guchar t;
- guint *folder_nstreams = NULL, num_digests = 0, digests_read = 0;
+ unsigned char t;
+ unsigned int *folder_nstreams = NULL, num_digests = 0, digests_read = 0;
while (p != NULL && p < end) {
/*
case kCodersUnPackSize:
for (i = 0; i < num_folders && p != NULL && p < end; i++) {
if (folder_nstreams) {
- for (guint j = 0; j < folder_nstreams[i]; j++) {
+ for (unsigned int j = 0; j < folder_nstreams[i]; j++) {
SZ_READ_VINT(tmp); /* Unpacked size */
msg_debug_archive("7zip: unpacked size "
"(folder=%d, stream=%d) = %L",
- (gint) i, j, tmp);
+ (int) i, j, tmp);
}
}
else {
return p;
}
-static const guchar *
+static const unsigned char *
rspamd_7zip_read_substreams_info(struct rspamd_task *task,
- const guchar *p, const guchar *end,
+ const unsigned char *p, const unsigned char *end,
struct rspamd_archive *arch,
- guint num_folders, guint num_nodigest)
+ unsigned int num_folders, unsigned int num_nodigest)
{
- guchar t;
- guint i;
+ unsigned char t;
+ unsigned int i;
uint64_t *folder_nstreams;
if (num_folders > 8192) {
* In fact, it is just absent in the real life...
*/
for (i = 0; i < num_folders; i++) {
- for (guint j = 0; j < folder_nstreams[i]; j++) {
+ for (unsigned int j = 0; j < folder_nstreams[i]; j++) {
uint64_t tmp;
SZ_READ_VINT(tmp); /* Who cares indeed */
return p;
}
-static const guchar *
+static const unsigned char *
rspamd_7zip_read_main_streams_info(struct rspamd_task *task,
- const guchar *p, const guchar *end,
+ const unsigned char *p, const unsigned char *end,
struct rspamd_archive *arch)
{
- guchar t;
- guint num_folders = 0, unknown_digests = 0;
+ unsigned char t;
+ unsigned int num_folders = 0, unknown_digests = 0;
while (p != NULL && p < end) {
t = *p;
return p;
}
-static const guchar *
+static const unsigned char *
rspamd_7zip_read_archive_props(struct rspamd_task *task,
- const guchar *p, const guchar *end,
+ const unsigned char *p, const unsigned char *end,
struct rspamd_archive *arch)
{
- guchar proptype;
+ unsigned char proptype;
uint64_t proplen;
/*
}
static GString *
-rspamd_7zip_ucs2_to_utf8(struct rspamd_task *task, const guchar *p,
- const guchar *end)
+rspamd_7zip_ucs2_to_utf8(struct rspamd_task *task, const unsigned char *p,
+ const unsigned char *end)
{
GString *res;
goffset dest_pos = 0, src_pos = 0;
- const gsize len = (end - p) / sizeof(guint16);
- guint16 *up;
+ const gsize len = (end - p) / sizeof(uint16_t);
+ uint16_t *up;
UChar32 wc;
UBool is_error = 0;
res = g_string_sized_new((end - p) * 3 / 2 + sizeof(wc) + 1);
- up = (guint16 *) p;
+ up = (uint16_t *) p;
while (src_pos < len) {
U16_NEXT(up, src_pos, len, wc);
return res;
}
-static const guchar *
+static const unsigned char *
rspamd_7zip_read_files_info(struct rspamd_task *task,
- const guchar *p, const guchar *end,
+ const unsigned char *p, const unsigned char *end,
struct rspamd_archive *arch)
{
uint64_t nfiles = 0, sz, i;
- guchar t, b;
+ unsigned char t, b;
struct rspamd_archive_file *fentry;
SZ_READ_VINT(nfiles);
for (i = 0; i < nfiles; i++) {
/* Zero terminated wchar_t: happy converting... */
/* First, find terminator */
- const guchar *fend = NULL, *tp = p;
+ const unsigned char *fend = NULL, *tp = p;
GString *res;
while (tp < end - 1) {
return p;
}
-static const guchar *
+static const unsigned char *
rspamd_7zip_read_next_section(struct rspamd_task *task,
- const guchar *p, const guchar *end,
+ const unsigned char *p, const unsigned char *end,
struct rspamd_archive *arch,
struct rspamd_mime_part *part)
{
- guchar t = *p;
+ unsigned char t = *p;
SZ_SKIP_BYTES(1);
struct rspamd_mime_part *part)
{
struct rspamd_archive *arch;
- const guchar *start, *p, *end;
- const guchar sz_magic[] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};
+ const unsigned char *start, *p, *end;
+ const unsigned char sz_magic[] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};
uint64_t section_offset = 0, section_length = 0;
start = part->parsed_data.begin;
struct rspamd_mime_part *part)
{
struct rspamd_archive *arch;
- const guchar *start, *p, *end;
- const guchar gz_magic[] = {0x1F, 0x8B};
- guchar flags;
+ const unsigned char *start, *p, *end;
+ const unsigned char gz_magic[] = {0x1F, 0x8B};
+ unsigned char flags;
start = part->parsed_data.begin;
p = start;
if (flags & (1u << 2)) {
/* Optional section */
- guint16 optlen = 0;
+ uint16_t optlen = 0;
RAR_READ_UINT16(optlen);
}
/* Read file name */
- const guchar *fname_start = p;
+ const unsigned char *fname_start = p;
while (p < end) {
if (*p == '\0') {
/* Fallback, we need to extract file name from archive name if possible */
if (part->cd && part->cd->filename.len > 0) {
- const gchar *dot_pos, *slash_pos;
+ const char *dot_pos, *slash_pos;
dot_pos = rspamd_memrchr(part->cd->filename.begin, '.',
part->cd->filename.len);
goto set;
}
else {
- const gchar *fname_start = part->cd->filename.begin;
+ const char *fname_start = part->cd->filename.begin;
f = g_malloc0(sizeof(*f));
}
static gboolean
-rspamd_archive_cheat_detect(struct rspamd_mime_part *part, const gchar *str,
- const guchar *magic_start, gsize magic_len)
+rspamd_archive_cheat_detect(struct rspamd_mime_part *part, const char *str,
+ const unsigned char *magic_start, gsize magic_len)
{
struct rspamd_content_type *ct;
- const gchar *p;
+ const char *p;
rspamd_ftok_t srch, *fname;
ct = part->ct;
void rspamd_archives_process(struct rspamd_task *task)
{
- guint i;
+ unsigned int i;
struct rspamd_mime_part *part;
- const guchar rar_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07};
- const guchar zip_magic[] = {0x50, 0x4b, 0x03, 0x04};
- const guchar sz_magic[] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};
- const guchar gz_magic[] = {0x1F, 0x8B, 0x08};
+ const unsigned char rar_magic[] = {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07};
+ const unsigned char zip_magic[] = {0x50, 0x4b, 0x03, 0x04};
+ const unsigned char sz_magic[] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};
+ const unsigned char gz_magic[] = {0x1F, 0x8B, 0x08};
PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, parts), i, part)
{
}
-const gchar *
+const char *
rspamd_archive_type_str(enum rspamd_archive_type type)
{
- const gchar *ret = "unknown";
+ const char *ret = "unknown";
switch (type) {
case RSPAMD_ARCHIVE_ZIP:
/**
* Get textual representation of an archive's type
*/
-const gchar *rspamd_archive_type_str(enum rspamd_archive_type type);
+const char *rspamd_archive_type_str(enum rspamd_archive_type type);
#ifdef __cplusplus
}
static gboolean
rspamd_rfc2231_decode(rspamd_mempool_t *pool,
struct rspamd_content_type_param *param,
- gchar *value_start, gchar *value_end)
+ char *value_start, char *value_end)
{
- gchar *quote_pos;
+ char *quote_pos;
quote_pos = memchr(value_start, '\'', value_end - value_start);
* encoding'data (in theory).
* Try to handle both...
*/
- const gchar *charset = NULL;
+ const char *charset = NULL;
rspamd_ftok_t ctok;
ctok.begin = value_start;
static gboolean
rspamd_param_maybe_rfc2231_process(rspamd_mempool_t *pool,
struct rspamd_content_type_param *param,
- gchar *name_start, gchar *name_end,
- gchar *value_start, gchar *value_end)
+ char *name_start, char *name_end,
+ char *value_start, char *value_end)
{
- const gchar *star_pos;
+ const char *star_pos;
star_pos = memchr(name_start, '*', name_end - name_start);
if (param->flags & RSPAMD_CONTENT_PARAM_PIECEWISE) {
/* Reconstruct param */
gsize tlen = 0;
- gchar *ndata, *pos;
+ char *ndata, *pos;
sorted = param;
DL_SORT(sorted, rspamd_cmp_pieces);
if (rspamd_ftok_icase_equal(¶m->name, &srch)) {
found = param;
- gchar *lc_boundary;
+ char *lc_boundary;
/* Adjust boundary */
lc_boundary = rspamd_mempool_alloc(pool, param->value.len);
memcpy(lc_boundary, param->value.begin, param->value.len);
RSPAMD_FTOK_ASSIGN(&srch, "name");
if (!rspamd_ftok_icase_equal(¶m->name, &srch)) {
/* Just lowercase */
- rspamd_str_lc_utf8((gchar *) param->value.begin, param->value.len);
+ rspamd_str_lc_utf8((char *) param->value.begin, param->value.len);
}
}
}
void rspamd_content_type_add_param(rspamd_mempool_t *pool,
struct rspamd_content_type *ct,
- gchar *name_start, gchar *name_end,
- gchar *value_start, gchar *value_end)
+ char *name_start, char *name_end,
+ char *value_start, char *value_end)
{
struct rspamd_content_type_param *nparam;
rspamd_ftok_t srch;
}
static struct rspamd_content_type *
-rspamd_content_type_parser(gchar *in, gsize len, rspamd_mempool_t *pool)
+rspamd_content_type_parser(char *in, gsize len, rspamd_mempool_t *pool)
{
- guint obraces = 0, ebraces = 0, qlen = 0;
- gchar *p, *c, *end, *pname_start = NULL, *pname_end = NULL;
+ unsigned int obraces = 0, ebraces = 0, qlen = 0;
+ char *p, *c, *end, *pname_start = NULL, *pname_end = NULL;
struct rspamd_content_type *res = NULL, val;
gboolean eqsign_seen = FALSE;
enum {
}
if (val.type.len > 0) {
- gchar *tmp;
+ char *tmp;
res = rspamd_mempool_alloc(pool, sizeof(val));
memcpy(res, &val, sizeof(val));
}
struct rspamd_content_type *
-rspamd_content_type_parse(const gchar *in,
+rspamd_content_type_parse(const char *in,
gsize len, rspamd_mempool_t *pool)
{
struct rspamd_content_type *res = NULL;
rspamd_ftok_t srch;
- gchar *cpy;
+ char *cpy;
cpy = rspamd_mempool_alloc(pool, len + 1);
rspamd_strlcpy(cpy, in, len + 1);
}
}
else {
- msg_warn_pool("cannot parse content type: %*s", (gint) len, cpy);
+ msg_warn_pool("cannot parse content type: %*s", (int) len, cpy);
}
return res;
void rspamd_content_disposition_add_param(rspamd_mempool_t *pool,
struct rspamd_content_disposition *cd,
- const gchar *name_start, const gchar *name_end,
- const gchar *value_start, const gchar *value_end)
+ const char *name_start, const char *name_end,
+ const char *value_start, const char *value_end)
{
rspamd_ftok_t srch;
- gchar *name_cpy, *value_cpy, *name_cpy_end, *value_cpy_end;
+ char *name_cpy, *value_cpy, *name_cpy_end, *value_cpy_end;
struct rspamd_content_type_param *found = NULL, *nparam;
g_assert(cd != NULL);
}
struct rspamd_content_disposition *
-rspamd_content_disposition_parse(const gchar *in,
+rspamd_content_disposition_parse(const char *in,
gsize len, rspamd_mempool_t *pool)
{
struct rspamd_content_disposition *res = NULL, val;
}
else {
msg_warn_pool("cannot parse content disposition: %*s",
- (gint) len, in);
+ (int) len, in);
}
return res;
struct rspamd_content_type_param {
rspamd_ftok_t name;
rspamd_ftok_t value;
- guint rfc2231_id;
+ unsigned int rfc2231_id;
enum rspamd_content_param_flags flags;
struct rspamd_content_type_param *prev, *next;
};
struct rspamd_content_type {
- gchar *cpy;
+ char *cpy;
rspamd_ftok_t type;
rspamd_ftok_t subtype;
rspamd_ftok_t charset;
};
struct rspamd_content_disposition {
- gchar *lc_data;
+ char *lc_data;
enum rspamd_content_disposition_type type;
rspamd_ftok_t filename;
GHashTable *attrs; /* Can be empty */
*/
void rspamd_content_type_add_param(rspamd_mempool_t *pool,
struct rspamd_content_type *ct,
- gchar *name_start, gchar *name_end,
- gchar *value_start, gchar *value_end);
+ char *name_start, char *name_end,
+ char *value_start, char *value_end);
/**
* Parse content type from the header (performs copy + lowercase)
* @param pool
* @return
*/
-struct rspamd_content_type *rspamd_content_type_parse(const gchar *in,
+struct rspamd_content_type *rspamd_content_type_parse(const char *in,
gsize len, rspamd_mempool_t *pool);
/**
*/
void rspamd_content_disposition_add_param(rspamd_mempool_t *pool,
struct rspamd_content_disposition *cd,
- const gchar *name_start, const gchar *name_end,
- const gchar *value_start, const gchar *value_end);
+ const char *name_start, const char *name_end,
+ const char *value_start, const char *value_end);
/**
* Parse content-disposition header
* @param pool
* @return
*/
-struct rspamd_content_disposition *rspamd_content_disposition_parse(const gchar *in,
+struct rspamd_content_disposition *rspamd_content_disposition_parse(const char *in,
gsize len,
rspamd_mempool_t *pool);
}
struct rspamd_email_address *
-rspamd_email_address_from_smtp(const gchar *str, guint len)
+rspamd_email_address_from_smtp(const char *str, unsigned int len)
{
struct rspamd_email_address addr, *ret;
gsize nlen;
nlen = ret->domain_len + ret->user_len + 2;
ret->addr = g_malloc(nlen + 1);
ret->addr_len = rspamd_snprintf((char *) ret->addr, nlen, "%*s@%*s",
- (gint) ret->user_len, ret->user,
- (gint) ret->domain_len, ret->domain);
+ (int) ret->user_len, ret->user,
+ (int) ret->domain_len, ret->domain);
ret->flags |= RSPAMD_EMAIL_ADDR_ADDR_ALLOCATED;
}
GString *name)
{
struct rspamd_email_address *elt;
- guint nlen;
+ unsigned int nlen;
elt = g_malloc0(sizeof(*elt));
rspamd_mempool_notify_alloc(pool, sizeof(*elt));
elt->addr = g_malloc(nlen + 1);
rspamd_mempool_notify_alloc(pool, nlen + 1);
elt->addr_len = rspamd_snprintf((char *) elt->addr, nlen, "%*s@%*s",
- (gint) elt->user_len, elt->user,
- (gint) elt->domain_len, elt->domain);
+ (int) elt->user_len, elt->user,
+ (int) elt->domain_len, elt->domain);
elt->flags |= RSPAMD_EMAIL_ADDR_ADDR_ALLOCATED;
}
rspamd_email_address_parse_heuristic(const char *data, size_t len,
struct rspamd_email_address *addr)
{
- const gchar *p = data, *at = NULL, *end = data + len;
+ const char *p = data, *at = NULL, *end = data + len;
gboolean ret = FALSE;
memset(addr, 0, sizeof(*addr));
}
static inline int
-rspamd_email_address_check_and_add(const gchar *start, gsize len,
+rspamd_email_address_check_and_add(const char *start, gsize len,
GPtrArray *res,
rspamd_mempool_t *pool,
GString *ns,
- gint max_elements)
+ int max_elements)
{
struct rspamd_email_address addr;
}
GPtrArray *
-rspamd_email_address_from_mime(rspamd_mempool_t *pool, const gchar *hdr,
- guint len,
+rspamd_email_address_from_mime(rspamd_mempool_t *pool, const char *hdr,
+ unsigned int len,
GPtrArray *src,
- gint max_elements)
+ int max_elements)
{
GPtrArray *res = src;
gboolean seen_at = FALSE, seen_obrace = FALSE;
- const gchar *p = hdr, *end = hdr + len, *c = hdr, *t;
+ const char *p = hdr, *end = hdr + len, *c = hdr, *t;
GString *ns, *cpy;
- gint obraces, ebraces;
+ int obraces, ebraces;
enum {
parse_name = 0,
parse_quoted,
if (*p == '"') {
/* We need to strip last spaces and update `ns` */
if (p > c) {
- guint nspaces = 0;
+ unsigned int nspaces = 0;
t = p - 1;
void rspamd_email_address_list_destroy(gpointer ptr)
{
GPtrArray *ar = ptr;
- guint i;
+ unsigned int i;
struct rspamd_email_address *addr;
PTR_ARRAY_FOREACH(ar, i, addr)
* Structure that represents email address in a convenient way
*/
struct rspamd_email_address {
- const gchar *raw;
- const gchar *addr;
- const gchar *user;
- const gchar *domain;
- const gchar *name;
+ const char *raw;
+ const char *addr;
+ const char *user;
+ const char *domain;
+ const char *name;
- guint raw_len;
- guint addr_len;
- guint domain_len;
- guint user_len;
- guint flags;
+ unsigned int raw_len;
+ unsigned int addr_len;
+ unsigned int domain_len;
+ unsigned int user_len;
+ unsigned int flags;
};
struct rspamd_task;
* @param len length of string
* @return
*/
-struct rspamd_email_address *rspamd_email_address_from_smtp(const gchar *str, guint len);
+struct rspamd_email_address *rspamd_email_address_from_smtp(const char *str, unsigned int len);
/**
* Parses email address from the mime header, decodes names and return the array
* @return
*/
GPtrArray *
-rspamd_email_address_from_mime(rspamd_mempool_t *pool, const gchar *hdr, guint len,
- GPtrArray *src, gint max_elements);
+rspamd_email_address_from_mime(rspamd_mempool_t *pool, const char *hdr, unsigned int len,
+ GPtrArray *src, int max_elements);
/**
* Destroys list of email addresses
static rspamd_lru_hash_t *images_hash = NULL;
#endif
-static const guint8 png_signature[] = {137, 80, 78, 71, 13, 10, 26, 10};
-static const guint8 jpg_sig1[] = {0xff, 0xd8};
-static const guint8 jpg_sig_jfif[] = {0xff, 0xe0};
-static const guint8 jpg_sig_exif[] = {0xff, 0xe1};
-static const guint8 gif_signature[] = {'G', 'I', 'F', '8'};
-static const guint8 bmp_signature[] = {'B', 'M'};
+static const uint8_t png_signature[] = {137, 80, 78, 71, 13, 10, 26, 10};
+static const uint8_t jpg_sig1[] = {0xff, 0xd8};
+static const uint8_t jpg_sig_jfif[] = {0xff, 0xe0};
+static const uint8_t jpg_sig_exif[] = {0xff, 0xe1};
+static const uint8_t gif_signature[] = {'G', 'I', 'F', '8'};
+static const uint8_t bmp_signature[] = {'B', 'M'};
static bool process_image(struct rspamd_task *task, struct rspamd_mime_part *part);
void rspamd_images_process(struct rspamd_task *task)
{
- guint i;
+ unsigned int i;
struct rspamd_mime_part *part;
PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, parts), i, part)
{
struct rspamd_image *img;
uint32_t t;
- const guint8 *p;
+ const uint8_t *p;
if (data->len < 24) {
msg_info_pool("bad png detected (maybe striped)");
static struct rspamd_image *
process_jpg_image(rspamd_mempool_t *pool, rspamd_ftok_t *data)
{
- const guint8 *p, *end;
- guint16 h, w;
+ const uint8_t *p, *end;
+ uint16_t h, w;
struct rspamd_image *img;
img = rspamd_mempool_alloc0(pool, sizeof(struct rspamd_image));
while (p < end) {
if (p[0] == 0xFF && p[1] != 0xFF) {
- guint len = p[2] * 256 + p[3];
+ unsigned int len = p[2] * 256 + p[3];
p++;
if (*p == 0xc0 || *p == 0xc1 || *p == 0xc2 || *p == 0xc3 ||
*p == 0xc9 || *p == 0xca || *p == 0xcb) {
- memcpy(&h, p + 4, sizeof(guint16));
+ memcpy(&h, p + 4, sizeof(uint16_t));
h = p[4] * 0xff + p[5];
img->height = h;
w = p[6] * 0xff + p[7];
process_gif_image(rspamd_mempool_t *pool, rspamd_ftok_t *data)
{
struct rspamd_image *img;
- const guint8 *p;
- guint16 t;
+ const uint8_t *p;
+ uint16_t t;
if (data->len < 10) {
msg_info_pool("bad gif detected (maybe striped)");
img->data = data;
p = data->begin + 6;
- memcpy(&t, p, sizeof(guint16));
+ memcpy(&t, p, sizeof(uint16_t));
img->width = GUINT16_FROM_LE(t);
- memcpy(&t, p + 2, sizeof(guint16));
+ memcpy(&t, p + 2, sizeof(uint16_t));
img->height = GUINT16_FROM_LE(t);
return img;
{
struct rspamd_image *img;
int32_t t;
- const guint8 *p;
+ const uint8_t *p;
if (data->len < 28) {
msg_info_pool("bad bmp detected (maybe striped)");
* http://unix4lyfe.org/dct/
*/
static void
-rspamd_image_dct_block(gint pixels[8][8], gdouble *out)
+rspamd_image_dct_block(int pixels[8][8], double *out)
{
- gint i;
- gint rows[8][8];
+ int i;
+ int rows[8][8];
- static const gint c1 = 1004 /* cos(pi/16) << 10 */,
- s1 = 200 /* sin(pi/16) */,
- c3 = 851 /* cos(3pi/16) << 10 */,
- s3 = 569 /* sin(3pi/16) << 10 */,
- r2c6 = 554 /* sqrt(2)*cos(6pi/16) << 10 */,
- r2s6 = 1337 /* sqrt(2)*sin(6pi/16) << 10 */,
- r2 = 181; /* sqrt(2) << 7*/
+ static const int c1 = 1004 /* cos(pi/16) << 10 */,
+ s1 = 200 /* sin(pi/16) */,
+ c3 = 851 /* cos(3pi/16) << 10 */,
+ s3 = 569 /* sin(3pi/16) << 10 */,
+ r2c6 = 554 /* sqrt(2)*cos(6pi/16) << 10 */,
+ r2s6 = 1337 /* sqrt(2)*sin(6pi/16) << 10 */,
+ r2 = 181; /* sqrt(2) << 7*/
- gint x0, x1, x2, x3, x4, x5, x6, x7, x8;
+ int x0, x1, x2, x3, x4, x5, x6, x7, x8;
/* transform rows */
for (i = 0; i < 8; i++) {
}
struct rspamd_image_cache_entry {
- guchar digest[64];
- guchar dct[RSPAMD_DCT_LEN / NBBY];
+ unsigned char digest[64];
+ unsigned char dct[RSPAMD_DCT_LEN / NBBY];
};
static void
{
#ifdef USABLE_GD
gdImagePtr src = NULL, dst = NULL;
- guint i, j, k, l;
- gdouble *dct;
+ unsigned int i, j, k, l;
+ double *dct;
if (img->data->len == 0 || img->data->len > G_MAXINT32) {
return;
gdImageDestroy(src);
img->is_normalized = TRUE;
- dct = g_malloc0(sizeof(gdouble) * RSPAMD_DCT_LEN);
+ dct = g_malloc0(sizeof(double) * RSPAMD_DCT_LEN);
img->dct = g_malloc0(RSPAMD_DCT_LEN / NBBY);
rspamd_mempool_add_destructor(task->task_pool, g_free,
img->dct);
*/
for (i = 0; i < RSPAMD_NORMALIZED_DIM; i += 8) {
for (j = 0; j < RSPAMD_NORMALIZED_DIM; j += 8) {
- gint p[8][8];
+ int p[8][8];
for (k = 0; k < 8; k++) {
p[k][0] = gdImageGetPixel(dst, i + k, j);
rspamd_image_dct_block(p,
dct + i * RSPAMD_NORMALIZED_DIM + j);
- gdouble avg = 0.0;
+ double avg = 0.0;
for (k = 0; k < 8; k++) {
for (l = 0; l < 8; l++) {
- gdouble x = *(dct +
- i * RSPAMD_NORMALIZED_DIM + j + k * 8 + l);
- avg += (x - avg) / (gdouble) (k * 8 + l + 1);
+ double x = *(dct +
+ i * RSPAMD_NORMALIZED_DIM + j + k * 8 + l);
+ avg += (x - avg) / (double) (k * 8 + l + 1);
}
}
for (k = 0; k < 8; k++) {
for (l = 0; l < 8; l++) {
- guint idx = i * RSPAMD_NORMALIZED_DIM + j + k * 8 + l;
+ unsigned int idx = i * RSPAMD_NORMALIZED_DIM + j + k * 8 + l;
if (dct[idx] >= avg) {
setbit(img->dct, idx);
return false;
}
-const gchar *
+const char *
rspamd_image_type_str(enum rspamd_image_type type)
{
switch (type) {
struct rspamd_mime_header *rh;
struct rspamd_mime_text_part *tp;
struct html_image *himg;
- const gchar *cid;
- guint cid_len, i;
+ const char *cid;
+ unsigned int cid_len, i;
struct rspamd_image *img;
img = (struct rspamd_image *) part->specific.img;
void rspamd_images_link(struct rspamd_task *task)
{
struct rspamd_mime_part *part;
- guint i;
+ unsigned int i;
PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, parts), i, part)
{
uint32_t width;
uint32_t height;
gboolean is_normalized;
- guchar *dct;
+ unsigned char *dct;
};
/*
/*
* Get textual representation of an image's type
*/
-const gchar *rspamd_image_type_str(enum rspamd_image_type type);
+const char *rspamd_image_type_str(enum rspamd_image_type type);
void rspamd_image_normalize(struct rspamd_task *task, struct rspamd_image *img);
static const gsize default_short_text_limit = 10;
static const gsize default_words = 80;
-static const gdouble update_prob = 0.6;
-static const gchar *default_languages_path = RSPAMD_SHAREDIR "/languages";
+static const double update_prob = 0.6;
+static const char *default_languages_path = RSPAMD_SHAREDIR "/languages";
#undef EXTRA_LANGDET_DEBUG
struct rspamd_language_unicode_match {
- const gchar *lang;
- gint unicode_code;
+ const char *lang;
+ int unicode_code;
};
/*
/*
* Top languages
*/
-static const gchar *tier0_langs[] = {
+static const char *tier0_langs[] = {
"en",
};
-static const gchar *tier1_langs[] = {
+static const char *tier1_langs[] = {
"fr", "it", "de", "es", "nl",
"pt", "ru", "pl", "tk", "th", "ar"};
};
struct rspamd_language_elt {
- const gchar *name; /* e.g. "en" or "ru" */
- gint flags; /* enum rspamd_language_elt_flags */
+ const char *name; /* e.g. "en" or "ru" */
+ int flags; /* enum rspamd_language_elt_flags */
enum rspamd_language_category category;
- guint trigrams_words;
- guint stop_words;
- gdouble mean;
- gdouble std;
- guint occurrences; /* total number of parts with this language */
+ unsigned int trigrams_words;
+ unsigned int stop_words;
+ double mean;
+ double std;
+ unsigned int occurrences; /* total number of parts with this language */
};
struct rspamd_ngramm_elt {
struct rspamd_language_elt *elt;
- gdouble prob;
+ double prob;
};
struct rspamd_ngramm_chain {
GPtrArray *languages;
- gdouble mean;
- gdouble std;
- gchar *utf;
+ double mean;
+ double std;
+ char *utf;
};
struct rspamd_stop_word_range {
- guint start;
- guint stop;
+ unsigned int start;
+ unsigned int stop;
struct rspamd_language_elt *elt;
};
INIT_LOG_MODULE_PUBLIC(langdet)
static const struct rspamd_language_unicode_match *
-rspamd_language_search_unicode_match(const gchar *key,
+rspamd_language_search_unicode_match(const char *key,
const struct rspamd_language_unicode_match *elts, size_t nelts)
{
size_t i;
}
static gboolean
-rspamd_language_search_str(const gchar *key, const gchar *elts[], size_t nelts)
+rspamd_language_search_str(const char *key, const char *elts[], size_t nelts)
{
size_t i;
return FALSE;
}
-static guint
+static unsigned int
rspamd_trigram_hash_func(gconstpointer key)
{
return rspamd_cryptobox_fast_hash(key, 3 * sizeof(UChar32),
KHASH_INIT(rspamd_trigram_hash, const UChar32 *, struct rspamd_ngramm_chain, true,
rspamd_trigram_hash_func, rspamd_trigram_equal_func);
-KHASH_INIT(rspamd_candidates_hash, const gchar *,
+KHASH_INIT(rspamd_candidates_hash, const char *,
struct rspamd_lang_detector_res *, true,
rspamd_str_hash, rspamd_str_equal);
KHASH_INIT(rspamd_stopwords_hash, rspamd_ftok_t *,
char, false,
rspamd_ftok_hash, rspamd_ftok_equal);
-KHASH_INIT(rspamd_languages_hash, const gchar *, struct rspamd_language_elt *, true,
+KHASH_INIT(rspamd_languages_hash, const char *, struct rspamd_language_elt *, true,
rspamd_str_hash, rspamd_str_equal);
struct rspamd_lang_detector {
khash_t(rspamd_languages_hash) * languages;
}
struct rspamd_language_ucs_elt {
- guint freq;
- const gchar *utf;
+ unsigned int freq;
+ const char *utf;
UChar32 s[0];
};
struct rspamd_lang_detector *d,
struct rspamd_language_elt *lelt,
struct rspamd_language_ucs_elt *ucs,
- guint len,
- guint freq,
- guint total,
+ unsigned int len,
+ unsigned int freq,
+ unsigned int total,
khash_t(rspamd_trigram_hash) * htb)
{
struct rspamd_ngramm_chain *chain = NULL, st_chain;
struct rspamd_ngramm_elt *elt;
khiter_t k;
- guint i;
+ unsigned int i;
gboolean found;
switch (len) {
chain->utf = rspamd_mempool_strdup(cfg->cfg_pool, ucs->utf);
elt = rspamd_mempool_alloc(cfg->cfg_pool, sizeof(*elt));
elt->elt = lelt;
- elt->prob = ((gdouble) freq) / ((gdouble) total);
+ elt->prob = ((double) freq) / ((double) total);
g_ptr_array_add(chain->languages, elt);
k = kh_put(rspamd_trigram_hash, htb, ucs->s, &i);
{
if (strcmp(elt->elt->name, lelt->name) == 0) {
found = TRUE;
- elt->prob += ((gdouble) freq) / ((gdouble) total);
+ elt->prob += ((double) freq) / ((double) total);
break;
}
}
if (!found) {
elt = rspamd_mempool_alloc(cfg->cfg_pool, sizeof(*elt));
elt->elt = lelt;
- elt->prob = ((gdouble) freq) / ((gdouble) total);
+ elt->prob = ((double) freq) / ((double) total);
g_ptr_array_add(chain->languages, elt);
}
}
}
static inline enum rspamd_language_category
-rspamd_language_detector_get_category(guint uflags)
+rspamd_language_detector_get_category(unsigned int uflags)
{
enum rspamd_language_category cat = RSPAMD_LANGUAGE_LATIN;
return cat;
}
-static const gchar *
+static const char *
rspamd_language_detector_print_flags(struct rspamd_language_elt *elt)
{
- static gchar flags_buf[256];
+ static char flags_buf[256];
goffset r = 0;
if (elt->flags & RS_LANGUAGE_TIER1) {
return flags_buf;
}
-static gint
+static int
rspamd_language_detector_cmp_ngramm(gconstpointer a, gconstpointer b)
{
struct rspamd_language_ucs_elt *e1 = *(struct rspamd_language_ucs_elt **) a;
struct rspamd_language_ucs_elt *e2 = *(struct rspamd_language_ucs_elt **) b;
- return (gint) e2->freq - (gint) e1->freq;
+ return (int) e2->freq - (int) e1->freq;
}
static void
rspamd_language_detector_read_file(struct rspamd_config *cfg,
struct rspamd_lang_detector *d,
- const gchar *path,
+ const char *path,
const ucl_object_t *stop_words)
{
struct ucl_parser *parser;
struct rspamd_language_elt *nelt;
struct rspamd_language_ucs_elt *ucs_elt;
khash_t(rspamd_trigram_hash) *htb = NULL;
- gchar *pos;
- guint total = 0, total_latin = 0, total_ngramms = 0, i, skipped,
- loaded;
- gdouble mean = 0, std = 0, delta = 0, delta2 = 0, m2 = 0;
+ char *pos;
+ unsigned int total = 0, total_latin = 0, total_ngramms = 0, i, skipped,
+ loaded;
+ double mean = 0, std = 0, delta = 0, delta2 = 0, m2 = 0;
enum rspamd_language_category cat = RSPAMD_LANGUAGE_MAX;
parser = ucl_parser_new(UCL_PARSER_NO_FILEVARS);
return;
}
else {
- const gchar *stype = ucl_object_tostring(type);
+ const char *stype = ucl_object_tostring(type);
if (strcmp(stype, "latin") == 0) {
cat = RSPAMD_LANGUAGE_LATIN;
const ucl_object_t *cur;
while ((cur = ucl_object_iterate(flags, &it, true)) != NULL) {
- const gchar *fl = ucl_object_tostring(cur);
+ const char *fl = ucl_object_tostring(cur);
if (cur) {
if (strcmp(fl, "diacritics") == 0) {
struct sb_stemmer *stem = NULL;
it = NULL;
const ucl_object_t *w;
- guint start, stop;
+ unsigned int start, stop;
stem = sb_stemmer_new(nelt->name, "UTF_8");
start = rspamd_multipattern_get_npatterns(d->stop_words[cat].mp);
gsize wlen;
const char *word = ucl_object_tolstring(w, &wlen);
const char *saved;
- guint mp_flags = RSPAMD_MULTIPATTERN_ICASE | RSPAMD_MULTIPATTERN_UTF8;
+ unsigned int mp_flags = RSPAMD_MULTIPATTERN_ICASE | RSPAMD_MULTIPATTERN_UTF8;
if (rspamd_multipattern_has_hyperscan()) {
mp_flags |= RSPAMD_MULTIPATTERN_RE;
}
if (saved) {
- gint rc;
+ int rc;
rspamd_ftok_t *tok;
- gchar *dst;
+ char *dst;
tok = rspamd_mempool_alloc(cfg->cfg_pool,
sizeof(*tok) + wlen + 1);
- dst = ((gchar *) tok) + sizeof(*tok);
+ dst = ((char *) tok) + sizeof(*tok);
rspamd_strlcpy(dst, saved, wlen + 1);
tok->begin = dst;
tok->len = wlen;
htb = d->trigrams[cat];
GPtrArray *ngramms;
- guint nsym;
+ unsigned int nsym;
if (rspamd_language_search_str(nelt->name, tier1_langs,
G_N_ELEMENTS(tier1_langs))) {
loaded = 0;
while ((cur = ucl_object_iterate(freqs, &it, true)) != NULL) {
- const gchar *key;
+ const char *key;
gsize keylen;
- guint freq;
+ unsigned int freq;
key = ucl_object_keyl(cur, &keylen);
freq = ucl_object_toint(cur);
if (!U_SUCCESS(uc_err)) {
msg_warn_config("cannot convert key %*s to unicode: %s",
- (gint) keylen, key, u_errorName(uc_err));
+ (int) keylen, key, u_errorName(uc_err));
continue;
}
"std=%.2f, mean=%.2f, skipped=%d, loaded=%d, stop_words=%d; "
"(%s)",
nelt->name,
- (gint) nelt->trigrams_words,
+ (int) nelt->trigrams_words,
total,
std, mean,
skipped, loaded, nelt->stop_words,
}
static gboolean
-rspamd_ucl_array_find_str(const gchar *str, const ucl_object_t *ar)
+rspamd_ucl_array_find_str(const char *str, const ucl_object_t *ar)
{
ucl_object_iter_t it = NULL;
const ucl_object_t *cur;
struct rspamd_ngramm_chain *chain)
{
struct rspamd_ngramm_elt *elt;
- guint i;
- gdouble delta, mean = 0, delta2, m2 = 0, std;
+ unsigned int i;
+ double delta, mean = 0, delta2, m2 = 0, std;
if (chain->languages->len > 3) {
PTR_ARRAY_FOREACH(chain->languages, i, elt)
rspamd_language_detector_dtor(struct rspamd_lang_detector *d)
{
if (d) {
- for (guint i = 0; i < RSPAMD_LANGUAGE_MAX; i++) {
+ for (unsigned int i = 0; i < RSPAMD_LANGUAGE_MAX; i++) {
kh_destroy(rspamd_trigram_hash, d->trigrams[i]);
rspamd_multipattern_destroy(d->stop_words[i].mp);
g_array_free(d->stop_words[i].ranges, TRUE);
{
const ucl_object_t *section, *elt, *languages_enable = NULL,
*languages_disable = NULL;
- const gchar *languages_path = default_languages_path;
+ const char *languages_path = default_languages_path;
glob_t gl;
size_t i, short_text_limit = default_short_text_limit, total = 0;
UErrorCode uc_err = U_ZERO_ERROR;
GString *languages_pattern;
struct rspamd_ngramm_chain *chain, schain;
- gchar *fname;
+ char *fname;
struct rspamd_lang_detector *ret = NULL;
struct ucl_parser *parser;
ucl_object_t *stop_words;
msg_info_config("loaded %d languages, "
"%d trigrams; %s",
- (gint) kh_size(ret->languages),
- (gint) total, fasttext_status);
+ (int) kh_size(ret->languages),
+ (int) total, fasttext_status);
g_free(fasttext_status);
if (stop_words) {
}
static void
-rspamd_language_detector_random_select(GArray *ucs_tokens, guint nwords,
+rspamd_language_detector_random_select(GArray *ucs_tokens, unsigned int nwords,
goffset *offsets_out,
uint64_t *seed)
{
- guint step_len, remainder, i, out_idx;
+ unsigned int step_len, remainder, i, out_idx;
uint64_t coin, sel;
rspamd_stat_token_t *tok;
for (i = step_len + remainder; i < ucs_tokens->len;
i += step_len, out_idx++) {
- guint ntries = 0;
+ unsigned int ntries = 0;
coin = rspamd_random_uint64_fast_seed(seed);
sel = (coin % step_len) + i;
static goffset
rspamd_language_detector_next_ngramm(rspamd_stat_token_t *tok, UChar32 *window,
- guint wlen, goffset cur_off)
+ unsigned int wlen, goffset cur_off)
{
- guint i;
+ unsigned int i;
if (wlen > 1) {
/* Deal with spaces at the beginning and ending */
khash_t(rspamd_candidates_hash) * candidates,
khash_t(rspamd_trigram_hash) * trigrams)
{
- guint i;
- gint ret;
+ unsigned int i;
+ int ret;
struct rspamd_ngramm_chain *chain = NULL;
struct rspamd_ngramm_elt *elt;
struct rspamd_lang_detector_res *cand;
khiter_t k;
- gdouble prob;
+ double prob;
k = kh_get(rspamd_trigram_hash, trigrams, window);
if (k != kh_end(trigrams)) {
khash_t(rspamd_candidates_hash) * candidates,
khash_t(rspamd_trigram_hash) * trigrams)
{
- const guint wlen = 3;
+ const unsigned int wlen = 3;
UChar32 window[3];
goffset cur = 0;
}
}
-static const gdouble cutoff_limit = -8.0;
+static const double cutoff_limit = -8.0;
/*
* Converts frequencies to log probabilities, filter those candidates who
* has the lowest probabilities
static inline void
rspamd_language_detector_filter_step1(struct rspamd_task *task,
struct rspamd_lang_detector_res *cand,
- gdouble *max_prob, guint *filtered)
+ double *max_prob, unsigned int *filtered)
{
if (!isnan(cand->prob)) {
if (cand->prob == 0) {
static inline void
rspamd_language_detector_filter_step2(struct rspamd_task *task,
struct rspamd_lang_detector_res *cand,
- gdouble max_prob, guint *filtered)
+ double max_prob, unsigned int *filtered)
{
/*
* Probabilities are logarithmic, so if prob1 - prob2 > 4, it means that
khash_t(rspamd_candidates_hash) * candidates)
{
struct rspamd_lang_detector_res *cand;
- guint filtered = 0;
- gdouble max_prob = -(G_MAXDOUBLE);
+ unsigned int filtered = 0;
+ double max_prob = -(G_MAXDOUBLE);
kh_foreach_value(candidates, cand,
rspamd_language_detector_filter_step1(task, cand, &max_prob, &filtered));
static void
rspamd_language_detector_detect_type(struct rspamd_task *task,
- guint nwords,
+ unsigned int nwords,
struct rspamd_lang_detector *d,
GArray *words,
enum rspamd_language_category cat,
khash_t(rspamd_candidates_hash) * candidates,
struct rspamd_mime_text_part *part)
{
- guint nparts = MIN(words->len, nwords);
+ unsigned int nparts = MIN(words->len, nwords);
goffset *selected_words;
rspamd_stat_token_t *tok;
- guint i;
+ unsigned int i;
uint64_t seed;
/* Seed PRNG with part digest to provide some sort of determinism */
g_free(selected_words);
}
-static gint
+static int
rspamd_language_detector_cmp(gconstpointer a, gconstpointer b)
{
const struct rspamd_lang_detector_res
static enum rspamd_language_detected_type
rspamd_language_detector_try_ngramm(struct rspamd_task *task,
- guint nwords,
+ unsigned int nwords,
struct rspamd_lang_detector *d,
GArray *ucs_tokens,
enum rspamd_language_category cat,
khash_t(rspamd_candidates_hash) * candidates,
struct rspamd_mime_text_part *part)
{
- guint cand_len = 0;
+ unsigned int cand_len = 0;
struct rspamd_lang_detector_res *cand;
rspamd_language_detector_detect_type(task,
struct rspamd_frequency_sort_cbdata {
struct rspamd_lang_detector *d;
enum rspamd_language_sort_flags flags;
- gdouble std;
- gdouble mean;
+ double std;
+ double mean;
};
-static const gdouble tier0_adjustment = 1.2;
-static const gdouble tier1_adjustment = 0.8;
-static const gdouble frequency_adjustment = 0.8;
+static const double tier0_adjustment = 1.2;
+static const double tier1_adjustment = 0.8;
+static const double frequency_adjustment = 0.8;
-static gint
+static int
rspamd_language_detector_cmp_heuristic(gconstpointer a, gconstpointer b,
gpointer ud)
{
struct rspamd_lang_detector_res
*canda = *(struct rspamd_lang_detector_res **) a,
*candb = *(struct rspamd_lang_detector_res **) b;
- gdouble adj;
- gdouble proba_adjusted, probb_adjusted, freqa, freqb;
+ double adj;
+ double proba_adjusted, probb_adjusted, freqa, freqb;
if (cbd->d->total_occurrences == 0) {
/* Not enough data, compare directly */
return rspamd_language_detector_cmp(a, b);
}
- freqa = ((gdouble) canda->elt->occurrences) /
- (gdouble) cbd->d->total_occurrences;
- freqb = ((gdouble) candb->elt->occurrences) /
- (gdouble) cbd->d->total_occurrences;
+ freqa = ((double) canda->elt->occurrences) /
+ (double) cbd->d->total_occurrences;
+ freqb = ((double) candb->elt->occurrences) /
+ (double) cbd->d->total_occurrences;
proba_adjusted = canda->prob;
probb_adjusted = candb->prob;
static void
rspamd_language_detector_unicode_scripts(struct rspamd_task *task,
struct rspamd_mime_text_part *part,
- guint *pchinese,
- guint *pspecial)
+ unsigned int *pchinese,
+ unsigned int *pspecial)
{
- const gchar *p = part->utf_stripped_content->data, *end;
- guint i = 0, cnt = 0;
+ const char *p = part->utf_stripped_content->data, *end;
+ unsigned int i = 0, cnt = 0;
end = p + part->utf_stripped_content->len;
int32_t uc, sc;
- guint nlatin = 0, nchinese = 0, nspecial = 0;
- const guint cutoff_limit = 32;
+ unsigned int nlatin = 0, nchinese = 0, nspecial = 0;
+ const unsigned int cutoff_limit = 32;
while (p + i < end) {
U8_NEXT(p, i, part->utf_stripped_content->len, uc);
static inline void
rspamd_language_detector_set_language(struct rspamd_task *task,
struct rspamd_mime_text_part *part,
- const gchar *code,
+ const char *code,
struct rspamd_language_elt *elt)
{
struct rspamd_lang_detector_res *r;
static gboolean
rspamd_language_detector_try_uniscript(struct rspamd_task *task,
struct rspamd_mime_text_part *part,
- guint nchinese,
- guint nspecial)
+ unsigned int nchinese,
+ unsigned int nspecial)
{
- guint i;
+ unsigned int i;
for (i = 0; i < G_N_ELEMENTS(unicode_langs); i++) {
if (unicode_langs[i].unicode_code & part->unicode_scripts) {
return FALSE;
}
-static guint
+static unsigned int
rspamd_langelt_hash_func(gconstpointer key)
{
const struct rspamd_language_elt *elt = (const struct rspamd_language_elt *) key;
GArray *ranges;
};
-static gint
+static int
rspamd_ranges_cmp(const void *k, const void *memb)
{
- gint pos = GPOINTER_TO_INT(k);
+ int pos = GPOINTER_TO_INT(k);
const struct rspamd_stop_word_range *r = (struct rspamd_stop_word_range *) memb;
if (pos >= r->start && pos < r->stop) {
return 1;
}
-static gint
+static int
rspamd_language_detector_sw_cb(struct rspamd_multipattern *mp,
- guint strnum,
- gint match_start,
- gint match_pos,
- const gchar *text,
+ unsigned int strnum,
+ int match_start,
+ int match_pos,
+ const char *text,
gsize len,
void *context)
{
/* Check if boundary */
- const gchar *prev = text, *next = text + len;
+ const char *prev = text, *next = text + len;
struct rspamd_stop_word_range *r;
struct rspamd_sw_cbdata *cbdata = (struct rspamd_sw_cbdata *) context;
khiter_t k;
g_assert(r != NULL);
k = kh_get(rspamd_sw_hash, cbdata->res, r->elt);
- gint nwords = 1;
+ int nwords = 1;
if (k != kh_end(cbdata->res)) {
khiter_t set_k;
}
}
else {
- gint tt;
+ int tt;
k = kh_put(rspamd_sw_hash, cbdata->res, r->elt, &tt);
kh_value(cbdata->res, k) = kh_init(rspamd_sw_res_set);
{
khash_t(rspamd_candidates_hash) * candidates;
GPtrArray *result;
- gdouble mean, std, start_ticks, end_ticks;
- guint cand_len;
+ double mean, std, start_ticks, end_ticks;
+ unsigned int cand_len;
enum rspamd_language_category cat;
struct rspamd_lang_detector_res *cand;
enum rspamd_language_detected_type r;
start_ticks = rspamd_get_ticks(TRUE);
- guint nchinese = 0, nspecial = 0;
+ unsigned int nchinese = 0, nspecial = 0;
rspamd_language_detector_unicode_scripts(task, part, &nchinese, &nspecial);
/* Disable internal language detection heuristics if we have fasttext */
mean /= cand_len;
kh_foreach_value(candidates, cand, {
- gdouble err;
+ double err;
if (!isnan(cand->prob)) {
err = cand->prob - mean;
std += fabs(err);
gboolean
rspamd_language_detector_is_stop_word(struct rspamd_lang_detector *d,
- const gchar *word, gsize wlen)
+ const char *word, gsize wlen)
{
khiter_t k;
rspamd_ftok_t search;
return FALSE;
}
-gint rspamd_language_detector_elt_flags(const struct rspamd_language_elt *elt)
+int rspamd_language_detector_elt_flags(const struct rspamd_language_elt *elt)
{
if (elt) {
return elt->flags;
};
struct rspamd_lang_detector_res {
- gdouble prob;
- const gchar *lang;
+ double prob;
+ const char *lang;
struct rspamd_language_elt *elt;
};
* @return
*/
gboolean rspamd_language_detector_is_stop_word(struct rspamd_lang_detector *d,
- const gchar *word, gsize wlen);
+ const char *word, gsize wlen);
/**
* Return language flags for a specific language elt
* @param elt
* @return
*/
-gint rspamd_language_detector_elt_flags(const struct rspamd_language_elt *elt);
+int rspamd_language_detector_elt_flags(const struct rspamd_language_elt *elt);
#ifdef __cplusplus
}
#endif
return nullptr;
#else
/* Avoid too long inputs */
- static const guint max_fasttext_input_len = 1024 * 1024;
+ static const unsigned int max_fasttext_input_len = 1024 * 1024;
auto *real_model = FASTTEXT_MODEL_TO_C_API(ud);
std::vector<std::int32_t> words_vec;
words_vec.reserve(utf_words->len);
}
-guint rspamd_lang_detection_fasttext_get_nlangs(rspamd_fasttext_predict_result_t res)
+unsigned int rspamd_lang_detection_fasttext_get_nlangs(rspamd_fasttext_predict_result_t res)
{
#ifdef WITH_FASTTEXT
auto *real_res = FASTTEXT_RESULT_TO_C_API(res);
* @param ud
* @return
*/
-guint rspamd_lang_detection_fasttext_get_nlangs(rspamd_fasttext_predict_result_t ud);
+unsigned int rspamd_lang_detection_fasttext_get_nlangs(rspamd_fasttext_predict_result_t ud);
/**
* Get language from fasttext result
* @param res
#define SET_PART_RAW(part) ((part)->flags &= ~RSPAMD_MIME_TEXT_PART_FLAG_UTF)
#define SET_PART_UTF(part) ((part)->flags |= RSPAMD_MIME_TEXT_PART_FLAG_UTF)
-static const gchar gtube_pattern_reject[] = "XJS*C4JDBQADN1.NSBN3*2IDNEN*"
- "GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X";
-static const gchar gtube_pattern_add_header[] = "YJS*C4JDBQADN1.NSBN3*2IDNEN*"
- "GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X";
-static const gchar gtube_pattern_rewrite_subject[] = "ZJS*C4JDBQADN1.NSBN3*2IDNEN*"
- "GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X";
-static const gchar gtube_pattern_no_action[] = "AJS*C4JDBQADN1.NSBN3*2IDNEN*"
+static const char gtube_pattern_reject[] = "XJS*C4JDBQADN1.NSBN3*2IDNEN*"
+ "GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X";
+static const char gtube_pattern_add_header[] = "YJS*C4JDBQADN1.NSBN3*2IDNEN*"
"GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X";
+static const char gtube_pattern_rewrite_subject[] = "ZJS*C4JDBQADN1.NSBN3*2IDNEN*"
+ "GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X";
+static const char gtube_pattern_no_action[] = "AJS*C4JDBQADN1.NSBN3*2IDNEN*"
+ "GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X";
struct rspamd_multipattern *gtube_matcher = NULL;
static const uint64_t words_hash_seed = 0xdeadbabe;
struct rspamd_mime_text_part *part)
{
rspamd_stat_token_t *w;
- guint i, total_len = 0, short_len = 0;
+ unsigned int i, total_len = 0, short_len = 0;
if (part->utf_words) {
rspamd_stem_words(part->utf_words, task->task_pool, part->language,
}
if (part->utf_words->len) {
- gdouble *avg_len_p, *short_len_p;
+ double *avg_len_p, *short_len_p;
avg_len_p = rspamd_mempool_get_variable(task->task_pool,
RSPAMD_MEMPOOL_AVG_WORDS_LEN);
#if U_ICU_VERSION_MAJOR_NUM < 50
/* Hack to prevent hang with Thai in old libicu */
- const gchar *p = part->utf_stripped_content->data, *end;
- guint i = 0;
+ const char *p = part->utf_stripped_content->data, *end;
+ unsigned int i = 0;
end = p + part->utf_stripped_content->len;
int32_t uc, sc;
static void
rspamd_strip_newlines_parse(struct rspamd_task *task,
- const gchar *begin, const gchar *pe,
+ const char *begin, const char *pe,
struct rspamd_mime_text_part *part)
{
- const gchar *p = begin, *c = begin;
+ const char *p = begin, *c = begin;
gboolean crlf_added = FALSE, is_utf = IS_TEXT_PART_UTF(part);
gboolean url_open_bracket = FALSE;
UChar32 uc;
if (p > c) {
g_byte_array_append(part->utf_stripped_content,
- (const guint8 *) c, p - c);
+ (const uint8_t *) c, p - c);
c = begin + off;
p = c;
}
state = seen_cr;
if (p > c) {
g_byte_array_append(part->utf_stripped_content,
- (const guint8 *) c, p - c);
+ (const uint8_t *) c, p - c);
}
crlf_added = FALSE;
/* Double \r\r */
if (!crlf_added) {
g_byte_array_append(part->utf_stripped_content,
- (const guint8 *) " ", 1);
+ (const uint8_t *) " ", 1);
crlf_added = TRUE;
g_ptr_array_add(part->newlines,
(((gpointer) (goffset) (part->utf_stripped_content->len))));
if (p > c) {
g_byte_array_append(part->utf_stripped_content,
- (const guint8 *) c, p - c);
+ (const uint8_t *) c, p - c);
}
c = p + 1;
if (IS_TEXT_PART_HTML(part) || !url_open_bracket) {
g_byte_array_append(part->utf_stripped_content,
- (const guint8 *) " ", 1);
+ (const uint8_t *) " ", 1);
g_ptr_array_add(part->newlines,
(((gpointer) (goffset) (part->utf_stripped_content->len))));
crlf_added = TRUE;
if (!crlf_added) {
if (IS_TEXT_PART_HTML(part) || !url_open_bracket) {
g_byte_array_append(part->utf_stripped_content,
- (const guint8 *) " ", 1);
+ (const uint8_t *) " ", 1);
crlf_added = TRUE;
}
/* Double \n\n */
if (!crlf_added) {
g_byte_array_append(part->utf_stripped_content,
- (const guint8 *) " ", 1);
+ (const uint8_t *) " ", 1);
crlf_added = TRUE;
g_ptr_array_add(part->newlines,
(((gpointer) (goffset) (part->utf_stripped_content->len))));
if (*p == ' ') {
if (!crlf_added) {
g_byte_array_append(part->utf_stripped_content,
- (const guint8 *) " ", 1);
+ (const uint8_t *) " ", 1);
}
while (p < pe && *p == ' ') {
switch (state) {
case normal_char:
g_byte_array_append(part->utf_stripped_content,
- (const guint8 *) c, p - c);
+ (const uint8_t *) c, p - c);
while (c < p) {
if (*c == ' ') {
if (!crlf_added) {
g_byte_array_append(part->utf_stripped_content,
- (const guint8 *) " ", 1);
+ (const uint8_t *) " ", 1);
g_ptr_array_add(part->newlines,
(((gpointer) (goffset) (part->utf_stripped_content->len))));
}
rspamd_normalize_text_part(struct rspamd_task *task,
struct rspamd_mime_text_part *part)
{
- const gchar *p, *end;
- guint i;
+ const char *p, *end;
+ unsigned int i;
goffset off;
struct rspamd_process_exception *ex;
UErrorCode uc_err = U_ZERO_ERROR;
else {
part->utf_stripped_content = g_byte_array_sized_new(part->utf_content.len);
- p = (const gchar *) part->utf_content.begin;
+ p = (const char *) part->utf_content.begin;
end = p + part->utf_content.len;
rspamd_strip_newlines_parse(task, p, end, part);
#define MIN3(a, b, c) ((a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c)))
-static guint
+static unsigned int
rspamd_words_levenshtein_distance(struct rspamd_task *task,
GArray *w1, GArray *w2)
{
- guint s1len, s2len, x, y, lastdiag, olddiag;
- guint *column, ret;
+ unsigned int s1len, s2len, x, y, lastdiag, olddiag;
+ unsigned int *column, ret;
uint64_t h1, h2;
- gint eq;
- static const guint max_words = 8192;
+ int eq;
+ static const unsigned int max_words = 8192;
s1len = w1->len;
s2len = w2->len;
}
}
- column = g_malloc0((s1len + 1) * sizeof(guint));
+ column = g_malloc0((s1len + 1) * sizeof(unsigned int));
for (y = 1; y <= s1len; y++) {
column[y] = y;
return ret;
}
-static gint
+static int
rspamd_multipattern_gtube_cb(struct rspamd_multipattern *mp,
- guint strnum,
- gint match_start,
- gint match_pos,
- const gchar *text,
+ unsigned int strnum,
+ int match_start,
+ int match_pos,
+ const char *text,
gsize len,
void *context)
{
rspamd_check_gtube(struct rspamd_task *task, struct rspamd_mime_text_part *part)
{
static const gsize max_check_size = 8 * 1024;
- gint ret;
+ int ret;
enum rspamd_action_type act = METRIC_ACTION_NOACTION;
enum rspamd_gtube_patterns_policy policy = task->cfg ? task->cfg->gtube_patterns_policy : RSPAMD_GTUBE_REJECT;
g_assert(part != NULL);
return act;
}
-static gint
+static int
exceptions_compare_func(gconstpointer a, gconstpointer b)
{
const struct rspamd_process_exception *ea = a, *eb = b;
if (text_part->utf_raw_content != NULL) {
/* Just have the same content */
- text_part->utf_content.begin = (const gchar *) text_part->utf_raw_content->data;
+ text_part->utf_content.begin = (const char *) text_part->utf_raw_content->data;
text_part->utf_content.len = text_part->utf_raw_content->len;
}
else {
uint16_t *cur_url_order)
{
struct rspamd_mime_text_part *text_part;
- guint flags = 0;
+ unsigned int flags = 0;
enum rspamd_action_type act;
/* Skip attachments */
act = rspamd_check_gtube(task, text_part);
if (act != METRIC_ACTION_NOACTION) {
struct rspamd_action *action;
- gdouble score = NAN;
+ double score = NAN;
action = rspamd_config_get_action_by_type(task->cfg, act);
/* Creates message from various data using libmagic to detect type */
static void
-rspamd_message_from_data(struct rspamd_task *task, const guchar *start,
+rspamd_message_from_data(struct rspamd_task *task, const unsigned char *start,
gsize len)
{
struct rspamd_content_type *ct = NULL;
struct rspamd_mime_part *part;
const char *mb = "application/octet-stream";
- gchar *mid;
+ char *mid;
rspamd_ftok_t srch, *tok;
- gchar cdbuf[1024];
+ char cdbuf[1024];
g_assert(start != NULL);
static void
rspamd_message_dtor(struct rspamd_message *msg)
{
- guint i;
+ unsigned int i;
struct rspamd_mime_part *p;
struct rspamd_mime_text_part *tp;
gboolean
rspamd_message_parse(struct rspamd_task *task)
{
- const gchar *p;
+ const char *p;
gsize len;
- guint i;
+ unsigned int i;
GError *err = NULL;
uint64_t n[2], seed;
enum rspamd_mime_parse_error ret;
debug_task("construct mime parser from string length %d",
- (gint) task->msg.len);
+ (int) task->msg.len);
ret = rspamd_mime_parse_task(task, &err);
switch (ret) {
struct rspamd_mime_part *part;
/* Blake2b applied to string 'rspamd' */
- static const guchar RSPAMD_ALIGNED(32) hash_key[] = {
+ static const unsigned char RSPAMD_ALIGNED(32) hash_key[] = {
0xef,
0x43,
0xae,
msg_info_task("loaded message; id: <%s>; queue-id: <%s>; size: %z; "
"checksum: <%*xs>",
MESSAGE_FIELD(task, message_id), task->queue_id, task->msg.len,
- (gint) sizeof(MESSAGE_FIELD(task, digest)), MESSAGE_FIELD(task, digest));
+ (int) sizeof(MESSAGE_FIELD(task, digest)), MESSAGE_FIELD(task, digest));
}
else {
msg_info_task("loaded message; id: <%s>; size: %z; "
"checksum: <%*xs>",
MESSAGE_FIELD(task, message_id), task->msg.len,
- (gint) sizeof(MESSAGE_FIELD(task, digest)), MESSAGE_FIELD(task, digest));
+ (int) sizeof(MESSAGE_FIELD(task, digest)), MESSAGE_FIELD(task, digest));
}
return TRUE;
void rspamd_message_process(struct rspamd_task *task)
{
- guint i;
+ unsigned int i;
struct rspamd_mime_text_part *p1, *p2;
- gdouble diff, *pdiff;
- guint tw, *ptw, dw;
+ double diff, *pdiff;
+ unsigned int tw, *ptw, dw;
struct rspamd_mime_part *part;
lua_State *L = NULL;
- gint magic_func_pos = -1, content_func_pos = -1, old_top = -1, funcs_top = -1;
+ int magic_func_pos = -1, content_func_pos = -1, old_top = -1, funcs_top = -1;
if (task->cfg) {
L = task->cfg->lua_state;
struct rspamd_task **ptask;
lua_pushcfunction(L, &rspamd_lua_traceback);
- gint err_idx = lua_gettop(L);
+ int err_idx = lua_gettop(L);
lua_pushvalue(L, magic_func_pos);
pmime = lua_newuserdata(L, sizeof(struct rspamd_mime_part *));
rspamd_lua_setclass(L, rspamd_mimepart_classname, -1);
}
else {
if (lua_istable(L, -1)) {
- const gchar *mb;
+ const char *mb;
/* First returned value */
part->detected_ext = rspamd_mempool_strdup(task->task_pool,
struct rspamd_task **ptask;
lua_pushcfunction(L, &rspamd_lua_traceback);
- gint err_idx = lua_gettop(L);
+ int err_idx = lua_gettop(L);
lua_pushvalue(L, content_func_pos);
pmime = lua_newuserdata(L, sizeof(struct rspamd_mime_part *));
rspamd_lua_setclass(L, rspamd_mimepart_classname, -1);
/* Calculate average words length and number of short words */
struct rspamd_mime_text_part *text_part;
- gdouble *var;
- guint total_words = 0;
+ double *var;
+ unsigned int total_words = 0;
PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, text_parts), i, text_part)
{
dw = rspamd_words_levenshtein_distance(task,
p1->normalized_hashes,
p2->normalized_hashes);
- diff = dw / (gdouble) tw;
+ diff = dw / (double) tw;
msg_debug_task(
"different words: %d, total words: %d, "
diff);
pdiff = rspamd_mempool_alloc(task->task_pool,
- sizeof(gdouble));
+ sizeof(double));
*pdiff = diff;
rspamd_mempool_set_variable(task->task_pool,
"parts_distance",
pdiff,
NULL);
ptw = rspamd_mempool_alloc(task->task_pool,
- sizeof(gint));
+ sizeof(int));
*ptw = tw;
rspamd_mempool_set_variable(task->task_pool,
"total_words",
};
struct rspamd_lua_specific_part {
- gint cbref;
+ int cbref;
enum rspamd_lua_specific_type type;
};
struct rspamd_mime_part {
struct rspamd_content_type *ct;
struct rspamd_content_type *detected_ct;
- gchar *detected_type;
- gchar *detected_ext;
+ char *detected_type;
+ char *detected_ext;
struct rspamd_content_disposition *cd;
rspamd_ftok_t raw_data;
rspamd_ftok_t parsed_data;
struct rspamd_mime_headers_table *raw_headers;
GPtrArray *urls;
- gchar *raw_headers_str;
+ char *raw_headers_str;
gsize raw_headers_len;
enum rspamd_cte cte;
- guint flags;
+ unsigned int flags;
enum rspamd_mime_part_type part_type;
- guint part_number;
+ unsigned int part_number;
union {
struct rspamd_mime_multipart *mp;
struct rspamd_lua_specific_part lua_specific;
} specific;
- guchar digest[rspamd_cryptobox_HASHBYTES];
+ unsigned char digest[rspamd_cryptobox_HASHBYTES];
};
#define RSPAMD_MIME_TEXT_PART_FLAG_UTF (1 << 0)
struct rspamd_mime_text_part {
- const gchar *language;
+ const char *language;
GPtrArray *languages;
- const gchar *real_charset;
+ const char *real_charset;
/* Raw data in native encoding */
rspamd_ftok_t raw;
GList *exceptions; /**< list of offsets of urls */
struct rspamd_mime_part *mime_part;
- guint flags;
- guint nlines;
- guint spaces;
- guint nwords;
- guint non_ascii_chars;
- guint ascii_chars;
- guint double_spaces;
- guint non_spaces;
- guint empty_lines;
- guint capital_letters;
- guint numeric_characters;
- guint unicode_scripts;
+ unsigned int flags;
+ unsigned int nlines;
+ unsigned int spaces;
+ unsigned int nwords;
+ unsigned int non_ascii_chars;
+ unsigned int ascii_chars;
+ unsigned int double_spaces;
+ unsigned int non_spaces;
+ unsigned int empty_lines;
+ unsigned int capital_letters;
+ unsigned int numeric_characters;
+ unsigned int unicode_scripts;
};
struct rspamd_message_raw_headers_content {
- const gchar *begin;
+ const char *begin;
gsize len;
- const gchar *body_start;
+ const char *body_start;
};
struct rspamd_message {
- const gchar *message_id;
- gchar *subject;
+ const char *message_id;
+ char *subject;
GPtrArray *parts; /**< list of parsed parts */
GPtrArray *text_parts; /**< list of text parts */
struct rspamd_task *task;
GPtrArray *rcpt_mime;
GPtrArray *from_mime;
- guchar digest[16];
+ unsigned char digest[16];
enum rspamd_newlines_type nlines_type; /**< type of newlines (detected on most of headers */
ref_entry_t ref;
};
* @param str
* @return
*/
-enum rspamd_cte rspamd_cte_from_string(const gchar *str);
+enum rspamd_cte rspamd_cte_from_string(const char *str);
/**
* Converts cte to string
* @param ct
* @return
*/
-const gchar *rspamd_cte_to_string(enum rspamd_cte ct);
+const char *rspamd_cte_to_string(enum rspamd_cte ct);
struct rspamd_message *rspamd_message_new(struct rspamd_task *task);
static rspamd_regexp_t *utf_compatible_re = NULL;
struct rspamd_charset_substitution {
- const gchar *input;
- const gchar *canon;
- gint flags;
+ const char *input;
+ const char *canon;
+ int flags;
};
#include "mime_encoding_list.h"
0x0171, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x0119, 0x021B, 0x00FF};
struct rspamd_charset_converter {
- gchar *canon_name;
+ char *canon_name;
union {
UConverter *conv;
const UChar *cnv_table;
}
else {
UChar *d = dest, *dend = dest + destCapacity;
- const guchar *p = src, *end = src + srcLength;
+ const unsigned char *p = src, *end = src + srcLength;
while (p < end && d < dend) {
if (*p <= 127) {
struct rspamd_charset_converter *
-rspamd_mime_get_converter_cached(const gchar *enc,
+rspamd_mime_get_converter_cached(const char *enc,
rspamd_mempool_t *pool,
gboolean is_canon,
UErrorCode *err)
{
- const gchar *canon_name;
+ const char *canon_name;
static rspamd_lru_hash_t *cache;
struct rspamd_charset_converter *conv;
static void
rspamd_mime_encoding_substitute_init(void)
{
- guint i;
+ unsigned int i;
sub_hash = g_hash_table_new(rspamd_strcase_hash, rspamd_strcase_equal);
}
static void
-rspamd_charset_normalize(gchar *in)
+rspamd_charset_normalize(char *in)
{
/*
* This is a simple routine to validate input charset
* we just check that charset starts with alphanumeric and ends
* with alphanumeric
*/
- gchar *begin, *end;
+ char *begin, *end;
gboolean changed = FALSE;
begin = in;
}
}
-const gchar *
+const char *
rspamd_mime_detect_charset(const rspamd_ftok_t *in, rspamd_mempool_t *pool)
{
- gchar *ret = NULL, *h, *t;
+ char *ret = NULL, *h, *t;
struct rspamd_charset_substitution *s;
- const gchar *cset;
+ const char *cset;
rspamd_ftok_t utf8_tok;
UErrorCode uc_err = U_ZERO_ERROR;
return cset;
}
-gchar *
+char *
rspamd_mime_text_to_utf8(rspamd_mempool_t *pool,
- gchar *input, gsize len, const gchar *in_enc,
+ char *input, gsize len, const char *in_enc,
gsize *olen, GError **err)
{
- gchar *d;
+ char *d;
int32_t r, clen, dlen;
UChar *tmp_buf;
rspamd_mime_text_part_utf8_convert(struct rspamd_task *task,
struct rspamd_mime_text_part *text_part,
GByteArray *input,
- const gchar *charset,
+ const char *charset,
GError **err)
{
- gchar *d;
+ char *d;
int32_t r, clen, dlen, uc_len;
UChar *tmp_buf;
UErrorCode uc_err = U_ZERO_ERROR;
rspamd_mime_to_utf8_byte_array(GByteArray *in,
GByteArray *out,
rspamd_mempool_t *pool,
- const gchar *enc)
+ const char *enc)
{
int32_t r, clen, dlen;
UChar *tmp_buf;
RSPAMD_FTOK_FROM_STR(&charset_tok, enc);
- if (rspamd_mime_charset_utf_check(&charset_tok, (gchar *) in->data, in->len,
+ if (rspamd_mime_charset_utf_check(&charset_tok, (char *) in->data, in->len,
FALSE)) {
g_byte_array_set_size(out, in->len);
memcpy(out->data, in->data, out->len);
return TRUE;
}
-void rspamd_mime_charset_utf_enforce(gchar *in, gsize len)
+void rspamd_mime_charset_utf_enforce(char *in, gsize len)
{
- gchar *p, *end;
+ char *p, *end;
goffset err_offset;
UChar32 uc = 0;
}
const char *
-rspamd_mime_charset_find_by_content(const gchar *in, gsize inlen,
+rspamd_mime_charset_find_by_content(const char *in, gsize inlen,
bool check_utf8)
{
int nconsumed;
bool is_reliable;
- const gchar *ced_name;
+ const char *ced_name;
if (check_utf8) {
if (rspamd_fast_utf8_validate(in, inlen) == 0) {
}
static const char *
-rspamd_mime_charset_find_by_content_maybe_split(const gchar *in, gsize inlen)
+rspamd_mime_charset_find_by_content_maybe_split(const char *in, gsize inlen)
{
if (inlen < RSPAMD_CHARSET_MAX_CONTENT * 3) {
return rspamd_mime_charset_find_by_content(in, inlen, false);
}
else {
- const gchar *c1, *c2, *c3;
+ const char *c1, *c2, *c3;
c1 = rspamd_mime_charset_find_by_content(in, RSPAMD_CHARSET_MAX_CONTENT, false);
c2 = rspamd_mime_charset_find_by_content(in + inlen / 2,
gboolean
rspamd_mime_charset_utf_check(rspamd_ftok_t *charset,
- gchar *in, gsize len, gboolean content_check)
+ char *in, gsize len, gboolean content_check)
{
- const gchar *real_charset;
+ const char *real_charset;
if (utf_compatible_re == NULL) {
utf_compatible_re = rspamd_regexp_new(
struct rspamd_mime_text_part *text_part)
{
GError *err = NULL;
- const gchar *charset = NULL;
+ const char *charset = NULL;
gboolean checked = FALSE, need_charset_heuristic = TRUE, valid_utf8 = FALSE;
GByteArray *part_content;
rspamd_ftok_t charset_tok;
* @param in
* @return
*/
-const gchar *rspamd_mime_detect_charset(const rspamd_ftok_t *in,
- rspamd_mempool_t *pool);
+const char *rspamd_mime_detect_charset(const rspamd_ftok_t *in,
+ rspamd_mempool_t *pool);
/**
* Convert text chunk to utf-8. Input encoding is substituted using
* @param err
* @return
*/
-gchar *rspamd_mime_text_to_utf8(rspamd_mempool_t *pool,
- gchar *input, gsize len, const gchar *in_enc,
- gsize *olen, GError **err);
+char *rspamd_mime_text_to_utf8(rspamd_mempool_t *pool,
+ char *input, gsize len, const char *in_enc,
+ gsize *olen, GError **err);
/**
* Converts data from `in` to `out`,
gboolean rspamd_mime_to_utf8_byte_array(GByteArray *in,
GByteArray *out,
rspamd_mempool_t *pool,
- const gchar *enc);
+ const char *enc);
/**
* Maybe convert part to utf-8
* @return
*/
gboolean rspamd_mime_charset_utf_check(rspamd_ftok_t *charset,
- gchar *in, gsize len,
+ char *in, gsize len,
gboolean content_check);
/**
* @param in
* @param len
*/
-void rspamd_mime_charset_utf_enforce(gchar *in, gsize len);
+void rspamd_mime_charset_utf_enforce(char *in, gsize len);
/**
* Gets cached converter
* @return converter
*/
struct rspamd_charset_converter *rspamd_mime_get_converter_cached(
- const gchar *enc,
+ const char *enc,
rspamd_mempool_t *pool,
gboolean is_canon,
UErrorCode *err);
* @param inlen
* @return detected charset name or NULL
*/
-const char *rspamd_mime_charset_find_by_content(const gchar *in, gsize inlen,
+const char *rspamd_mime_charset_find_by_content(const char *in, gsize inlen,
bool check_utf8);
#ifdef __cplusplus
GArray *args,
void *unused);
-static rspamd_expression_atom_t *rspamd_mime_expr_parse(const gchar *line, gsize len,
+static rspamd_expression_atom_t *rspamd_mime_expr_parse(const char *line, gsize len,
rspamd_mempool_t *pool, gpointer ud, GError **err);
-static gdouble rspamd_mime_expr_process(void *ud, rspamd_expression_atom_t *atom);
-static gint rspamd_mime_expr_priority(rspamd_expression_atom_t *atom);
+static double rspamd_mime_expr_process(void *ud, rspamd_expression_atom_t *atom);
+static int rspamd_mime_expr_priority(rspamd_expression_atom_t *atom);
static void rspamd_mime_expr_destroy(rspamd_expression_atom_t *atom);
/**
*/
struct rspamd_regexp_atom {
enum rspamd_re_type type; /**< regexp type */
- gchar *regexp_text; /**< regexp text representation */
+ char *regexp_text; /**< regexp text representation */
rspamd_regexp_t *regexp; /**< regexp structure */
union {
- const gchar *header; /**< header name for header regexps */
- const gchar *selector; /**< selector name for lua selector regexp */
+ const char *header; /**< header name for header regexps */
+ const char *selector; /**< selector name for lua selector regexp */
} extra;
gboolean is_test; /**< true if this expression must be tested */
gboolean is_strong; /**< true if headers search must be case sensitive */
* Rspamd expression function
*/
struct rspamd_function_atom {
- gchar *name; /**< name of function */
+ char *name; /**< name of function */
GArray *args; /**< its args */
};
};
struct rspamd_mime_atom {
- gchar *str;
+ char *str;
union {
struct rspamd_regexp_atom *re;
struct rspamd_function_atom *func;
- const gchar *lua_function;
- gint lua_cbref;
+ const char *lua_function;
+ int lua_cbref;
} d;
enum rspamd_mime_atom_type type;
};
* Sorted by name to use bsearch
*/
static struct _fl {
- const gchar *name;
+ const char *name;
rspamd_internal_func_t func;
void *user_data;
} rspamd_functions_list[] = {
static gboolean list_allocated = FALSE;
/* Bsearch routine */
-static gint
+static int
fl_cmp(const void *s1, const void *s2)
{
struct _fl *fl1 = (struct _fl *) s1;
#define TYPE_CHECK(str, type, len) (sizeof(type) - 1 == (len) && rspamd_lc_cmp((str), (type), (len)) == 0)
static gboolean
-rspamd_parse_long_option(const gchar *start, gsize len,
+rspamd_parse_long_option(const char *start, gsize len,
struct rspamd_regexp_atom *a)
{
gboolean ret = FALSE;
* Rspamd regexp utility functions
*/
static struct rspamd_regexp_atom *
-rspamd_mime_expr_parse_regexp_atom(rspamd_mempool_t *pool, const gchar *line,
+rspamd_mime_expr_parse_regexp_atom(rspamd_mempool_t *pool, const char *line,
struct rspamd_config *cfg)
{
- const gchar *begin, *end, *p, *src, *start, *brace;
- gchar *dbegin, *dend, *extra = NULL;
+ const char *begin, *end, *p, *src, *start, *brace;
+ char *dbegin, *dend, *extra = NULL;
struct rspamd_regexp_atom *result;
GError *err = NULL;
GString *re_flags;
}
struct rspamd_function_atom *
-rspamd_mime_expr_parse_function_atom(rspamd_mempool_t *pool, const gchar *input)
+rspamd_mime_expr_parse_function_atom(rspamd_mempool_t *pool, const char *input)
{
- const gchar *obrace, *ebrace, *p, *c;
- gchar t, *databuf;
- guint len;
+ const char *obrace, *ebrace, *p, *c;
+ char t, *databuf;
+ unsigned int len;
struct rspamd_function_atom *res;
struct expression_argument arg;
GError *err = NULL;
}
static rspamd_expression_atom_t *
-rspamd_mime_expr_parse(const gchar *line, gsize len,
+rspamd_mime_expr_parse(const char *line, gsize len,
rspamd_mempool_t *pool, gpointer ud, GError **err)
{
rspamd_expression_atom_t *a = NULL;
struct rspamd_mime_atom *mime_atom = NULL;
- const gchar *p, *end, *c = NULL;
+ const char *p, *end, *c = NULL;
struct rspamd_mime_expr_ud *real_ud = (struct rspamd_mime_expr_ud *) ud;
struct rspamd_config *cfg;
rspamd_regexp_t *own_re;
- gchar t;
- gint type = MIME_ATOM_REGEXP, obraces = 0, ebraces = 0;
+ char t;
+ int type = MIME_ATOM_REGEXP, obraces = 0, ebraces = 0;
enum {
in_header = 0,
got_slash,
g_set_error(err, rspamd_mime_expr_quark(), 100, "cannot parse"
" mime atom '%s' when reading symbol '%c' at offset %d, "
"near %.*s",
- line, t, (gint) (p - line),
- (gint) MIN(end - p, 10), p);
+ line, t, (int) (p - line),
+ (int) MIN(end - p, 10), p);
return NULL;
case end_atom:
goto set;
goto err;
}
else {
- gint lua_cbref = -1;
+ int lua_cbref = -1;
/* Check regexp condition */
if (real_ud->conf_obj != NULL) {
return NULL;
}
-static gint
+static int
rspamd_mime_expr_process_regexp(struct rspamd_regexp_atom *re,
struct rspamd_task *task)
{
- gint ret;
+ int ret;
if (re == NULL) {
msg_info_task("invalid regexp passed");
}
-static gint
+static int
rspamd_mime_expr_priority(rspamd_expression_atom_t *atom)
{
struct rspamd_mime_atom *mime_atom = atom->data;
- gint ret = 0;
+ int ret = 0;
switch (mime_atom->type) {
case MIME_ATOM_INTERNAL_FUNCTION:
return selected->func(task, func->args, selected->user_data);
}
-static gdouble
+static double
rspamd_mime_expr_process(void *ud, rspamd_expression_atom_t *atom)
{
struct rspamd_task *task = (struct rspamd_task *) ud;
struct rspamd_mime_atom *mime_atom;
lua_State *L;
- gdouble ret = 0;
+ double ret = 0;
g_assert(task != NULL);
g_assert(atom != NULL);
}
}
else if (mime_atom->type == MIME_ATOM_LOCAL_LUA_FUNCTION) {
- gint err_idx;
+ int err_idx;
L = task->cfg->lua_state;
lua_pushcfunction(L, &rspamd_lua_traceback);
return ret;
}
-void register_expression_function(const gchar *name,
+void register_expression_function(const char *name,
rspamd_internal_func_t func,
void *user_data)
{
}
rh = rspamd_message_get_header_array(task,
- (gchar *) arg->data, FALSE);
+ (char *) arg->data, FALSE);
- debug_task("try to get header %s: %d", (gchar *) arg->data,
+ debug_task("try to get header %s: %d", (char *) arg->data,
(rh != NULL));
if (rh) {
gboolean
rspamd_parts_distance(struct rspamd_task *task, GArray *args, void *unused)
{
- gint threshold, threshold2 = -1;
+ int threshold, threshold2 = -1;
struct expression_argument *arg;
- gdouble *pdiff, diff;
+ double *pdiff, diff;
if (args == NULL || args->len == 0) {
debug_task("no threshold is specified, assume it 100");
return FALSE;
}
- threshold = strtoul((gchar *) arg->data, NULL, 10);
+ threshold = strtoul((char *) arg->data, NULL, 10);
if (errno != 0) {
msg_info_task("bad numeric value for threshold \"%s\", assume it 100",
- (gchar *) arg->data);
+ (char *) arg->data);
threshold = 100;
}
if (args->len >= 2) {
}
errno = 0;
- threshold2 = strtoul((gchar *) arg->data, NULL, 10);
+ threshold2 = strtoul((char *) arg->data, NULL, 10);
if (errno != 0) {
msg_info_task("bad numeric value for threshold \"%s\", ignore it",
- (gchar *) arg->data);
+ (char *) arg->data);
threshold2 = -1;
}
}
}
struct addr_list {
- const gchar *name;
- guint namelen;
- const gchar *addr;
- guint addrlen;
+ const char *name;
+ unsigned int namelen;
+ const char *addr;
+ unsigned int addrlen;
};
-static gint
+static int
addr_list_cmp_func(const void *a, const void *b)
{
const struct addr_list *addra = (struct addr_list *) a,
struct rspamd_email_address *cur;
double threshold;
struct addr_list *ar;
- gint num, i, hits = 0;
+ int num, i, hits = 0;
if (args == NULL) {
msg_warn_task("no parameters to function");
}
errno = 0;
- threshold = strtod((gchar *) arg->data, NULL);
+ threshold = strtod((char *) arg->data, NULL);
if (errno != 0) {
msg_warn_task("invalid numeric value '%s': %s",
- (gchar *) arg->data,
+ (char *) arg->data,
strerror(errno));
return FALSE;
}
void *unused)
{
struct rspamd_mime_text_part *p;
- guint i, cnt_html = 0, cnt_txt = 0;
+ unsigned int i, cnt_html = 0, cnt_txt = 0;
PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, text_parts), i, p)
{
struct rspamd_email_address *addr;
gboolean res = TRUE;
rspamd_ftok_t cur, prev;
- gint i;
+ int i;
/* Do not check to short address lists */
if (ar == NULL || ar->len < MIN_RCPT_TO_COMPARE) {
void *unused)
{
struct expression_argument *arg;
- guint i;
+ unsigned int i;
struct rspamd_mime_part *part;
enum rspamd_cte cte;
{
struct rspamd_mime_text_part *p;
struct expression_argument *arg;
- guint i;
+ unsigned int i;
gboolean res = FALSE;
if (args == NULL) {
rspamd_has_fake_html(struct rspamd_task *task, GArray *args, void *unused)
{
struct rspamd_mime_text_part *p;
- guint i;
+ unsigned int i;
gboolean res = FALSE;
PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, text_parts), i, p)
static gboolean
match_smtp_data(struct rspamd_task *task,
struct expression_argument *arg,
- const gchar *what, gsize len)
+ const char *what, gsize len)
{
rspamd_regexp_t *re;
- gint r = 0;
+ int r = 0;
if (arg->type == EXPRESSION_ARGUMENT_REGEXP) {
/* This is a regexp */
struct expression_argument *arg;
struct rspamd_email_address *addr = NULL;
GPtrArray *rcpts = NULL;
- const gchar *type, *str = NULL;
- guint i;
+ const char *type, *str = NULL;
+ unsigned int i;
if (args == NULL) {
msg_warn_task("no parameters to function");
}
static inline gboolean
-rspamd_check_ct_attr(const gchar *begin, gsize len,
+rspamd_check_ct_attr(const char *begin, gsize len,
struct expression_argument *arg_pattern)
{
rspamd_regexp_t *re;
struct expression_argument *arg, *arg1, *arg_pattern;
gboolean recursive = FALSE;
struct rspamd_mime_part *cur_part;
- guint i;
+ unsigned int i;
rspamd_ftok_t srch;
struct rspamd_content_type_param *found = NULL, *cur;
- const gchar *param_name;
+ const char *param_name;
if (args == NULL || args->len < 2) {
msg_warn_task("no parameters to function");
struct expression_argument *arg, *arg1;
gboolean recursive = FALSE;
struct rspamd_mime_part *cur_part;
- guint i;
+ unsigned int i;
rspamd_ftok_t srch;
struct rspamd_content_type_param *found = NULL;
- const gchar *param_name;
+ const char *param_name;
if (args == NULL || args->len < 1) {
msg_warn_task("no parameters to function");
rspamd_regexp_t *re;
struct expression_argument *arg1, *arg_pattern;
struct rspamd_content_type *ct;
- gint r = 0;
- guint i;
+ int r = 0;
+ unsigned int i;
gboolean recursive = FALSE;
struct rspamd_mime_part *cur_part;
{
rspamd_regexp_t *re;
rspamd_ftok_t srch;
- gint r = 0;
+ int r = 0;
if (subtype == NULL || ct == NULL) {
msg_warn_task("invalid parameters passed");
}
static gboolean
-compare_len(struct rspamd_mime_part *part, guint min, guint max)
+compare_len(struct rspamd_mime_part *part, unsigned int min, unsigned int max)
{
if (min == 0 && max == 0) {
return TRUE;
common_has_content_part(struct rspamd_task *task,
struct expression_argument *param_type,
struct expression_argument *param_subtype,
- gint min_len,
- gint max_len)
+ int min_len,
+ int max_len)
{
rspamd_regexp_t *re;
struct rspamd_mime_part *part;
struct rspamd_content_type *ct;
rspamd_ftok_t srch;
- gint r = 0;
- guint i;
+ int r = 0;
+ unsigned int i;
PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, parts), i, part)
{
void *unused)
{
struct expression_argument *param_type = NULL, *param_subtype = NULL;
- gint min = 0, max = 0;
+ int min = 0, max = 0;
struct expression_argument *arg;
if (args == NULL) {
if (errno != 0) {
msg_warn_task("invalid numeric value '%s': %s",
- (gchar *) arg->data,
+ (char *) arg->data,
strerror(errno));
return FALSE;
}
if (errno != 0) {
msg_warn_task("invalid numeric value '%s': %s",
- (gchar *) arg->data,
+ (char *) arg->data,
strerror(errno));
return FALSE;
}
void *unused)
{
struct rspamd_mime_part *part;
- guint i;
+ unsigned int i;
PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, parts), i, part)
{
{
gboolean found = FALSE, result = FALSE;
struct expression_argument *flag_arg;
- const gchar *flag_str;
+ const char *flag_str;
if (args == NULL) {
msg_warn_task("no parameters to function");
return FALSE;
}
- flag_str = (const gchar *) flag_arg->data;
+ flag_str = (const char *) flag_arg->data;
TASK_GET_FLAG(flag_str, "pass_all", RSPAMD_TASK_FLAG_PASS_ALL);
TASK_GET_FLAG(flag_str, "no_log", RSPAMD_TASK_FLAG_NO_LOG);
void *unused)
{
struct expression_argument *sym_arg;
- const gchar *symbol_str;
+ const char *symbol_str;
if (args == NULL) {
msg_warn_task("no parameters to function");
return FALSE;
}
- symbol_str = (const gchar *) sym_arg->data;
+ symbol_str = (const char *) sym_arg->data;
if (rspamd_task_find_symbol_result(task, symbol_str, NULL)) {
return TRUE;
* @param name name of function
* @param func pointer to function
*/
-void register_expression_function(const gchar *name,
+void register_expression_function(const char *name,
rspamd_internal_func_t func,
void *user_data);
* @param limit new limit in bytes
* @return old limit value
*/
-guint rspamd_mime_expression_set_re_limit(guint limit);
+unsigned int rspamd_mime_expression_set_re_limit(unsigned int limit);
#ifdef __cplusplus
}
#include "libutil/util.h"
#include <unicode/utf8.h>
-KHASH_INIT(rspamd_mime_headers_htb, gchar *,
+KHASH_INIT(rspamd_mime_headers_htb, char *,
struct rspamd_mime_header *, 1,
rspamd_strcase_hash, rspamd_strcase_equal);
struct rspamd_mime_header *rh)
{
uint64_t h;
- const gchar *p, *end;
- gchar *id;
- gint max_recipients = -1, len;
+ const char *p, *end;
+ char *id;
+ int max_recipients = -1, len;
if (task->cfg) {
max_recipients = task->cfg->max_recipients;
}
if (end > p) {
- gchar *d;
+ char *d;
if (*(end - 1) == '>') {
end--;
void rspamd_mime_headers_process(struct rspamd_task *task,
struct rspamd_mime_headers_table *target,
struct rspamd_mime_header **order_ptr,
- const gchar *in, gsize len,
+ const char *in, gsize len,
gboolean check_newlines)
{
struct rspamd_mime_header *nh = NULL;
- const gchar *p, *c, *end;
- gchar *tmp, *tp;
- gint state = 0, l, next_state = 100, err_state = 100, t_state;
+ const char *p, *c, *end;
+ char *tmp, *tp;
+ int state = 0, l, next_state = 100, err_state = 100, t_state;
gboolean valid_folding = FALSE, shift_by_one = FALSE;
- guint nlines_count[RSPAMD_TASK_NEWLINES_MAX];
- guint norder = 0;
+ unsigned int nlines_count[RSPAMD_TASK_NEWLINES_MAX];
+ unsigned int norder = 0;
p = in;
end = p + len;
LL_REVERSE(*order_ptr);
if (check_newlines) {
- guint max_cnt = 0;
- gint sel = 0;
+ unsigned int max_cnt = 0;
+ int sel = 0;
rspamd_cryptobox_hash_state_t hs;
- guchar hout[rspamd_cryptobox_HASHBYTES], *hexout;
+ unsigned char hout[rspamd_cryptobox_HASHBYTES], *hexout;
- for (gint i = RSPAMD_TASK_NEWLINES_CR; i < RSPAMD_TASK_NEWLINES_MAX; i++) {
+ for (int i = RSPAMD_TASK_NEWLINES_CR; i < RSPAMD_TASK_NEWLINES_MAX; i++) {
if (nlines_count[i] > max_cnt) {
max_cnt = nlines_count[i];
sel = i;
rspamd_mime_header_sanity_check(GString *str)
{
gsize i;
- gchar t;
+ char t;
for (i = 0; i < str->len; i++) {
t = str->str[i];
}
}
-gchar *
-rspamd_mime_header_decode(rspamd_mempool_t *pool, const gchar *in,
+char *
+rspamd_mime_header_decode(rspamd_mempool_t *pool, const char *in,
gsize inlen, gboolean *invalid_utf)
{
GString *out;
- const guchar *c, *p, *end;
- const gchar *tok_start = NULL;
+ const unsigned char *c, *p, *end;
+ const char *tok_start = NULL;
gsize tok_len = 0, pos;
GByteArray *token = NULL, *decoded;
rspamd_ftok_t cur_charset = {0, NULL}, old_charset = {0, NULL};
- gint encoding;
+ int encoding;
gssize r;
- guint qmarks = 0;
- gchar *ret;
+ unsigned int qmarks = 0;
+ char *ret;
enum {
parse_normal = 0,
got_eqsign,
state = got_eqsign;
}
else if (*p >= 128) {
- gint off = 0;
+ int off = 0;
UChar32 uc;
/* Unencoded character */
g_string_append_len(out, c, p - c);
return ret;
}
-gchar *
-rspamd_mime_header_encode(const gchar *in, gsize len)
+char *
+rspamd_mime_header_encode(const char *in, gsize len)
{
- const gchar *p = in, *end = in + len;
- gchar *out, encode_buf[80 * sizeof(uint32_t)];
+ const char *p = in, *end = in + len;
+ char *out, encode_buf[80 * sizeof(uint32_t)];
GString *res;
gboolean need_encoding = FALSE;
/* Check if we need to encode */
while (p < end) {
- if ((((guchar) *p) & 0x80) != 0) {
+ if ((((unsigned char) *p) & 0x80) != 0) {
need_encoding = TRUE;
break;
}
else {
/* Need encode */
gsize ulen, pos;
- gint r;
- const gchar *prev;
+ int r;
+ const char *prev;
/* Choose step: =?UTF-8?Q?<qp>?= should be less than 76 chars */
- guint step = (76 - 12) / 3 + 1;
+ unsigned int step = (76 - 12) / 3 + 1;
ulen = g_utf8_strlen(in, len);
res = g_string_sized_new(len * 2 + 1);
pos = 0;
prev = in;
/* Adjust chunk size for unicode average length */
- step *= 1.0 * ulen / (gdouble) len;
+ step *= 1.0 * ulen / (double) len;
while (pos < ulen) {
p = g_utf8_offset_to_pointer(in, pos);
return out;
}
-gchar *
-rspamd_mime_message_id_generate(const gchar *fqdn)
+char *
+rspamd_mime_message_id_generate(const char *fqdn)
{
GString *out;
uint64_t rnd, clk;
clk = rspamd_get_calendar_ticks() * 1e6;
rspamd_printf_gstring(out, "%*bs.%*bs@%s",
- (gint) sizeof(uint64_t) - 3, (guchar *) &clk,
- (gint) sizeof(uint64_t), (gchar *) &rnd,
+ (int) sizeof(uint64_t) - 3, (unsigned char *) &clk,
+ (int) sizeof(uint64_t), (char *) &rnd,
fqdn);
return g_string_free(out, FALSE);
struct rspamd_mime_header *
rspamd_message_get_header_from_hash(struct rspamd_mime_headers_table *hdrs,
- const gchar *field,
+ const char *field,
gboolean need_modified)
{
if (hdrs == NULL) {
struct rspamd_mime_header *hdr;
if (htb) {
- k = kh_get(rspamd_mime_headers_htb, htb, (gchar *) field);
+ k = kh_get(rspamd_mime_headers_htb, htb, (char *) field);
if (k == kh_end(htb)) {
return NULL;
}
struct rspamd_mime_header *
-rspamd_message_get_header_array(struct rspamd_task *task, const gchar *field,
+rspamd_message_get_header_array(struct rspamd_task *task, const char *field,
gboolean need_modified)
{
return rspamd_message_get_header_from_hash(
bool rspamd_mime_headers_foreach(const struct rspamd_mime_headers_table *hdrs,
rspamd_hdr_traverse_func_t func, void *ud)
{
- const gchar *name;
+ const char *name;
struct rspamd_mime_header *hdr;
kh_foreach(&hdrs->htb, name, hdr, {
void rspamd_message_set_modified_header(struct rspamd_task *task,
struct rspamd_mime_headers_table *hdrs,
- const gchar *hdr_name,
+ const char *hdr_name,
const ucl_object_t *obj,
struct rspamd_mime_header **order_ptr)
{
int i;
if (htb) {
- k = kh_get(rspamd_mime_headers_htb, htb, (gchar *) hdr_name);
+ k = kh_get(rspamd_mime_headers_htb, htb, (char *) hdr_name);
if (k == kh_end(htb)) {
hdr_elt = rspamd_mempool_alloc0(task->task_pool, sizeof(*hdr_elt));
}
}
-gsize rspamd_strip_smtp_comments_inplace(gchar *input, gsize len)
+gsize rspamd_strip_smtp_comments_inplace(char *input, gsize len)
{
enum parser_state {
parse_normal,
parse_quoted_ignore,
} state = parse_normal,
next_state = parse_normal;
- gchar *d = input, *end = input + len, *start = input;
- gchar t;
+ char *d = input, *end = input + len, *start = input;
+ char t;
int obraces = 0, ebraces = 0;
while (input < end) {
};
struct rspamd_mime_header {
- const gchar *raw_value; /* As it is in the message (unfolded and unparsed) */
+ const char *raw_value; /* As it is in the message (unfolded and unparsed) */
gsize raw_len;
- guint order;
+ unsigned int order;
int flags; /* see enum rspamd_mime_header_flags */
/* These are zero terminated (historically) */
- gchar *name; /* Also used for key */
- gchar *value;
- gchar *separator;
- gchar *decoded;
+ char *name; /* Also used for key */
+ char *value;
+ char *separator;
+ char *decoded;
struct rspamd_mime_header *modified_chain; /* Headers modified during transform */
struct rspamd_mime_header *prev, *next; /* Headers with the same name */
struct rspamd_mime_header *ord_next; /* Overall order of headers, slist */
void rspamd_mime_headers_process(struct rspamd_task *task,
struct rspamd_mime_headers_table *target,
struct rspamd_mime_header **order_ptr,
- const gchar *in, gsize len,
+ const char *in, gsize len,
gboolean check_newlines);
/**
* @param inlen
* @return
*/
-gchar *rspamd_mime_header_decode(rspamd_mempool_t *pool, const gchar *in,
- gsize inlen, gboolean *invalid_utf);
+char *rspamd_mime_header_decode(rspamd_mempool_t *pool, const char *in,
+ gsize inlen, gboolean *invalid_utf);
/**
* Encode mime header if needed
* @param len
* @return newly allocated encoded header
*/
-gchar *rspamd_mime_header_encode(const gchar *in, gsize len);
+char *rspamd_mime_header_encode(const char *in, gsize len);
/**
* Generate new unique message id
* @param fqdn
* @return
*/
-gchar *rspamd_mime_message_id_generate(const gchar *fqdn);
+char *rspamd_mime_message_id_generate(const char *fqdn);
/**
* Get an array of header's values with specified header's name using raw headers
*/
struct rspamd_mime_header *
rspamd_message_get_header_array(struct rspamd_task *task,
- const gchar *field,
+ const char *field,
gboolean need_modified);
/**
*/
struct rspamd_mime_header *
rspamd_message_get_header_from_hash(struct rspamd_mime_headers_table *hdrs,
- const gchar *field,
+ const char *field,
gboolean need_modified);
/**
*/
void rspamd_message_set_modified_header(struct rspamd_task *task,
struct rspamd_mime_headers_table *hdrs,
- const gchar *hdr_name,
+ const char *hdr_name,
const ucl_object_t *obj,
struct rspamd_mime_header **order_ptr);
*/
gsize rspamd_mime_headers_count(struct rspamd_mime_headers_table *hdrs);
-typedef bool(rspamd_hdr_traverse_func_t)(const gchar *, const struct rspamd_mime_header *, void *);
+typedef bool(rspamd_hdr_traverse_func_t)(const char *, const struct rspamd_mime_header *, void *);
/**
* Traverse all headers in a table
* @param func
* @param len length of the input
* @return new length of the input
*/
-gsize rspamd_strip_smtp_comments_inplace(gchar *input, gsize len);
+gsize rspamd_strip_smtp_comments_inplace(char *input, gsize len);
/**
* Unfold header in place
struct rspamd_mime_parser_lib_ctx {
struct rspamd_multipattern *mp_boundary;
- guchar hkey[rspamd_cryptobox_SIPKEYBYTES]; /* Key for hashing */
- guint key_usages;
+ unsigned char hkey[rspamd_cryptobox_SIPKEYBYTES]; /* Key for hashing */
+ unsigned int key_usages;
};
struct rspamd_mime_parser_lib_ctx *lib_ctx = NULL;
-static const guint max_nested = 64;
-static const guint max_key_usages = 10000;
+static const unsigned int max_nested = 64;
+static const unsigned int max_key_usages = 10000;
#define msg_debug_mime(...) rspamd_conditional_debug_fast(NULL, task->from_addr, \
rspamd_mime_log_id, "mime", task->task_pool->tag.uid, \
goffset start;
uint64_t hash;
uint64_t closed_hash;
- gint flags;
+ int flags;
};
struct rspamd_mime_parser_ctx {
GPtrArray *stack; /* Stack of parts */
GArray *boundaries; /* Boundaries found in the whole message */
- const gchar *start;
- const gchar *pos;
- const gchar *end;
+ const char *start;
+ const char *pos;
+ const char *end;
struct rspamd_task *task;
- guint nesting;
+ unsigned int nesting;
};
static enum rspamd_mime_parse_error
rspamd_mime_process_multipart_node(struct rspamd_task *task,
struct rspamd_mime_parser_ctx *st,
struct rspamd_mime_part *multipart,
- const gchar *start, const gchar *end,
+ const char *start, const char *end,
gboolean is_finished,
GError **err);
return g_quark_from_static_string("mime-parser");
}
-const gchar *
+const char *
rspamd_cte_to_string(enum rspamd_cte ct)
{
- const gchar *ret = "unknown";
+ const char *ret = "unknown";
switch (ct) {
case RSPAMD_CTE_7BIT:
}
enum rspamd_cte
-rspamd_cte_from_string(const gchar *str)
+rspamd_cte_from_string(const char *str)
{
enum rspamd_cte ret = RSPAMD_CTE_UNKNOWN;
}
static enum rspamd_cte
-rspamd_mime_parse_cte(const gchar *in, gsize len)
+rspamd_mime_parse_cte(const char *in, gsize len)
{
uint64_t h;
enum rspamd_cte ret = RSPAMD_CTE_UNKNOWN;
rspamd_mime_part_get_cte_heuristic(struct rspamd_task *task,
struct rspamd_mime_part *part)
{
- const guint check_len = 128;
- guint real_len, nspaces = 0, neqsign = 0, n8bit = 0, nqpencoded = 0,
- padeqsign = 0, nupper = 0, nlower = 0;
+ const unsigned int check_len = 128;
+ unsigned int real_len, nspaces = 0, neqsign = 0, n8bit = 0, nqpencoded = 0,
+ padeqsign = 0, nupper = 0, nlower = 0;
gboolean b64_chars = TRUE;
- const guchar *p, *end;
+ const unsigned char *p, *end;
enum rspamd_cte ret = RSPAMD_CTE_UNKNOWN;
real_len = MIN(check_len, part->raw_data.len);
- p = (const guchar *) part->raw_data.begin;
+ p = (const unsigned char *) part->raw_data.begin;
end = p + part->raw_data.len;
while (p < end && g_ascii_isspace(*p)) {
}
if (end - p > sizeof("begin-base64 ")) {
- const guchar *uue_start;
+ const unsigned char *uue_start;
if (memcmp(p, "begin ", sizeof("begin ") - 1) == 0) {
uue_start = p + sizeof("begin ") - 1;
}
else {
- if (((end - (const guchar *) part->raw_data.begin) + padeqsign) % 4 == 0) {
+ if (((end - (const unsigned char *) part->raw_data.begin) + padeqsign) % 4 == 0) {
if (padeqsign == 0) {
/*
* It can be either base64 or plain text, hard to say
DL_FOREACH(hdr, cur)
{
gsize hlen;
- gchar lc_buf[128];
+ char lc_buf[128];
hlen = rspamd_snprintf(lc_buf, sizeof(lc_buf), "%s", cur->value);
rspamd_str_lc(lc_buf, hlen);
void rspamd_mime_parser_calc_digest(struct rspamd_mime_part *part)
{
/* Blake2b applied to string 'rspamd' */
- static const guchar hash_key[] = {
+ static const unsigned char hash_key[] = {
0xef,
0x43,
0xae,
* Since ASN.1 structures are freed, we need to copy
* the content
*/
- gchar *cpy = rspamd_mempool_alloc(task->task_pool,
- p7_signed_content->d.data->length);
+ char *cpy = rspamd_mempool_alloc(task->task_pool,
+ p7_signed_content->d.data->length);
memcpy(cpy, p7_signed_content->d.data->data,
p7_signed_content->d.data->length);
ret = rspamd_mime_process_multipart_node(task,
struct rspamd_task *task;
struct rspamd_mime_part *multipart;
struct rspamd_mime_parser_ctx *st;
- const gchar *part_start;
+ const char *part_start;
rspamd_ftok_t *cur_boundary;
uint64_t bhash;
GError **err;
rspamd_mime_process_multipart_node(struct rspamd_task *task,
struct rspamd_mime_parser_ctx *st,
struct rspamd_mime_part *multipart,
- const gchar *start, const gchar *end,
+ const char *start, const char *end,
gboolean is_finished,
GError **err)
{
enum rspamd_mime_parse_error ret = RSPAMD_MIME_PARSE_FATAL;
- str.str = (gchar *) start;
+ str.str = (char *) start;
str.len = end - start;
if (*start == '\n' || *start == '\r') {
if (!is_finished) {
/* Ignore garbage */
- const gchar *p = start;
+ const char *p = start;
gboolean seen_something = FALSE;
while (p < end) {
struct rspamd_mime_multipart_cbdata *cb,
struct rspamd_mime_boundary *b)
{
- const gchar *pos = st->start + b->boundary;
+ const char *pos = st->start + b->boundary;
enum rspamd_mime_parse_error ret;
task = cb->task;
{
struct rspamd_mime_boundary *cur;
goffset last_offset;
- guint i, sel = 0;
+ unsigned int i, sel = 0;
enum rspamd_mime_parse_error ret;
last_offset = (multipart->raw_data.begin - st->start) +
if (part->ct->boundary.len > 0) {
/* We know our boundary */
cbdata.cur_boundary = &part->ct->boundary;
- rspamd_cryptobox_siphash((guchar *) &cbdata.bhash,
+ rspamd_cryptobox_siphash((unsigned char *) &cbdata.bhash,
cbdata.cur_boundary->begin, cbdata.cur_boundary->len,
lib_ctx->hkey);
msg_debug_mime("hash: %T -> %L", cbdata.cur_boundary, cbdata.bhash);
}
/* Process boundary like structures in a message */
-static gint
+static int
rspamd_mime_preprocess_cb(struct rspamd_multipattern *mp,
- guint strnum,
- gint match_start,
- gint match_pos,
- const gchar *text,
+ unsigned int strnum,
+ int match_start,
+ int match_pos,
+ const char *text,
gsize len,
void *context)
{
- const gchar *end = text + len, *p = text + match_pos, *bend;
+ const char *end = text + len, *p = text + match_pos, *bend;
gsize blen;
gboolean closing = FALSE;
struct rspamd_mime_boundary b;
b.start = bend - st->start;
/* Small optimisation as boundaries are usually short strings */
- gchar *lc_copy, lc_copy_buf[128];
+ char *lc_copy, lc_copy_buf[128];
if (blen + 2 < sizeof(lc_copy_buf)) {
lc_copy = lc_copy_buf;
rspamd_str_lc(lc_copy, blen);
}
- rspamd_cryptobox_siphash((guchar *) &b.hash, lc_copy, blen,
+ rspamd_cryptobox_siphash((unsigned char *) &b.hash, lc_copy, blen,
lib_ctx->hkey);
msg_debug_mime("normal hash: %*s -> %L, %d boffset, %d data offset",
- (gint) blen, lc_copy, b.hash, (int) b.boundary, (int) b.start);
+ (int) blen, lc_copy, b.hash, (int) b.boundary, (int) b.start);
if (closing) {
b.flags = RSPAMD_MIME_BOUNDARY_FLAG_CLOSED;
- rspamd_cryptobox_siphash((guchar *) &b.closed_hash, lc_copy,
+ rspamd_cryptobox_siphash((unsigned char *) &b.closed_hash, lc_copy,
blen + 2,
lib_ctx->hkey);
msg_debug_mime("closing hash: %*s -> %L, %d boffset, %d data offset",
- (gint) blen + 2, lc_copy,
+ (int) blen + 2, lc_copy,
b.closed_hash,
(int) b.boundary, (int) b.start);
}
{
const gsize default_max_len = 76;
gsize max_len = MIN(input->len, default_max_len);
- const gchar *p, *end;
+ const char *p, *end;
enum {
st_before_colon = 0,
st_colon,
{
struct rspamd_content_type *ct, *sel = NULL;
struct rspamd_mime_header *hdr = NULL, *cur;
- const gchar *pbegin, *p;
+ const char *pbegin, *p;
gsize plen, len;
struct rspamd_mime_part *npart;
goffset hdr_pos, body_pos;
- guint i;
+ unsigned int i;
enum rspamd_mime_parse_error ret = RSPAMD_MIME_PARSE_OK;
GString str;
struct rspamd_mime_parser_ctx *nst = st;
p = task->msg.begin;
len = task->msg.len;
- str.str = (gchar *) p;
+ str.str = (char *) p;
str.len = len;
hdr_pos = rspamd_string_find_eoh(&str, &body_pos);
nst->nesting = st->nesting;
st->nesting++;
- str.str = (gchar *) part->parsed_data.begin;
+ str.str = (char *) part->parsed_data.begin;
str.len = part->parsed_data.len;
hdr_pos = rspamd_string_find_eoh(&str, &body_pos);
*end_boundary = NULL;
goffset cur_offset = nst->pos - nst->start,
end_offset = st->end - st->start;
- guint sel_idx = 0;
+ unsigned int sel_idx = 0;
for (;;) {
start_boundary = NULL;
}
if (start_boundary) {
- const gchar *start, *end;
+ const char *start, *end;
if (nst->boundaries->len > sel_idx + 1) {
end_boundary = &g_array_index(nst->boundaries,
};
static inline auto
-received_part_set_or_append(const gchar *begin,
+received_part_set_or_append(const char *begin,
gsize len,
mime_string &dest) -> void
{
RSPAMD_INET_ADDRESS_PARSE_RECEIVED);
if (addr) {
- const gchar *addr_str;
+ const char *addr_str;
if (rspamd_inet_address_get_port(addr) != 0) {
addr_str = rspamd_inet_address_to_string_pretty(addr);
struct rspamd_scan_result *
rspamd_create_metric_result(struct rspamd_task *task,
- const gchar *name, gint lua_sym_cbref)
+ const char *name, int lua_sym_cbref)
{
struct rspamd_scan_result *metric_res;
bool rspamd_add_passthrough_result(struct rspamd_task *task,
struct rspamd_action *action,
- guint priority,
+ unsigned int priority,
double target_score,
- const gchar *message,
- const gchar *module,
+ const char *message,
+ const char *module,
uint flags,
struct rspamd_scan_result *scan_result)
{
return true;
}
-static inline gdouble
+static inline double
rspamd_check_group_score(struct rspamd_task *task,
- const gchar *symbol,
+ const char *symbol,
struct rspamd_symbols_group *gr,
- gdouble *group_score,
- gdouble w)
+ double *group_score,
+ double w)
{
if (gr != NULL && group_score && gr->max_score > 0.0 && w > 0.0) {
if (*group_score >= gr->max_score && w > 0) {
static struct rspamd_symbol_result *
insert_metric_result(struct rspamd_task *task,
- const gchar *symbol,
+ const char *symbol,
double weight,
- const gchar *opt,
+ const char *opt,
struct rspamd_scan_result *metric_res,
enum rspamd_symbol_insert_flags flags,
bool *new_sym)
{
struct rspamd_symbol_result *symbol_result = NULL;
- gdouble final_score, *gr_score = NULL, next_gf = 1.0, diff;
+ double final_score, *gr_score = NULL, next_gf = 1.0, diff;
struct rspamd_symbol *sdef;
struct rspamd_symbols_group *gr = NULL;
const ucl_object_t *mobj, *sobj;
- gint max_shots = G_MAXINT, ret;
- guint i;
+ int max_shots = G_MAXINT, ret;
+ unsigned int i;
khiter_t k;
gboolean single = !!(flags & RSPAMD_SYMBOL_INSERT_SINGLE);
- gchar *sym_cpy;
+ char *sym_cpy;
if (!isfinite(weight)) {
msg_warn_task("detected %s score for symbol %s, replace it with zero",
}
if (task->settings) {
- gdouble corr;
+ double corr;
mobj = ucl_object_lookup(task->settings, "scores");
if (!mobj) {
if (sdef) {
PTR_ARRAY_FOREACH(sdef->groups, i, gr)
{
- gdouble cur_diff;
+ double cur_diff;
k = kh_get(rspamd_symbols_group_hash,
metric_res->sym_groups, gr);
/* Check group limits */
PTR_ARRAY_FOREACH(sdef->groups, i, gr)
{
- gdouble cur_score;
+ double cur_score;
k = kh_get(rspamd_symbols_group_hash, metric_res->sym_groups, gr);
g_assert(k != kh_end(metric_res->sym_groups));
struct rspamd_symbol_result *
rspamd_task_insert_result_full(struct rspamd_task *task,
- const gchar *symbol,
+ const char *symbol,
double weight,
- const gchar *opt,
+ const char *opt,
enum rspamd_symbol_insert_flags flags,
struct rspamd_scan_result *result)
{
return ret;
}
-static gchar *
+static char *
rspamd_task_option_safe_copy(struct rspamd_task *task,
- const gchar *val,
+ const char *val,
gsize vlen,
gsize *outlen)
{
- const gchar *p, *end;
+ const char *p, *end;
p = val;
end = val + vlen;
while (p < end) {
if (*p & 0x80) {
UChar32 uc;
- gint off = 0;
+ int off = 0;
U8_NEXT(p, off, end - p, uc);
}
}
- gchar *dest, *d;
+ char *dest, *d;
dest = rspamd_mempool_alloc(task->task_pool, vlen + 1);
d = dest;
while (p < end) {
if (*p & 0x80) {
UChar32 uc;
- gint off = 0;
+ int off = 0;
U8_NEXT(p, off, end - p, uc);
gboolean
rspamd_task_add_result_option(struct rspamd_task *task,
struct rspamd_symbol_result *s,
- const gchar *val,
+ const char *val,
gsize vlen)
{
struct rspamd_symbol_option *opt, srch;
gboolean ret = FALSE;
- gchar *opt_cpy = NULL;
+ char *opt_cpy = NULL;
gsize cpy_len;
khiter_t k;
- gint r;
+ int r;
struct rspamd_symbol_result *cur;
if (s && val) {
if (!(cur->sym && (cur->sym->flags & RSPAMD_SYMBOL_FLAG_ONEPARAM))) {
- srch.option = (gchar *) val;
+ srch.option = (char *) val;
srch.optlen = vlen;
k = kh_get(rspamd_options_hash, cur->options, &srch);
if (k == kh_end(cur->options)) {
opt_cpy = rspamd_task_option_safe_copy(task, val, vlen, &cpy_len);
if (cpy_len != vlen) {
- srch.option = (gchar *) opt_cpy;
+ srch.option = (char *) opt_cpy;
srch.optlen = cpy_len;
k = kh_get(rspamd_options_hash, cur->options, &srch);
}
struct rspamd_symbol_result *rspamd_task_remove_symbol_result(
struct rspamd_task *task,
- const gchar *symbol,
+ const char *symbol,
struct rspamd_scan_result *result)
{
struct rspamd_symbol_result *res = NULL;
/* Also check the group limit */
if (result->sym_groups && res->sym) {
struct rspamd_symbol_group *gr;
- gint i;
+ int i;
khiter_t k_groups;
PTR_ARRAY_FOREACH(res->sym->groups, i, gr)
{
- gdouble *gr_score;
+ double *gr_score;
k_groups = kh_get(rspamd_symbols_group_hash,
result->sym_groups, gr);
struct rspamd_scan_result *result, GHFunc func,
gpointer ud)
{
- const gchar *kk;
+ const char *kk;
struct rspamd_symbol_result *res;
if (result == NULL) {
struct rspamd_scan_result *
rspamd_find_metric_result(struct rspamd_task *task,
- const gchar *name)
+ const char *name)
{
struct rspamd_scan_result *res;
struct rspamd_classifier_config;
struct rspamd_symbol_option {
- gchar *option;
+ char *option;
gsize optlen;
struct rspamd_symbol_option *prev, *next;
};
double score; /**< symbol's score */
struct kh_rspamd_options_hash_s *options; /**< list of symbol's options */
struct rspamd_symbol_option *opts_head; /**< head of linked list of options */
- const gchar *name;
+ const char *name;
struct rspamd_symbol *sym; /**< symbol configuration */
gssize opts_len; /**< total size of all options (negative if truncated option is added) */
- guint nshots;
+ unsigned int nshots;
int flags;
struct rspamd_symbol_result *next; /**< for shadow results */
};
struct rspamd_passthrough_result {
struct rspamd_action *action;
- guint priority;
- guint flags;
+ unsigned int priority;
+ unsigned int flags;
double target_score;
- const gchar *message;
- const gchar *module;
+ const char *message;
+ const char *module;
struct rspamd_passthrough_result *prev, *next;
};
RSPAMD_ACTION_RESULT_DISABLED = (1u << 1u),
};
struct rspamd_action_config {
- gdouble cur_limit;
+ double cur_limit;
int flags;
struct rspamd_action *action;
};
struct kh_rspamd_symbols_hash_s *symbols; /**< symbols of metric */
struct kh_rspamd_symbols_group_hash_s *sym_groups; /**< groups of symbols */
struct rspamd_action_config *actions_config;
- const gchar *name; /**< for named results, NULL is the default result */
+ const char *name; /**< for named results, NULL is the default result */
struct rspamd_task *task; /**< back reference */
- gint symbol_cbref; /**< lua function that defines if a symbol can be inserted, -1 if unused */
- guint nactions;
- guint npositive;
- guint nnegative;
- guint nresults; /**< all results: positive, negative, passthrough etc */
- guint nresults_postfilters; /**< how many results are there before postfilters stage */
+ int symbol_cbref; /**< lua function that defines if a symbol can be inserted, -1 if unused */
+ unsigned int nactions;
+ unsigned int npositive;
+ unsigned int nnegative;
+ unsigned int nresults; /**< all results: positive, negative, passthrough etc */
+ unsigned int nresults_postfilters; /**< how many results are there before postfilters stage */
struct rspamd_scan_result *prev, *next; /**< double linked list of results */
};
* @return metric result or NULL if metric `name` has not been found
*/
struct rspamd_scan_result *rspamd_create_metric_result(struct rspamd_task *task,
- const gchar *name, gint lua_sym_cbref);
+ const char *name, int lua_sym_cbref);
/**
* Find result with a specific name (NULL means the default result)
* @return
*/
struct rspamd_scan_result *rspamd_find_metric_result(struct rspamd_task *task,
- const gchar *name);
+ const char *name);
/**
* Adds a new passthrough result to a task
* @param module
*/
bool rspamd_add_passthrough_result(struct rspamd_task *task,
- struct rspamd_action *action, guint priority,
- double target_score, const gchar *message,
- const gchar *module, guint flags,
+ struct rspamd_action *action, unsigned int priority,
+ double target_score, const char *message,
+ const char *module, unsigned int flags,
struct rspamd_scan_result *scan_result);
enum rspamd_symbol_insert_flags {
* @param opts list of symbol's options
*/
struct rspamd_symbol_result *rspamd_task_insert_result_full(struct rspamd_task *task,
- const gchar *symbol,
+ const char *symbol,
double weight,
- const gchar *opts,
+ const char *opts,
enum rspamd_symbol_insert_flags flags,
struct rspamd_scan_result *result);
*/
struct rspamd_symbol_result *rspamd_task_remove_symbol_result(
struct rspamd_task *task,
- const gchar *symbol,
+ const char *symbol,
struct rspamd_scan_result *result);
/**
* Adds new option to symbol
*/
gboolean rspamd_task_add_result_option(struct rspamd_task *task,
struct rspamd_symbol_result *s,
- const gchar *opt,
+ const char *opt,
gsize vlen);
/**
* @return result metric weight
*/
double rspamd_factor_consolidation_func(struct rspamd_task *task,
- const gchar *metric_name,
- const gchar *unused);
+ const char *metric_name,
+ const char *unused);
/**
rspamd_mempool_t *pool);
gboolean
-rspamd_rfc2047_parser(const gchar *in, gsize len, gint *pencoding,
- const gchar **charset, gsize *charset_len,
- const gchar **encoded, gsize *encoded_len);
+rspamd_rfc2047_parser(const char *in, gsize len, int *pencoding,
+ const char **charset, gsize *charset_len,
+ const char **encoded, gsize *encoded_len);
rspamd_inet_addr_t *rspamd_parse_smtp_ip(const char *data, size_t len,
rspamd_mempool_t *pool);
struct rspamd_async_event {
- const gchar *subsystem;
- const gchar *event_source;
+ const char *subsystem;
+ const char *event_source;
event_finalizer_t fin;
void *user_data;
};
khash_t(rspamd_events_hash) * events;
void *user_data;
rspamd_mempool_t *pool;
- guint flags;
+ unsigned int flags;
};
static void
rspamd_session_add_event_full(struct rspamd_async_session *session,
event_finalizer_t fin,
gpointer user_data,
- const gchar *subsystem,
- const gchar *event_source)
+ const char *subsystem,
+ const char *event_source)
{
struct rspamd_async_event *new_event;
- gint ret;
+ int ret;
if (session == NULL) {
msg_err("session is NULL");
void rspamd_session_remove_event_full(struct rspamd_async_session *session,
event_finalizer_t fin,
void *ud,
- const gchar *event_source)
+ const char *event_source)
{
struct rspamd_async_event search_ev, *found_ev;
khiter_t k;
return ret;
}
-guint rspamd_session_events_pending(struct rspamd_async_session *session)
+unsigned int rspamd_session_events_pending(struct rspamd_async_session *session)
{
- guint npending;
+ unsigned int npending;
g_assert(session != NULL);
rspamd_session_add_event_full(struct rspamd_async_session *session,
event_finalizer_t fin,
gpointer user_data,
- const gchar *subsystem,
- const gchar *event_source);
+ const char *subsystem,
+ const char *event_source);
#define rspamd_session_add_event(session, fin, user_data, subsystem) \
rspamd_session_add_event_full(session, fin, user_data, subsystem, G_STRLOC)
void rspamd_session_remove_event_full(struct rspamd_async_session *session,
event_finalizer_t fin,
gpointer ud,
- const gchar *event_source);
+ const char *event_source);
#define rspamd_session_remove_event(session, fin, user_data) \
rspamd_session_remove_event_full(session, fin, user_data, G_STRLOC)
* @param session
* @return
*/
-guint rspamd_session_events_pending(struct rspamd_async_session *session);
+unsigned int rspamd_session_events_pending(struct rspamd_async_session *session);
/**
};
struct rspamd_worker_log_pipe {
- gint fd;
- gint type;
+ int fd;
+ int type;
struct rspamd_worker_log_pipe *prev, *next;
};
* script module list item
*/
struct script_module {
- gchar *name; /**< name of module */
- gchar *path; /**< path to module */
- gchar *digest;
+ char *name; /**< name of module */
+ char *path; /**< path to module */
+ char *digest;
};
enum rspamd_symbol_group_flags {
*/
struct rspamd_symbol;
struct rspamd_symbols_group {
- gchar *name;
- gchar *description;
+ char *name;
+ char *description;
GHashTable *symbols;
- gdouble max_score;
- guint flags;
+ double max_score;
+ unsigned int flags;
};
enum rspamd_symbol_flags {
* Symbol config definition
*/
struct rspamd_symbol {
- gchar *name;
- gchar *description;
- gdouble *weight_ptr;
- gdouble score;
- guint priority;
+ char *name;
+ char *description;
+ double *weight_ptr;
+ double score;
+ unsigned int priority;
struct rspamd_symbols_group *gr; /* Main group */
GPtrArray *groups; /* Other groups */
- guint flags;
+ unsigned int flags;
void *cache_item;
- gint nshots;
+ int nshots;
};
/**
* Statfile config definition
*/
struct rspamd_statfile_config {
- gchar *symbol; /**< symbol of statfile */
- gchar *label; /**< label of this statfile */
+ char *symbol; /**< symbol of statfile */
+ char *label; /**< label of this statfile */
ucl_object_t *opts; /**< other options */
gboolean is_spam; /**< spam flag */
struct rspamd_classifier_config *clcf; /**< parent pointer of classifier configuration */
struct rspamd_tokenizer_config {
const ucl_object_t *opts; /**< other options */
- const gchar *name; /**< name of tokenizer */
+ const char *name; /**< name of tokenizer */
};
struct rspamd_classifier_config {
GList *statfiles; /**< statfiles list */
GHashTable *labels; /**< statfiles with labels */
- gchar *metric; /**< metric of this classifier */
- gchar *classifier; /**< classifier interface */
+ char *metric; /**< metric of this classifier */
+ char *classifier; /**< classifier interface */
struct rspamd_tokenizer_config *tokenizer; /**< tokenizer used for classifier */
- const gchar *backend; /**< name of statfile's backend */
+ const char *backend; /**< name of statfile's backend */
ucl_object_t *opts; /**< other options */
GList *learn_conditions; /**< list of learn condition callbacks */
GList *classify_conditions; /**< list of classify condition callbacks */
- gchar *name; /**< unique name of classifier */
+ char *name; /**< unique name of classifier */
uint32_t min_tokens; /**< minimal number of tokens to process classifier */
uint32_t max_tokens; /**< maximum number of tokens */
- guint min_token_hits; /**< minimum number of hits for a token to be considered */
- gdouble min_prob_strength; /**< use only tokens with probability in [0.5 - MPS, 0.5 + MPS] */
- guint min_learns; /**< minimum number of learns for each statfile */
- guint flags;
+ unsigned int min_token_hits; /**< minimum number of hits for a token to be considered */
+ double min_prob_strength; /**< use only tokens with probability in [0.5 - MPS, 0.5 + MPS] */
+ unsigned int min_learns; /**< minimum number of learns for each statfile */
+ unsigned int flags;
};
struct rspamd_worker_bind_conf {
GPtrArray *addrs;
- guint cnt;
- gchar *name;
- gchar *bind_line;
+ unsigned int cnt;
+ char *name;
+ char *bind_line;
gboolean is_systemd;
struct rspamd_worker_bind_conf *next;
};
struct rspamd_worker_lua_script {
- gint cbref;
+ int cbref;
struct rspamd_worker_lua_script *prev, *next;
};
struct worker_s *worker; /**< pointer to worker type */
GQuark type; /**< type of worker */
struct rspamd_worker_bind_conf *bind_conf; /**< bind configuration */
- gint16 count; /**< number of workers */
+ int16_t count; /**< number of workers */
GList *listen_socks; /**< listening sockets descriptors */
uint64_t rlimit_nofile; /**< max files limit */
uint64_t rlimit_maxcore; /**< maximum core file size */
struct rspamd_log_format {
enum rspamd_log_format_type type;
- guint flags;
+ unsigned int flags;
gsize len;
gpointer data;
struct rspamd_log_format *prev, *next;
struct rspamd_action;
struct rspamd_config_cfg_lua_script {
- gint cbref;
- gint priority;
- gchar *lua_src_pos;
+ int cbref;
+ int priority;
+ char *lua_src_pos;
struct rspamd_config_cfg_lua_script *prev, *next;
};
struct rspamd_config_post_init_script {
- gint cbref;
+ int cbref;
struct rspamd_config_post_init_script *prev, *next;
};
struct rspamd_config_settings_elt {
uint32_t id;
enum rspamd_config_settings_policy policy;
- const gchar *name;
+ const char *name;
ucl_object_t *symbols_enabled;
ucl_object_t *symbols_disabled;
struct rspamd_config_settings_elt *prev, *next;
* Structure that stores all config data
*/
struct rspamd_config {
- gchar *rspamd_user; /**< user to run as */
- gchar *rspamd_group; /**< group to run as */
+ char *rspamd_user; /**< user to run as */
+ char *rspamd_group; /**< group to run as */
rspamd_mempool_t *cfg_pool; /**< memory pool for config */
- gchar *cfg_name; /**< name of config file */
- gchar *pid_file; /**< name of pid file */
- gchar *temp_dir; /**< dir for temp files */
- gchar *control_socket_path; /**< path to the control socket */
+ char *cfg_name; /**< name of config file */
+ char *pid_file; /**< name of pid file */
+ char *temp_dir; /**< dir for temp files */
+ char *control_socket_path; /**< path to the control socket */
const ucl_object_t *local_addrs; /**< tree of local addresses */
#ifdef WITH_GPERF_TOOLS
- gchar *profile_path;
+ char *profile_path;
#endif
- gdouble unknown_weight; /**< weight of unknown symbols */
- gdouble grow_factor; /**< grow factor for metric */
- GHashTable *symbols; /**< weights of symbols in metric */
- const gchar *subject; /**< subject rewrite string */
- GHashTable *groups; /**< groups of symbols */
- void *actions; /**< all actions of the metric (opaque type) */
+ double unknown_weight; /**< weight of unknown symbols */
+ double grow_factor; /**< grow factor for metric */
+ GHashTable *symbols; /**< weights of symbols in metric */
+ const char *subject; /**< subject rewrite string */
+ GHashTable *groups; /**< groups of symbols */
+ void *actions; /**< all actions of the metric (opaque type) */
gboolean one_shot_mode; /**< rules add only one symbol */
gboolean check_text_attachements; /**< check text attachements as text */
gsize max_cores_size; /**< maximum size occupied by rspamd core files */
gsize max_cores_count; /**< maximum number of core files */
- gchar *cores_dir; /**< directory for core files */
+ char *cores_dir; /**< directory for core files */
gsize max_message; /**< maximum size for messages */
gsize max_pic_size; /**< maximum size for a picture to process */
gsize images_cache_size; /**< size of LRU cache for DCT data from images */
- gdouble task_timeout; /**< maximum message processing time */
- gint default_max_shots; /**< default maximum count of symbols hits permitted (-1 for unlimited) */
+ double task_timeout; /**< maximum message processing time */
+ int default_max_shots; /**< default maximum count of symbols hits permitted (-1 for unlimited) */
int32_t heartbeats_loss_max; /**< number of heartbeats lost to consider worker's termination */
- gdouble heartbeat_interval; /**< interval for heartbeats for workers */
+ double heartbeat_interval; /**< interval for heartbeats for workers */
enum rspamd_log_type log_type; /**< log type */
- gint log_facility; /**< log facility in case of syslog */
- gint log_level; /**< log level trigger */
- gchar *log_file; /**< path to logfile in case of file logging */
+ int log_facility; /**< log facility in case of syslog */
+ int log_level; /**< log level trigger */
+ char *log_file; /**< path to logfile in case of file logging */
gboolean log_buffered; /**< whether logging is buffered */
gboolean log_silent_workers; /**< silence info messages from workers */
uint32_t log_buf_size; /**< length of log buffer */
gboolean log_urls; /**< whether we should log URLs */
GHashTable *debug_modules; /**< logging modules to debug */
struct rspamd_cryptobox_pubkey *log_encryption_key; /**< encryption key for logs */
- guint log_flags; /**< logging flags */
- guint log_error_elts; /**< number of elements in error logbuf */
- guint log_error_elt_maxlen; /**< maximum size of error log element */
- guint log_task_max_elts; /**< maximum number of elements in task logging */
+ unsigned int log_flags; /**< logging flags */
+ unsigned int log_error_elts; /**< number of elements in error logbuf */
+ unsigned int log_error_elt_maxlen; /**< maximum size of error log element */
+ unsigned int log_task_max_elts; /**< maximum number of elements in task logging */
struct rspamd_worker_log_pipe *log_pipes;
gboolean compat_messages; /**< use old messages in the protocol (array) */
GList *statfiles; /**< list of all statfiles in config file order */
GHashTable *classifiers_symbols; /**< hashtable indexed by symbol name of classifiers */
GHashTable *cfg_params; /**< all cfg params indexed by its name in this structure */
- gchar *dynamic_conf; /**< path to dynamic configuration */
+ char *dynamic_conf; /**< path to dynamic configuration */
ucl_object_t *current_dynamic_conf; /**< currently loaded dynamic configuration */
- gint clock_res; /**< resolution of clock used */
+ int clock_res; /**< resolution of clock used */
- GList *maps; /**< maps active */
- gdouble map_timeout; /**< maps watch timeout */
- gdouble map_file_watch_multiplier; /**< multiplier for watch timeout when maps are files */
- gchar *maps_cache_dir; /**< where to save HTTP cached data */
+ GList *maps; /**< maps active */
+ double map_timeout; /**< maps watch timeout */
+ double map_file_watch_multiplier; /**< multiplier for watch timeout when maps are files */
+ char *maps_cache_dir; /**< where to save HTTP cached data */
- gdouble monitored_interval; /**< interval between monitored checks */
+ double monitored_interval; /**< interval between monitored checks */
gboolean disable_monitored; /**< disable monitoring completely */
gboolean fips_mode; /**< turn on fips mode for openssl */
struct rspamd_symcache *cache; /**< symbols cache object */
- gchar *cache_filename; /**< filename of cache file */
- gdouble cache_reload_time; /**< how often cache reload should be performed */
- gchar *checksum; /**< real checksum of config file */
+ char *cache_filename; /**< filename of cache file */
+ double cache_reload_time; /**< how often cache reload should be performed */
+ char *checksum; /**< real checksum of config file */
gpointer lua_state; /**< pointer to lua state */
gpointer lua_thread_pool; /**< pointer to lua thread (coroutine) pool */
- gchar *rrd_file; /**< rrd file to store statistics */
- gchar *history_file; /**< file to save rolling history */
- gchar *stats_file; /**< file to save stats */
- gchar *tld_file; /**< file to load effective tld list from */
- gchar *hs_cache_dir; /**< directory to save hyperscan databases */
- gchar *events_backend; /**< string representation of the events backend used */
+ char *rrd_file; /**< rrd file to store statistics */
+ char *history_file; /**< file to save rolling history */
+ char *stats_file; /**< file to save stats */
+ char *tld_file; /**< file to load effective tld list from */
+ char *hs_cache_dir; /**< directory to save hyperscan databases */
+ char *events_backend; /**< string representation of the events backend used */
- gdouble dns_timeout; /**< timeout in milliseconds for waiting for dns reply */
+ double dns_timeout; /**< timeout in milliseconds for waiting for dns reply */
uint32_t dns_retransmits; /**< maximum retransmits count */
uint32_t dns_io_per_server; /**< number of sockets per DNS server */
const ucl_object_t *nameservers; /**< list of nameservers or NULL to parse resolv.conf */
uint32_t dns_max_requests; /**< limit of DNS requests per task */
gboolean enable_dnssec; /**< enable dnssec stub resolver */
- guint upstream_max_errors; /**< upstream max errors before shutting off */
- gdouble upstream_error_time; /**< rate of upstream errors */
- gdouble upstream_revive_time; /**< revive timeout for upstreams */
- gdouble upstream_lazy_resolve_time; /**< lazy resolve time for upstreams */
+ unsigned int upstream_max_errors; /**< upstream max errors before shutting off */
+ double upstream_error_time; /**< rate of upstream errors */
+ double upstream_revive_time; /**< revive timeout for upstreams */
+ double upstream_lazy_resolve_time; /**< lazy resolve time for upstreams */
struct upstream_ctx *ups_ctx; /**< upstream context */
struct rspamd_dns_resolver *dns_resolver; /**< dns resolver if loaded */
- guint min_word_len; /**< minimum length of the word to be considered */
- guint max_word_len; /**< maximum length of the word to be considered */
- guint words_decay; /**< limit for words for starting adaptive ignoring */
- guint history_rows; /**< number of history rows stored */
- guint max_sessions_cache; /**< maximum number of sessions cache elts */
- guint lua_gc_step; /**< lua gc step */
- guint lua_gc_pause; /**< lua gc pause */
- guint full_gc_iters; /**< iterations between full gc cycle */
- guint max_lua_urls; /**< maximum number of urls to be passed to Lua */
- guint max_urls; /**< maximum number of urls to be processed in general */
- gint max_recipients; /**< maximum number of recipients to be processed */
- guint max_blas_threads; /**< maximum threads for openblas when learning ANN */
- guint max_opts_len; /**< maximum length for all options for a symbol */
- gsize max_html_len; /**< maximum length of HTML document */
+ unsigned int min_word_len; /**< minimum length of the word to be considered */
+ unsigned int max_word_len; /**< maximum length of the word to be considered */
+ unsigned int words_decay; /**< limit for words for starting adaptive ignoring */
+ unsigned int history_rows; /**< number of history rows stored */
+ unsigned int max_sessions_cache; /**< maximum number of sessions cache elts */
+ unsigned int lua_gc_step; /**< lua gc step */
+ unsigned int lua_gc_pause; /**< lua gc pause */
+ unsigned int full_gc_iters; /**< iterations between full gc cycle */
+ unsigned int max_lua_urls; /**< maximum number of urls to be passed to Lua */
+ unsigned int max_urls; /**< maximum number of urls to be processed in general */
+ int max_recipients; /**< maximum number of recipients to be processed */
+ unsigned int max_blas_threads; /**< maximum threads for openblas when learning ANN */
+ unsigned int max_opts_len; /**< maximum length for all options for a symbol */
+ gsize max_html_len; /**< maximum length of HTML document */
struct module_s **compiled_modules; /**< list of compiled C modules */
struct worker_s **compiled_workers; /**< list of compiled C modules */
struct rspamd_log_format *log_format; /**< parsed log format */
- gchar *log_format_str; /**< raw log format string */
+ char *log_format_str; /**< raw log format string */
struct rspamd_external_libs_ctx *libs_ctx; /**< context for external libraries */
struct rspamd_monitored_ctx *monitored_ctx; /**< context for monitored resources */
struct rspamd_config_cfg_lua_script *on_term_scripts; /**< list of callbacks called on worker's termination */
struct rspamd_config_cfg_lua_script *config_unload_scripts; /**< list of scripts executed on config unload */
- gchar *ssl_ca_path; /**< path to CA certs */
- gchar *ssl_ciphers; /**< set of preferred ciphers */
- gchar *zstd_input_dictionary; /**< path to zstd input dictionary */
- gchar *zstd_output_dictionary; /**< path to zstd output dictionary */
- ucl_object_t *neighbours; /**< other servers in the cluster */
+ char *ssl_ca_path; /**< path to CA certs */
+ char *ssl_ciphers; /**< set of preferred ciphers */
+ char *zstd_input_dictionary; /**< path to zstd input dictionary */
+ char *zstd_output_dictionary; /**< path to zstd output dictionary */
+ ucl_object_t *neighbours; /**< other servers in the cluster */
struct rspamd_config_settings_elt *setting_ids; /**< preprocessed settings ids */
struct rspamd_lang_detector *lang_det; /**< language detector */
* @return 1 if line was successfully parsed and 0 in case of error
*/
gboolean rspamd_parse_bind_line(struct rspamd_config *cfg,
- struct rspamd_worker_conf *cf, const gchar *str);
+ struct rspamd_worker_conf *cf, const char *str);
enum rspamd_config_init_flags {
* @return module value or NULL if option does not defined
*/
const ucl_object_t *rspamd_config_get_module_opt(struct rspamd_config *cfg,
- const gchar *module_name,
- const gchar *opt_name) G_GNUC_WARN_UNUSED_RESULT;
+ const char *module_name,
+ const char *opt_name) G_GNUC_WARN_UNUSED_RESULT;
/**
* @param str string representation of flag (eg. 'on')
* @return numeric value of flag (0 or 1)
*/
-gint rspamd_config_parse_flag(const gchar *str, guint len);
+int rspamd_config_parse_flag(const char *str, unsigned int len);
enum rspamd_post_load_options {
RSPAMD_CONFIG_INIT_URL = 1 << 0,
*/
struct rspamd_symbols_group *rspamd_config_new_group(
struct rspamd_config *cfg,
- const gchar *name);
+ const char *name);
/*
* Return a new statfile structure, setting default and non-conflicting attributes
*/
struct rspamd_classifier_config *rspamd_config_find_classifier(
struct rspamd_config *cfg,
- const gchar *name);
+ const char *name);
void rspamd_ucl_add_conf_macros(struct ucl_parser *parser,
struct rspamd_config *cfg);
* @return TRUE if symbol has been inserted or FALSE if symbol already exists with higher priority
*/
gboolean rspamd_config_add_symbol(struct rspamd_config *cfg,
- const gchar *symbol,
- gdouble score,
- const gchar *description,
- const gchar *group,
- guint flags,
- guint priority,
- gint nshots);
+ const char *symbol,
+ double score,
+ const char *description,
+ const char *group,
+ unsigned int flags,
+ unsigned int priority,
+ int nshots);
/**
* Adds new group for a symbol
* @return
*/
gboolean rspamd_config_add_symbol_group(struct rspamd_config *cfg,
- const gchar *symbol,
- const gchar *group);
+ const char *symbol,
+ const char *group);
/**
* Sets action score for a specified metric with the specified priority
* @return TRUE if symbol has been inserted or FALSE if action already exists with higher priority
*/
gboolean rspamd_config_set_action_score(struct rspamd_config *cfg,
- const gchar *action_name,
+ const char *action_name,
const ucl_object_t *obj);
/**
* @return
*/
gboolean rspamd_config_maybe_disable_action(struct rspamd_config *cfg,
- const gchar *action_name,
- guint priority);
+ const char *action_name,
+ unsigned int priority);
/**
* Checks if a specified C or lua module is enabled or disabled in the config.
* @return TRUE if a module is enabled
*/
gboolean rspamd_config_is_module_enabled(struct rspamd_config *cfg,
- const gchar *module_name);
+ const char *module_name);
/**
* Verifies enabled/disabled combination in the specified object
/*
* Get action from a string
*/
-gboolean rspamd_action_from_str(const gchar *data, enum rspamd_action_type *result);
+gboolean rspamd_action_from_str(const char *data, enum rspamd_action_type *result);
/*
* Return textual representation of action enumeration
*/
-const gchar *rspamd_action_to_str(enum rspamd_action_type action);
+const char *rspamd_action_to_str(enum rspamd_action_type action);
-const gchar *rspamd_action_to_str_alt(enum rspamd_action_type action);
+const char *rspamd_action_to_str_alt(enum rspamd_action_type action);
/**
* Parse radix tree or radix map from ucl object
*/
struct rspamd_radix_map_helper;
-gboolean rspamd_config_radix_from_ucl(struct rspamd_config *cfg, const ucl_object_t *obj, const gchar *description,
+gboolean rspamd_config_radix_from_ucl(struct rspamd_config *cfg, const ucl_object_t *obj, const char *description,
struct rspamd_radix_map_helper **target, GError **err,
- struct rspamd_worker *worker, const gchar *map_name);
+ struct rspamd_worker *worker, const char *map_name);
/**
* Adds new settings id to be preprocessed
* @param symbols_disabled (ownership is transferred to callee)
*/
void rspamd_config_register_settings_id(struct rspamd_config *cfg,
- const gchar *name,
+ const char *name,
ucl_object_t *symbols_enabled,
ucl_object_t *symbols_disabled,
enum rspamd_config_settings_policy policy);
* @param namelen
* @return
*/
-uint32_t rspamd_config_name_to_id(const gchar *name, gsize namelen);
+uint32_t rspamd_config_name_to_id(const char *name, gsize namelen);
/**
* Finds settings id element and obtain reference count (must be unrefed by caller)
*/
struct rspamd_config_settings_elt *rspamd_config_find_settings_name_ref(
struct rspamd_config *cfg,
- const gchar *name, gsize namelen);
+ const char *name, gsize namelen);
/**
* Returns action object by name
* @return
*/
struct rspamd_action *rspamd_config_get_action(struct rspamd_config *cfg,
- const gchar *name);
+ const char *name);
struct rspamd_action *rspamd_config_get_action_by_type(struct rspamd_config *cfg,
enum rspamd_action_type type);
gsize rspamd_config_actions_size(struct rspamd_config *cfg);
int rspamd_config_ev_backend_get(struct rspamd_config *cfg);
-const gchar *rspamd_config_ev_backend_to_string(int ev_backend, gboolean *effective);
+const char *rspamd_config_ev_backend_to_string(int ev_backend, gboolean *effective);
struct rspamd_external_libs_ctx;
cfg->cfg_pool->tag.tagname, cfg->checksum, \
RSPAMD_LOG_FUNC, \
__VA_ARGS__)
-#define msg_err_config_forced(...) rspamd_default_log_function((gint) G_LOG_LEVEL_CRITICAL | (gint) RSPAMD_LOG_FORCED, \
- cfg->cfg_pool->tag.tagname, cfg->checksum, \
- RSPAMD_LOG_FUNC, \
+#define msg_err_config_forced(...) rspamd_default_log_function((int) G_LOG_LEVEL_CRITICAL | (int) RSPAMD_LOG_FORCED, \
+ cfg->cfg_pool->tag.tagname, cfg->checksum, \
+ RSPAMD_LOG_FUNC, \
__VA_ARGS__)
#define msg_warn_config(...) rspamd_default_log_function(G_LOG_LEVEL_WARNING, \
cfg->cfg_pool->tag.tagname, cfg->checksum, \
cfg->cfg_pool->tag.tagname, cfg->checksum, \
RSPAMD_LOG_FUNC, \
__VA_ARGS__)
-extern guint rspamd_config_log_id;
+extern unsigned int rspamd_config_log_id;
#define msg_debug_config(...) rspamd_conditional_debug_fast(NULL, NULL, \
rspamd_config_log_id, "config", cfg->checksum, \
RSPAMD_LOG_FUNC, \
struct rspamd_action {
enum rspamd_action_type action_type;
int flags; /* enum rspamd_action_flags */
- guint priority;
- gdouble threshold;
- gchar *name;
+ unsigned int priority;
+ double threshold;
+ char *name;
};
#ifdef __cplusplus
ankerl::unordered_dense::map<std::pair<std::string, gpointer>,
rspamd_worker_param_parser, pair_hash>
parsers; /**< parsers hash */
- gint type; /**< workers quark */
+ int type; /**< workers quark */
gboolean (*def_obj_parser)(ucl_object_t *obj, gpointer ud); /**< default object parser */
gpointer def_ud;
};
*/
static gboolean
rspamd_rcl_logging_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
- const gchar *key, gpointer ud, struct rspamd_rcl_section *section,
+ const char *key, gpointer ud, struct rspamd_rcl_section *section,
GError **err)
{
const ucl_object_t *val;
- const gchar *facility = nullptr, *log_type = nullptr, *log_level = nullptr;
+ const char *facility = nullptr, *log_type = nullptr, *log_level = nullptr;
auto *cfg = (struct rspamd_config *) ud;
val = ucl_object_lookup(obj, "type");
static gboolean
rspamd_rcl_options_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
- const gchar *key, gpointer ud,
+ const char *key, gpointer ud,
struct rspamd_rcl_section *section, GError **err)
{
const ucl_object_t *dns, *upstream, *neighbours;
static gboolean
rspamd_rcl_group_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
- const gchar *key, gpointer ud,
+ const char *key, gpointer ud,
struct rspamd_rcl_section *section, GError **err)
{
auto *cfg = static_cast<rspamd_config *>(ud);
static gboolean
rspamd_rcl_symbol_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
- const gchar *key, gpointer ud,
+ const char *key, gpointer ud,
struct rspamd_rcl_section *section, GError **err)
{
auto *sd = static_cast<rspamd_rcl_symbol_data *>(ud);
struct rspamd_config *cfg;
const ucl_object_t *elt;
- const gchar *description = nullptr;
- gdouble score = NAN;
- guint priority = 1, flags = 0;
- gint nshots = 0;
+ const char *description = nullptr;
+ double score = NAN;
+ unsigned int priority = 1, flags = 0;
+ int nshots = 0;
g_assert(key != nullptr);
cfg = sd->cfg;
static gboolean
rspamd_rcl_actions_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
- const gchar *key, gpointer ud,
+ const char *key, gpointer ud,
struct rspamd_rcl_section *section, GError **err)
{
auto *cfg = static_cast<rspamd_config *>(ud);
it = ucl_object_iterate_new(obj);
while ((cur = ucl_object_iterate_safe(it, true)) != nullptr) {
- gint type = ucl_object_type(cur);
+ int type = ucl_object_type(cur);
if (type == UCL_NULL) {
rspamd_config_maybe_disable_action(cfg, ucl_object_key(cur),
});
static gboolean
rspamd_rcl_worker_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
- const gchar *key, gpointer ud,
+ const char *key, gpointer ud,
struct rspamd_rcl_section *section, GError **err)
{
auto *cfg = static_cast<rspamd_config *>(ud);
static gboolean
rspamd_rcl_lua_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
- const gchar *key, gpointer ud,
+ const char *key, gpointer ud,
struct rspamd_rcl_section *section, GError **err)
{
namespace fs = std::filesystem;
gboolean
rspamd_rcl_add_lua_plugins_path(struct rspamd_rcl_sections_map *sections,
struct rspamd_config *cfg,
- const gchar *path,
+ const char *path,
gboolean main_path,
GError **err)
{
static gboolean
rspamd_rcl_modules_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
- const gchar *key, gpointer ud,
+ const char *key, gpointer ud,
struct rspamd_rcl_section *section, GError **err)
{
auto *cfg = static_cast<rspamd_config *>(ud);
static gboolean
rspamd_rcl_statfile_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
- const gchar *key, gpointer ud,
+ const char *key, gpointer ud,
struct rspamd_rcl_section *section, GError **err)
{
auto *stud = (struct statfile_parser_data *) ud;
static gboolean
rspamd_rcl_classifier_handler(rspamd_mempool_t *pool,
const ucl_object_t *obj,
- const gchar *key,
+ const char *key,
gpointer ud,
struct rspamd_rcl_section *section,
GError **err)
LL_FOREACH(val, cur)
{
if (ucl_object_type(cur) == UCL_STRING) {
- const gchar *lua_script;
+ const char *lua_script;
gsize slen;
- gint ref_idx;
+ int ref_idx;
lua_script = ucl_object_tolstring(cur, &slen);
ref_idx = rspamd_lua_function_ref_from_str(RSPAMD_LUA_CFG_STATE(cfg),
LL_FOREACH(val, cur)
{
if (ucl_object_type(cur) == UCL_STRING) {
- const gchar *lua_script;
+ const char *lua_script;
gsize slen;
- gint ref_idx;
+ int ref_idx;
lua_script = ucl_object_tolstring(cur, &slen);
ref_idx = rspamd_lua_function_ref_from_str(RSPAMD_LUA_CFG_STATE(cfg),
static gboolean
rspamd_rcl_composite_handler(rspamd_mempool_t *pool,
const ucl_object_t *obj,
- const gchar *key,
+ const char *key,
gpointer ud,
struct rspamd_rcl_section *section,
GError **err)
{
auto *cfg = static_cast<rspamd_config *>(ud);
void *composite;
- const gchar *composite_name;
+ const char *composite_name;
g_assert(key != nullptr);
static gboolean
rspamd_rcl_composites_handler(rspamd_mempool_t *pool,
const ucl_object_t *obj,
- const gchar *key,
+ const char *key,
gpointer ud,
struct rspamd_rcl_section *section,
GError **err)
static gboolean
rspamd_rcl_neighbours_handler(rspamd_mempool_t *pool,
const ucl_object_t *obj,
- const gchar *key,
+ const char *key,
gpointer ud,
struct rspamd_rcl_section *section,
GError **err)
{
auto *cfg = static_cast<rspamd_config *>(ud);
auto has_port = FALSE, has_proto = FALSE;
- const gchar *p;
+ const char *p;
if (key == nullptr) {
g_set_error(err,
struct rspamd_rcl_section *
rspamd_rcl_add_section(struct rspamd_rcl_sections_map **top,
struct rspamd_rcl_section *parent_section,
- const gchar *name, const gchar *key_attr, rspamd_rcl_handler_t handler,
+ const char *name, const char *key_attr, rspamd_rcl_handler_t handler,
enum ucl_type type, gboolean required, gboolean strict_type)
{
return rspamd_rcl_add_section_doc(top, parent_section, name, key_attr, handler,
struct rspamd_rcl_section *
rspamd_rcl_add_section_doc(struct rspamd_rcl_sections_map **top,
struct rspamd_rcl_section *parent_section,
- const gchar *name, const gchar *key_attr, rspamd_rcl_handler_t handler,
+ const char *name, const char *key_attr, rspamd_rcl_handler_t handler,
enum ucl_type type, gboolean required, gboolean strict_type,
ucl_object_t *doc_target,
- const gchar *doc_string)
+ const char *doc_string)
{
if (top == nullptr) {
g_error("invalid arguments to rspamd_rcl_add_section");
struct rspamd_rcl_default_handler_data *
rspamd_rcl_add_default_handler(struct rspamd_rcl_section *section,
- const gchar *name,
+ const char *name,
rspamd_rcl_default_handler_t handler,
goffset offset,
- gint flags,
- const gchar *doc_string)
+ int flags,
+ const char *doc_string)
{
auto it = section->default_parser.emplace(std::make_pair(std::string{name}, rspamd_rcl_default_handler_data{}));
ucl_object_iter_t it;
const ucl_object_t *cur;
auto is_nested = true;
- const gchar *key = nullptr;
+ const char *key = nullptr;
if (sec.processed) {
/* Section has been already processed */
auto *pd = (struct rspamd_rcl_struct_parser *) ud;
const gsize num_str_len = 32;
- auto target = (gchar **) (((gchar *) pd->user_struct) + pd->offset);
+ auto target = (char **) (((char *) pd->user_struct) + pd->offset);
switch (obj->type) {
case UCL_STRING:
*target =
rspamd_mempool_strdup(pool, ucl_copy_value_trash(obj));
break;
case UCL_INT:
- *target = (gchar *) rspamd_mempool_alloc(pool, num_str_len);
+ *target = (char *) rspamd_mempool_alloc(pool, num_str_len);
rspamd_snprintf(*target, num_str_len, "%L", obj->value.iv);
break;
case UCL_FLOAT:
- *target = (gchar *) rspamd_mempool_alloc(pool, num_str_len);
+ *target = (char *) rspamd_mempool_alloc(pool, num_str_len);
rspamd_snprintf(*target, num_str_len, "%f", obj->value.dv);
break;
case UCL_BOOLEAN:
- *target = (gchar *) rspamd_mempool_alloc(pool, num_str_len);
+ *target = (char *) rspamd_mempool_alloc(pool, num_str_len);
rspamd_snprintf(*target, num_str_len, "%s",
((gboolean) obj->value.iv) ? "true" : "false");
break;
{
auto *pd = (struct rspamd_rcl_struct_parser *) ud;
union {
- gint *ip;
+ int *ip;
int32_t *i32p;
- gint16 *i16p;
+ int16_t *i16p;
int64_t *i64p;
- guint *up;
+ unsigned int *up;
gsize *sp;
} target;
int64_t val;
if (pd->flags == RSPAMD_CL_FLAG_INT_32) {
- target.i32p = (int32_t *) (((gchar *) pd->user_struct) + pd->offset);
+ target.i32p = (int32_t *) (((char *) pd->user_struct) + pd->offset);
if (!ucl_object_toint_safe(obj, &val)) {
g_set_error(err,
CFG_RCL_ERROR,
*target.i32p = val;
}
else if (pd->flags == RSPAMD_CL_FLAG_INT_64) {
- target.i64p = (int64_t *) (((gchar *) pd->user_struct) + pd->offset);
+ target.i64p = (int64_t *) (((char *) pd->user_struct) + pd->offset);
if (!ucl_object_toint_safe(obj, &val)) {
g_set_error(err,
CFG_RCL_ERROR,
*target.i64p = val;
}
else if (pd->flags == RSPAMD_CL_FLAG_INT_SIZE) {
- target.sp = (gsize *) (((gchar *) pd->user_struct) + pd->offset);
+ target.sp = (gsize *) (((char *) pd->user_struct) + pd->offset);
if (!ucl_object_toint_safe(obj, &val)) {
g_set_error(err,
CFG_RCL_ERROR,
*target.sp = val;
}
else if (pd->flags == RSPAMD_CL_FLAG_INT_16) {
- target.i16p = (gint16 *) (((gchar *) pd->user_struct) + pd->offset);
+ target.i16p = (int16_t *) (((char *) pd->user_struct) + pd->offset);
if (!ucl_object_toint_safe(obj, &val)) {
g_set_error(err,
CFG_RCL_ERROR,
*target.i16p = val;
}
else if (pd->flags == RSPAMD_CL_FLAG_UINT) {
- target.up = (guint *) (((gchar *) pd->user_struct) + pd->offset);
+ target.up = (unsigned int *) (((char *) pd->user_struct) + pd->offset);
if (!ucl_object_toint_safe(obj, &val)) {
g_set_error(err,
CFG_RCL_ERROR,
*target.up = val;
}
else {
- target.ip = (gint *) (((gchar *) pd->user_struct) + pd->offset);
+ target.ip = (int *) (((char *) pd->user_struct) + pd->offset);
if (!ucl_object_toint_safe(obj, &val)) {
g_set_error(err,
CFG_RCL_ERROR,
GError **err)
{
auto *pd = (struct rspamd_rcl_struct_parser *) ud;
- gdouble *target;
+ double *target;
- target = (gdouble *) (((gchar *) pd->user_struct) + pd->offset);
+ target = (double *) (((char *) pd->user_struct) + pd->offset);
if (!ucl_object_todouble_safe(obj, target)) {
g_set_error(err,
{
auto *pd = (struct rspamd_rcl_struct_parser *) ud;
union {
- gint *psec;
+ int *psec;
uint32_t *pu32;
- gdouble *pdv;
+ double *pdv;
struct timeval *ptv;
struct timespec *pts;
} target;
- gdouble val;
+ double val;
if (!ucl_object_todouble_safe(obj, &val)) {
g_set_error(err,
if (pd->flags == RSPAMD_CL_FLAG_TIME_TIMEVAL) {
target.ptv =
- (struct timeval *) (((gchar *) pd->user_struct) + pd->offset);
+ (struct timeval *) (((char *) pd->user_struct) + pd->offset);
target.ptv->tv_sec = (glong) val;
target.ptv->tv_usec = (val - (glong) val) * 1000000;
}
else if (pd->flags == RSPAMD_CL_FLAG_TIME_TIMESPEC) {
target.pts =
- (struct timespec *) (((gchar *) pd->user_struct) + pd->offset);
+ (struct timespec *) (((char *) pd->user_struct) + pd->offset);
target.pts->tv_sec = (glong) val;
target.pts->tv_nsec = (val - (glong) val) * 1000000000000LL;
}
else if (pd->flags == RSPAMD_CL_FLAG_TIME_FLOAT) {
- target.pdv = (double *) (((gchar *) pd->user_struct) + pd->offset);
+ target.pdv = (double *) (((char *) pd->user_struct) + pd->offset);
*target.pdv = val;
}
else if (pd->flags == RSPAMD_CL_FLAG_TIME_INTEGER) {
- target.psec = (gint *) (((gchar *) pd->user_struct) + pd->offset);
+ target.psec = (int *) (((char *) pd->user_struct) + pd->offset);
*target.psec = val * 1000;
}
else if (pd->flags == RSPAMD_CL_FLAG_TIME_UINT_32) {
- target.pu32 = (uint32_t *) (((gchar *) pd->user_struct) + pd->offset);
+ target.pu32 = (uint32_t *) (((char *) pd->user_struct) + pd->offset);
*target.pu32 = val * 1000;
}
else {
auto *pd = (struct rspamd_rcl_struct_parser *) ud;
struct rspamd_cryptobox_keypair **target, *kp;
- target = (struct rspamd_cryptobox_keypair **) (((gchar *) pd->user_struct) +
+ target = (struct rspamd_cryptobox_keypair **) (((char *) pd->user_struct) +
pd->offset);
if (obj->type == UCL_OBJECT) {
kp = rspamd_keypair_from_ucl(obj);
*target = kp;
}
else {
- gchar *dump = (char *) ucl_object_emit(obj, UCL_EMIT_JSON_COMPACT);
+ char *dump = (char *) ucl_object_emit(obj, UCL_EMIT_JSON_COMPACT);
g_set_error(err,
CFG_RCL_ERROR,
EINVAL,
auto *pd = (struct rspamd_rcl_struct_parser *) ud;
struct rspamd_cryptobox_pubkey **target, *pk;
gsize len;
- const gchar *str;
+ const char *str;
rspamd_cryptobox_keypair_type keypair_type = RSPAMD_KEYPAIR_KEX;
rspamd_cryptobox_mode keypair_mode = RSPAMD_CRYPTOBOX_MODE_25519;
keypair_mode = RSPAMD_CRYPTOBOX_MODE_NIST;
}
- target = (struct rspamd_cryptobox_pubkey **) (((gchar *) pd->user_struct) +
+ target = (struct rspamd_cryptobox_pubkey **) (((char *) pd->user_struct) +
pd->offset);
if (obj->type == UCL_STRING) {
str = ucl_object_tolstring(obj, &len);
GList *lv;
gpointer p;
} d;
- gchar *val;
+ char *val;
d.p = *target;
auto is_hash = pd->flags & RSPAMD_CL_FLAG_STRING_LIST_HASH;
- auto *target = (gpointer *) (((gchar *) pd->user_struct) + pd->offset);
+ auto *target = (gpointer *) (((char *) pd->user_struct) + pd->offset);
if (!is_hash && *target != nullptr) {
need_destructor = FALSE;
continue;
}
case UCL_INT: {
- auto *val = (gchar *) rspamd_mempool_alloc(pool, num_str_len);
+ auto *val = (char *) rspamd_mempool_alloc(pool, num_str_len);
rspamd_snprintf(val, num_str_len, "%L", cur->value.iv);
rspamd_rcl_insert_string_list_item(target, pool, val, is_hash);
break;
}
case UCL_FLOAT: {
- auto *val = (gchar *) rspamd_mempool_alloc(pool, num_str_len);
+ auto *val = (char *) rspamd_mempool_alloc(pool, num_str_len);
rspamd_snprintf(val, num_str_len, "%f", cur->value.dv);
rspamd_rcl_insert_string_list_item(target, pool, val, is_hash);
break;
}
case UCL_BOOLEAN: {
- auto *val = (gchar *) rspamd_mempool_alloc(pool, num_str_len);
+ auto *val = (char *) rspamd_mempool_alloc(pool, num_str_len);
rspamd_snprintf(val, num_str_len, "%s",
((gboolean) cur->value.iv) ? "true" : "false");
rspamd_rcl_insert_string_list_item(target, pool, val, is_hash);
auto *pd = (struct rspamd_rcl_struct_parser *) ud;
const ucl_object_t **target;
- target = (const ucl_object_t **) (((gchar *) pd->user_struct) + pd->offset);
+ target = (const ucl_object_t **) (((char *) pd->user_struct) + pd->offset);
*target = obj;
auto *pd = (struct rspamd_rcl_struct_parser *) ud;
gboolean *target;
- target = (gboolean *) (((gchar *) pd->user_struct) + pd->offset);
+ target = (gboolean *) (((char *) pd->user_struct) + pd->offset);
if (obj->type == UCL_BOOLEAN) {
*target = obj->value.iv;
{
auto *pd = (struct rspamd_rcl_struct_parser *) ud;
rspamd_inet_addr_t **target;
- const gchar *val;
+ const char *val;
gsize size;
- target = (rspamd_inet_addr_t **) (((gchar *) pd->user_struct) + pd->offset);
+ target = (rspamd_inet_addr_t **) (((char *) pd->user_struct) + pd->offset);
if (ucl_object_type(obj) == UCL_STRING) {
val = ucl_object_tolstring(obj, &size);
{
auto *pd = (struct rspamd_rcl_struct_parser *) ud;
GPtrArray **target, *tmp_addr = nullptr;
- const gchar *val;
+ const char *val;
ucl_object_iter_t it;
const ucl_object_t *cur;
- target = (GPtrArray **) (((gchar *) pd->user_struct) + pd->offset);
+ target = (GPtrArray **) (((char *) pd->user_struct) + pd->offset);
it = ucl_object_iterate_new(obj);
while ((cur = ucl_object_iterate_safe(it, true)) != nullptr) {
void rspamd_rcl_register_worker_option(struct rspamd_config *cfg,
GQuark type,
- const gchar *name,
+ const char *name,
rspamd_rcl_default_handler_t handler,
gpointer target,
glong offset,
- gint flags,
- const gchar *doc_string)
+ int flags,
+ const char *doc_string)
{
auto parser_it = cfg->rcl_top_section->workers_parser.try_emplace(type, rspamd_worker_cfg_parser{});
auto &parser = parser_it.first->second;
d[0] = nchars;
d[1] = c;
- rspamd_cryptobox_hash_update(hs, (const guchar *) d, sizeof(d));
+ rspamd_cryptobox_hash_update(hs, (const unsigned char *) d, sizeof(d));
return 0;
}
{
auto *hs = (rspamd_cryptobox_hash_state_t *) ud;
- rspamd_cryptobox_hash_update(hs, (const guchar *) &elt, sizeof(elt));
+ rspamd_cryptobox_hash_update(hs, (const unsigned char *) &elt, sizeof(elt));
return 0;
}
{
auto *hs = (rspamd_cryptobox_hash_state_t *) ud;
- rspamd_cryptobox_hash_update(hs, (const guchar *) &elt, sizeof(elt));
+ rspamd_cryptobox_hash_update(hs, (const unsigned char *) &elt, sizeof(elt));
return 0;
}
gboolean
rspamd_config_parse_ucl(struct rspamd_config *cfg,
- const gchar *filename,
+ const char *filename,
GHashTable *vars,
ucl_include_trace_func_t inc_trace,
void *trace_data,
gboolean
rspamd_config_read(struct rspamd_config *cfg,
- const gchar *filename,
+ const char *filename,
rspamd_rcl_section_fin_t logger_fin,
gpointer logger_ud,
GHashTable *vars,
gboolean skip_jinja,
- gchar **lua_env)
+ char **lua_env)
{
GError *err = nullptr;
static void
rspamd_rcl_doc_obj_from_handler(ucl_object_t *doc_obj,
rspamd_rcl_default_handler_t handler,
- gint flags)
+ int flags)
{
auto has_example = ucl_object_lookup(doc_obj, "example") != nullptr;
auto has_type = ucl_object_lookup(doc_obj, "type") != nullptr;
const char *doc_name,
ucl_type_t type,
rspamd_rcl_default_handler_t handler,
- gint flags,
+ int flags,
const char *default_value,
gboolean required)
{
ucl_object_t *
rspamd_rcl_add_doc_by_path(struct rspamd_config *cfg,
- const gchar *doc_path,
+ const char *doc_path,
const char *doc_string,
const char *doc_name,
ucl_type_t type,
rspamd_rcl_default_handler_t handler,
- gint flags,
+ int flags,
const char *default_value,
gboolean required)
{
ucl_object_t *
rspamd_rcl_add_doc_by_example(struct rspamd_config *cfg,
- const gchar *root_path,
- const gchar *doc_string,
- const gchar *doc_name,
- const gchar *example_data, gsize example_len)
+ const char *root_path,
+ const char *doc_string,
+ const char *doc_name,
+ const char *example_data, gsize example_len)
{
auto parser = std::shared_ptr<ucl_parser>(ucl_parser_new(UCL_PARSER_NO_FILEVARS | UCL_PARSER_SAVE_COMMENTS), ucl_parser_free);
*/
typedef gboolean (*rspamd_rcl_handler_t)(rspamd_mempool_t *pool,
const ucl_object_t *obj,
- const gchar *key,
+ const char *key,
gpointer ud,
struct rspamd_rcl_section *section,
GError **err);
*/
struct rspamd_rcl_default_handler_data *rspamd_rcl_add_default_handler(
struct rspamd_rcl_section *section,
- const gchar *name,
+ const char *name,
rspamd_rcl_default_handler_t handler,
goffset offset,
- gint flags,
- const gchar *doc_string);
+ int flags,
+ const char *doc_string);
/**
* Add new section to the configuration
struct rspamd_rcl_section *rspamd_rcl_add_section(
struct rspamd_rcl_sections_map **top,
struct rspamd_rcl_section *parent_section,
- const gchar *name,
- const gchar *key_attr,
+ const char *name,
+ const char *key_attr,
rspamd_rcl_handler_t handler,
enum ucl_type type,
gboolean required,
struct rspamd_rcl_section *rspamd_rcl_add_section_doc(
struct rspamd_rcl_sections_map **top,
struct rspamd_rcl_section *parent_section,
- const gchar *name, const gchar *key_attr,
+ const char *name, const char *key_attr,
rspamd_rcl_handler_t handler,
enum ucl_type type, gboolean required,
gboolean strict_type,
ucl_object_t *doc_target,
- const gchar *doc_string);
+ const char *doc_string);
/**
* Init common sections known to rspamd
*/
void rspamd_rcl_register_worker_option(struct rspamd_config *cfg,
GQuark type,
- const gchar *name,
+ const char *name,
rspamd_rcl_default_handler_t handler,
gpointer target,
glong offset,
- gint flags,
- const gchar *doc_string);
+ int flags,
+ const char *doc_string);
/**
* Adds new documentation object to the configuration
const char *doc_name,
ucl_type_t type,
rspamd_rcl_default_handler_t handler,
- gint flags,
+ int flags,
const char *default_value,
gboolean required);
* split by dots
*/
ucl_object_t *rspamd_rcl_add_doc_by_path(struct rspamd_config *cfg,
- const gchar *doc_path,
+ const char *doc_path,
const char *doc_string,
const char *doc_name,
ucl_type_t type,
rspamd_rcl_default_handler_t handler,
- gint flags,
+ int flags,
const char *default_value,
gboolean required);
* @return
*/
ucl_object_t *rspamd_rcl_add_doc_by_example(struct rspamd_config *cfg,
- const gchar *root_path,
- const gchar *doc_string,
- const gchar *doc_name,
- const gchar *example_data, gsize example_len);
+ const char *root_path,
+ const char *doc_string,
+ const char *doc_name,
+ const char *example_data, gsize example_len);
/**
* Add lua modules path
*/
gboolean rspamd_rcl_add_lua_plugins_path(struct rspamd_rcl_sections_map *sections,
struct rspamd_config *cfg,
- const gchar *path,
+ const char *path,
gboolean main_path,
GError **err);
* Read configuration file
*/
gboolean rspamd_config_parse_ucl(struct rspamd_config *cfg,
- const gchar *filename,
+ const char *filename,
GHashTable *vars,
ucl_include_trace_func_t inc_trace,
void *trace_data,
gboolean skip_jinja,
GError **err);
gboolean rspamd_config_read(struct rspamd_config *cfg,
- const gchar *filename,
+ const char *filename,
rspamd_rcl_section_fin_t logger_fin,
gpointer logger_ud,
GHashTable *vars,
gboolean skip_jinja,
- gchar **lua_env);
+ char **lua_env);
#ifdef __cplusplus
}
{
}
};
-static gchar *rspamd_ucl_read_cb(gchar *chunk,
- gint len,
- struct map_cb_data *data,
- gboolean final);
+static char *rspamd_ucl_read_cb(char *chunk,
+ int len,
+ struct map_cb_data *data,
+ gboolean final);
static void rspamd_ucl_fin_cb(struct map_cb_data *data, void **target);
static void rspamd_ucl_dtor_cb(struct map_cb_data *data);
-guint rspamd_config_log_id = (guint) -1;
+unsigned int rspamd_config_log_id = (unsigned int) -1;
RSPAMD_CONSTRUCTOR(rspamd_config_log_init)
{
rspamd_config_log_id = rspamd_logger_add_debug_module("config");
gboolean
rspamd_parse_bind_line(struct rspamd_config *cfg,
struct rspamd_worker_conf *cf,
- const gchar *str)
+ const char *str)
{
struct rspamd_worker_bind_conf *cnf;
- const gchar *fdname;
+ const char *fdname;
gboolean ret = TRUE;
if (str == nullptr) {
const ucl_object_t *
rspamd_config_get_module_opt(struct rspamd_config *cfg,
- const gchar *module_name,
- const gchar *opt_name)
+ const char *module_name,
+ const char *opt_name)
{
const ucl_object_t *res = nullptr, *sec;
return res;
}
-gint rspamd_config_parse_flag(const gchar *str, guint len)
+int rspamd_config_parse_flag(const char *str, unsigned int len)
{
- gint c;
+ int c;
if (!str || !*str) {
return -1;
static gboolean
rspamd_config_parse_log_format(struct rspamd_config *cfg)
{
- const gchar *p, *c, *end, *s;
- gchar *d;
+ const char *p, *c, *end, *s;
+ char *d;
struct rspamd_log_format *lf = nullptr;
rspamd_ftok_t var, var_content;
enum {
parse_var_name,
parse_var_content,
} state = parse_str;
- gint braces = 0;
+ int braces = 0;
g_assert(cfg != nullptr);
c = cfg->log_format_str;
}
struct rspamd_symbols_group *
-rspamd_config_new_group(struct rspamd_config *cfg, const gchar *name)
+rspamd_config_new_group(struct rspamd_config *cfg, const char *name)
{
struct rspamd_symbols_group *gr;
static bool
-rspamd_include_map_handler(const guchar *data, gsize len,
+rspamd_include_map_handler(const unsigned char *data, gsize len,
const ucl_object_t *args, void *ud)
{
auto *cfg = (struct rspamd_config *) ud;
}
struct rspamd_classifier_config *
-rspamd_config_find_classifier(struct rspamd_config *cfg, const gchar *name)
+rspamd_config_find_classifier(struct rspamd_config *cfg, const char *name)
{
if (name == nullptr) {
return nullptr;
return res;
}
-static gchar *
-rspamd_ucl_read_cb(gchar *chunk,
- gint len,
+static char *
+rspamd_ucl_read_cb(char *chunk,
+ int len,
struct map_cb_data *data,
gboolean final)
{
if (mod != nullptr) {
if (mod->module_version != RSPAMD_CUR_MODULE_VERSION) {
msg_err_config("module %s has incorrect version %xd (%xd expected)",
- mod->name, (gint) mod->module_version, RSPAMD_CUR_MODULE_VERSION);
+ mod->name, (int) mod->module_version, RSPAMD_CUR_MODULE_VERSION);
ret = FALSE;
}
if (ret && mod->rspamd_version != RSPAMD_VERSION_NUM) {
{
GList *cur;
module_t *mod, **pmod;
- guint i = 0;
+ unsigned int i = 0;
struct module_ctx *mod_ctx, *cur_ctx;
gboolean ret = TRUE;
PTR_ARRAY_FOREACH(cfg->c_modules, i, cur_ctx)
{
if (g_ascii_strcasecmp(cur_ctx->mod->name,
- (const gchar *) cur->data) == 0) {
+ (const char *) cur->data) == 0) {
mod_ctx = cur_ctx;
break;
}
}
static void
-rspamd_config_new_symbol(struct rspamd_config *cfg, const gchar *symbol,
- gdouble score, const gchar *description, const gchar *group,
- guint flags, guint priority, gint nshots)
+rspamd_config_new_symbol(struct rspamd_config *cfg, const char *symbol,
+ double score, const char *description, const char *group,
+ unsigned int flags, unsigned int priority, int nshots)
{
struct rspamd_symbols_group *sym_group;
struct rspamd_symbol *sym_def;
gboolean
rspamd_config_add_symbol(struct rspamd_config *cfg,
- const gchar *symbol,
- gdouble score,
- const gchar *description,
- const gchar *group,
- guint flags,
- guint priority,
- gint nshots)
+ const char *symbol,
+ double score,
+ const char *description,
+ const char *group,
+ unsigned int flags,
+ unsigned int priority,
+ int nshots)
{
struct rspamd_symbol *sym_def;
struct rspamd_symbols_group *sym_group;
- guint i;
+ unsigned int i;
g_assert(cfg != nullptr);
g_assert(symbol != nullptr);
gboolean
rspamd_config_add_symbol_group(struct rspamd_config *cfg,
- const gchar *symbol,
- const gchar *group)
+ const char *symbol,
+ const char *group)
{
struct rspamd_symbol *sym_def;
struct rspamd_symbols_group *sym_group;
- guint i;
+ unsigned int i;
g_assert(cfg != nullptr);
g_assert(symbol != nullptr);
return ucl_object_toboolean(enabled);
}
else if (ucl_object_type(enabled) == UCL_STRING) {
- gint ret = rspamd_config_parse_flag(ucl_object_tostring(enabled), 0);
+ int ret = rspamd_config_parse_flag(ucl_object_tostring(enabled), 0);
if (ret == 0) {
return FALSE;
return !ucl_object_toboolean(disabled);
}
else if (ucl_object_type(disabled) == UCL_STRING) {
- gint ret = rspamd_config_parse_flag(ucl_object_tostring(disabled), 0);
+ int ret = rspamd_config_parse_flag(ucl_object_tostring(disabled), 0);
if (ret == 0) {
return TRUE;
gboolean
rspamd_config_is_module_enabled(struct rspamd_config *cfg,
- const gchar *module_name)
+ const char *module_name)
{
gboolean is_c = FALSE, enabled;
const ucl_object_t *conf;
struct rspamd_symbols_group *gr;
lua_State *L = RSPAMD_LUA_CFG_STATE(cfg);
struct module_ctx *cur_ctx;
- guint i;
+ unsigned int i;
PTR_ARRAY_FOREACH(cfg->c_modules, i, cur_ctx)
{
rspamd_config_action_from_ucl(struct rspamd_config *cfg,
struct rspamd_action *act,
const ucl_object_t *obj,
- guint priority)
+ unsigned int priority)
{
auto threshold = NAN;
int flags = 0;
while ((cur = ucl_object_iterate(elt, &it, true)) != nullptr) {
if (ucl_object_type(cur) == UCL_STRING) {
- const gchar *fl_str = ucl_object_tostring(cur);
+ const char *fl_str = ucl_object_tostring(cur);
if (g_ascii_strcasecmp(fl_str, "no_threshold") == 0) {
flags |= RSPAMD_ACTION_NO_THRESHOLD;
elt = ucl_object_lookup(obj, "milter");
if (elt) {
- const gchar *milter_action = ucl_object_tostring(elt);
+ const char *milter_action = ucl_object_tostring(elt);
if (strcmp(milter_action, "discard") == 0) {
flags |= RSPAMD_ACTION_MILTER;
gboolean
rspamd_config_set_action_score(struct rspamd_config *cfg,
- const gchar *action_name,
+ const char *action_name,
const ucl_object_t *obj)
{
enum rspamd_action_type std_act;
const ucl_object_t *elt;
- guint priority = ucl_object_get_priority(obj), obj_type;
+ unsigned int priority = ucl_object_get_priority(obj), obj_type;
g_assert(cfg != nullptr);
g_assert(action_name != nullptr);
gboolean
rspamd_config_maybe_disable_action(struct rspamd_config *cfg,
- const gchar *action_name,
- guint priority)
+ const char *action_name,
+ unsigned int priority)
{
auto actions = RSPAMD_CFG_ACTIONS(cfg);
auto maybe_act = rspamd::find_map(actions->actions_by_name, action_name);
}
struct rspamd_action *
-rspamd_config_get_action(struct rspamd_config *cfg, const gchar *name)
+rspamd_config_get_action(struct rspamd_config *cfg, const char *name)
{
auto actions = RSPAMD_CFG_ACTIONS(cfg);
auto maybe_act = rspamd::find_map(actions->actions_by_name, name);
}
gboolean
-rspamd_config_radix_from_ucl(struct rspamd_config *cfg, const ucl_object_t *obj, const gchar *description,
+rspamd_config_radix_from_ucl(struct rspamd_config *cfg, const ucl_object_t *obj, const char *description,
struct rspamd_radix_map_helper **target, GError **err,
- struct rspamd_worker *worker, const gchar *map_name)
+ struct rspamd_worker *worker, const char *map_name)
{
ucl_type_t type;
ucl_object_iter_t it = nullptr;
const ucl_object_t *cur, *cur_elt;
- const gchar *str;
+ const char *str;
/* Cleanup */
*target = nullptr;
});
gboolean
-rspamd_action_from_str(const gchar *data, enum rspamd_action_type *result)
+rspamd_action_from_str(const char *data, enum rspamd_action_type *result)
{
auto maybe_action = rspamd::find_map(action_types, std::string_view{data});
}
}
-const gchar *
+const char *
rspamd_action_to_str(enum rspamd_action_type action)
{
switch (action) {
return "unknown action";
}
-const gchar *
+const char *
rspamd_action_to_str_alt(enum rspamd_action_type action)
{
switch (action) {
}
uint32_t
-rspamd_config_name_to_id(const gchar *name, gsize namelen)
+rspamd_config_name_to_id(const char *name, gsize namelen)
{
uint64_t h;
struct rspamd_config_settings_elt *rspamd_config_find_settings_name_ref(
struct rspamd_config *cfg,
- const gchar *name, gsize namelen)
+ const char *name, gsize namelen)
{
uint32_t id;
}
void rspamd_config_register_settings_id(struct rspamd_config *cfg,
- const gchar *name,
+ const char *name,
ucl_object_t *symbols_enabled,
ucl_object_t *symbols_disabled,
enum rspamd_config_settings_policy policy)
return AUTO_BACKEND;
}
-const gchar *
+const char *
rspamd_config_ev_backend_to_string(int ev_backend, gboolean *effective)
{
#define SET_EFFECTIVE(b) \
#endif
/* Configure utf8 library */
- guint utf8_flags = 0;
+ unsigned int utf8_flags = 0;
if ((ctx->crypto_ctx->cpu_config & CPUID_SSE41)) {
utf8_flags |= RSPAMD_FAST_UTF8_FLAG_SSE41;
namespace rspamd::composites {
-static rspamd_expression_atom_t *rspamd_composite_expr_parse(const gchar *line, gsize len,
+static rspamd_expression_atom_t *rspamd_composite_expr_parse(const char *line, gsize len,
rspamd_mempool_t *pool,
gpointer ud, GError **err);
-static gdouble rspamd_composite_expr_process(void *ud, rspamd_expression_atom_t *atom);
-static gint rspamd_composite_expr_priority(rspamd_expression_atom_t *atom);
+static double rspamd_composite_expr_process(void *ud, rspamd_expression_atom_t *atom);
+static int rspamd_composite_expr_priority(rspamd_expression_atom_t *atom);
static void rspamd_composite_expr_destroy(rspamd_expression_atom_t *atom);
static void composites_foreach_callback(gpointer key, gpointer value, void *data);
}
static rspamd_expression_atom_t *
-rspamd_composite_expr_parse(const gchar *line, gsize len,
+rspamd_composite_expr_parse(const char *line, gsize len,
rspamd_mempool_t *pool,
gpointer ud, GError **err)
{
gsize clen = 0;
- const gchar *p, *end;
+ const char *p, *end;
enum composite_expr_state {
comp_state_read_symbol = 0,
comp_state_read_obrace,
res->str = line;
/* Full state machine to fill a composite atom */
- const gchar *opt_start = nullptr;
+ const char *opt_start = nullptr;
while (p < end) {
if (state == comp_state_read_end) {
case comp_state_read_option:
if (*p == ',' || *p == ']') {
/* Plain match, copy option to ensure string_view validity */
- gint opt_len = p - opt_start;
+ int opt_len = p - opt_start;
auto *opt_buf = rspamd_mempool_alloc_buffer(pool, opt_len + 1);
rspamd_strlcpy(opt_buf, opt_start, opt_len + 1);
opt_buf = g_strstrip(opt_buf);
struct rspamd_composite_atom *atom) -> double
{
struct rspamd_symbol_result *ms = nullptr;
- gdouble rc = 0;
+ double rc = 0;
struct rspamd_task *task = cd->task;
if ((ms = rspamd_task_find_symbol_result(cd->task, sym.data(), cd->metric_res)) == nullptr) {
struct rspamd_symbol_result *ms = NULL;
struct rspamd_task *task = cd->task;
- gdouble rc = 0;
+ double rc = 0;
if (cd->checked[cd->composite->id * 2]) {
/* We have already checked this composite, so just return its value */
/*
* We don't have preferences for composites
*/
-static gint
+static int
rspamd_composite_expr_priority(rspamd_expression_atom_t *atom)
{
return 0;
{
auto *cd = (struct composites_data *) data;
auto *comp = (struct rspamd_composite *) value;
- auto *str_key = (const gchar *) key;
+ auto *str_key = (const char *) key;
struct rspamd_task *task;
- gdouble rc;
+ double rc;
cd->composite = comp;
task = cd->task;
want_remove_score = TRUE,
want_remove_symbol = TRUE,
want_forced = FALSE;
- const gchar *disable_score_reason = "no policy",
- *disable_symbol_reason = "no policy";
+ const char *disable_score_reason = "no policy",
+ *disable_symbol_reason = "no policy";
task = cd.task;
std::string str_expr;
std::string sym;
struct rspamd_expression *expr;
- gint id;
+ int id;
rspamd_composite_policy policy;
};
}// namespace rspamd::css
/* C API */
-const gchar *rspamd_css_unescape(rspamd_mempool_t *pool,
- const guchar *begin,
- gsize len,
- gsize *outlen)
+const char *rspamd_css_unescape(rspamd_mempool_t *pool,
+ const unsigned char *begin,
+ gsize len,
+ gsize *outlen)
{
auto sv = rspamd::css::unescape_css(pool, {(const char *) begin, len});
const auto *v = sv.begin();
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
union rspamd_dkim_header_stat {
struct _st {
- guint16 count;
- guint16 flags;
+ uint16_t count;
+ uint16_t flags;
} s;
uint32_t n;
};
EVP_MD_CTX *headers_hash;
EVP_MD_CTX *body_hash;
enum rspamd_dkim_type type;
- guint idx;
- gint header_canon_type;
- gint body_canon_type;
- guint body_canonicalised;
- guint headers_canonicalised;
+ unsigned int idx;
+ int header_canon_type;
+ int body_canon_type;
+ unsigned int body_canonicalised;
+ unsigned int headers_canonicalised;
gboolean is_sign;
};
struct rspamd_dns_resolver *resolver;
gsize blen;
gsize bhlen;
- gint sig_alg;
- guint ver;
+ int sig_alg;
+ unsigned int ver;
time_t timestamp;
time_t expiration;
- gchar *domain;
- gchar *selector;
- gint8 *b;
- gchar *short_b;
- gint8 *bh;
- gchar *dns_key;
+ char *domain;
+ char *selector;
+ int8_t *b;
+ char *short_b;
+ int8_t *bh;
+ char *dns_key;
enum rspamd_arc_seal_cv cv;
- const gchar *dkim_header;
+ const char *dkim_header;
};
#define RSPAMD_DKIM_KEY_ID_LEN 16
struct rspamd_dkim_key_s {
- guint8 *keydata;
- guint8 *raw_key;
+ uint8_t *keydata;
+ uint8_t *raw_key;
gsize keylen;
gsize decoded_len;
- gchar key_id[RSPAMD_DKIM_KEY_ID_LEN];
+ char key_id[RSPAMD_DKIM_KEY_ID_LEN];
union {
RSA *key_rsa;
EC_KEY *key_ecdsa;
- guchar *key_eddsa;
+ unsigned char *key_eddsa;
} key;
BIO *key_bio;
EVP_PKEY *key_evp;
time_t mtime;
- guint ttl;
+ unsigned int ttl;
enum rspamd_dkim_key_type type;
ref_entry_t ref;
};
};
struct rspamd_dkim_header {
- const gchar *name;
- gint count;
+ const char *name;
+ int count;
};
/* Parser of dkim params */
typedef gboolean (*dkim_parse_param_f)(rspamd_dkim_context_t *ctx,
- const gchar *param, gsize len, GError **err);
+ const char *param, gsize len, GError **err);
static gboolean rspamd_dkim_parse_signature(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err);
static gboolean rspamd_dkim_parse_signalg(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err);
static gboolean rspamd_dkim_parse_domain(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err);
static gboolean rspamd_dkim_parse_canonalg(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err);
static gboolean rspamd_dkim_parse_ignore(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err);
static gboolean rspamd_dkim_parse_selector(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err);
static gboolean rspamd_dkim_parse_hdrlist(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err);
static gboolean rspamd_dkim_parse_version(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err);
static gboolean rspamd_dkim_parse_timestamp(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err);
static gboolean rspamd_dkim_parse_expiration(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err);
static gboolean rspamd_dkim_parse_bodyhash(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err);
static gboolean rspamd_dkim_parse_bodylength(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err);
static gboolean rspamd_dkim_parse_idx(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err);
static gboolean rspamd_dkim_parse_cv(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err);
/* Parsers implementation */
static gboolean
rspamd_dkim_parse_signature(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err)
{
static gboolean
rspamd_dkim_parse_signalg(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err)
{
static gboolean
rspamd_dkim_parse_domain(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err)
{
static gboolean
rspamd_dkim_parse_canonalg(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err)
{
- const gchar *p, *slash = NULL, *end = param + len;
+ const char *p, *slash = NULL, *end = param + len;
gsize sl = 0;
p = param;
static gboolean
rspamd_dkim_parse_ignore(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err)
{
static gboolean
rspamd_dkim_parse_selector(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err)
{
static gboolean
rspamd_dkim_parse_hdrlist_common(struct rspamd_dkim_common_ctx *ctx,
- const gchar *param,
+ const char *param,
gsize len,
gboolean sign,
GError **err)
{
- const gchar *c, *p, *end = param + len;
- gchar *h;
+ const char *c, *p, *end = param + len;
+ char *h;
gboolean from_found = FALSE, oversign, existing;
- guint count = 0;
+ unsigned int count = 0;
struct rspamd_dkim_header *new;
gpointer found;
union rspamd_dkim_header_stat u;
static gboolean
rspamd_dkim_parse_hdrlist(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err)
{
static gboolean
rspamd_dkim_parse_version(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err)
{
static gboolean
rspamd_dkim_parse_timestamp(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err)
{
static gboolean
rspamd_dkim_parse_expiration(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err)
{
static gboolean
rspamd_dkim_parse_bodyhash(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err)
{
static gboolean
rspamd_dkim_parse_bodylength(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err)
{
static gboolean
rspamd_dkim_parse_idx(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err)
{
static gboolean
rspamd_dkim_parse_cv(rspamd_dkim_context_t *ctx,
- const gchar *param,
+ const char *param,
gsize len,
GError **err)
{
struct rspamd_dkim_common_ctx *ctx)
{
struct rspamd_dkim_header *hdr;
- gint count = ctx->idx, i;
+ int count = ctx->idx, i;
ctx->hlist = g_ptr_array_sized_new(count * 3 - 1);
* @return new context or NULL
*/
rspamd_dkim_context_t *
-rspamd_create_dkim_context(const gchar *sig,
+rspamd_create_dkim_context(const char *sig,
rspamd_mempool_t *pool,
struct rspamd_dns_resolver *resolver,
- guint time_jitter,
+ unsigned int time_jitter,
enum rspamd_dkim_type type,
GError **err)
{
- const gchar *p, *c, *tag = NULL, *end;
- gint taglen;
- gint param = DKIM_PARAM_UNKNOWN;
+ const char *p, *c, *tag = NULL, *end;
+ int taglen;
+ int param = DKIM_PARAM_UNKNOWN;
const EVP_MD *md_alg;
time_t now;
rspamd_dkim_context_t *ctx;
}
else {
/* Cut trailing spaces for value */
- gint tlen = p - c;
- const gchar *tmp = p - 1;
+ int tlen = p - c;
+ const char *tmp = p - 1;
while (tlen > 0) {
if (!g_ascii_isspace(*tmp)) {
}
else if (p == end) {
/* Last parameter with no `;` character */
- gint tlen = p - c;
- const gchar *tmp = p - 1;
+ int tlen = p - c;
+ const char *tmp = p - 1;
while (tlen > 0) {
if (!g_ascii_isspace(*tmp)) {
if (type != RSPAMD_DKIM_ARC_SEAL) {
if (ctx->sig_alg == DKIM_SIGN_RSASHA1) {
/* Check bh length */
- if (ctx->bhlen != (guint) EVP_MD_size(EVP_sha1())) {
+ if (ctx->bhlen != (unsigned int) EVP_MD_size(EVP_sha1())) {
g_set_error(err,
DKIM_ERROR,
DKIM_SIGERROR_BADSIG,
else if (ctx->sig_alg == DKIM_SIGN_RSASHA256 ||
ctx->sig_alg == DKIM_SIGN_ECDSASHA256) {
if (ctx->bhlen !=
- (guint) EVP_MD_size(EVP_sha256())) {
+ (unsigned int) EVP_MD_size(EVP_sha256())) {
g_set_error(err,
DKIM_ERROR,
DKIM_SIGERROR_BADSIG,
else if (ctx->sig_alg == DKIM_SIGN_RSASHA512 ||
ctx->sig_alg == DKIM_SIGN_ECDSASHA512) {
if (ctx->bhlen !=
- (guint) EVP_MD_size(EVP_sha512())) {
+ (unsigned int) EVP_MD_size(EVP_sha512())) {
g_set_error(err,
DKIM_ERROR,
DKIM_SIGERROR_BADSIG,
/* Check expiration */
now = time(NULL);
- if (ctx->timestamp && now < ctx->timestamp && ctx->timestamp - now > (gint) time_jitter) {
+ if (ctx->timestamp && now < ctx->timestamp && ctx->timestamp - now > (int) time_jitter) {
g_set_error(err,
DKIM_ERROR,
DKIM_SIGERROR_FUTURE,
};
rspamd_dkim_key_t *
-rspamd_dkim_make_key(const gchar *keydata,
- guint keylen, enum rspamd_dkim_key_type type, GError **err)
+rspamd_dkim_make_key(const char *keydata,
+ unsigned int keylen, enum rspamd_dkim_key_type type, GError **err)
{
rspamd_dkim_key_t *key = NULL;
/* Copy key skipping all spaces and newlines */
const char *h = keydata;
- guint8 *t = key->raw_key;
+ uint8_t *t = key->raw_key;
while (h - keydata < keylen) {
if (!g_ascii_isspace(*h)) {
#endif
if (EVP_DigestInit_ex(mdctx, EVP_md5(), NULL) == 1) {
- guint dlen = sizeof(key->key_id);
+ unsigned int dlen = sizeof(key->key_id);
EVP_DigestUpdate(mdctx, key->keydata, key->decoded_len);
EVP_DigestFinal_ex(mdctx, key->key_id, &dlen);
DKIM_ERROR,
DKIM_SIGERROR_KEYFAIL,
"DKIM key is has invalid length %d for eddsa; expected %d",
- (gint) key->decoded_len,
+ (int) key->decoded_len,
rspamd_cryptobox_pk_sig_bytes(RSPAMD_CRYPTOBOX_MODE_25519));
REF_RELEASE(key);
return key;
}
-const guchar *
+const unsigned char *
rspamd_dkim_key_id(rspamd_dkim_key_t *key)
{
if (key) {
}
rspamd_dkim_key_t *
-rspamd_dkim_parse_key(const gchar *txt, gsize *keylen, GError **err)
+rspamd_dkim_parse_key(const char *txt, gsize *keylen, GError **err)
{
- const gchar *c, *p, *end, *key = NULL, *alg = "rsa";
+ const char *c, *p, *end, *key = NULL, *alg = "rsa";
enum {
read_tag = 0,
read_tag_before_eqsign,
skip_spaces,
} state = read_tag,
next_state;
- gchar tag = '\0';
+ char tag = '\0';
gsize klen = 0, alglen = 0;
c = txt;
gsize keylen = 0;
if (reply->code != RDNS_RC_NOERROR) {
- gint err_code = DKIM_SIGERROR_NOKEY;
+ int err_code = DKIM_SIGERROR_NOKEY;
if (reply->code == RDNS_RC_NOREC) {
err_code = DKIM_SIGERROR_NOREC;
}
static gboolean
rspamd_dkim_relaxed_body_step(struct rspamd_dkim_common_ctx *ctx, EVP_MD_CTX *ck,
- const gchar **start, guint size,
+ const char **start, unsigned int size,
gssize *remain)
{
- const gchar *h;
- gchar *t;
- guint len, inlen;
+ const char *h;
+ char *t;
+ unsigned int len, inlen;
gssize octets_remain;
gboolean got_sp, ret = TRUE;
- gchar buf[1024];
+ char buf[1024];
len = size;
inlen = sizeof(buf) - 1;
static gboolean
rspamd_dkim_simple_body_step(struct rspamd_dkim_common_ctx *ctx,
- EVP_MD_CTX *ck, const gchar **start, guint size,
+ EVP_MD_CTX *ck, const char **start, unsigned int size,
gssize *remain)
{
- const gchar *h;
- gchar *t;
- guint len, inlen;
+ const char *h;
+ char *t;
+ unsigned int len, inlen;
gssize octets_remain;
- gchar buf[1024];
+ char buf[1024];
len = size;
inlen = sizeof(buf) - 1;
return ((len != 0) && (octets_remain != 0));
}
-static const gchar *
-rspamd_dkim_skip_empty_lines(const gchar *start, const gchar *end,
- guint type, gboolean sign, gboolean *need_crlf)
+static const char *
+rspamd_dkim_skip_empty_lines(const char *start, const char *end,
+ unsigned int type, gboolean sign, gboolean *need_crlf)
{
- const gchar *p = end - 1, *t;
+ const char *p = end - 1, *t;
enum {
init = 0,
init_2,
got_crlf,
test_spaces,
} state = init;
- guint skip = 0;
+ unsigned int skip = 0;
while (p >= start) {
switch (state) {
static gboolean
rspamd_dkim_canonize_body(struct rspamd_dkim_common_ctx *ctx,
- const gchar *start,
- const gchar *end,
+ const char *start,
+ const char *end,
gboolean sign)
{
- const gchar *p;
+ const char *p;
gssize remain = ctx->len ? ctx->len : G_MAXSSIZE;
- guint total_len = end - start;
+ unsigned int total_len = end - start;
gboolean need_crlf = FALSE;
if (start == NULL) {
/* Update hash converting all CR and LF to CRLF */
static void
-rspamd_dkim_hash_update(EVP_MD_CTX *ck, const gchar *begin, gsize len)
+rspamd_dkim_hash_update(EVP_MD_CTX *ck, const char *begin, gsize len)
{
- const gchar *p, *c, *end;
+ const char *p, *c, *end;
end = begin + len;
p = begin;
/* Update hash by signature value (ignoring b= tag) */
static void
rspamd_dkim_signature_update(struct rspamd_dkim_common_ctx *ctx,
- const gchar *begin,
- guint len)
+ const char *begin,
+ unsigned int len)
{
- const gchar *p, *c, *end;
+ const char *p, *c, *end;
gboolean tag, skip;
end = begin + len;
if (tag && p[0] == 'b' && p[1] == '=') {
/* Add to signature */
msg_debug_dkim("initial update hash with signature part: %*s",
- (gint) (p - c + 2),
+ (int) (p - c + 2),
c);
ctx->headers_canonicalised += p - c + 2;
rspamd_dkim_hash_update(ctx->headers_hash, c, p - c + 2);
if (p - c + 1 > 0) {
msg_debug_dkim("final update hash with signature part: %*s",
- (gint) (p - c + 1), c);
+ (int) (p - c + 1), c);
ctx->headers_canonicalised += p - c + 1;
rspamd_dkim_hash_update(ctx->headers_hash, c, p - c + 1);
}
}
goffset
-rspamd_dkim_canonize_header_relaxed_str(const gchar *hname,
- const gchar *hvalue,
- gchar *out,
+rspamd_dkim_canonize_header_relaxed_str(const char *hname,
+ const char *hvalue,
+ char *out,
gsize outlen)
{
- gchar *t;
- const guchar *h;
+ char *t;
+ const unsigned char *h;
gboolean got_sp;
/* Name part */
static gboolean
rspamd_dkim_canonize_header_relaxed(struct rspamd_dkim_common_ctx *ctx,
- const gchar *header,
- const gchar *header_name,
+ const char *header,
+ const char *header_name,
gboolean is_sign,
- guint count,
+ unsigned int count,
bool is_seal)
{
- static gchar st_buf[8192];
- gchar *buf;
- guint inlen;
+ static char st_buf[8192];
+ char *buf;
+ unsigned int inlen;
goffset r;
gboolean allocated = FALSE;
static gboolean
rspamd_dkim_canonize_header(struct rspamd_dkim_common_ctx *ctx,
struct rspamd_task *task,
- const gchar *header_name,
- gint count,
- const gchar *dkim_header,
- const gchar *dkim_domain)
+ const char *header_name,
+ int count,
+ const char *dkim_header,
+ const char *dkim_domain)
{
struct rspamd_mime_header *rh, *cur, *sel = NULL;
- gint hdr_cnt = 0;
+ int hdr_cnt = 0;
bool use_idx = false, is_sign = ctx->is_sign;
/*
* TODO:
* Temporary hack to prevent linked list being misused until refactored
*/
- const guint max_list_iters = 1000;
+ const unsigned int max_list_iters = 1000;
if (count < 0) {
use_idx = true;
header_name,
hdr_cnt);
rspamd_dkim_hash_update(ctx->headers_hash,
- (const gchar *) &random_cookie,
+ (const char *) &random_cookie,
sizeof(random_cookie));
ctx->headers_canonicalised += sizeof(random_cookie);
* This branch is used for ARC headers, and it orders them based on
* i=<number> string and not their real order in the list of headers
*/
- gchar idx_buf[16];
- gint id_len, i;
+ char idx_buf[16];
+ int id_len, i;
id_len = rspamd_snprintf(idx_buf, sizeof(idx_buf), "i=%d;",
count);
ctx->headers_canonicalised += sel->raw_len;
msg_debug_dkim("update %s with header (idx=%d): %*s",
(use_idx ? "seal" : "signature"),
- count, (gint) sel->raw_len, sel->raw_value);
+ count, (int) sel->raw_len, sel->raw_value);
}
else {
if (is_sign && (sel->flags & RSPAMD_HEADER_FROM)) {
/* Special handling of the From handling when rewrite is done */
gboolean has_rewrite = FALSE;
- guint i;
+ unsigned int i;
struct rspamd_email_address *addr;
PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, from_mime), i, addr)
}
struct rspamd_dkim_cached_hash {
- guchar *digest_normal;
- guchar *digest_cr;
- guchar *digest_crlf;
- gchar *type;
+ unsigned char *digest_normal;
+ unsigned char *digest_cr;
+ unsigned char *digest_crlf;
+ char *type;
};
static struct rspamd_dkim_cached_hash *
rspamd_dkim_check_bh_cached(struct rspamd_dkim_common_ctx *ctx,
struct rspamd_task *task, gsize bhlen, gboolean is_sign)
{
- gchar typebuf[64];
+ char typebuf[64];
struct rspamd_dkim_cached_hash *res;
rspamd_snprintf(typebuf, sizeof(typebuf),
rspamd_dkim_key_t *key,
struct rspamd_task *task)
{
- const gchar *body_end, *body_start;
- guchar raw_digest[EVP_MAX_MD_SIZE];
+ const char *body_end, *body_start;
+ unsigned char raw_digest[EVP_MAX_MD_SIZE];
struct rspamd_dkim_cached_hash *cached_bh = NULL;
EVP_MD_CTX *cpy_ctx = NULL;
gsize dlen = 0;
struct rspamd_dkim_check_result *res;
- guint i;
+ unsigned int i;
struct rspamd_dkim_header *dh;
- gint nid;
+ int nid;
g_return_val_if_fail(ctx != NULL, NULL);
g_return_val_if_fail(key != NULL, NULL);
if (memcmp(ctx->bh, cached_bh->digest_normal, ctx->bhlen) != 0) {
msg_debug_dkim(
"bh value mismatch: %*xs versus %*xs, try add LF; try adding CRLF",
- (gint) dlen, ctx->bh,
- (gint) dlen, raw_digest);
+ (int) dlen, ctx->bh,
+ (int) dlen, raw_digest);
if (cpy_ctx) {
/* Try add CRLF */
if (memcmp(ctx->bh, raw_digest, ctx->bhlen) != 0) {
msg_debug_dkim(
"bh value mismatch after added CRLF: %*xs versus %*xs, try add LF",
- (gint) dlen, ctx->bh,
- (gint) dlen, raw_digest);
+ (int) dlen, ctx->bh,
+ (int) dlen, raw_digest);
/* Try add LF */
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
if (memcmp(ctx->bh, raw_digest, ctx->bhlen) != 0) {
msg_debug_dkim("bh value mismatch after added LF: %*xs versus %*xs",
- (gint) dlen, ctx->bh,
- (gint) dlen, raw_digest);
+ (int) dlen, ctx->bh,
+ (int) dlen, raw_digest);
res->fail_reason = "body hash did not verify";
res->rcode = DKIM_REJECT;
}
else if (cached_bh->digest_crlf) {
if (memcmp(ctx->bh, cached_bh->digest_crlf, ctx->bhlen) != 0) {
msg_debug_dkim("bh value mismatch after added CRLF: %*xs versus %*xs",
- (gint) dlen, ctx->bh,
- (gint) dlen, cached_bh->digest_crlf);
+ (int) dlen, ctx->bh,
+ (int) dlen, cached_bh->digest_crlf);
if (cached_bh->digest_cr) {
if (memcmp(ctx->bh, cached_bh->digest_cr, ctx->bhlen) != 0) {
msg_debug_dkim(
"bh value mismatch after added LF: %*xs versus %*xs",
- (gint) dlen, ctx->bh,
- (gint) dlen, cached_bh->digest_cr);
+ (int) dlen, ctx->bh,
+ (int) dlen, cached_bh->digest_cr);
res->fail_reason = "body hash did not verify";
res->rcode = DKIM_REJECT;
else {
msg_debug_dkim(
"bh value mismatch: %*xs versus %*xs",
- (gint) dlen, ctx->bh,
- (gint) dlen, cached_bh->digest_normal);
+ (int) dlen, ctx->bh,
+ (int) dlen, cached_bh->digest_normal);
res->fail_reason = "body hash did not verify";
res->rcode = DKIM_REJECT;
}
"%s: bh value mismatch: got %*Bs, expected %*Bs; "
"body length %d->%d; d=%s; s=%s",
rspamd_dkim_type_to_string(ctx->common.type),
- (gint) dlen, cached_bh->digest_normal,
- (gint) dlen, ctx->bh,
- (gint) (body_end - body_start), ctx->common.body_canonicalised,
+ (int) dlen, cached_bh->digest_normal,
+ (int) dlen, ctx->bh,
+ (int) (body_end - body_start), ctx->common.body_canonicalised,
ctx->domain, ctx->selector);
return res;
"%s: headers RSA verification failure; "
"body length %d->%d; headers length %d; d=%s; s=%s; key_md5=%*xs; orig header: %s",
rspamd_dkim_type_to_string(ctx->common.type),
- (gint) (body_end - body_start), ctx->common.body_canonicalised,
+ (int) (body_end - body_start), ctx->common.body_canonicalised,
ctx->common.headers_canonicalised,
ctx->domain, ctx->selector,
RSPAMD_DKIM_KEY_ID_LEN, rspamd_dkim_key_id(key),
"%s: headers ECDSA verification failure; "
"body length %d->%d; headers length %d; d=%s; s=%s; key_md5=%*xs; orig header: %s",
rspamd_dkim_type_to_string(ctx->common.type),
- (gint) (body_end - body_start), ctx->common.body_canonicalised,
+ (int) (body_end - body_start), ctx->common.body_canonicalised,
ctx->common.headers_canonicalised,
ctx->domain, ctx->selector,
RSPAMD_DKIM_KEY_ID_LEN, rspamd_dkim_key_id(key),
"%s: headers EDDSA verification failure; "
"body length %d->%d; headers length %d; d=%s; s=%s; key_md5=%*xs; orig header: %s",
rspamd_dkim_type_to_string(ctx->common.type),
- (gint) (body_end - body_start), ctx->common.body_canonicalised,
+ (int) (body_end - body_start), ctx->common.body_canonicalised,
ctx->common.headers_canonicalised,
ctx->domain, ctx->selector,
RSPAMD_DKIM_KEY_ID_LEN, rspamd_dkim_key_id(key),
REF_RELEASE(k);
}
-const gchar *
+const char *
rspamd_dkim_get_domain(rspamd_dkim_context_t *ctx)
{
if (ctx) {
return NULL;
}
-const gchar *
+const char *
rspamd_dkim_get_selector(rspamd_dkim_context_t *ctx)
{
if (ctx) {
return NULL;
}
-guint rspamd_dkim_key_get_ttl(rspamd_dkim_key_t *k)
+unsigned int rspamd_dkim_key_get_ttl(rspamd_dkim_key_t *k)
{
if (k) {
return k->ttl;
return 0;
}
-const gchar *
+const char *
rspamd_dkim_get_dns_key(rspamd_dkim_context_t *ctx)
{
if (ctx) {
#define PEM_SIG "-----BEGIN"
rspamd_dkim_sign_key_t *
-rspamd_dkim_sign_key_load(const gchar *key, gsize len,
+rspamd_dkim_sign_key_load(const char *key, gsize len,
enum rspamd_dkim_key_format type,
GError **err)
{
- guchar *map = NULL, *tmp = NULL;
+ unsigned char *map = NULL, *tmp = NULL;
gsize maplen;
rspamd_dkim_sign_key_t *nkey;
time_t mtime = time(NULL);
rspamd_dkim_sign_context_t *
rspamd_create_dkim_sign_context(struct rspamd_task *task,
rspamd_dkim_sign_key_t *priv_key,
- gint headers_canon,
- gint body_canon,
- const gchar *headers,
+ int headers_canon,
+ int body_canon,
+ const char *headers,
enum rspamd_dkim_type type,
GError **err)
{
GString *
-rspamd_dkim_sign(struct rspamd_task *task, const gchar *selector,
- const gchar *domain, time_t expire, gsize len, guint idx,
- const gchar *arc_cv, rspamd_dkim_sign_context_t *ctx)
+rspamd_dkim_sign(struct rspamd_task *task, const char *selector,
+ const char *domain, time_t expire, gsize len, unsigned int idx,
+ const char *arc_cv, rspamd_dkim_sign_context_t *ctx)
{
GString *hdr;
struct rspamd_dkim_header *dh;
- const gchar *body_end, *body_start, *hname;
- guchar raw_digest[EVP_MAX_MD_SIZE];
+ const char *body_end, *body_start, *hname;
+ unsigned char raw_digest[EVP_MAX_MD_SIZE];
struct rspamd_dkim_cached_hash *cached_bh = NULL;
gsize dlen = 0;
- guint i, j;
- gchar *b64_data;
- guchar *sig_buf;
- guint sig_len;
- guint headers_len = 0, cur_len = 0;
+ unsigned int i, j;
+ char *b64_data;
+ unsigned char *sig_buf;
+ unsigned int sig_len;
+ unsigned int headers_len = 0, cur_len = 0;
union rspamd_dkim_header_stat hstat;
g_assert(ctx != NULL);
if (hstat.s.flags & RSPAMD_DKIM_FLAG_OVERSIGN) {
/* Do oversigning */
- guint count = 0;
+ unsigned int count = 0;
rh = rspamd_message_get_header_array(task, dh->name, FALSE);
hdr->len);
ctx->common.headers_canonicalised += hdr->len;
msg_debug_task("update signature with header: %*s",
- (gint) hdr->len, hdr->str);
+ (int) hdr->len, hdr->str);
}
dlen = EVP_MD_CTX_size(ctx->common.headers_hash);
enum rspamd_dkim_check_rcode rcode;
rspamd_dkim_context_t *ctx;
/* Processed parts */
- const gchar *selector;
- const gchar *domain;
- const gchar *short_b;
- const gchar *fail_reason;
+ const char *selector;
+ const char *domain;
+ const char *short_b;
+ const char *fail_reason;
};
* @param err pointer to error object
* @return new context or NULL
*/
-rspamd_dkim_context_t *rspamd_create_dkim_context(const gchar *sig,
+rspamd_dkim_context_t *rspamd_create_dkim_context(const char *sig,
rspamd_mempool_t *pool,
struct rspamd_dns_resolver *resolver,
- guint time_jitter,
+ unsigned int time_jitter,
enum rspamd_dkim_type type,
GError **err);
*/
rspamd_dkim_sign_context_t *rspamd_create_dkim_sign_context(struct rspamd_task *task,
rspamd_dkim_sign_key_t *priv_key,
- gint headers_canon,
- gint body_canon,
- const gchar *dkim_headers,
+ int headers_canon,
+ int body_canon,
+ const char *dkim_headers,
enum rspamd_dkim_type type,
GError **err);
* @param err
* @return
*/
-rspamd_dkim_sign_key_t *rspamd_dkim_sign_key_load(const gchar *what, gsize len,
+rspamd_dkim_sign_key_t *rspamd_dkim_sign_key_load(const char *what, gsize len,
enum rspamd_dkim_key_format type,
GError **err);
struct rspamd_task *task);
GString *rspamd_dkim_sign(struct rspamd_task *task,
- const gchar *selector,
- const gchar *domain,
+ const char *selector,
+ const char *domain,
time_t expire,
gsize len,
- guint idx,
- const gchar *arc_cv,
+ unsigned int idx,
+ const char *arc_cv,
rspamd_dkim_sign_context_t *ctx);
rspamd_dkim_key_t *rspamd_dkim_key_ref(rspamd_dkim_key_t *k);
void rspamd_dkim_sign_key_unref(rspamd_dkim_sign_key_t *k);
-const gchar *rspamd_dkim_get_domain(rspamd_dkim_context_t *ctx);
+const char *rspamd_dkim_get_domain(rspamd_dkim_context_t *ctx);
-const gchar *rspamd_dkim_get_selector(rspamd_dkim_context_t *ctx);
+const char *rspamd_dkim_get_selector(rspamd_dkim_context_t *ctx);
-const gchar *rspamd_dkim_get_dns_key(rspamd_dkim_context_t *ctx);
+const char *rspamd_dkim_get_dns_key(rspamd_dkim_context_t *ctx);
-guint rspamd_dkim_key_get_ttl(rspamd_dkim_key_t *k);
+unsigned int rspamd_dkim_key_get_ttl(rspamd_dkim_key_t *k);
/**
* Create DKIM public key from a raw data
* @param err
* @return
*/
-rspamd_dkim_key_t *rspamd_dkim_make_key(const gchar *keydata, guint keylen,
+rspamd_dkim_key_t *rspamd_dkim_make_key(const char *keydata, unsigned int keylen,
enum rspamd_dkim_key_type type,
GError **err);
* @param key
* @return
*/
-const guchar *rspamd_dkim_key_id(rspamd_dkim_key_t *key);
+const unsigned char *rspamd_dkim_key_id(rspamd_dkim_key_t *key);
/**
* Parse DKIM public key from a TXT record
* @param err
* @return
*/
-rspamd_dkim_key_t *rspamd_dkim_parse_key(const gchar *txt, gsize *keylen,
+rspamd_dkim_key_t *rspamd_dkim_parse_key(const char *txt, gsize *keylen,
GError **err);
/**
* @param outlen
* @return
*/
-goffset rspamd_dkim_canonize_header_relaxed_str(const gchar *hname,
- const gchar *hvalue,
- gchar *out,
+goffset rspamd_dkim_canonize_header_relaxed_str(const char *hname,
+ const char *hvalue,
+ char *out,
gsize outlen);
/**
#include <unicode/uidna.h>
-static const gchar *M = "rspamd dns";
+static const char *M = "rspamd dns";
static struct rdns_upstream_elt *rspamd_dns_select_upstream(const char *name,
size_t len, void *ups_data);
static void rspamd_dns_upstream_ok(struct rdns_upstream_elt *elt,
void *ups_data);
static void rspamd_dns_upstream_fail(struct rdns_upstream_elt *elt,
- void *ups_data, const gchar *reason);
+ void *ups_data, const char *reason);
static unsigned int rspamd_dns_upstream_count(void *ups_data);
static struct rdns_upstream_context rspamd_ups_ctx = {
enum rdns_request_type type;
};
-static const gint8 ascii_dns_table[128] = {
+static const int8_t ascii_dns_table[128] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* HYPHEN-MINUS..FULL STOP */
-1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1};
-static guint
+static unsigned int
rspamd_dns_fail_hash(gconstpointer ptr)
{
struct rspamd_dns_fail_cache_entry *elt =
reqdata->task->resolver->fails_cache) {
/* Add to cache... */
- const gchar *name = reqdata->req->requested_names[0].name;
- gchar *target;
+ const char *name = reqdata->req->requested_names[0].name;
+ char *target;
gsize namelen;
struct rspamd_dns_fail_cache_entry *nentry;
/* Allocate in a single entry to allow further free in a single call */
namelen = strlen(name);
nentry = g_malloc(sizeof(nentry) + namelen + 1);
- target = ((gchar *) nentry) + sizeof(nentry);
+ target = ((char *) nentry) + sizeof(nentry);
rspamd_strlcpy(target, name, namelen + 1);
nentry->type = reqdata->req->requested_names[0].type;
nentry->name = target;
{
struct rdns_request *req;
struct rspamd_dns_request_ud *reqdata = NULL;
- guint nlen = strlen(name);
- gchar *real_name = NULL;
+ unsigned int nlen = strlen(name);
+ char *real_name = NULL;
g_assert(resolver != NULL);
}
static void
-rspamd_dns_server_init(struct upstream *up, guint idx, gpointer ud)
+rspamd_dns_server_init(struct upstream *up, unsigned int idx, gpointer ud)
{
struct rspamd_dns_resolver *r = ud;
rspamd_inet_addr_t *addr;
}
static void
-rspamd_dns_server_reorder(struct upstream *up, guint idx, gpointer ud)
+rspamd_dns_server_reorder(struct upstream *up, unsigned int idx, gpointer ud)
{
struct rspamd_dns_resolver *r = ud;
struct rspamd_dns_resolver *dns_resolver = ud;
struct rspamd_config *cfg;
rspamd_inet_addr_t *addr;
- gint test_fd;
+ int test_fd;
cfg = dns_resolver->cfg;
enum rdns_request_type rtype = RDNS_REQUEST_A;
enum dns_rcode rcode = RDNS_RC_NOERROR;
struct rdns_reply_entry *replies = NULL;
- const gchar *name = NULL;
+ const char *name = NULL;
if (ucl_object_type(cur) != UCL_OBJECT) {
continue;
rep_it = ucl_object_iterate_new(replies_obj);
while ((rep_obj = ucl_object_iterate_safe(rep_it, true))) {
- const gchar *str_rep = ucl_object_tostring(rep_obj);
+ const char *str_rep = ucl_object_tostring(rep_obj);
struct rdns_reply_entry *rep;
- gchar **svec;
+ char **svec;
if (str_rep == NULL) {
msg_err_config("invalid reply element for fake DNS record %s",
if (replies) {
struct rdns_reply_entry *tmp_entry;
- guint i = 0;
+ unsigned int i = 0;
DL_COUNT(replies, tmp_entry, i);
msg_info_config("added fake record: %s(%s); %d replies", name,
static bool
rspamd_dns_read_hosts_file(struct rspamd_config *cfg,
struct rspamd_dns_resolver *dns_resolver,
- const gchar *fname)
+ const char *fname)
{
- gchar *linebuf = NULL;
+ char *linebuf = NULL;
gsize buflen = 0;
gssize r;
FILE *fp;
- guint nadded = 0;
+ unsigned int nadded = 0;
fp = fopen(fname, "r");
g_strchomp(linebuf);
- gchar **elts = g_strsplit_set(linebuf, " \t\v", -1);
+ char **elts = g_strsplit_set(linebuf, " \t\v", -1);
rspamd_inet_addr_t *addr;
if (!rspamd_parse_inet_address(&addr, elts[0], strlen(elts[0]),
}
else {
/* Add all FQDN + aliases if any */
- gchar **cur_name = &elts[1];
+ char **cur_name = &elts[1];
while (*cur_name) {
if (strlen(*cur_name) == 0) {
static void
rspamd_dns_upstream_fail(struct rdns_upstream_elt *elt,
- void *ups_data, const gchar *reason)
+ void *ups_data, const char *reason)
{
struct upstream *up = elt->lib_data;
return rspamd_upstreams_alive(ups);
}
-gchar *
+char *
rspamd_dns_resolver_idna_convert_utf8(struct rspamd_dns_resolver *resolver,
rspamd_mempool_t *pool,
const char *name,
- gint namelen,
- guint *outlen)
+ int namelen,
+ unsigned int *outlen)
{
if (resolver == NULL || resolver->uidna == NULL || name == NULL || namelen > DNS_D_MAXNAME) {
return NULL;
}
- guint dest_len;
+ unsigned int dest_len;
UErrorCode uc_err = U_ZERO_ERROR;
UIDNAInfo info = UIDNA_INFO_INITIALIZER;
/* Calculate length required */
NULL, 0, &info, &uc_err);
if (uc_err == U_BUFFER_OVERFLOW_ERROR) {
- gchar *dest;
+ char *dest;
if (pool) {
dest = rspamd_mempool_alloc(pool, dest_len + 1);
double fails_cache_time;
struct upstream_list *ups;
struct rspamd_config *cfg;
- gdouble request_timeout;
- guint max_retransmits;
+ double request_timeout;
+ unsigned int max_retransmits;
};
/* Rspamd DNS API */
* @param namelen length of input (-1 for zero terminated)
* @return encoded string
*/
-gchar *rspamd_dns_resolver_idna_convert_utf8(struct rspamd_dns_resolver *resolver,
- rspamd_mempool_t *pool,
- const char *name,
- gint namelen,
- guint *outlen);
+char *rspamd_dns_resolver_idna_convert_utf8(struct rspamd_dns_resolver *resolver,
+ rspamd_mempool_t *pool,
+ const char *name,
+ int namelen,
+ unsigned int *outlen);
#ifdef __cplusplus
}
enum rspamd_action_type test_act;
const ucl_object_t *cur_elt, *cur_nm, *it_val;
ucl_object_iter_t it = NULL;
- const gchar *name;
- gdouble nscore;
- static const guint priority = 3;
+ const char *name;
+ double nscore;
+ static const unsigned int priority = 3;
while ((cur_elt = ucl_object_iterate(top, &it, true))) {
if (ucl_object_type(cur_elt) != UCL_OBJECT) {
}
/* Callbacks for reading json dynamic rules */
-static gchar *
-json_config_read_cb(gchar *chunk,
- gint len,
+static char *
+json_config_read_cb(char *chunk,
+ int len,
struct map_cb_data *data,
gboolean final)
{
dump_dynamic_config(struct rspamd_config *cfg)
{
struct stat st;
- gchar *dir, pathbuf[PATH_MAX];
- gint fd;
+ char *dir, pathbuf[PATH_MAX];
+ int fd;
if (cfg->dynamic_conf == NULL || cfg->current_dynamic_conf == NULL) {
/* No dynamic conf has been specified, so do not try to dump it */
}
static ucl_object_t *
-new_dynamic_metric(const gchar *metric_name, ucl_object_t *top)
+new_dynamic_metric(const char *metric_name, ucl_object_t *top)
{
ucl_object_t *metric;
}
static ucl_object_t *
-dynamic_metric_find_elt(const ucl_object_t *arr, const gchar *name)
+dynamic_metric_find_elt(const ucl_object_t *arr, const char *name)
{
ucl_object_iter_t it = NULL;
const ucl_object_t *cur, *n;
}
static ucl_object_t *
-dynamic_metric_find_metric(const ucl_object_t *arr, const gchar *metric)
+dynamic_metric_find_metric(const ucl_object_t *arr, const char *metric)
{
ucl_object_iter_t it = NULL;
const ucl_object_t *cur, *n;
}
static ucl_object_t *
-new_dynamic_elt(ucl_object_t *arr, const gchar *name, gdouble value)
+new_dynamic_elt(ucl_object_t *arr, const char *name, double value)
{
ucl_object_t *n;
return n;
}
-static gint
+static int
rspamd_maybe_add_lua_dynsym(struct rspamd_config *cfg,
- const gchar *sym,
- gdouble score)
+ const char *sym,
+ double score)
{
lua_State *L = cfg->lua_state;
- gint ret = -1;
+ int ret = -1;
struct rspamd_config **pcfg;
lua_getglobal(L, "rspamd_plugins");
return ret;
}
-static gint
+static int
rspamd_maybe_add_lua_dynact(struct rspamd_config *cfg,
- const gchar *action,
- gdouble score)
+ const char *action,
+ double score)
{
lua_State *L = cfg->lua_state;
- gint ret = -1;
+ int ret = -1;
struct rspamd_config **pcfg;
lua_getglobal(L, "rspamd_plugins");
*/
gboolean
add_dynamic_symbol(struct rspamd_config *cfg,
- const gchar *metric_name,
- const gchar *symbol,
- gdouble value)
+ const char *metric_name,
+ const char *symbol,
+ double value)
{
ucl_object_t *metric, *syms;
- gint ret;
+ int ret;
if ((ret = rspamd_maybe_add_lua_dynsym(cfg, symbol, value)) != -1) {
return ret == 0 ? FALSE : TRUE;
gboolean
remove_dynamic_symbol(struct rspamd_config *cfg,
- const gchar *metric_name,
- const gchar *symbol)
+ const char *metric_name,
+ const char *symbol)
{
ucl_object_t *metric, *syms;
gboolean ret = FALSE;
*/
gboolean
add_dynamic_action(struct rspamd_config *cfg,
- const gchar *metric_name,
- guint action,
- gdouble value)
+ const char *metric_name,
+ unsigned int action,
+ double value)
{
ucl_object_t *metric, *acts;
- const gchar *action_name = rspamd_action_to_str(action);
- gint ret;
+ const char *action_name = rspamd_action_to_str(action);
+ int ret;
if ((ret = rspamd_maybe_add_lua_dynact(cfg, action_name, value)) != -1) {
return ret == 0 ? FALSE : TRUE;
gboolean
remove_dynamic_action(struct rspamd_config *cfg,
- const gchar *metric_name,
- guint action)
+ const char *metric_name,
+ unsigned int action)
{
ucl_object_t *metric, *acts;
- const gchar *action_name = rspamd_action_to_str(action);
+ const char *action_name = rspamd_action_to_str(action);
gboolean ret = FALSE;
if (cfg->dynamic_conf == NULL) {
* @return
*/
gboolean add_dynamic_symbol(struct rspamd_config *cfg,
- const gchar *metric,
- const gchar *symbol,
- gdouble value);
+ const char *metric,
+ const char *symbol,
+ double value);
gboolean remove_dynamic_symbol(struct rspamd_config *cfg,
- const gchar *metric,
- const gchar *symbol);
+ const char *metric,
+ const char *symbol);
/**
* Add action for specified metric
* @return
*/
gboolean add_dynamic_action(struct rspamd_config *cfg,
- const gchar *metric,
- guint action,
- gdouble value);
+ const char *metric,
+ unsigned int action,
+ double value);
/**
* Removes dynamic action
*/
gboolean remove_dynamic_action(struct rspamd_config *cfg,
- const gchar *metric,
- guint action);
+ const char *metric,
+ unsigned int action);
#ifdef __cplusplus
}
rspamd_fuzzy_check_cb cb, void *ud,
void *subr_ud);
static void rspamd_fuzzy_backend_update_sqlite(struct rspamd_fuzzy_backend *bk,
- GArray *updates, const gchar *src,
+ GArray *updates, const char *src,
rspamd_fuzzy_update_cb cb, void *ud,
void *subr_ud);
static void rspamd_fuzzy_backend_count_sqlite(struct rspamd_fuzzy_backend *bk,
rspamd_fuzzy_count_cb cb, void *ud,
void *subr_ud);
static void rspamd_fuzzy_backend_version_sqlite(struct rspamd_fuzzy_backend *bk,
- const gchar *src,
+ const char *src,
rspamd_fuzzy_version_cb cb, void *ud,
void *subr_ud);
-static const gchar *rspamd_fuzzy_backend_id_sqlite(struct rspamd_fuzzy_backend *bk,
- void *subr_ud);
+static const char *rspamd_fuzzy_backend_id_sqlite(struct rspamd_fuzzy_backend *bk,
+ void *subr_ud);
static void rspamd_fuzzy_backend_expire_sqlite(struct rspamd_fuzzy_backend *bk,
void *subr_ud);
static void rspamd_fuzzy_backend_close_sqlite(struct rspamd_fuzzy_backend *bk,
rspamd_fuzzy_check_cb cb, void *ud,
void *subr_ud);
void (*update)(struct rspamd_fuzzy_backend *bk,
- GArray *updates, const gchar *src,
+ GArray *updates, const char *src,
rspamd_fuzzy_update_cb cb, void *ud,
void *subr_ud);
void (*count)(struct rspamd_fuzzy_backend *bk,
rspamd_fuzzy_count_cb cb, void *ud,
void *subr_ud);
void (*version)(struct rspamd_fuzzy_backend *bk,
- const gchar *src,
+ const char *src,
rspamd_fuzzy_version_cb cb, void *ud,
void *subr_ud);
- const gchar *(*id)(struct rspamd_fuzzy_backend *bk, void *subr_ud);
+ const char *(*id)(struct rspamd_fuzzy_backend *bk, void *subr_ud);
void (*periodic)(struct rspamd_fuzzy_backend *bk, void *subr_ud);
void (*close)(struct rspamd_fuzzy_backend *bk, void *subr_ud);
};
struct rspamd_fuzzy_backend {
enum rspamd_fuzzy_backend_type type;
- gdouble expire;
- gdouble sync;
+ double expire;
+ double sync;
struct ev_loop *event_loop;
rspamd_fuzzy_periodic_cb periodic_cb;
void *periodic_ud;
static void
rspamd_fuzzy_backend_update_sqlite(struct rspamd_fuzzy_backend *bk,
- GArray *updates, const gchar *src,
+ GArray *updates, const char *src,
rspamd_fuzzy_update_cb cb, void *ud,
void *subr_ud)
{
struct rspamd_fuzzy_backend_sqlite *sq = subr_ud;
gboolean success = FALSE;
- guint i;
+ unsigned int i;
struct fuzzy_peer_cmd *io_cmd;
struct rspamd_fuzzy_cmd *cmd;
gpointer ptr;
- guint nupdates = 0, nadded = 0, ndeleted = 0, nextended = 0, nignored = 0;
+ unsigned int nupdates = 0, nadded = 0, ndeleted = 0, nextended = 0, nignored = 0;
if (rspamd_fuzzy_backend_sqlite_prepare_update(sq, src)) {
for (i = 0; i < updates->len; i++) {
static void
rspamd_fuzzy_backend_version_sqlite(struct rspamd_fuzzy_backend *bk,
- const gchar *src,
+ const char *src,
rspamd_fuzzy_version_cb cb, void *ud,
void *subr_ud)
{
}
}
-static const gchar *
+static const char *
rspamd_fuzzy_backend_id_sqlite(struct rspamd_fuzzy_backend *bk,
void *subr_ud)
{
struct rspamd_fuzzy_backend *bk;
enum rspamd_fuzzy_backend_type type = RSPAMD_FUZZY_BACKEND_SQLITE;
const ucl_object_t *elt;
- gdouble expire = DEFAULT_EXPIRE;
+ double expire = DEFAULT_EXPIRE;
if (config != NULL) {
elt = ucl_object_lookup(config, "backend");
bk->subr->check(bk, cmd, cb, ud, bk->subr_ud);
}
-static guint
+static unsigned int
rspamd_fuzzy_digest_hash(gconstpointer key)
{
- guint ret;
+ unsigned int ret;
/* Distributed uniformly already */
memcpy(&ret, key, sizeof(ret));
rspamd_fuzzy_digest_equal);
struct fuzzy_peer_cmd *io_cmd, *found;
struct rspamd_fuzzy_cmd *cmd;
- guchar *digest;
- guint i;
+ unsigned char *digest;
+ unsigned int i;
for (i = 0; i < updates->len; i++) {
io_cmd = &g_array_index(updates, struct fuzzy_peer_cmd, i);
}
void rspamd_fuzzy_backend_process_updates(struct rspamd_fuzzy_backend *bk,
- GArray *updates, const gchar *src, rspamd_fuzzy_update_cb cb,
+ GArray *updates, const char *src, rspamd_fuzzy_update_cb cb,
void *ud)
{
g_assert(bk != NULL);
void rspamd_fuzzy_backend_version(struct rspamd_fuzzy_backend *bk,
- const gchar *src,
+ const char *src,
rspamd_fuzzy_version_cb cb, void *ud)
{
g_assert(bk != NULL);
bk->subr->version(bk, src, cb, ud, bk->subr_ud);
}
-const gchar *
+const char *
rspamd_fuzzy_backend_id(struct rspamd_fuzzy_backend *bk)
{
g_assert(bk != NULL);
rspamd_fuzzy_backend_periodic_cb(EV_P_ ev_timer *w, int revents)
{
struct rspamd_fuzzy_backend *bk = (struct rspamd_fuzzy_backend *) w->data;
- gdouble jittered;
+ double jittered;
jittered = rspamd_time_jitter(bk->sync, bk->sync / 2.0);
w->repeat = jittered;
}
void rspamd_fuzzy_backend_start_update(struct rspamd_fuzzy_backend *bk,
- gdouble timeout,
+ double timeout,
rspamd_fuzzy_periodic_cb cb,
void *ud)
{
- gdouble jittered;
+ double jittered;
g_assert(bk != NULL);
return backend->event_loop;
}
-gdouble
+double
rspamd_fuzzy_backend_get_expire(struct rspamd_fuzzy_backend *backend)
{
return backend->expire;
typedef void (*rspamd_fuzzy_check_cb)(struct rspamd_fuzzy_reply *rep, void *ud);
typedef void (*rspamd_fuzzy_update_cb)(gboolean success,
- guint nadded,
- guint ndeleted,
- guint nextended,
- guint nignored,
+ unsigned int nadded,
+ unsigned int ndeleted,
+ unsigned int nextended,
+ unsigned int nignored,
void *ud);
typedef void (*rspamd_fuzzy_version_cb)(uint64_t rev, void *ud);
* @param src
*/
void rspamd_fuzzy_backend_process_updates(struct rspamd_fuzzy_backend *bk,
- GArray *updates, const gchar *src, rspamd_fuzzy_update_cb cb,
+ GArray *updates, const char *src, rspamd_fuzzy_update_cb cb,
void *ud);
/**
* @param ud
*/
void rspamd_fuzzy_backend_version(struct rspamd_fuzzy_backend *bk,
- const gchar *src,
+ const char *src,
rspamd_fuzzy_version_cb cb, void *ud);
/**
* @param backend
* @return
*/
-const gchar *rspamd_fuzzy_backend_id(struct rspamd_fuzzy_backend *backend);
+const char *rspamd_fuzzy_backend_id(struct rspamd_fuzzy_backend *backend);
/**
* Starts expire process for the backend
* @param backend
*/
void rspamd_fuzzy_backend_start_update(struct rspamd_fuzzy_backend *backend,
- gdouble timeout,
+ double timeout,
rspamd_fuzzy_periodic_cb cb,
void *ud);
struct ev_loop *rspamd_fuzzy_backend_event_base(struct rspamd_fuzzy_backend *backend);
-gdouble rspamd_fuzzy_backend_get_expire(struct rspamd_fuzzy_backend *backend);
+double rspamd_fuzzy_backend_get_expire(struct rspamd_fuzzy_backend *backend);
/**
* Closes backend
struct rspamd_fuzzy_backend_redis {
lua_State *L;
- const gchar *redis_object;
- const gchar *username;
- const gchar *password;
- const gchar *dbname;
- gchar *id;
+ const char *redis_object;
+ const char *username;
+ const char *password;
+ const char *dbname;
+ char *id;
struct rspamd_redis_pool *pool;
- gdouble timeout;
- gint conf_ref;
+ double timeout;
+ int conf_ref;
bool terminated;
ref_entry_t ref;
};
gboolean shingles_checked;
enum rspamd_fuzzy_redis_command command;
- guint nargs;
+ unsigned int nargs;
- guint nadded;
- guint ndeleted;
- guint nextended;
- guint nignored;
+ unsigned int nadded;
+ unsigned int ndeleted;
+ unsigned int nextended;
+ unsigned int nignored;
union {
rspamd_fuzzy_check_cb cb_check;
} callback;
void *cbdata;
- gchar **argv;
+ char **argv;
gsize *argv_lens;
struct upstream *up;
- guchar found_digest[rspamd_cryptobox_HASHBYTES];
+ unsigned char found_digest[rspamd_cryptobox_HASHBYTES];
};
static inline struct upstream_list *
rspamd_redis_get_servers(struct rspamd_fuzzy_backend_redis *ctx,
- const gchar *what)
+ const char *what)
{
lua_State *L = ctx->L;
struct upstream_list *res = NULL;
}
else {
struct lua_logger_trace tr;
- gchar outbuf[8192];
+ char outbuf[8192];
memset(&tr, 0, sizeof(tr));
lua_logger_out_type(L, -2, outbuf, sizeof(outbuf) - 1, &tr,
static inline void
rspamd_fuzzy_redis_session_free_args(struct rspamd_fuzzy_redis_session *session)
{
- guint i;
+ unsigned int i;
if (session->argv) {
for (i = 0; i < session->nargs; i++) {
struct rspamd_fuzzy_backend_redis *backend;
const ucl_object_t *elt;
gboolean ret = FALSE;
- guchar id_hash[rspamd_cryptobox_HASHBYTES];
+ unsigned char id_hash[rspamd_cryptobox_HASHBYTES];
rspamd_cryptobox_hash_state_t st;
lua_State *L = (lua_State *) cfg->lua_state;
- gint conf_ref = -1;
+ int conf_ref = -1;
backend = g_malloc0(sizeof(*backend));
gpointer priv);
struct _rspamd_fuzzy_shingles_helper {
- guchar digest[64];
- guint found;
+ unsigned char digest[64];
+ unsigned int found;
};
-static gint
+static int
rspamd_fuzzy_backend_redis_shingles_cmp(const void *a, const void *b)
{
const struct _rspamd_fuzzy_shingles_helper *sha = a,
struct rspamd_fuzzy_reply rep;
GString *key;
struct _rspamd_fuzzy_shingles_helper *shingles, *prev = NULL, *sel = NULL;
- guint i, found = 0, max_found = 0, cur_found = 0;
+ unsigned int i, found = 0, max_found = 0, cur_found = 0;
ev_timer_stop(session->event_loop, &session->timeout);
memset(&rep, 0, sizeof(rep));
/* Prepare new check command */
rspamd_fuzzy_redis_session_free_args(session);
session->nargs = 5;
- session->argv = g_malloc(sizeof(gchar *) * session->nargs);
+ session->argv = g_malloc(sizeof(char *) * session->nargs);
session->argv_lens = g_malloc(sizeof(gsize) * session->nargs);
key = g_string_new(session->backend->redis_object);
if (redisAsyncCommandArgv(session->ctx,
rspamd_fuzzy_redis_check_callback,
session, session->nargs,
- (const gchar **) session->argv,
+ (const char **) session->argv,
session->argv_lens) != REDIS_OK) {
if (session->callback.cb_check) {
struct rspamd_fuzzy_reply rep;
const struct rspamd_fuzzy_shingle_cmd *shcmd;
GString *key;
- guint i, init_len;
+ unsigned int i, init_len;
rspamd_fuzzy_redis_session_free_args(session);
/* First of all check digest */
session->nargs = RSPAMD_SHINGLE_SIZE + 1;
- session->argv = g_malloc(sizeof(gchar *) * session->nargs);
+ session->argv = g_malloc(sizeof(char *) * session->nargs);
session->argv_lens = g_malloc(sizeof(gsize) * session->nargs);
shcmd = (const struct rspamd_fuzzy_shingle_cmd *) session->cmd;
if (redisAsyncCommandArgv(session->ctx, rspamd_fuzzy_redis_shingles_callback,
session, session->nargs,
- (const gchar **) session->argv, session->argv_lens) != REDIS_OK) {
+ (const char **) session->argv, session->argv_lens) != REDIS_OK) {
msg_err("cannot execute redis command on %s: %s",
rspamd_inet_address_to_string_pretty(rspamd_upstream_addr_cur(session->up)),
session->ctx->errstr);
redisReply *reply = r, *cur;
struct rspamd_fuzzy_reply rep;
gulong value;
- guint found_elts = 0;
+ unsigned int found_elts = 0;
ev_timer_stop(session->event_loop, &session->timeout);
memset(&rep, 0, sizeof(rep));
/* First of all check digest */
session->nargs = 5;
- session->argv = g_malloc(sizeof(gchar *) * session->nargs);
+ session->argv = g_malloc(sizeof(char *) * session->nargs);
session->argv_lens = g_malloc(sizeof(gsize) * session->nargs);
key = g_string_new(backend->redis_object);
else {
if (redisAsyncCommandArgv(session->ctx, rspamd_fuzzy_redis_check_callback,
session, session->nargs,
- (const gchar **) session->argv, session->argv_lens) != REDIS_OK) {
+ (const char **) session->argv, session->argv_lens) != REDIS_OK) {
rspamd_fuzzy_redis_session_dtor(session, TRUE);
if (cb) {
session->event_loop = rspamd_fuzzy_backend_event_base(bk);
session->nargs = 2;
- session->argv = g_malloc(sizeof(gchar *) * 2);
+ session->argv = g_malloc(sizeof(char *) * 2);
session->argv_lens = g_malloc(sizeof(gsize) * 2);
key = g_string_new(backend->redis_object);
g_string_append(key, "_count");
else {
if (redisAsyncCommandArgv(session->ctx, rspamd_fuzzy_redis_count_callback,
session, session->nargs,
- (const gchar **) session->argv, session->argv_lens) != REDIS_OK) {
+ (const char **) session->argv, session->argv_lens) != REDIS_OK) {
rspamd_fuzzy_redis_session_dtor(session, TRUE);
if (cb) {
}
void rspamd_fuzzy_backend_version_redis(struct rspamd_fuzzy_backend *bk,
- const gchar *src,
+ const char *src,
rspamd_fuzzy_version_cb cb, void *ud,
void *subr_ud)
{
session->event_loop = rspamd_fuzzy_backend_event_base(bk);
session->nargs = 2;
- session->argv = g_malloc(sizeof(gchar *) * 2);
+ session->argv = g_malloc(sizeof(char *) * 2);
session->argv_lens = g_malloc(sizeof(gsize) * 2);
key = g_string_new(backend->redis_object);
g_string_append(key, src);
else {
if (redisAsyncCommandArgv(session->ctx, rspamd_fuzzy_redis_version_callback,
session, session->nargs,
- (const gchar **) session->argv, session->argv_lens) != REDIS_OK) {
+ (const char **) session->argv, session->argv_lens) != REDIS_OK) {
rspamd_fuzzy_redis_session_dtor(session, TRUE);
if (cb) {
}
}
-const gchar *
+const char *
rspamd_fuzzy_backend_id_redis(struct rspamd_fuzzy_backend *bk,
void *subr_ud)
{
static gboolean
rspamd_fuzzy_update_append_command(struct rspamd_fuzzy_backend *bk,
struct rspamd_fuzzy_redis_session *session,
- struct fuzzy_peer_cmd *io_cmd, guint *shift)
+ struct fuzzy_peer_cmd *io_cmd, unsigned int *shift)
{
GString *key, *value;
- guint cur_shift = *shift;
- guint i, klen;
+ unsigned int cur_shift = *shift;
+ unsigned int i, klen;
struct rspamd_fuzzy_cmd *cmd;
if (io_cmd->is_shingle) {
if (redisAsyncCommandArgv(session->ctx, NULL, NULL,
4,
- (const gchar **) &session->argv[cur_shift - 4],
+ (const char **) &session->argv[cur_shift - 4],
&session->argv_lens[cur_shift - 4]) != REDIS_OK) {
return FALSE;
if (redisAsyncCommandArgv(session->ctx, NULL, NULL,
4,
- (const gchar **) &session->argv[cur_shift - 4],
+ (const char **) &session->argv[cur_shift - 4],
&session->argv_lens[cur_shift - 4]) != REDIS_OK) {
return FALSE;
if (redisAsyncCommandArgv(session->ctx, NULL, NULL,
4,
- (const gchar **) &session->argv[cur_shift - 4],
+ (const char **) &session->argv[cur_shift - 4],
&session->argv_lens[cur_shift - 4]) != REDIS_OK) {
return FALSE;
g_string_append_len(key, cmd->digest, sizeof(cmd->digest));
value = g_string_sized_new(sizeof("4294967296"));
rspamd_printf_gstring(value, "%d",
- (gint) rspamd_fuzzy_backend_get_expire(bk));
+ (int) rspamd_fuzzy_backend_get_expire(bk));
session->argv[cur_shift] = g_strdup("EXPIRE");
session->argv_lens[cur_shift++] = sizeof("EXPIRE") - 1;
session->argv[cur_shift] = key->str;
if (redisAsyncCommandArgv(session->ctx, NULL, NULL,
3,
- (const gchar **) &session->argv[cur_shift - 3],
+ (const char **) &session->argv[cur_shift - 3],
&session->argv_lens[cur_shift - 3]) != REDIS_OK) {
return FALSE;
if (redisAsyncCommandArgv(session->ctx, NULL, NULL,
2,
- (const gchar **) &session->argv[cur_shift - 2],
+ (const char **) &session->argv[cur_shift - 2],
&session->argv_lens[cur_shift - 2]) != REDIS_OK) {
return FALSE;
if (redisAsyncCommandArgv(session->ctx, NULL, NULL,
2,
- (const gchar **) &session->argv[cur_shift - 2],
+ (const char **) &session->argv[cur_shift - 2],
&session->argv_lens[cur_shift - 2]) != REDIS_OK) {
return FALSE;
if (redisAsyncCommandArgv(session->ctx, NULL, NULL,
2,
- (const gchar **) &session->argv[cur_shift - 2],
+ (const char **) &session->argv[cur_shift - 2],
&session->argv_lens[cur_shift - 2]) != REDIS_OK) {
return FALSE;
g_string_append_len(key, cmd->digest, sizeof(cmd->digest));
value = g_string_sized_new(sizeof("4294967296"));
rspamd_printf_gstring(value, "%d",
- (gint) rspamd_fuzzy_backend_get_expire(bk));
+ (int) rspamd_fuzzy_backend_get_expire(bk));
session->argv[cur_shift] = g_strdup("EXPIRE");
session->argv_lens[cur_shift++] = sizeof("EXPIRE") - 1;
session->argv[cur_shift] = key->str;
if (redisAsyncCommandArgv(session->ctx, NULL, NULL,
3,
- (const gchar **) &session->argv[cur_shift - 3],
+ (const char **) &session->argv[cur_shift - 3],
&session->argv_lens[cur_shift - 3]) != REDIS_OK) {
return FALSE;
64 + 1;
for (i = 0; i < RSPAMD_SHINGLE_SIZE; i++) {
- guchar *hval;
+ unsigned char *hval;
/*
* For each command with shingles we additionally emit 32 commands:
* SETEX <prefix>_<number>_<value> <expire> <digest>
io_cmd->cmd.shingle.sgl.hashes[i]);
value = g_string_sized_new(sizeof("4294967296"));
rspamd_printf_gstring(value, "%d",
- (gint) rspamd_fuzzy_backend_get_expire(bk));
+ (int) rspamd_fuzzy_backend_get_expire(bk));
hval = g_malloc(sizeof(io_cmd->cmd.shingle.basic.digest));
memcpy(hval, io_cmd->cmd.shingle.basic.digest,
sizeof(io_cmd->cmd.shingle.basic.digest));
if (redisAsyncCommandArgv(session->ctx, NULL, NULL,
4,
- (const gchar **) &session->argv[cur_shift - 4],
+ (const char **) &session->argv[cur_shift - 4],
&session->argv_lens[cur_shift - 4]) != REDIS_OK) {
return FALSE;
if (redisAsyncCommandArgv(session->ctx, NULL, NULL,
2,
- (const gchar **) &session->argv[cur_shift - 2],
+ (const char **) &session->argv[cur_shift - 2],
&session->argv_lens[cur_shift - 2]) != REDIS_OK) {
return FALSE;
io_cmd->cmd.shingle.sgl.hashes[i]);
value = g_string_sized_new(sizeof("18446744073709551616"));
rspamd_printf_gstring(value, "%d",
- (gint) rspamd_fuzzy_backend_get_expire(bk));
+ (int) rspamd_fuzzy_backend_get_expire(bk));
session->argv[cur_shift] = g_strdup("EXPIRE");
session->argv_lens[cur_shift++] = sizeof("EXPIRE") - 1;
session->argv[cur_shift] = key->str;
if (redisAsyncCommandArgv(session->ctx, NULL, NULL,
3,
- (const gchar **) &session->argv[cur_shift - 3],
+ (const char **) &session->argv[cur_shift - 3],
&session->argv_lens[cur_shift - 3]) != REDIS_OK) {
return FALSE;
}
void rspamd_fuzzy_backend_update_redis(struct rspamd_fuzzy_backend *bk,
- GArray *updates, const gchar *src,
+ GArray *updates, const char *src,
rspamd_fuzzy_update_cb cb, void *ud,
void *subr_ud)
{
struct upstream *up;
struct upstream_list *ups;
rspamd_inet_addr_t *addr;
- guint i;
+ unsigned int i;
GString *key;
struct fuzzy_peer_cmd *io_cmd;
struct rspamd_fuzzy_cmd *cmd = NULL;
- guint nargs, cur_shift;
+ unsigned int nargs, cur_shift;
g_assert(backend != NULL);
/* First of all check digest */
session->nargs = nargs;
- session->argv = g_malloc0(sizeof(gchar *) * session->nargs);
+ session->argv = g_malloc0(sizeof(char *) * session->nargs);
session->argv_lens = g_malloc0(sizeof(gsize) * session->nargs);
up = rspamd_upstream_get(ups,
if (redisAsyncCommandArgv(session->ctx, NULL, NULL,
1,
- (const gchar **) session->argv,
+ (const char **) session->argv,
session->argv_lens) != REDIS_OK) {
if (cb) {
if (redisAsyncCommandArgv(session->ctx, NULL, NULL,
2,
- (const gchar **) &session->argv[cur_shift - 2],
+ (const char **) &session->argv[cur_shift - 2],
&session->argv_lens[cur_shift - 2]) != REDIS_OK) {
if (cb) {
if (redisAsyncCommandArgv(session->ctx,
rspamd_fuzzy_redis_update_callback, session,
1,
- (const gchar **) &session->argv[cur_shift],
+ (const char **) &session->argv[cur_shift],
&session->argv_lens[cur_shift]) != REDIS_OK) {
if (cb) {
void *subr_ud);
void rspamd_fuzzy_backend_update_redis(struct rspamd_fuzzy_backend *bk,
- GArray *updates, const gchar *src,
+ GArray *updates, const char *src,
rspamd_fuzzy_update_cb cb, void *ud,
void *subr_ud);
void *subr_ud);
void rspamd_fuzzy_backend_version_redis(struct rspamd_fuzzy_backend *bk,
- const gchar *src,
+ const char *src,
rspamd_fuzzy_version_cb cb, void *ud,
void *subr_ud);
-const gchar *rspamd_fuzzy_backend_id_redis(struct rspamd_fuzzy_backend *bk,
- void *subr_ud);
+const char *rspamd_fuzzy_backend_id_redis(struct rspamd_fuzzy_backend *bk,
+ void *subr_ud);
void rspamd_fuzzy_backend_expire_redis(struct rspamd_fuzzy_backend *bk,
void *subr_ud);
struct rspamd_fuzzy_backend_sqlite {
sqlite3 *db;
char *path;
- gchar id[MEMPOOL_UID_LEN];
+ char id[MEMPOOL_UID_LEN];
gsize count;
gsize expired;
rspamd_mempool_t *pool;
};
-static const gdouble sql_sleep_time = 0.1;
-static const guint max_retries = 10;
+static const double sql_sleep_time = 0.1;
+static const unsigned int max_retries = 10;
#define msg_err_fuzzy_backend(...) rspamd_default_log_function(G_LOG_LEVEL_CRITICAL, \
backend->pool->tag.tagname, backend->pool->tag.uid, \
};
static struct rspamd_fuzzy_stmts {
enum rspamd_fuzzy_statement_idx idx;
- const gchar *sql;
- const gchar *args;
+ const char *sql;
+ const char *args;
sqlite3_stmt *stmt;
- gint result;
+ int result;
} prepared_stmts[RSPAMD_FUZZY_BACKEND_MAX] =
{
{.idx = RSPAMD_FUZZY_BACKEND_TRANSACTION_START,
sqlite3_stmt *stmt;
int i;
const char *argtypes;
- guint retries = 0;
+ unsigned int retries = 0;
struct timespec ts;
if (idx < 0 || idx >= RSPAMD_FUZZY_BACKEND_MAX) {
sqlite3_bind_int64(stmt, i + 1, va_arg(ap, int64_t));
break;
case 'S':
- sqlite3_bind_int(stmt, i + 1, va_arg(ap, gint));
+ sqlite3_bind_int(stmt, i + 1, va_arg(ap, int));
break;
case 'D':
/* Special case for digests variable */
}
static gboolean
-rspamd_fuzzy_backend_sqlite_run_sql(const gchar *sql, struct rspamd_fuzzy_backend_sqlite *bk,
+rspamd_fuzzy_backend_sqlite_run_sql(const char *sql, struct rspamd_fuzzy_backend_sqlite *bk,
GError **err)
{
- guint retries = 0;
+ unsigned int retries = 0;
struct timespec ts;
- gint ret;
+ int ret;
do {
ret = sqlite3_exec(bk->db, sql, NULL, NULL, NULL);
}
static struct rspamd_fuzzy_backend_sqlite *
-rspamd_fuzzy_backend_sqlite_open_db(const gchar *path, GError **err)
+rspamd_fuzzy_backend_sqlite_open_db(const char *path, GError **err)
{
struct rspamd_fuzzy_backend_sqlite *bk;
rspamd_cryptobox_hash_state_t st;
- guchar hash_out[rspamd_cryptobox_HASHBYTES];
+ unsigned char hash_out[rspamd_cryptobox_HASHBYTES];
g_assert(path != NULL);
}
struct rspamd_fuzzy_backend_sqlite *
-rspamd_fuzzy_backend_sqlite_open(const gchar *path,
+rspamd_fuzzy_backend_sqlite_open(const char *path,
gboolean vacuum,
GError **err)
{
return backend;
}
-static gint
+static int
rspamd_fuzzy_backend_sqlite_int64_cmp(const void *a, const void *b)
{
int64_t ia = *(int64_t *) a, ib = *(int64_t *) b;
gboolean
rspamd_fuzzy_backend_sqlite_prepare_update(struct rspamd_fuzzy_backend_sqlite *backend,
- const gchar *source)
+ const char *source)
{
- gint rc;
+ int rc;
if (backend == NULL) {
return FALSE;
if (rc != SQLITE_OK) {
msg_warn_fuzzy_backend("cannot update hash to %d -> "
"%*xs: %s",
- (gint) cmd->flag,
- (gint) sizeof(cmd->digest), cmd->digest,
+ (int) cmd->flag,
+ (int) sizeof(cmd->digest), cmd->digest,
sqlite3_errmsg(backend->db));
}
}
if (rc != SQLITE_OK) {
msg_warn_fuzzy_backend("cannot update hash to %d -> "
"%*xs: %s",
- (gint) cmd->flag,
- (gint) sizeof(cmd->digest), cmd->digest,
+ (int) cmd->flag,
+ (int) sizeof(cmd->digest), cmd->digest,
sqlite3_errmsg(backend->db));
}
}
rspamd_fuzzy_backend_sqlite_cleanup_stmt(backend, RSPAMD_FUZZY_BACKEND_CHECK);
rc = rspamd_fuzzy_backend_sqlite_run_stmt(backend, FALSE,
RSPAMD_FUZZY_BACKEND_INSERT,
- (gint) cmd->flag,
+ (int) cmd->flag,
cmd->digest,
(int64_t) cmd->value);
else {
msg_warn_fuzzy_backend("cannot add hash to %d -> "
"%*xs: %s",
- (gint) cmd->flag,
- (gint) sizeof(cmd->digest), cmd->digest,
+ (int) cmd->flag,
+ (int) sizeof(cmd->digest), cmd->digest,
sqlite3_errmsg(backend->db));
}
gboolean
rspamd_fuzzy_backend_sqlite_finish_update(struct rspamd_fuzzy_backend_sqlite *backend,
- const gchar *source, gboolean version_bump)
+ const char *source, gboolean version_bump)
{
- gint rc = SQLITE_OK, wal_frames, wal_checkpointed, ver;
+ int rc = SQLITE_OK, wal_frames, wal_checkpointed, ver;
/* Get and update version */
if (version_bump) {
if (rc != SQLITE_OK) {
msg_warn_fuzzy_backend("cannot update hash to %d -> "
"%*xs: %s",
- (gint) cmd->flag,
- (gint) sizeof(cmd->digest), cmd->digest,
+ (int) cmd->flag,
+ (int) sizeof(cmd->digest), cmd->digest,
sqlite3_errmsg(backend->db));
}
}
const uint64_t max_changes = 5000;
gboolean ret = FALSE;
int64_t expire_lim, expired;
- gint rc, i, orphaned_cnt = 0;
+ int rc, i, orphaned_cnt = 0;
GError *err = NULL;
- static const gchar orphaned_shingles[] = "SELECT shingles.value,shingles.number "
- "FROM shingles "
- "LEFT JOIN digests ON "
- "shingles.digest_id=digests.id WHERE "
- "digests.id IS NULL;";
+ static const char orphaned_shingles[] = "SELECT shingles.value,shingles.number "
+ "FROM shingles "
+ "LEFT JOIN digests ON "
+ "shingles.digest_id=digests.id WHERE "
+ "digests.id IS NULL;";
sqlite3_stmt *stmt;
GArray *orphaned;
struct orphaned_shingle_elt orphaned_elt, *pelt;
"going to delete %ud orphaned shingles",
orphaned_cnt);
/* Need to delete orphaned elements */
- for (i = 0; i < (gint) orphaned_cnt; i++) {
+ for (i = 0; i < (int) orphaned_cnt; i++) {
pelt = &g_array_index(orphaned,
struct orphaned_shingle_elt,
i);
return 0;
}
-gint rspamd_fuzzy_backend_sqlite_version(struct rspamd_fuzzy_backend_sqlite *backend,
- const gchar *source)
+int rspamd_fuzzy_backend_sqlite_version(struct rspamd_fuzzy_backend_sqlite *backend,
+ const char *source)
{
- gint ret = 0;
+ int ret = 0;
if (backend) {
if (rspamd_fuzzy_backend_sqlite_run_stmt(backend, FALSE,
return backend != NULL ? backend->expired : 0;
}
-const gchar *
+const char *
rspamd_fuzzy_sqlite_backend_id(struct rspamd_fuzzy_backend_sqlite *backend)
{
return backend != NULL ? backend->id : 0;
* @param err error pointer
* @return backend structure or NULL
*/
-struct rspamd_fuzzy_backend_sqlite *rspamd_fuzzy_backend_sqlite_open(const gchar *path,
+struct rspamd_fuzzy_backend_sqlite *rspamd_fuzzy_backend_sqlite_open(const char *path,
gboolean vacuum,
GError **err);
* Prepare storage for updates (by starting transaction)
*/
gboolean rspamd_fuzzy_backend_sqlite_prepare_update(struct rspamd_fuzzy_backend_sqlite *backend,
- const gchar *source);
+ const char *source);
/**
* Add digest to the database
* Commit updates to storage
*/
gboolean rspamd_fuzzy_backend_sqlite_finish_update(struct rspamd_fuzzy_backend_sqlite *backend,
- const gchar *source, gboolean version_bump);
+ const char *source, gboolean version_bump);
/**
* Sync storage
gsize rspamd_fuzzy_backend_sqlite_count(struct rspamd_fuzzy_backend_sqlite *backend);
-gint rspamd_fuzzy_backend_sqlite_version(struct rspamd_fuzzy_backend_sqlite *backend, const gchar *source);
+int rspamd_fuzzy_backend_sqlite_version(struct rspamd_fuzzy_backend_sqlite *backend, const char *source);
gsize rspamd_fuzzy_backend_sqlite_expired(struct rspamd_fuzzy_backend_sqlite *backend);
-const gchar *rspamd_fuzzy_sqlite_backend_id(struct rspamd_fuzzy_backend_sqlite *backend);
+const char *rspamd_fuzzy_sqlite_backend_id(struct rspamd_fuzzy_backend_sqlite *backend);
#ifdef __cplusplus
}
RSPAMD_PACKED(rspamd_fuzzy_cmd)
{
- guint8 version;
- guint8 cmd;
- guint8 shingles_count;
- guint8 flag;
+ uint8_t version;
+ uint8_t cmd;
+ uint8_t shingles_count;
+ uint8_t flag;
int32_t value;
uint32_t tag;
- gchar digest[rspamd_cryptobox_HASHBYTES];
+ char digest[rspamd_cryptobox_HASHBYTES];
};
RSPAMD_PACKED(rspamd_fuzzy_shingle_cmd)
RSPAMD_PACKED(rspamd_fuzzy_reply)
{
struct rspamd_fuzzy_reply_v1 v1;
- gchar digest[rspamd_cryptobox_HASHBYTES];
+ char digest[rspamd_cryptobox_HASHBYTES];
uint32_t ts;
- guchar reserved[12];
+ unsigned char reserved[12];
};
RSPAMD_PACKED(rspamd_fuzzy_encrypted_req_hdr)
{
- guchar magic[4];
- guchar key_id[RSPAMD_FUZZY_KEYLEN];
- guchar pubkey[32];
- guchar nonce[rspamd_cryptobox_MAX_NONCEBYTES];
- guchar mac[rspamd_cryptobox_MAX_MACBYTES];
+ unsigned char magic[4];
+ unsigned char key_id[RSPAMD_FUZZY_KEYLEN];
+ unsigned char pubkey[32];
+ unsigned char nonce[rspamd_cryptobox_MAX_NONCEBYTES];
+ unsigned char mac[rspamd_cryptobox_MAX_MACBYTES];
};
RSPAMD_PACKED(rspamd_fuzzy_encrypted_cmd)
RSPAMD_PACKED(rspamd_fuzzy_encrypted_rep_hdr)
{
- guchar nonce[rspamd_cryptobox_MAX_NONCEBYTES];
- guchar mac[rspamd_cryptobox_MAX_MACBYTES];
+ unsigned char nonce[rspamd_cryptobox_MAX_NONCEBYTES];
+ unsigned char mac[rspamd_cryptobox_MAX_MACBYTES];
};
RSPAMD_PACKED(rspamd_fuzzy_encrypted_reply)
struct rspamd_fuzzy_reply rep;
};
-static const guchar fuzzy_encrypted_magic[4] = {'r', 's', 'f', 'e'};
+static const unsigned char fuzzy_encrypted_magic[4] = {'r', 's', 'f', 'e'};
enum rspamd_fuzzy_extension_type {
RSPAMD_FUZZY_EXT_SOURCE_DOMAIN = 'd',
struct rspamd_fuzzy_cmd_extension {
enum rspamd_fuzzy_extension_type ext;
- guint length;
+ unsigned int length;
struct rspamd_fuzzy_cmd_extension *next;
- guchar *payload;
+ unsigned char *payload;
};
struct rspamd_fuzzy_stat_entry {
- const gchar *name;
+ const char *name;
uint64_t fuzzy_cnt;
};
namespace rspamd::html {
-static const guint max_tags = 8192; /* Ignore tags if this maximum is reached */
+static const unsigned int max_tags = 8192; /* Ignore tags if this maximum is reached */
static const html_tags_storage html_tags_defs;
"%*s%s%*s",
(int) hc->base_url->urllen, hc->base_url->string,
need_slash ? "/" : "",
- (gint) orig_len, href_value.data());
+ (int) orig_len, href_value.data());
href_value = {buf, nlen};
}
else if (href_value.size() > 2 && href_value[0] == '/' && href_value[1] != '/') {
auto nlen = (std::size_t) rspamd_snprintf(buf, len + 1, "%*s://%*s/%*s",
(int) hc->base_url->protocollen, hc->base_url->string,
(int) hc->base_url->hostlen, rspamd_url_host_unsafe(hc->base_url),
- (gint) orig_len, href_value.data());
+ (int) orig_len, href_value.data());
href_value = {buf, nlen};
}
}
* We ignore content type so far
*/
struct rspamd_image *parsed_image;
- const gchar *semicolon_pos = input.data(),
- *end = input.data() + input.size();
+ const char *semicolon_pos = input.data(),
+ *end = input.data() + input.size();
- if ((semicolon_pos = (const gchar *) memchr(semicolon_pos, ';', end - semicolon_pos)) != NULL) {
+ if ((semicolon_pos = (const char *) memchr(semicolon_pos, ';', end - semicolon_pos)) != NULL) {
if (end - semicolon_pos > sizeof("base64,")) {
if (memcmp(semicolon_pos + 1, "base64,", sizeof("base64,") - 1) == 0) {
- const gchar *data_pos = semicolon_pos + sizeof("base64,");
- gchar *decoded;
+ const char *data_pos = semicolon_pos + sizeof("base64,");
+ char *decoded;
gsize encoded_len = end - data_pos, decoded_len;
rspamd_ftok_t inp;
decoded_len = (encoded_len / 4 * 3) + 12;
decoded = rspamd_mempool_alloc_buffer(pool, decoded_len);
rspamd_cryptobox_base64_decode(data_pos, encoded_len,
- reinterpret_cast<guchar *>(decoded), &decoded_len);
+ reinterpret_cast<unsigned char *>(decoded), &decoded_len);
inp.begin = decoded;
inp.len = decoded_len;
static auto
html_append_tag_content(rspamd_mempool_t *pool,
- const gchar *start, gsize len,
+ const char *start, gsize len,
struct html_content *hc,
html_tag *tag,
GList **exceptions,
bool allow_css,
std::uint16_t *cur_url_order) -> html_content *
{
- const gchar *p, *c, *end, *start;
- guchar t;
+ const char *p, *c, *end, *start;
+ unsigned char t;
auto closing = false;
- guint obrace = 0, ebrace = 0;
+ unsigned int obrace = 0, ebrace = 0;
struct rspamd_url *url = nullptr;
- gint href_offset = -1;
+ int href_offset = -1;
auto overflow_input = false;
struct html_tag *cur_tag = nullptr, *parent_tag = nullptr, cur_closing_tag;
struct tag_content_parser_state content_parser_env;
* Since closing tags must not have attributes, these assumptions
* seems to be reasonable enough for our toy parser.
*/
- gint cur_lookahead = 1;
- gint max_lookahead = MIN(end - p, 30);
+ int cur_lookahead = 1;
+ int max_lookahead = MIN(end - p, 30);
bool valid_closing_tag = true;
if (p + 1 < end && !g_ascii_isalpha(p[1])) {
}
else {
while (cur_lookahead < max_lookahead) {
- gchar tt = p[cur_lookahead];
+ char tt = p[cur_lookahead];
if (tt == '>') {
break;
}
NULL, NULL, FALSE, &order);
}
-guint rspamd_html_decode_entitles_inplace(gchar *s, gsize len)
+unsigned int rspamd_html_decode_entitles_inplace(char *s, gsize len)
{
return rspamd::html::decode_html_entitles_inplace(s, len);
}
-gint rspamd_html_tag_by_name(const gchar *name)
+int rspamd_html_tag_by_name(const char *name)
{
const auto *td = rspamd::html::html_tags_defs.by_name(name);
}
gboolean
-rspamd_html_tag_seen(void *ptr, const gchar *tagname)
+rspamd_html_tag_seen(void *ptr, const char *tagname)
{
- gint id;
+ int id;
auto *hc = rspamd::html::html_content::from_ptr(ptr);
g_assert(hc != NULL);
return FALSE;
}
-const gchar *
-rspamd_html_tag_by_id(gint id)
+const char *
+rspamd_html_tag_by_id(int id)
{
if (id > Tag_UNKNOWN && id < Tag_MAX) {
const auto *td = rspamd::html::html_tags_defs.by_id(id);
return nullptr;
}
-const gchar *
+const char *
rspamd_html_tag_name(void *p, gsize *len)
{
auto *tag = reinterpret_cast<rspamd::html::html_tag *>(p);
struct rspamd_image;
struct html_image {
- guint height;
- guint width;
- guint flags;
- gchar *src;
+ unsigned int height;
+ unsigned int width;
+ unsigned int flags;
+ char *src;
struct rspamd_url *url;
struct rspamd_image *embedded_image;
void *tag;
/*
* Decode HTML entitles in text. Text is modified in place.
*/
-guint rspamd_html_decode_entitles_inplace(gchar *s, gsize len);
+unsigned int rspamd_html_decode_entitles_inplace(char *s, gsize len);
void *rspamd_html_process_part(rspamd_mempool_t *pool,
GByteArray *in);
/*
* Returns true if a specified tag has been seen in a part
*/
-gboolean rspamd_html_tag_seen(void *ptr, const gchar *tagname);
+gboolean rspamd_html_tag_seen(void *ptr, const char *tagname);
/**
* Returns name for the specified tag id
* @param id
* @return
*/
-const gchar *rspamd_html_tag_by_id(gint id);
+const char *rspamd_html_tag_by_id(int id);
/**
* Returns HTML tag id by name
* @param name
* @return
*/
-gint rspamd_html_tag_by_name(const gchar *name);
+int rspamd_html_tag_by_name(const char *name);
/**
* Gets a name for a tag
* @param len
* @return
*/
-const gchar *rspamd_html_tag_name(void *tag, gsize *len);
+const char *rspamd_html_tag_name(void *tag, gsize *len);
/**
* Find HTML image by content id
struct html_content {
struct rspamd_url *base_url = nullptr;
struct html_tag *root_tag = nullptr;
- gint flags = 0;
+ int flags = 0;
std::vector<bool> tags_seen;
std::vector<html_image *> images;
std::vector<std::unique_ptr<struct html_tag>> all_tags;
* e - begin of entity
*/
char *t = s, *h = s, *e = s;
- const gchar *end;
+ const char *end;
bool seen_hash = false, seen_hex = false;
enum {
do_undefined,
struct html_tag_def {
std::string name;
tag_id_t id;
- guint flags;
+ unsigned int flags;
};
#define TAG_DEF(id, name, flags) \
-/*-
- * Copyright 2021 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
SUBCASE((std::string("extract tags from: ") + c.first).c_str())
{
GByteArray *tmp = g_byte_array_sized_new(c.first.size());
- g_byte_array_append(tmp, (const guint8 *) c.first.data(), c.first.size());
+ g_byte_array_append(tmp, (const uint8_t *) c.first.data(), c.first.size());
auto *hc = html_process_input(&fake_task, tmp, nullptr, nullptr, nullptr, true, nullptr);
CHECK(hc != nullptr);
auto dump = html_debug_structure(*hc);
SUBCASE((fmt::format("html extraction case {}", i)).c_str())
{
GByteArray *tmp = g_byte_array_sized_new(c.first.size());
- g_byte_array_append(tmp, (const guint8 *) c.first.data(), c.first.size());
+ g_byte_array_append(tmp, (const uint8_t *) c.first.data(), c.first.size());
auto *hc = html_process_input(&fake_task, tmp, nullptr, nullptr, nullptr, true, nullptr);
CHECK(hc != nullptr);
replace_newlines(hc->parsed);
GPtrArray *purls = g_ptr_array_new();
auto input = std::get<0>(c);
GByteArray *tmp = g_byte_array_sized_new(input.size());
- g_byte_array_append(tmp, (const guint8 *) input.data(), input.size());
+ g_byte_array_append(tmp, (const uint8_t *) input.data(), input.size());
auto *hc = html_process_input(&fake_task, tmp, nullptr, nullptr, purls, true, nullptr);
CHECK(hc != nullptr);
auto &expected_text = std::get<2>(c);
struct rspamd_url *text_url;
std::string_view disp_tok, href_tok;
goffset url_pos;
- gchar *url_str = NULL;
+ char *url_str = NULL;
auto sz = text_data.size();
const auto *trimmed = rspamd_string_unicode_trim_inplace(text_data.data(), &sz);
struct rspamd_url *displayed_url = nullptr;
struct rspamd_url *turl;
struct rspamd_process_exception *ex;
- guint saved_flags = 0;
+ unsigned int saved_flags = 0;
gsize dlen;
if (visible_part.empty()) {
-> std::optional<struct rspamd_url *>
{
struct rspamd_url *url;
- guint saved_flags = 0;
- gint rc;
- const gchar *s, *prefix = "http://";
- gchar *d;
+ unsigned int saved_flags = 0;
+ int rc;
+ const char *s, *prefix = "http://";
+ char *d;
gsize dlen;
gboolean has_bad_chars = FALSE, no_prefix = FALSE;
- static const gchar hexdigests[] = "0123456789abcdef";
+ static const char hexdigests[] = "0123456789abcdef";
auto sz = input.length();
const auto *trimmed = rspamd_string_unicode_trim_inplace(input.data(), &sz);
dlen = 0;
for (auto i = 0; i < sz; i++) {
- if (G_UNLIKELY(((guint) s[i]) < 0x80 && !g_ascii_isgraph(s[i]))) {
+ if (G_UNLIKELY(((unsigned int) s[i]) < 0x80 && !g_ascii_isgraph(s[i]))) {
dlen += 3;
}
else {
if (G_UNLIKELY(g_ascii_isspace(s[i]))) {
continue;
}
- else if (G_UNLIKELY(((guint) s[i]) < 0x80 && !g_ascii_isgraph(s[i]))) {
+ else if (G_UNLIKELY(((unsigned int) s[i]) < 0x80 && !g_ascii_isgraph(s[i]))) {
/* URL encode */
*d++ = '%';
*d++ = hexdigests[(s[i] >> 4) & 0xf];
struct _rspamd_http_privbuf {
rspamd_fstring_t *data;
- const gchar *zc_buf;
+ const char *zc_buf;
gsize zc_remain;
ref_entry_t ref;
};
ev_tstamp timeout;
struct rspamd_http_message *msg;
struct iovec *out;
- guint outlen;
+ unsigned int outlen;
enum rspamd_http_priv_flags flags;
gsize wr_pos;
gsize wr_total;
g_free(p);
}
-static const gchar *
-rspamd_http_code_to_str(gint code)
+static const char *
+rspamd_http_code_to_str(int code)
{
if (code == 200) {
return "OK";
rspamd_http_parse_key(rspamd_ftok_t *data, struct rspamd_http_connection *conn,
struct rspamd_http_connection_private *priv)
{
- guchar *decoded_id;
- const gchar *eq_pos;
+ unsigned char *decoded_id;
+ const char *eq_pos;
gsize id_len;
struct rspamd_cryptobox_pubkey *pk;
}
}
-static gint
-rspamd_http_on_url(http_parser *parser, const gchar *at, size_t length)
+static int
+rspamd_http_on_url(http_parser *parser, const char *at, size_t length)
{
struct rspamd_http_connection *conn =
(struct rspamd_http_connection *) parser->data;
return 0;
}
-static gint
-rspamd_http_on_status(http_parser *parser, const gchar *at, size_t length)
+static int
+rspamd_http_on_status(http_parser *parser, const char *at, size_t length)
{
struct rspamd_http_connection *conn =
(struct rspamd_http_connection *) parser->data;
{
struct rspamd_http_header *hdr;
khiter_t k;
- gint r;
+ int r;
priv->header->combined = rspamd_fstring_append(priv->header->combined,
"\r\n", 2);
priv->header->combined = rspamd_fstring_new();
}
-static gint
+static int
rspamd_http_on_header_field(http_parser *parser,
- const gchar *at,
+ const char *at,
size_t length)
{
struct rspamd_http_connection *conn =
return 0;
}
-static gint
+static int
rspamd_http_on_header_value(http_parser *parser,
- const gchar *at,
+ const char *at,
size_t length)
{
struct rspamd_http_connection *conn =
}
static int
-rspamd_http_on_body(http_parser *parser, const gchar *at, size_t length)
+rspamd_http_on_body(http_parser *parser, const char *at, size_t length)
{
struct rspamd_http_connection *conn =
(struct rspamd_http_connection *) parser->data;
struct rspamd_http_connection_private *priv;
struct rspamd_http_message *msg;
struct _rspamd_http_privbuf *pbuf;
- const gchar *p;
+ const char *p;
priv = conn->priv;
msg = priv->msg;
else {
if (msg->body_buf.begin + msg->body_buf.len != at) {
/* Likely chunked encoding */
- memmove((gchar *) msg->body_buf.begin + msg->body_buf.len, at, length);
+ memmove((char *) msg->body_buf.begin + msg->body_buf.len, at, length);
p = msg->body_buf.begin + msg->body_buf.len;
}
}
static int
-rspamd_http_on_body_decrypted(http_parser *parser, const gchar *at, size_t length)
+rspamd_http_on_body_decrypted(http_parser *parser, const char *at, size_t length)
{
struct rspamd_http_connection *conn =
(struct rspamd_http_connection *) parser->data;
struct rspamd_http_connection_private *priv,
struct rspamd_cryptobox_pubkey *peer_key)
{
- guchar *nonce, *m;
- const guchar *nm;
+ unsigned char *nonce, *m;
+ const unsigned char *nm;
gsize dec_len;
struct rspamd_http_message *msg = priv->msg;
struct rspamd_http_header *hdr, *hcur, *hcurtmp;
if (!rspamd_cryptobox_decrypt_nm_inplace(m, dec_len, nonce,
nm, m - rspamd_cryptobox_mac_bytes(mode), mode)) {
msg_err("cannot verify encrypted message, first bytes of the input: %*xs",
- (gint) MIN(msg->body_buf.len, 64), msg->body_buf.begin);
+ (int) MIN(msg->body_buf.len, 64), msg->body_buf.begin);
return -1;
}
{
struct rspamd_http_connection_private *priv;
gpointer ssl;
- gint request_method;
+ int request_method;
GString *prev_host = NULL;
priv = conn->priv;
{
struct rspamd_http_connection_private *priv;
struct iovec *start;
- guint niov, i;
- gint flags = 0;
+ unsigned int niov, i;
+ int flags = 0;
gsize remain;
gssize r;
GError *err;
}
static gssize
-rspamd_http_try_read(gint fd,
+rspamd_http_try_read(int fd,
struct rspamd_http_connection *conn,
struct rspamd_http_connection_private *priv,
struct _rspamd_http_privbuf *pbuf,
- const gchar **buf_ptr)
+ const char **buf_ptr)
{
gssize r;
- gchar *data;
+ char *data;
gsize len;
struct rspamd_http_message *msg;
len = priv->buf->data->allocated;
}
else {
- data = (gchar *) pbuf->zc_buf;
+ data = (char *) pbuf->zc_buf;
len = pbuf->zc_remain;
if (len == 0) {
rspamd_http_message_grow_body(priv->msg, priv->buf->data->allocated);
rspamd_http_switch_zc(pbuf, msg);
- data = (gchar *) pbuf->zc_buf;
+ data = (char *) pbuf->zc_buf;
len = pbuf->zc_remain;
}
}
struct rspamd_http_connection *conn = (struct rspamd_http_connection *) ud;
struct rspamd_http_connection_private *priv;
struct _rspamd_http_privbuf *pbuf;
- const gchar *d;
+ const char *d;
gssize r;
GError *err;
static struct rspamd_http_connection *
rspamd_http_connection_new_common(struct rspamd_http_context *ctx,
- gint fd,
+ int fd,
rspamd_http_body_handler_t body_handler,
rspamd_http_error_handler_t error_handler,
rspamd_http_finish_handler_t finish_handler,
struct rspamd_http_connection *
rspamd_http_connection_new_server(struct rspamd_http_context *ctx,
- gint fd,
+ int fd,
rspamd_http_body_handler_t body_handler,
rspamd_http_error_handler_t error_handler,
rspamd_http_finish_handler_t finish_handler,
rspamd_http_error_handler_t error_handler,
rspamd_http_finish_handler_t finish_handler,
unsigned opts,
- gint fd)
+ int fd)
{
return rspamd_http_connection_new_common(ctx, fd, body_handler,
error_handler, finish_handler, opts, RSPAMD_HTTP_CLIENT, 0, NULL);
unsigned opts,
rspamd_inet_addr_t *addr)
{
- gint fd;
+ int fd;
if (ctx == NULL) {
ctx = rspamd_http_context_default();
rspamd_http_finish_handler_t finish_handler,
unsigned opts,
rspamd_inet_addr_t *addr,
- const gchar *host)
+ const char *host)
{
struct rspamd_http_connection *conn;
{
struct rspamd_http_message *new_msg;
struct rspamd_http_header *hdr, *nhdr, *nhdrs, *hcur;
- const gchar *old_body;
+ const char *old_body;
gsize old_len;
struct stat st;
union _rspamd_storage_u *storage;
DL_APPEND(nhdrs, nhdr);
}
- gint r;
+ int r;
khiter_t k = kh_put(rspamd_http_headers_hash, new_msg->headers,
&nhdrs->name, &r);
static void
rspamd_http_connection_read_message_common(struct rspamd_http_connection *conn,
gpointer ud, ev_tstamp timeout,
- gint flags)
+ int flags)
{
struct rspamd_http_connection_private *priv = conn->priv;
struct rspamd_http_message *req;
struct rspamd_http_connection *conn,
struct rspamd_http_message *msg,
struct rspamd_http_connection_private *priv,
- guchar *pbody,
- guint bodylen,
- guchar *pmethod,
- guint methodlen,
- guint preludelen,
- gint hdrcount,
- guchar *np,
- guchar *mp,
+ unsigned char *pbody,
+ unsigned int bodylen,
+ unsigned char *pmethod,
+ unsigned int methodlen,
+ unsigned int preludelen,
+ int hdrcount,
+ unsigned char *np,
+ unsigned char *mp,
struct rspamd_cryptobox_pubkey *peer_key)
{
struct rspamd_cryptobox_segment *segments;
- guchar *crlfp;
- const guchar *nm;
- gint i, cnt;
- guint outlen;
+ unsigned char *crlfp;
+ const unsigned char *nm;
+ int i, cnt;
+ unsigned int outlen;
struct rspamd_http_header *hdr, *hcur;
enum rspamd_cryptobox_mode mode;
rspamd_http_message_set_body_from_fstring_steal(msg, cpy_str);
}
-gint rspamd_http_message_write_header(const gchar *mime_type, gboolean encrypted,
- gchar *repbuf, gsize replen, gsize bodylen, gsize enclen, const gchar *host,
- struct rspamd_http_connection *conn, struct rspamd_http_message *msg,
- rspamd_fstring_t **buf,
- struct rspamd_http_connection_private *priv,
- struct rspamd_cryptobox_pubkey *peer_key)
+int rspamd_http_message_write_header(const char *mime_type, gboolean encrypted,
+ char *repbuf, gsize replen, gsize bodylen, gsize enclen, const char *host,
+ struct rspamd_http_connection *conn, struct rspamd_http_message *msg,
+ rspamd_fstring_t **buf,
+ struct rspamd_http_connection_private *priv,
+ struct rspamd_cryptobox_pubkey *peer_key)
{
- gchar datebuf[64];
- gint meth_len = 0;
- const gchar *conn_type = "close";
+ char datebuf[64];
+ int meth_len = 0;
+ const char *conn_type = "close";
if (conn->type == RSPAMD_HTTP_SERVER) {
/* Format reply */
GString tmp;
/* Unfortunately, spamc protocol is deadly brain damaged */
- tmp.str = (gchar *) msg->body_buf.begin;
+ tmp.str = (char *) msg->body_buf.begin;
tmp.len = msg->body_buf.len;
if (rspamd_string_find_eoh(&tmp, &eoh_pos) != -1 &&
static gboolean
rspamd_http_connection_write_message_common(struct rspamd_http_connection *conn,
struct rspamd_http_message *msg,
- const gchar *host,
- const gchar *mime_type,
+ const char *host,
+ const char *mime_type,
gpointer ud,
ev_tstamp timeout,
gboolean allow_shared)
{
struct rspamd_http_connection_private *priv = conn->priv;
struct rspamd_http_header *hdr, *hcur;
- gchar repbuf[512], *pbody;
- gint i, hdrcount, meth_len = 0, preludelen = 0;
+ char repbuf[512], *pbody;
+ int i, hdrcount, meth_len = 0, preludelen = 0;
gsize bodylen, enclen = 0;
rspamd_fstring_t *buf;
gboolean encrypted = FALSE;
- guchar nonce[rspamd_cryptobox_MAX_NONCEBYTES], mac[rspamd_cryptobox_MAX_MACBYTES];
- guchar *np = NULL, *mp = NULL, *meth_pos = NULL;
+ unsigned char nonce[rspamd_cryptobox_MAX_NONCEBYTES], mac[rspamd_cryptobox_MAX_MACBYTES];
+ unsigned char *np = NULL, *mp = NULL, *meth_pos = NULL;
struct rspamd_cryptobox_pubkey *peer_key = NULL;
enum rspamd_cryptobox_mode mode;
GError *err;
}
if (allow_shared) {
- gchar tmpbuf[64];
+ char tmpbuf[64];
if (!(msg->flags & RSPAMD_HTTP_FLAG_SHMEM) ||
msg->body_buf.c.shared.name == NULL) {
if (priv->ctx->config.user_agent && conn->type == RSPAMD_HTTP_CLIENT) {
rspamd_ftok_t srch;
khiter_t k;
- gint r;
+ int r;
RSPAMD_FTOK_ASSIGN(&srch, "User-Agent");
if (r != 0) {
hdr = g_malloc0(sizeof(struct rspamd_http_header));
- guint vlen = strlen(priv->ctx->config.user_agent);
+ unsigned int vlen = strlen(priv->ctx->config.user_agent);
hdr->combined = rspamd_fstring_sized_new(srch.len + vlen + 4);
rspamd_printf_fstring(&hdr->combined, "%T: %*s\r\n", &srch, vlen,
priv->ctx->config.user_agent);
msg->method = HTTP_GET;
}
else {
- pbody = (gchar *) msg->body_buf.begin;
+ pbody = (char *) msg->body_buf.begin;
bodylen = msg->body_buf.len;
msg->method = HTTP_POST;
}
}
}
else {
- pbody = (gchar *) msg->body_buf.begin;
+ pbody = (char *) msg->body_buf.begin;
bodylen = msg->body_buf.len;
priv->outlen = 3;
}
else if (msg->body_buf.len > 0) {
allow_shared = FALSE;
- pbody = (gchar *) msg->body_buf.begin;
+ pbody = (char *) msg->body_buf.begin;
bodylen = msg->body_buf.len;
priv->outlen = 2;
}
/* Buf will be used eventually for encryption */
if (encrypted) {
- gint meth_offset, nonce_offset, mac_offset;
+ int meth_offset, nonce_offset, mac_offset;
mode = rspamd_keypair_alg(priv->local_key);
ottery_rand_bytes(nonce, rspamd_cryptobox_nonce_bytes(mode));
gboolean
rspamd_http_connection_write_message(struct rspamd_http_connection *conn,
struct rspamd_http_message *msg,
- const gchar *host,
- const gchar *mime_type,
+ const char *host,
+ const char *mime_type,
gpointer ud,
ev_tstamp timeout)
{
gboolean
rspamd_http_connection_write_message_shared(struct rspamd_http_connection *conn,
struct rspamd_http_message *msg,
- const gchar *host,
- const gchar *mime_type,
+ const char *host,
+ const char *mime_type,
gpointer ud,
ev_tstamp timeout)
{
GHashTable *res;
rspamd_fstring_t *key = NULL, *value = NULL;
rspamd_ftok_t *key_tok = NULL, *value_tok = NULL;
- const gchar *p, *c, *end;
+ const char *p, *c, *end;
struct http_parser_url u;
enum {
parse_key,
struct rspamd_keepalive_hash_key;
struct rspamd_storage_shmem {
- gchar *shm_name;
+ char *shm_name;
ref_entry_t ref;
};
typedef int (*rspamd_http_body_handler_t)(struct rspamd_http_connection *conn,
struct rspamd_http_message *msg,
- const gchar *chunk,
+ const char *chunk,
gsize len);
typedef void (*rspamd_http_error_handler_t)(struct rspamd_http_connection *conn,
rspamd_http_error_handler_t error_handler;
rspamd_http_finish_handler_t finish_handler;
gpointer ud;
- const gchar *log_tag;
+ const char *log_tag;
/* Used for keepalive */
struct rspamd_keepalive_hash_key *keepalive_hash_key;
gsize max_size;
unsigned opts;
enum rspamd_http_connection_type type;
gboolean finished;
- gint fd;
- gint ref;
+ int fd;
+ int ref;
};
/**
*/
struct rspamd_http_connection *rspamd_http_connection_new_server(
struct rspamd_http_context *ctx,
- gint fd,
+ int fd,
rspamd_http_body_handler_t body_handler,
rspamd_http_error_handler_t error_handler,
rspamd_http_finish_handler_t finish_handler,
rspamd_http_finish_handler_t finish_handler,
unsigned opts,
rspamd_inet_addr_t *addr,
- const gchar *host);
+ const char *host);
/**
* Creates an ordinary connection using the address specified (if proxy is not set)
rspamd_http_error_handler_t error_handler,
rspamd_http_finish_handler_t finish_handler,
unsigned opts,
- gint fd);
+ int fd);
/**
* Set key pointed by an opaque pointer
gboolean rspamd_http_connection_write_message(
struct rspamd_http_connection *conn,
struct rspamd_http_message *msg,
- const gchar *host,
- const gchar *mime_type,
+ const char *host,
+ const char *mime_type,
gpointer ud,
ev_tstamp timeout);
gboolean rspamd_http_connection_write_message_shared(
struct rspamd_http_connection *conn,
struct rspamd_http_message *msg,
- const gchar *host,
- const gchar *mime_type,
+ const char *host,
+ const char *mime_type,
gpointer ud,
ev_tstamp timeout);
struct rspamd_http_context *ctx;
static const int default_kp_size = 1024;
- static const gdouble default_rotate_time = 120;
- static const gdouble default_keepalive_interval = 65;
- static const gchar *default_user_agent = "rspamd-" RSPAMD_VERSION_FULL;
- static const gchar *default_server_hdr = "rspamd/" RSPAMD_VERSION_FULL;
+ static const double default_rotate_time = 120;
+ static const double default_keepalive_interval = 65;
+ static const char *default_user_agent = "rspamd-" RSPAMD_VERSION_FULL;
+ static const char *default_server_hdr = "rspamd/" RSPAMD_VERSION_FULL;
ctx = g_malloc0(sizeof(*ctx));
ctx->config.kp_cache_size_client = default_kp_size;
static void
rspamd_http_context_parse_proxy(struct rspamd_http_context *ctx,
- const gchar *name,
+ const char *name,
struct upstream_list **pls)
{
struct http_parser_url u;
struct rspamd_http_connection *
rspamd_http_context_check_keepalive(struct rspamd_http_context *ctx,
const rspamd_inet_addr_t *addr,
- const gchar *host,
+ const char *host,
bool is_ssl)
{
struct rspamd_keepalive_hash_key hk, *phk;
}
hk.addr = (rspamd_inet_addr_t *) addr;
- hk.host = (gchar *) host;
+ hk.host = (char *) host;
hk.port = rspamd_inet_address_get_port(addr);
hk.is_ssl = is_ssl;
if (g_queue_get_length(conns) > 0) {
struct rspamd_http_keepalive_cbdata *cbd;
struct rspamd_http_connection *conn;
- gint err;
- socklen_t len = sizeof(gint);
+ int err;
+ socklen_t len = sizeof(int);
cbd = g_queue_pop_head(conns);
rspamd_ev_watcher_stop(ctx->event_loop, &cbd->ev);
const rspamd_inet_addr_t *
rspamd_http_context_has_keepalive(struct rspamd_http_context *ctx,
- const gchar *host,
+ const char *host,
unsigned port,
bool is_ssl)
{
ctx = rspamd_http_context_default();
}
- hk.host = (gchar *) host;
+ hk.host = (char *) host;
hk.port = port;
hk.is_ssl = is_ssl;
void rspamd_http_context_prepare_keepalive(struct rspamd_http_context *ctx,
struct rspamd_http_connection *conn,
const rspamd_inet_addr_t *addr,
- const gchar *host,
+ const char *host,
bool is_ssl)
{
struct rspamd_keepalive_hash_key hk, *phk;
khiter_t k;
hk.addr = (rspamd_inet_addr_t *) addr;
- hk.host = (gchar *) host;
+ hk.host = (char *) host;
hk.is_ssl = is_ssl;
hk.port = rspamd_inet_address_get_port(addr);
else {
/* Create new one */
GQueue empty_init = G_QUEUE_INIT;
- gint r;
+ int r;
phk = g_malloc(sizeof(*phk));
phk->conns = empty_init;
}
static void
-rspamd_http_keepalive_handler(gint fd, short what, gpointer ud)
+rspamd_http_keepalive_handler(int fd, short what, gpointer ud)
{
struct rspamd_http_keepalive_cbdata *cbdata =
(struct rspamd_http_keepalive_cbdata *) ud; /*
struct ev_loop *event_loop)
{
struct rspamd_http_keepalive_cbdata *cbdata;
- gdouble timeout = ctx->config.keepalive_interval;
+ double timeout = ctx->config.keepalive_interval;
g_assert(conn->keepalive_hash_key != NULL);
struct upstream_ctx;
struct rspamd_http_context_cfg {
- guint kp_cache_size_client;
- guint kp_cache_size_server;
- guint ssl_cache_size;
- gdouble keepalive_interval;
- gdouble client_key_rotate_time;
- const gchar *user_agent;
- const gchar *http_proxy;
- const gchar *server_hdr;
+ unsigned int kp_cache_size_client;
+ unsigned int kp_cache_size_server;
+ unsigned int ssl_cache_size;
+ double keepalive_interval;
+ double client_key_rotate_time;
+ const char *user_agent;
+ const char *http_proxy;
+ const char *server_hdr;
};
/**
*/
struct rspamd_http_connection *rspamd_http_context_check_keepalive(struct rspamd_http_context *ctx,
const rspamd_inet_addr_t *addr,
- const gchar *host,
+ const char *host,
bool is_ssl);
/**
* @return
*/
const rspamd_inet_addr_t *rspamd_http_context_has_keepalive(struct rspamd_http_context *ctx,
- const gchar *host,
+ const char *host,
unsigned port,
bool is_ssl);
* @param host
*/
void rspamd_http_context_prepare_keepalive(struct rspamd_http_context *ctx, struct rspamd_http_connection *conn,
- const rspamd_inet_addr_t *addr, const gchar *host, bool is_ssl);
+ const rspamd_inet_addr_t *addr, const char *host, bool is_ssl);
/**
* Pushes a connection to keepalive pool after client request is finished,
}
struct rspamd_http_message *
-rspamd_http_message_from_url(const gchar *url)
+rspamd_http_message_from_url(const char *url)
{
struct http_parser_url pu;
struct rspamd_http_message *msg;
- const gchar *host, *path;
+ const char *host, *path;
size_t pathlen, urllen;
- guint flags = 0;
+ unsigned int flags = 0;
if (url == NULL) {
return NULL;
return msg;
}
-const gchar *
+const char *
rspamd_http_message_get_body(struct rspamd_http_message *msg,
gsize *blen)
{
- const gchar *ret = NULL;
+ const char *ret = NULL;
if (msg->body_buf.len > 0) {
ret = msg->body_buf.begin;
return NULL;
}
-guint rspamd_http_message_get_flags(struct rspamd_http_message *msg)
+unsigned int rspamd_http_message_get_flags(struct rspamd_http_message *msg)
{
return msg->flags;
}
gboolean
rspamd_http_message_set_body(struct rspamd_http_message *msg,
- const gchar *data, gsize len)
+ const char *data, gsize len)
{
union _rspamd_storage_u *storage;
storage = &msg->body_buf.c;
}
void rspamd_http_message_set_method(struct rspamd_http_message *msg,
- const gchar *method)
+ const char *method)
{
- gint i;
+ int i;
/* Linear search: not very efficient method */
for (i = 0; i < HTTP_METHOD_MAX; i++) {
gboolean
rspamd_http_message_set_body_from_fd(struct rspamd_http_message *msg,
- gint fd)
+ int fd)
{
union _rspamd_storage_u *storage;
struct stat st;
gboolean
rspamd_http_message_append_body(struct rspamd_http_message *msg,
- const gchar *data, gsize len)
+ const char *data, gsize len)
{
union _rspamd_storage_u *storage;
}
void rspamd_http_message_add_header_len(struct rspamd_http_message *msg,
- const gchar *name,
- const gchar *value,
+ const char *name,
+ const char *value,
gsize len)
{
struct rspamd_http_header *hdr, *found;
- guint nlen, vlen;
+ unsigned int nlen, vlen;
khiter_t k;
- gint r;
+ int r;
if (msg != NULL && name != NULL && value != NULL) {
hdr = g_malloc0(sizeof(struct rspamd_http_header));
}
hdr->combined = rspamd_fstring_sized_new(nlen + vlen + 4);
- rspamd_printf_fstring(&hdr->combined, "%s: %*s\r\n", name, (gint) vlen,
+ rspamd_printf_fstring(&hdr->combined, "%s: %*s\r\n", name, (int) vlen,
value);
hdr->name.begin = hdr->combined->str;
hdr->name.len = nlen;
}
void rspamd_http_message_add_header(struct rspamd_http_message *msg,
- const gchar *name,
- const gchar *value)
+ const char *name,
+ const char *value)
{
if (value) {
rspamd_http_message_add_header_len(msg, name, value, strlen(value));
}
void rspamd_http_message_add_header_fstr(struct rspamd_http_message *msg,
- const gchar *name,
+ const char *name,
rspamd_fstring_t *value)
{
struct rspamd_http_header *hdr, *found = NULL;
- guint nlen, vlen;
+ unsigned int nlen, vlen;
khiter_t k;
- gint r;
+ int r;
if (msg != NULL && name != NULL && value != NULL) {
hdr = g_malloc0(sizeof(struct rspamd_http_header));
const rspamd_ftok_t *
rspamd_http_message_find_header(struct rspamd_http_message *msg,
- const gchar *name)
+ const char *name)
{
const rspamd_ftok_t *res = NULL;
rspamd_ftok_t srch;
- guint slen = strlen(name);
+ unsigned int slen = strlen(name);
khiter_t k;
if (msg != NULL) {
GPtrArray *
rspamd_http_message_find_header_multiple(
struct rspamd_http_message *msg,
- const gchar *name)
+ const char *name)
{
GPtrArray *res = NULL;
struct rspamd_http_header *hdr, *cur;
rspamd_ftok_t srch;
khiter_t k;
- guint cnt = 0;
+ unsigned int cnt = 0;
- guint slen = strlen(name);
+ unsigned int slen = strlen(name);
if (msg != NULL) {
srch.begin = name;
gboolean
rspamd_http_message_remove_header(struct rspamd_http_message *msg,
- const gchar *name)
+ const char *name)
{
struct rspamd_http_header *hdr, *hcur, *hcurtmp;
gboolean res = FALSE;
- guint slen = strlen(name);
+ unsigned int slen = strlen(name);
rspamd_ftok_t srch;
khiter_t k;
return res;
}
-const gchar *
+const char *
rspamd_http_message_get_http_host(struct rspamd_http_message *msg,
gsize *hostlen)
{
return msg->port == 80;
}
-const gchar *rspamd_http_message_get_url(struct rspamd_http_message *msg, gsize *len)
+const char *rspamd_http_message_get_url(struct rspamd_http_message *msg, gsize *len)
{
if (msg->url) {
*len = msg->url->len;
* @param url
* @return new message or NULL
*/
-struct rspamd_http_message *rspamd_http_message_from_url(const gchar *url);
+struct rspamd_http_message *rspamd_http_message_from_url(const char *url);
/**
* Returns body for a message
* @param blen pointer where to save body length
* @return pointer to body start
*/
-const gchar *rspamd_http_message_get_body(struct rspamd_http_message *msg,
- gsize *blen);
+const char *rspamd_http_message_get_body(struct rspamd_http_message *msg,
+ gsize *blen);
/**
* Set message's body from the string
* @return TRUE if a message's body has been set
*/
gboolean rspamd_http_message_set_body(struct rspamd_http_message *msg,
- const gchar *data, gsize len);
+ const char *data, gsize len);
/**
* Set message's method by name
* @param method
*/
void rspamd_http_message_set_method(struct rspamd_http_message *msg,
- const gchar *method);
+ const char *method);
/**
* Maps fd as message's body
* @return TRUE if a message's body has been set
*/
gboolean rspamd_http_message_set_body_from_fd(struct rspamd_http_message *msg,
- gint fd);
+ int fd);
/**
* Uses rspamd_fstring_t as message's body, string is consumed by this operation
* @return TRUE if a message's body has been set
*/
gboolean rspamd_http_message_append_body(struct rspamd_http_message *msg,
- const gchar *data, gsize len);
+ const char *data, gsize len);
/**
* Append a header to http message
* @param value
*/
void rspamd_http_message_add_header(struct rspamd_http_message *msg,
- const gchar *name,
- const gchar *value);
+ const char *name,
+ const char *value);
void rspamd_http_message_add_header_len(struct rspamd_http_message *msg,
- const gchar *name,
- const gchar *value,
+ const char *name,
+ const char *value,
gsize len);
void rspamd_http_message_add_header_fstr(struct rspamd_http_message *msg,
- const gchar *name,
+ const char *name,
rspamd_fstring_t *value);
/**
*/
const rspamd_ftok_t *rspamd_http_message_find_header(
struct rspamd_http_message *msg,
- const gchar *name);
+ const char *name);
/**
* Search for a header that has multiple values
*/
GPtrArray *rspamd_http_message_find_header_multiple(
struct rspamd_http_message *msg,
- const gchar *name);
+ const char *name);
/**
* Remove specific header from a message
* @return
*/
gboolean rspamd_http_message_remove_header(struct rspamd_http_message *msg,
- const gchar *name);
+ const char *name);
/**
* Free HTTP message
* @param msg
* @return
*/
-guint rspamd_http_message_get_flags(struct rspamd_http_message *msg);
+unsigned int rspamd_http_message_get_flags(struct rspamd_http_message *msg);
/**
* Returns an HTTP hostname for a message, derived from a header if it has it
* @param hostlen output of the host length
* @return
*/
-const gchar *rspamd_http_message_get_http_host(struct rspamd_http_message *msg,
- gsize *hostlen);
+const char *rspamd_http_message_get_http_host(struct rspamd_http_message *msg,
+ gsize *hostlen);
/**
* Returns true if a message has standard port (80 or 443 for https)
*/
bool rspamd_http_message_is_standard_port(struct rspamd_http_message *msg);
-const gchar *rspamd_http_message_get_url(struct rspamd_http_message *msg, gsize *len);
+const char *rspamd_http_message_get_url(struct rspamd_http_message *msg, gsize *len);
#ifdef __cplusplus
}
struct _rspamd_body_buf_s {
/* Data start */
- const gchar *begin;
+ const char *begin;
/* Data len */
gsize len;
/* Allocated len */
gsize allocated_len;
/* Data buffer (used to write data inside) */
- gchar *str;
+ char *str;
/* Internal storage */
union _rspamd_storage_u {
rspamd_fstring_t *normal;
struct _rspamd_storage_shared_s {
struct rspamd_storage_shmem *name;
- gint shm_fd;
+ int shm_fd;
} shared;
} c;
} body_buf;
time_t last_modified;
unsigned port;
int type;
- gint code;
+ int code;
enum http_method method;
- gint flags;
+ int flags;
ref_entry_t ref;
};
struct rspamd_keepalive_hash_key {
rspamd_inet_addr_t *addr;
- gchar *host;
+ char *host;
gboolean is_ssl;
unsigned port;
GQueue conns;
};
static const struct _rspamd_http_magic {
- const gchar *ext;
- const gchar *ct;
+ const char *ext;
+ const char *ct;
} http_file_types[] = {
[HTTP_MAGIC_PLAIN] = {"txt", "text/plain"},
[HTTP_MAGIC_HTML] = {"html", "text/html"},
}
}
-static const gchar *
-rspamd_http_router_detect_ct(const gchar *path)
+static const char *
+rspamd_http_router_detect_ct(const char *path)
{
- const gchar *dot;
- guint i;
+ const char *dot;
+ unsigned int i;
dot = strrchr(path, '.');
if (dot == NULL) {
}
static gboolean
-rspamd_http_router_is_subdir(const gchar *parent, const gchar *sub)
+rspamd_http_router_is_subdir(const char *parent, const char *sub)
{
if (parent == NULL || sub == NULL || *parent == '\0') {
return FALSE;
rspamd_ftok_t *lookup, gboolean expand_path)
{
struct stat st;
- gint fd;
- gchar filebuf[PATH_MAX], realbuf[PATH_MAX], *dir;
+ int fd;
+ char filebuf[PATH_MAX], realbuf[PATH_MAX], *dir;
struct rspamd_http_message *reply_msg;
rspamd_snprintf(filebuf, sizeof(filebuf), "%s%c%T",
rspamd_ftok_t lookup;
const rspamd_ftok_t *encoding;
struct http_parser_url u;
- guint i;
+ unsigned int i;
rspamd_regexp_t *re;
struct rspamd_http_connection_router *router;
- gchar *pathbuf = NULL;
+ char *pathbuf = NULL;
G_STATIC_ASSERT(sizeof(rspamd_http_router_handler_t) ==
sizeof(gpointer));
}
void rspamd_http_router_add_path(struct rspamd_http_connection_router *router,
- const gchar *path, rspamd_http_router_handler_t handler)
+ const char *path, rspamd_http_router_handler_t handler)
{
gpointer ptr;
rspamd_ftok_t *key;
}
void rspamd_http_router_add_header(struct rspamd_http_connection_router *router,
- const gchar *name, const gchar *value)
+ const char *name, const char *value)
{
if (name != NULL && value != NULL && router != NULL) {
g_hash_table_replace(router->response_headers, g_strdup(name),
}
void rspamd_http_router_handle_socket(struct rspamd_http_connection_router *router,
- gint fd, gpointer ud)
+ int fd, gpointer ud)
{
struct rspamd_http_connection_entry *conn;
{
struct rspamd_http_connection_entry *conn, *tmp;
rspamd_regexp_t *re;
- guint i;
+ unsigned int i;
if (router) {
DL_FOREACH_SAFE(router->conns, conn, tmp)
ev_tstamp timeout;
struct ev_loop *event_loop;
struct rspamd_http_context *ctx;
- gchar *default_fs_path;
+ char *default_fs_path;
rspamd_http_router_handler_t unknown_method_handler;
struct rspamd_cryptobox_keypair *key;
rspamd_http_router_error_handler_t error_handler;
* Add new path to the router
*/
void rspamd_http_router_add_path(struct rspamd_http_connection_router *router,
- const gchar *path, rspamd_http_router_handler_t handler);
+ const char *path, rspamd_http_router_handler_t handler);
/**
* Add custom header to append to router replies
* @param value
*/
void rspamd_http_router_add_header(struct rspamd_http_connection_router *router,
- const gchar *name, const gchar *value);
+ const char *name, const char *value);
/**
* Sets method to handle unknown request methods
*/
void rspamd_http_router_handle_socket(
struct rspamd_http_connection_router *router,
- gint fd,
+ int fd,
gpointer ud);
/**
#include "libutil/printf.h"
#include "libutil/util.h"
-static const gchar *http_week[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
-static const gchar *http_month[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
+static const char *http_week[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
+static const char *http_month[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
/*
* Obtained from nginx
* Copyright (C) Igor Sysoev
*/
-static guint mday[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
+static unsigned int mday[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
time_t
-rspamd_http_parse_date(const gchar *header, gsize len)
+rspamd_http_parse_date(const char *header, gsize len)
{
- const gchar *p, *end;
- gint month;
- guint day, year, hour, min, sec;
+ const char *p, *end;
+ int month;
+ unsigned int day, year, hour, min, sec;
uint64_t time;
enum {
no = 0,
return (time_t) time;
}
-glong rspamd_http_date_format(gchar *buf, gsize len, time_t time)
+glong rspamd_http_date_format(char *buf, gsize len, time_t time)
{
struct tm tms;
* @param len length of header
* @return time_t or (time_t)-1 in case of error
*/
-time_t rspamd_http_parse_date(const gchar *header, gsize len);
+time_t rspamd_http_parse_date(const char *header, gsize len);
/**
* Prints HTTP date from `time` to `buf` using standard HTTP date format
* @param time time in unix seconds
* @return number of bytes written
*/
-glong rspamd_http_date_format(gchar *buf, gsize len, time_t time);
+glong rspamd_http_date_format(char *buf, gsize len, time_t time);
#ifdef __cplusplus
}
};
typedef struct rspamd_logger_s rspamd_logger_t;
-typedef bool (*rspamd_log_func_t)(const gchar *module, const gchar *id,
- const gchar *function,
- gint level_flags,
- const gchar *message,
+typedef bool (*rspamd_log_func_t)(const char *module, const char *id,
+ const char *function,
+ int level_flags,
+ const char *message,
gsize mlen,
rspamd_logger_t *logger,
gpointer arg);
* This logger is also used as an emergency logger
* @return new rspamd logger object
*/
-rspamd_logger_t *rspamd_log_open_emergency(rspamd_mempool_t *pool, gint flags);
+rspamd_logger_t *rspamd_log_open_emergency(rspamd_mempool_t *pool, int flags);
/**
* Open specific (configured logging)
*/
rspamd_logger_t *rspamd_log_open_specific(rspamd_mempool_t *pool,
struct rspamd_config *config,
- const gchar *ptype,
+ const char *ptype,
uid_t uid, gid_t gid);
/**
* @param logger
* @param level
*/
-void rspamd_log_set_log_level(rspamd_logger_t *logger, gint level);
-gint rspamd_log_get_log_level(rspamd_logger_t *logger);
-const gchar *rspamd_get_log_severity_string(gint level_flags);
+void rspamd_log_set_log_level(rspamd_logger_t *logger, int level);
+int rspamd_log_get_log_level(rspamd_logger_t *logger);
+const char *rspamd_get_log_severity_string(int level_flags);
/**
* Set log flags (from enum rspamd_log_flags)
* @param logger
* @param flags
*/
-void rspamd_log_set_log_flags(rspamd_logger_t *logger, gint flags);
+void rspamd_log_set_log_flags(rspamd_logger_t *logger, int flags);
/**
* Close log file or destroy other structures
/**
* Log function that is compatible for glib messages
*/
-void rspamd_glib_log_function(const gchar *log_domain,
+void rspamd_glib_log_function(const char *log_domain,
GLogLevelFlags log_level,
- const gchar *message,
+ const char *message,
gpointer arg);
/**
* Log function for printing glib assertions
*/
-void rspamd_glib_printerr_function(const gchar *message);
+void rspamd_glib_printerr_function(const char *message);
/**
* Function with variable number of arguments support
*/
bool rspamd_common_log_function(rspamd_logger_t *logger,
- gint level_flags,
- const gchar *module, const gchar *id,
- const gchar *function, const gchar *fmt, ...);
+ int level_flags,
+ const char *module, const char *id,
+ const char *function, const char *fmt, ...);
-bool rspamd_common_logv(rspamd_logger_t *logger, gint level_flags,
- const gchar *module, const gchar *id, const gchar *function,
- const gchar *fmt, va_list args);
+bool rspamd_common_logv(rspamd_logger_t *logger, int level_flags,
+ const char *module, const char *id, const char *function,
+ const char *fmt, va_list args);
/**
* Add new logging module, returns module ID
* @param mod
* @return
*/
-gint rspamd_logger_add_debug_module(const gchar *mod);
+int rspamd_logger_add_debug_module(const char *mod);
/*
* Macro to use for faster debug modules
*/
#define INIT_LOG_MODULE(mname) \
- static gint rspamd_##mname##_log_id = -1; \
+ static int rspamd_##mname##_log_id = -1; \
RSPAMD_CONSTRUCTOR(rspamd_##mname##_log_init) \
{ \
rspamd_##mname##_log_id = rspamd_logger_add_debug_module(#mname); \
#define INIT_LOG_MODULE_PUBLIC(mname) \
- gint rspamd_##mname##_log_id = -1; \
+ int rspamd_##mname##_log_id = -1; \
RSPAMD_CONSTRUCTOR(rspamd_##mname##_log_init) \
{ \
rspamd_##mname##_log_id = rspamd_logger_add_debug_module(#mname); \
}
#define EXTERN_LOG_MODULE_DEF(mname) \
- extern gint rspamd_##mname##_log_id
+ extern int rspamd_##mname##_log_id
void rspamd_logger_configure_modules(GHashTable *mods_enabled);
* Conditional debug function
*/
bool rspamd_conditional_debug(rspamd_logger_t *logger,
- rspamd_inet_addr_t *addr, const gchar *module, const gchar *id,
- const gchar *function, const gchar *fmt, ...);
+ rspamd_inet_addr_t *addr, const char *module, const char *id,
+ const char *function, const char *fmt, ...);
bool rspamd_conditional_debug_fast(rspamd_logger_t *logger,
rspamd_inet_addr_t *addr,
- gint mod_id,
- const gchar *module, const gchar *id,
- const gchar *function, const gchar *fmt, ...);
+ int mod_id,
+ const char *module, const char *id,
+ const char *function, const char *fmt, ...);
bool rspamd_conditional_debug_fast_num_id(rspamd_logger_t *logger,
rspamd_inet_addr_t *addr,
- gint mod_id,
- const gchar *module, uint64_t id,
- const gchar *function, const gchar *fmt, ...);
+ int mod_id,
+ const char *module, uint64_t id,
+ const char *function, const char *fmt, ...);
gboolean rspamd_logger_need_log(rspamd_logger_t *rspamd_log,
GLogLevelFlags log_level,
- gint module_id);
+ int module_id);
/**
* Function with variable number of arguments support that uses static default logger
*/
-bool rspamd_default_log_function(gint level_flags,
- const gchar *module, const gchar *id,
- const gchar *function,
- const gchar *fmt,
+bool rspamd_default_log_function(int level_flags,
+ const char *module, const char *id,
+ const char *function,
+ const char *fmt,
...);
/**
* @param fmt
* @param args
*/
-bool rspamd_default_logv(gint level_flags,
- const gchar *module, const gchar *id,
- const gchar *function,
- const gchar *fmt,
+bool rspamd_default_logv(int level_flags,
+ const char *module, const char *id,
+ const char *function,
+ const char *fmt,
va_list args);
/**
/* Typical functions */
-extern guint rspamd_task_log_id;
+extern unsigned int rspamd_task_log_id;
#ifdef __cplusplus
#define RSPAMD_LOG_FUNC __func__
#else
static rspamd_logger_t *emergency_logger = NULL;
static struct rspamd_log_modules *log_modules = NULL;
-static const gchar lf_chr = '\n';
+static const char lf_chr = '\n';
-guint rspamd_task_log_id = (guint) -1;
+unsigned int rspamd_task_log_id = (unsigned int) -1;
RSPAMD_CONSTRUCTOR(rspamd_task_log_init)
{
rspamd_task_log_id = rspamd_logger_add_debug_module("task");
return emergency_logger;
}
-void rspamd_log_set_log_level(rspamd_logger_t *logger, gint level)
+void rspamd_log_set_log_level(rspamd_logger_t *logger, int level)
{
if (logger == NULL) {
logger = default_logger;
logger->log_level = level;
}
-gint rspamd_log_get_log_level(rspamd_logger_t *logger)
+int rspamd_log_get_log_level(rspamd_logger_t *logger)
{
if (logger == NULL) {
logger = default_logger;
return logger->log_level;
}
-void rspamd_log_set_log_flags(rspamd_logger_t *logger, gint flags)
+void rspamd_log_set_log_flags(rspamd_logger_t *logger, int flags)
{
g_assert(logger != NULL);
}
rspamd_logger_t *
-rspamd_log_open_emergency(rspamd_mempool_t *pool, gint flags)
+rspamd_log_open_emergency(rspamd_mempool_t *pool, int flags)
{
rspamd_logger_t *logger;
GError *err = NULL;
rspamd_logger_t *
rspamd_log_open_specific(rspamd_mempool_t *pool,
struct rspamd_config *cfg,
- const gchar *ptype,
+ const char *ptype,
uid_t uid, gid_t gid)
{
rspamd_logger_t *logger;
inline gboolean
rspamd_logger_need_log(rspamd_logger_t *rspamd_log, GLogLevelFlags log_level,
- gint module_id)
+ int module_id)
{
g_assert(rspamd_log != NULL);
return FALSE;
}
-static gchar *
-rspamd_log_encrypt_message(const gchar *begin, const gchar *end, gsize *enc_len,
+static char *
+rspamd_log_encrypt_message(const char *begin, const char *end, gsize *enc_len,
rspamd_logger_t *rspamd_log)
{
- guchar *out;
- gchar *b64;
- guchar *p, *nonce, *mac;
- const guchar *comp;
- guint len, inlen;
+ unsigned char *out;
+ char *b64;
+ unsigned char *p, *nonce, *mac;
+ const unsigned char *comp;
+ unsigned int len, inlen;
g_assert(end > begin);
/* base64 (pubkey | nonce | message) */
static void
rspamd_log_write_ringbuffer(rspamd_logger_t *rspamd_log,
- const gchar *module, const gchar *id,
- const gchar *data, glong len)
+ const char *module, const char *id,
+ const char *data, glong len)
{
uint32_t row_num;
struct rspamd_logger_error_log *elog;
#endif
if (row_num < elog->max_elts) {
- elt = (struct rspamd_logger_error_elt *) (((guchar *) elog->elts) +
+ elt = (struct rspamd_logger_error_elt *) (((unsigned char *) elog->elts) +
(sizeof(*elt) + elog->elt_len) * row_num);
g_atomic_int_set(&elt->completed, 0);
}
g_atomic_int_set(&elt->completed, 1);
}
-bool rspamd_common_logv(rspamd_logger_t *rspamd_log, gint level_flags,
- const gchar *module, const gchar *id, const gchar *function,
- const gchar *fmt, va_list args)
+bool rspamd_common_logv(rspamd_logger_t *rspamd_log, int level_flags,
+ const char *module, const char *id, const char *function,
+ const char *fmt, va_list args)
{
- gchar *end;
- gint level = level_flags & (RSPAMD_LOG_LEVEL_MASK & G_LOG_LEVEL_MASK), mod_id;
+ char *end;
+ int level = level_flags & (RSPAMD_LOG_LEVEL_MASK & G_LOG_LEVEL_MASK), mod_id;
bool ret = false;
- gchar logbuf[RSPAMD_LOGBUF_SIZE], *log_line;
+ char logbuf[RSPAMD_LOGBUF_SIZE], *log_line;
gsize nescaped;
if (G_UNLIKELY(rspamd_log == NULL)) {
/* Just fprintf message to stderr */
if (level >= G_LOG_LEVEL_INFO) {
end = rspamd_vsnprintf(logbuf, sizeof(logbuf), fmt, args);
- rspamd_fprintf(stderr, "%*s\n", (gint) (end - log_line),
+ rspamd_fprintf(stderr, "%*s\n", (int) (end - log_line),
log_line);
}
}
if (!(rspamd_log->flags & RSPAMD_LOG_FLAG_RSPAMADM)) {
if ((nescaped = rspamd_log_line_need_escape(logbuf, end - logbuf)) != 0) {
gsize unescaped_len = end - logbuf;
- gchar *logbuf_escaped = g_alloca(unescaped_len + nescaped * 4);
+ char *logbuf_escaped = g_alloca(unescaped_len + nescaped * 4);
log_line = logbuf_escaped;
end = rspamd_log_line_hex_escape(logbuf, unescaped_len,
}
if ((level_flags & RSPAMD_LOG_ENCRYPTED) && rspamd_log->pk) {
- gchar *encrypted;
+ char *encrypted;
gsize enc_len;
encrypted = rspamd_log_encrypt_message(log_line, end, &enc_len,
* This log functions select real logger and write message if level is less or equal to configured log level
*/
bool rspamd_common_log_function(rspamd_logger_t *rspamd_log,
- gint level_flags,
- const gchar *module, const gchar *id,
- const gchar *function,
- const gchar *fmt,
+ int level_flags,
+ const char *module, const char *id,
+ const char *function,
+ const char *fmt,
...)
{
va_list vp;
return ret;
}
-bool rspamd_default_logv(gint level_flags, const gchar *module, const gchar *id,
- const gchar *function,
- const gchar *fmt, va_list args)
+bool rspamd_default_logv(int level_flags, const char *module, const char *id,
+ const char *function,
+ const char *fmt, va_list args)
{
return rspamd_common_logv(NULL, level_flags, module, id, function, fmt, args);
}
-bool rspamd_default_log_function(gint level_flags,
- const gchar *module, const gchar *id,
- const gchar *function, const gchar *fmt, ...)
+bool rspamd_default_log_function(int level_flags,
+ const char *module, const char *id,
+ const char *function, const char *fmt, ...)
{
va_list vp;
* Write log line depending on ip
*/
bool rspamd_conditional_debug(rspamd_logger_t *rspamd_log,
- rspamd_inet_addr_t *addr, const gchar *module, const gchar *id,
- const gchar *function, const gchar *fmt, ...)
+ rspamd_inet_addr_t *addr, const char *module, const char *id,
+ const char *function, const char *fmt, ...)
{
- static gchar logbuf[LOGBUF_LEN];
+ static char logbuf[LOGBUF_LEN];
va_list vp;
- gchar *end;
- gint mod_id;
+ char *end;
+ int mod_id;
if (rspamd_log == NULL) {
rspamd_log = default_logger;
bool rspamd_conditional_debug_fast(rspamd_logger_t *rspamd_log,
rspamd_inet_addr_t *addr,
- gint mod_id, const gchar *module, const gchar *id,
- const gchar *function, const gchar *fmt, ...)
+ int mod_id, const char *module, const char *id,
+ const char *function, const char *fmt, ...)
{
- static gchar logbuf[LOGBUF_LEN];
+ static char logbuf[LOGBUF_LEN];
va_list vp;
- gchar *end;
+ char *end;
if (rspamd_log == NULL) {
rspamd_log = default_logger;
bool rspamd_conditional_debug_fast_num_id(rspamd_logger_t *rspamd_log,
rspamd_inet_addr_t *addr,
- gint mod_id, const gchar *module, uint64_t id,
- const gchar *function, const gchar *fmt, ...)
+ int mod_id, const char *module, uint64_t id,
+ const char *function, const char *fmt, ...)
{
- static gchar logbuf[LOGBUF_LEN], idbuf[64];
+ static char logbuf[LOGBUF_LEN], idbuf[64];
va_list vp;
- gchar *end;
+ char *end;
if (rspamd_log == NULL) {
rspamd_log = default_logger;
/**
* Wrapper for glib logger
*/
-void rspamd_glib_log_function(const gchar *log_domain,
+void rspamd_glib_log_function(const char *log_domain,
GLogLevelFlags log_level,
- const gchar *message,
+ const char *message,
gpointer arg)
{
rspamd_logger_t *rspamd_log = (rspamd_logger_t *) arg;
}
}
-void rspamd_glib_printerr_function(const gchar *message)
+void rspamd_glib_printerr_function(const char *message)
{
rspamd_common_log_function(NULL, G_LOG_LEVEL_CRITICAL, "glib",
NULL, G_STRFUNC,
return NULL;
}
-static gint
+static int
rspamd_log_errlog_cmp(const ucl_object_t **o1, const ucl_object_t **o2)
{
const ucl_object_t *ts1, *ts2;
ts2 = ucl_object_lookup(*o2, "ts");
if (ts1 && ts2) {
- gdouble t1 = ucl_object_todouble(ts1), t2 = ucl_object_todouble(ts2);
+ double t1 = ucl_object_todouble(ts1), t2 = ucl_object_todouble(ts2);
if (t1 > t2) {
return -1;
{
struct rspamd_logger_error_elt *cpy, *cur;
ucl_object_t *top = ucl_object_typed_new(UCL_ARRAY);
- guint i;
+ unsigned int i;
if (logger->errlog == NULL) {
return top;
memcpy(cpy, logger->errlog->elts, logger->errlog->max_elts * (sizeof(*cpy) + logger->errlog->elt_len));
for (i = 0; i < logger->errlog->max_elts; i++) {
- cur = (struct rspamd_logger_error_elt *) ((guchar *) cpy +
+ cur = (struct rspamd_logger_error_elt *) ((unsigned char *) cpy +
i * ((sizeof(*cpy) + logger->errlog->elt_len)));
if (cur->completed) {
ucl_object_t *obj = ucl_object_typed_new(UCL_OBJECT);
return top;
}
-static guint
+static unsigned int
rspamd_logger_allocate_mod_bit(void)
{
if (log_modules->bitset_allocated * NBBY > log_modules->bitset_len + 1) {
}
}
-gint rspamd_logger_add_debug_module(const gchar *mname)
+int rspamd_logger_add_debug_module(const char *mname)
{
struct rspamd_log_module *m;
{
GHashTableIter it;
gpointer k, v;
- guint id;
+ unsigned int id;
/* Clear all in bitset_allocated -> this are bytes not bits */
memset(log_modules->bitset, 0, log_modules->bitset_allocated);
g_hash_table_iter_init(&it, mods_enabled);
while (g_hash_table_iter_next(&it, &k, &v)) {
- rspamd_logger_add_debug_module((const gchar *) k);
+ rspamd_logger_add_debug_module((const char *) k);
}
g_hash_table_iter_init(&it, mods_enabled);
while (g_hash_table_iter_next(&it, &k, &v)) {
- id = rspamd_logger_add_debug_module((const gchar *) k);
+ id = rspamd_logger_add_debug_module((const char *) k);
if (isclr(log_modules->bitset, id)) {
- msg_info("enable debugging for module %s (%d)", (const gchar *) k,
+ msg_info("enable debugging for module %s (%d)", (const char *) k,
id);
setbit(log_modules->bitset, id);
}
}
-gchar *
-rspamd_log_line_hex_escape(const guchar *src, gsize srclen,
- gchar *dst, gsize dstlen)
+char *
+rspamd_log_line_hex_escape(const unsigned char *src, gsize srclen,
+ char *dst, gsize dstlen)
{
- static const gchar hexdigests[16] = "0123456789ABCDEF";
- gchar *d = dst;
+ static const char hexdigests[16] = "0123456789ABCDEF";
+ char *d = dst;
static uint32_t escape[] = {
0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
return d;
}
-gsize rspamd_log_line_need_escape(const guchar *src, gsize srclen)
+gsize rspamd_log_line_need_escape(const unsigned char *src, gsize srclen)
{
static uint32_t escape[] = {
0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
return n;
}
-const gchar *
-rspamd_get_log_severity_string(gint level_flags)
+const char *
+rspamd_get_log_severity_string(int level_flags)
{
unsigned int bitnum;
static const char *level_strs[G_LOG_LEVEL_USER_SHIFT] = {
}
static inline void
-log_time(gdouble now, rspamd_logger_t *rspamd_log, gchar *timebuf,
+log_time(double now, rspamd_logger_t *rspamd_log, char *timebuf,
size_t len)
{
time_t sec = (time_t) now;
r = strftime(timebuf, len, "%F %H:%M:%S", &tms);
if (rspamd_log->flags & RSPAMD_LOG_FLAG_USEC) {
- gchar usec_buf[16];
+ char usec_buf[16];
rspamd_snprintf(usec_buf, sizeof(usec_buf), "%.5f",
- now - (gdouble) sec);
+ now - (double) sec);
rspamd_snprintf(timebuf + r, len - r,
"%s", usec_buf + 1);
}
void rspamd_log_fill_iov(struct rspamd_logger_iov_ctx *iov_ctx,
double ts,
- const gchar *module,
- const gchar *id,
- const gchar *function,
- gint level_flags,
- const gchar *message,
+ const char *module,
+ const char *id,
+ const char *function,
+ int level_flags,
+ const char *message,
gsize mlen,
rspamd_logger_t *logger)
{
}
glong r;
- static gchar timebuf[64], modulebuf[64];
- static gchar tmpbuf[256];
+ static char timebuf[64], modulebuf[64];
+ static char tmpbuf[256];
if (!log_json && !log_systemd) {
log_time(ts, logger, timebuf, sizeof(timebuf));
if (G_UNLIKELY(log_json)) {
/* Perform JSON logging */
- guint slen = id ? strlen(id) : strlen("(NULL)");
+ unsigned int slen = id ? strlen(id) : strlen("(NULL)");
slen = MIN(RSPAMD_LOG_ID_LEN, slen);
r = rspamd_snprintf(tmpbuf, sizeof(tmpbuf), "{\"ts\": %f, "
"\"pid\": %P, "
m = modulebuf;
if (id != NULL) {
- guint slen = strlen(id);
+ unsigned int slen = strlen(id);
slen = MIN(RSPAMD_LOG_ID_LEN, slen);
mr = rspamd_snprintf(m, mremain, "<%*.s>; ", slen,
id);
#define CONSOLE_LOG_QUARK g_quark_from_static_string("console_logger")
-static const gchar lf_chr = '\n';
+static const char lf_chr = '\n';
struct rspamd_console_logger_priv {
- gint fd;
- gint crit_fd;
+ int fd;
+ int crit_fd;
};
/* Copy & paste :( */
static inline void
-log_time(gdouble now, rspamd_logger_t *rspamd_log, gchar *timebuf,
+log_time(double now, rspamd_logger_t *rspamd_log, char *timebuf,
size_t len)
{
time_t sec = (time_t) now;
r = strftime(timebuf, len, "%F %H:%M:%S", &tms);
if (rspamd_log->flags & RSPAMD_LOG_FLAG_USEC) {
- gchar usec_buf[16];
+ char usec_buf[16];
rspamd_snprintf(usec_buf, sizeof(usec_buf), "%.5f",
- now - (gdouble) sec);
+ now - (double) sec);
rspamd_snprintf(timebuf + r, len - r,
"%s", usec_buf + 1);
}
g_free(priv);
}
-bool rspamd_log_console_log(const gchar *module, const gchar *id,
- const gchar *function,
- gint level_flags,
- const gchar *message,
+bool rspamd_log_console_log(const char *module, const char *id,
+ const char *function,
+ int level_flags,
+ const char *message,
gsize mlen,
rspamd_logger_t *rspamd_log,
gpointer arg)
{
struct rspamd_console_logger_priv *priv = (struct rspamd_console_logger_priv *) arg;
- gint fd, r;
+ int fd, r;
double now;
if (level_flags & G_LOG_LEVEL_CRITICAL) {
#define FILE_LOG_QUARK g_quark_from_static_string("file_logger")
struct rspamd_file_logger_priv {
- gint fd;
+ int fd;
struct {
uint32_t size;
uint32_t used;
u_char *buf;
} io_buf;
gboolean throttling;
- gchar *log_file;
+ char *log_file;
gboolean is_buffered;
gboolean log_severity;
time_t throttling_time;
uint32_t repeats;
uint64_t last_line_cksum;
- gchar *saved_message;
+ char *saved_message;
gsize saved_mlen;
- gchar *saved_function;
- gchar *saved_module;
- gchar *saved_id;
- guint saved_loglevel;
+ char *saved_function;
+ char *saved_module;
+ char *saved_id;
+ unsigned int saved_loglevel;
};
/**
* Calculate checksum for log line (used for repeating logic)
*/
static inline uint64_t
-rspamd_log_calculate_cksum(const gchar *message, size_t mlen)
+rspamd_log_calculate_cksum(const char *message, size_t mlen)
{
return rspamd_cryptobox_fast_hash(message, mlen, rspamd_hash_seed());
}
void *data,
gsize count,
gboolean is_iov,
- gint level_flags)
+ int level_flags)
{
struct iovec *iov;
- const gchar *line;
+ const char *line;
glong r;
- gint fd;
+ int fd;
gboolean locked = FALSE;
iov = (struct iovec *) data;
if (is_iov) {
tlen = 0;
- for (guint i = 0; i < count; i++) {
+ for (unsigned int i = 0; i < count; i++) {
tlen += iov[i].iov_len;
}
}
r = writev(fd, iov, count);
}
else {
- line = (const gchar *) data;
+ line = (const char *) data;
r = write(fd, line, count);
}
static void
fill_buffer(rspamd_logger_t *rspamd_log,
struct rspamd_file_logger_priv *priv,
- const struct iovec *iov, gint iovcnt)
+ const struct iovec *iov, int iovcnt)
{
- gint i;
+ int i;
for (i = 0; i < iovcnt; i++) {
memcpy(priv->io_buf.buf + priv->io_buf.used,
file_log_helper(rspamd_logger_t *rspamd_log,
struct rspamd_file_logger_priv *priv,
const struct iovec *iov,
- guint iovcnt,
- gint level_flags)
+ unsigned int iovcnt,
+ int level_flags)
{
size_t len = 0;
- guint i;
+ unsigned int i;
if (!priv->is_buffered) {
/* Write string directly */
rspamd_log_reset_repeated(rspamd_logger_t *rspamd_log,
struct rspamd_file_logger_priv *priv)
{
- gchar tmpbuf[256];
+ char tmpbuf[256];
gssize r;
if (priv->repeats > REPEATS_MIN) {
}
}
-static gint
+static int
rspamd_try_open_log_fd(rspamd_logger_t *rspamd_log,
struct rspamd_file_logger_priv *priv,
uid_t uid, gid_t gid,
GError **err)
{
- gint fd;
+ int fd;
fd = open(priv->log_file,
O_CREAT | O_WRONLY | O_APPEND,
g_free(priv);
}
-bool rspamd_log_file_log(const gchar *module, const gchar *id,
- const gchar *function,
- gint level_flags,
- const gchar *message,
+bool rspamd_log_file_log(const char *module, const char *id,
+ const char *function,
+ int level_flags,
+ const char *message,
gsize mlen,
rspamd_logger_t *rspamd_log,
gpointer arg)
{
struct rspamd_file_logger_priv *priv = (struct rspamd_file_logger_priv *) arg;
- gdouble now;
+ double now;
uint64_t cksum;
gboolean got_time = FALSE;
#define LOGBUF_LEN 8192
struct rspamd_log_module {
- gchar *mname;
- guint id;
+ char *mname;
+ unsigned int id;
};
struct rspamd_log_modules {
- guchar *bitset;
- guint bitset_len; /* Number of BITS used in bitset */
- guint bitset_allocated; /* Size of bitset allocated in BYTES */
+ unsigned char *bitset;
+ unsigned int bitset_len; /* Number of BITS used in bitset */
+ unsigned int bitset_allocated; /* Size of bitset allocated in BYTES */
GHashTable *modules;
};
struct rspamd_logger_error_elt {
- gint completed;
+ int completed;
GQuark ptype;
pid_t pid;
- gdouble ts;
- gchar id[RSPAMD_LOG_ID_LEN + 1];
- gchar module[9];
- gchar message[];
+ double ts;
+ char id[RSPAMD_LOG_ID_LEN + 1];
+ char module[9];
+ char message[];
};
struct rspamd_logger_error_log {
uint32_t max_elts;
uint32_t elt_len;
/* Avoid false cache sharing */
- guchar __padding[64 - sizeof(gpointer) * 2 - sizeof(uint64_t)];
- guint cur_row;
+ unsigned char __padding[64 - sizeof(gpointer) * 2 - sizeof(uint64_t)];
+ unsigned int cur_row;
};
/**
*/
struct rspamd_logger_s {
struct rspamd_logger_funcs ops;
- gint log_level;
+ int log_level;
struct rspamd_logger_error_log *errlog;
struct rspamd_cryptobox_pubkey *pk;
struct rspamd_cryptobox_keypair *keypair;
- guint flags;
+ unsigned int flags;
gboolean closed;
gboolean enabled;
gboolean is_debug;
gboolean no_lock;
pid_t pid;
- const gchar *process_type;
+ const char *process_type;
struct rspamd_radix_map_helper *debug_ip;
rspamd_mempool_mutex_t *mtx;
rspamd_mempool_t *pool;
void *rspamd_log_file_reload(rspamd_logger_t *logger, struct rspamd_config *cfg,
gpointer arg, uid_t uid, gid_t gid, GError **err);
void rspamd_log_file_dtor(rspamd_logger_t *logger, gpointer arg);
-bool rspamd_log_file_log(const gchar *module, const gchar *id,
- const gchar *function,
- gint level_flags,
- const gchar *message,
+bool rspamd_log_file_log(const char *module, const char *id,
+ const char *function,
+ int level_flags,
+ const char *message,
gsize mlen,
rspamd_logger_t *rspamd_log,
gpointer arg);
*/
void rspamd_log_fill_iov(struct rspamd_logger_iov_ctx *iov_ctx,
double ts,
- const gchar *module, const gchar *id,
- const gchar *function,
- gint level_flags,
- const gchar *message,
+ const char *module, const char *id,
+ const char *function,
+ int level_flags,
+ const char *message,
gsize mlen,
rspamd_logger_t *rspamd_log);
* @param dstlen
* @return end of the escaped buffer
*/
-gchar *rspamd_log_line_hex_escape(const guchar *src, gsize srclen,
- gchar *dst, gsize dstlen);
+char *rspamd_log_line_hex_escape(const unsigned char *src, gsize srclen,
+ char *dst, gsize dstlen);
/**
* Returns number of characters to be escaped, e.g. a caller can allocate a new buffer
* the desired number of characters
* @param srclen
* @return number of characters to be escaped
*/
-gsize rspamd_log_line_need_escape(const guchar *src, gsize srclen);
+gsize rspamd_log_line_need_escape(const unsigned char *src, gsize srclen);
static const struct rspamd_logger_funcs file_log_funcs = {
.init = rspamd_log_file_init,
void *rspamd_log_syslog_reload(rspamd_logger_t *logger, struct rspamd_config *cfg,
gpointer arg, uid_t uid, gid_t gid, GError **err);
void rspamd_log_syslog_dtor(rspamd_logger_t *logger, gpointer arg);
-bool rspamd_log_syslog_log(const gchar *module, const gchar *id,
- const gchar *function,
- gint level_flags,
- const gchar *message,
+bool rspamd_log_syslog_log(const char *module, const char *id,
+ const char *function,
+ int level_flags,
+ const char *message,
gsize mlen,
rspamd_logger_t *rspamd_log,
gpointer arg);
void *rspamd_log_console_reload(rspamd_logger_t *logger, struct rspamd_config *cfg,
gpointer arg, uid_t uid, gid_t gid, GError **err);
void rspamd_log_console_dtor(rspamd_logger_t *logger, gpointer arg);
-bool rspamd_log_console_log(const gchar *module, const gchar *id,
- const gchar *function,
- gint level_flags,
- const gchar *message,
+bool rspamd_log_console_log(const char *module, const char *id,
+ const char *function,
+ int level_flags,
+ const char *message,
gsize mlen,
rspamd_logger_t *rspamd_log,
gpointer arg);
#define SYSLOG_LOG_QUARK g_quark_from_static_string("syslog_logger")
struct rspamd_syslog_logger_priv {
- gint log_facility;
+ int log_facility;
};
#ifdef HAVE_SYSLOG_H
closelog();
g_free(priv);
}
-bool rspamd_log_syslog_log(const gchar *module, const gchar *id,
- const gchar *function,
- gint level_flags,
- const gchar *message,
+bool rspamd_log_syslog_log(const char *module, const char *id,
+ const char *function,
+ int level_flags,
+ const char *message,
gsize mlen,
rspamd_logger_t *rspamd_log,
gpointer arg)
{
static const struct {
GLogLevelFlags glib_level;
- gint syslog_level;
+ int syslog_level;
} levels_match[] = {
{G_LOG_LEVEL_DEBUG, LOG_DEBUG},
{G_LOG_LEVEL_INFO, LOG_INFO},
{G_LOG_LEVEL_WARNING, LOG_WARNING},
{G_LOG_LEVEL_CRITICAL, LOG_ERR}};
unsigned i;
- gint syslog_level;
+ int syslog_level;
if (!(level_flags & RSPAMD_LOG_FORCED) && !rspamd_log->enabled) {
return false;
idbuf,
module != NULL ? module : "",
function != NULL ? function : "",
- (gint) mlen, message);
+ (int) mlen, message);
}
else {
/* Escaped version */
idbuf,
module != NULL ? module : "",
function != NULL ? function : "",
- (gint) mlen, message);
+ (int) mlen, message);
}
return true;
return NULL;
}
-bool rspamd_log_syslog_log(const gchar *module, const gchar *id,
- const gchar *function,
- gint level_flags,
- const gchar *message,
+bool rspamd_log_syslog_log(const char *module, const char *id,
+ const char *function,
+ int level_flags,
+ const char *message,
gsize mlen,
rspamd_logger_t *rspamd_log,
gpointer arg)
static void rspamd_map_schedule_periodic(struct rspamd_map *map, int how);
static gboolean read_map_file_chunks(struct rspamd_map *map,
struct map_cb_data *cbdata,
- const gchar *fname,
+ const char *fname,
gsize len,
goffset off);
static gboolean rspamd_map_save_http_cached_file(struct rspamd_map *map,
struct rspamd_map_backend *bk,
struct http_map_data *htdata,
- const guchar *data,
+ const unsigned char *data,
gsize len);
static gboolean rspamd_map_update_http_cached_file(struct rspamd_map *map,
struct rspamd_map_backend *bk,
struct http_map_data *htdata);
-guint rspamd_map_log_id = (guint) -1;
+unsigned int rspamd_map_log_id = (unsigned int) -1;
RSPAMD_CONSTRUCTOR(rspamd_map_log_init)
{
rspamd_map_log_id = rspamd_logger_add_debug_module("map");
static void
write_http_request(struct http_callback_data *cbd)
{
- gchar datebuf[128];
+ char datebuf[128];
struct rspamd_http_message *msg;
msg = rspamd_http_new_message(HTTP_REQUEST);
if (cbd->addrs) {
rspamd_inet_addr_t *addr;
- guint i;
+ unsigned int i;
PTR_ARRAY_FOREACH(cbd->addrs, i, addr)
{
struct rspamd_http_map_cached_cbdata *cache_cbd;
const rspamd_ftok_t *expires_hdr, *etag_hdr;
char next_check_date[128];
- guchar *in = NULL;
+ unsigned char *in = NULL;
gsize dlen = 0;
map = cbd->map;
ZSTD_DStream *zstream;
ZSTD_inBuffer zin;
ZSTD_outBuffer zout;
- guchar *out;
+ unsigned char *out;
gsize outlen, r;
zstream = ZSTD_createDStream();
static gboolean
read_map_file_chunks(struct rspamd_map *map, struct map_cb_data *cbdata,
- const gchar *fname, gsize len, goffset off)
+ const char *fname, gsize len, goffset off)
{
- gint fd;
+ int fd;
gssize r, avail;
gsize buflen = 1024 * 1024;
- gchar *pos, *bytes;
+ char *pos, *bytes;
fd = rspamd_file_xopen(fname, O_RDONLY, 0, TRUE);
if (lseek(fd, off, SEEK_SET) == -1) {
msg_err_map("can't seek in map to pos %d for buffered reading %s: %s",
- (gint) off, fname, strerror(errno));
+ (int) off, fname, strerror(errno));
close(fd);
return FALSE;
pos = bytes;
while ((r = read(fd, pos, avail)) > 0) {
- gchar *end = bytes + (pos - bytes) + r;
+ char *end = bytes + (pos - bytes) + r;
msg_debug_map("%s: read map chunk, %z bytes", fname,
r);
pos = map->read_callback(bytes, end - bytes, cbdata, r == len);
if (pos && pos > bytes && pos < end) {
- guint remain = end - pos;
+ unsigned int remain = end - pos;
memmove(bytes, pos, remain);
pos = bytes + remain;
}
static gboolean
-rspamd_map_check_sig_pk_mem(const guchar *sig,
+rspamd_map_check_sig_pk_mem(const unsigned char *sig,
gsize siglen,
struct rspamd_map *map,
- const guchar *input,
+ const unsigned char *input,
gsize inlen,
struct rspamd_cryptobox_pubkey *pk)
{
rspamd_map_check_file_sig(const char *fname,
struct rspamd_map *map,
struct rspamd_map_backend *bk,
- const guchar *input,
+ const unsigned char *input,
gsize inlen)
{
- guchar *data;
+ unsigned char *data;
struct rspamd_cryptobox_pubkey *pk = NULL;
GString *b32_key;
gboolean ret = TRUE;
gsize len = 0;
- gchar fpath[PATH_MAX];
+ char fpath[PATH_MAX];
if (bk->trusted_pubkey == NULL) {
/* Try to load and check pubkey */
read_map_file(struct rspamd_map *map, struct file_map_data *data,
struct rspamd_map_backend *bk, struct map_periodic_cbdata *periodic)
{
- gchar *bytes;
+ char *bytes;
gsize len;
struct stat st;
ZSTD_DStream *zstream;
ZSTD_inBuffer zin;
ZSTD_outBuffer zout;
- guchar *out;
+ unsigned char *out;
gsize outlen, r;
zstream = ZSTD_createDStream();
read_map_static(struct rspamd_map *map, struct static_map_data *data,
struct rspamd_map_backend *bk, struct map_periodic_cbdata *periodic)
{
- guchar *bytes;
+ unsigned char *bytes;
gsize len;
if (map->read_callback == NULL || map->fin_callback == NULL) {
ZSTD_DStream *zstream;
ZSTD_inBuffer zin;
ZSTD_outBuffer zout;
- guchar *out;
+ unsigned char *out;
gsize outlen, r;
zstream = ZSTD_createDStream();
static void
rspamd_map_schedule_periodic(struct rspamd_map *map, int how)
{
- const gdouble error_mult = 20.0, lock_mult = 0.1;
- static const gdouble min_timer_interval = 2.0;
- const gchar *reason = "unknown reason";
- gdouble jittered_sec;
- gdouble timeout;
+ const double error_mult = 20.0, lock_mult = 0.1;
+ static const double min_timer_interval = 2.0;
+ const char *reason = "unknown reason";
+ double jittered_sec;
+ double timeout;
struct map_periodic_cbdata *cbd;
if (map->scheduled_check || (map->wrk &&
if (timeout > 0 && timeout < map->poll_timeout) {
/* Early check case, jitter */
- gdouble poll_timeout = map->poll_timeout;
+ double poll_timeout = map->poll_timeout;
if (how & RSPAMD_MAP_SCHEDULE_ERROR) {
poll_timeout = map->poll_timeout * error_mult;
cbd, jittered_sec, map->name, reason);
}
-static gint
+static int
rspamd_map_af_to_weight(const rspamd_inet_addr_t *addr)
{
int ret;
return ret;
}
-static gint
+static int
rspamd_map_dns_address_sort_func(gconstpointer a, gconstpointer b)
{
const rspamd_inet_addr_t *ip1 = *(const rspamd_inet_addr_t **) a,
*ip2 = *(const rspamd_inet_addr_t **) b;
- gint w1, w2;
+ int w1, w2;
w1 = rspamd_map_af_to_weight(ip1);
w2 = rspamd_map_af_to_weight(ip2);
struct http_callback_data *cbd = arg;
struct rdns_reply_entry *cur_rep;
struct rspamd_map *map;
- guint flags = RSPAMD_HTTP_CLIENT_SIMPLE | RSPAMD_HTTP_CLIENT_SHARED;
+ unsigned int flags = RSPAMD_HTTP_CLIENT_SIMPLE | RSPAMD_HTTP_CLIENT_SHARED;
map = cbd->map;
if (cbd->stage == http_map_http_conn && cbd->addrs->len > 0) {
rspamd_ptr_array_shuffle(cbd->addrs);
- gint idx = 0;
+ int idx = 0;
/*
* For the existing addr we can just select any address as we have
* data available
static gboolean
rspamd_map_read_cached(struct rspamd_map *map, struct rspamd_map_backend *bk,
- struct map_periodic_cbdata *periodic, const gchar *host)
+ struct map_periodic_cbdata *periodic, const char *host)
{
gsize mmap_len, len;
gpointer in;
ZSTD_DStream *zstream;
ZSTD_inBuffer zin;
ZSTD_outBuffer zout;
- guchar *out;
+ unsigned char *out;
gsize outlen, r;
zstream = ZSTD_createDStream();
rspamd_map_has_http_cached_file(struct rspamd_map *map,
struct rspamd_map_backend *bk)
{
- gchar path[PATH_MAX];
- guchar digest[rspamd_cryptobox_HASHBYTES];
+ char path[PATH_MAX];
+ unsigned char digest[rspamd_cryptobox_HASHBYTES];
struct rspamd_config *cfg = map->cfg;
struct stat st;
rspamd_map_save_http_cached_file(struct rspamd_map *map,
struct rspamd_map_backend *bk,
struct http_map_data *htdata,
- const guchar *data,
+ const unsigned char *data,
gsize len)
{
- gchar path[PATH_MAX];
- guchar digest[rspamd_cryptobox_HASHBYTES];
+ char path[PATH_MAX];
+ unsigned char digest[rspamd_cryptobox_HASHBYTES];
struct rspamd_config *cfg = map->cfg;
- gint fd;
+ int fd;
struct rspamd_http_file_data header;
if (cfg->maps_cache_dir == NULL || cfg->maps_cache_dir[0] == '\0') {
struct rspamd_map_backend *bk,
struct http_map_data *htdata)
{
- gchar path[PATH_MAX];
- guchar digest[rspamd_cryptobox_HASHBYTES];
+ char path[PATH_MAX];
+ unsigned char digest[rspamd_cryptobox_HASHBYTES];
struct rspamd_config *cfg = map->cfg;
- gint fd;
+ int fd;
struct rspamd_http_file_data header;
if (!rspamd_map_has_http_cached_file(map, bk)) {
struct http_map_data *htdata,
struct map_cb_data *cbdata)
{
- gchar path[PATH_MAX];
- guchar digest[rspamd_cryptobox_HASHBYTES];
+ char path[PATH_MAX];
+ unsigned char digest[rspamd_cryptobox_HASHBYTES];
struct rspamd_config *cfg = map->cfg;
- gint fd;
+ int fd;
struct stat st;
struct rspamd_http_file_data header;
}
struct tm tm;
- gchar ncheck_buf[32], lm_buf[32];
+ char ncheck_buf[32], lm_buf[32];
rspamd_localtime(map->next_check, &tm);
strftime(ncheck_buf, sizeof(ncheck_buf) - 1, "%Y-%m-%d %H:%M:%S", &tm);
{
struct http_map_data *data;
struct http_callback_data *cbd;
- guint flags = RSPAMD_HTTP_CLIENT_SIMPLE | RSPAMD_HTTP_CLIENT_SHARED;
+ unsigned int flags = RSPAMD_HTTP_CLIENT_SIMPLE | RSPAMD_HTTP_CLIENT_SHARED;
data = bk->data.hd;
}
else if (map->r->r) {
/* Send both A and AAAA requests */
- guint nreq = 0;
+ unsigned int nreq = 0;
if (rdns_make_request_full(map->r->r, rspamd_map_dns_callback, cbd,
map->cfg->dns_timeout, map->cfg->dns_retransmits, 1,
/* Fire need modify flag */
struct rspamd_map_backend *bk;
- guint i;
+ unsigned int i;
PTR_ARRAY_FOREACH(map->backends, i, bk)
{
GList *cur = cfg->maps;
struct rspamd_map *map;
struct rspamd_map_backend *bk;
- guint i;
+ unsigned int i;
g_assert(how > RSPAMD_MAP_WATCH_MIN && how < RSPAMD_MAP_WATCH_MAX);
GList *cur = cfg->maps;
struct rspamd_map *map;
struct rspamd_map_backend *bk;
- guint i;
+ unsigned int i;
gboolean map_ok;
/* First of all do synced read of data */
GList *cur;
struct rspamd_map_backend *bk;
struct map_cb_data cbdata;
- guint i;
+ unsigned int i;
for (cur = cfg->maps; cur != NULL; cur = g_list_next(cur)) {
map = cur->data;
cfg->maps = NULL;
}
-static const gchar *
+static const char *
rspamd_map_check_proto(struct rspamd_config *cfg,
- const gchar *map_line, struct rspamd_map_backend *bk)
+ const char *map_line, struct rspamd_map_backend *bk)
{
- const gchar *pos = map_line, *end, *end_key;
+ const char *pos = map_line, *end, *end_key;
g_assert(bk != NULL);
g_assert(pos != NULL);
}
gboolean
-rspamd_map_is_map(const gchar *map_line)
+rspamd_map_is_map(const char *map_line)
{
gboolean ret = FALSE;
}
static struct rspamd_map_backend *
-rspamd_map_parse_backend(struct rspamd_config *cfg, const gchar *map_line)
+rspamd_map_parse_backend(struct rspamd_config *cfg, const char *map_line)
{
struct rspamd_map_backend *bk;
struct file_map_data *fdata = NULL;
struct http_map_data *hdata = NULL;
struct static_map_data *sdata = NULL;
struct http_parser_url up;
- const gchar *end, *p;
+ const char *end, *p;
rspamd_ftok_t tok;
bk = g_malloc0(sizeof(*bk));
if (up.field_set & (1u << UF_USERINFO)) {
/* Create authorisation header for basic auth */
- guint len = sizeof("Basic ") +
- up.field_data[UF_USERINFO].len * 8 / 5 + 4;
+ unsigned int len = sizeof("Basic ") +
+ up.field_data[UF_USERINFO].len * 8 / 5 + 4;
hdata->userinfo = g_malloc(len);
rspamd_snprintf(hdata->userinfo, len, "Basic %*Bs",
(int) up.field_data[UF_USERINFO].len,
ucl_object_type(user_obj) == UCL_STRING &&
ucl_object_type(password_obj) == UCL_STRING) {
- gchar *tmpbuf;
+ char *tmpbuf;
unsigned tlen;
/* User + password + ':' */
rspamd_map_calculate_hash(struct rspamd_map *map)
{
struct rspamd_map_backend *bk;
- guint i;
+ unsigned int i;
rspamd_cryptobox_hash_state_t st;
- gchar *cksum_encoded, cksum[rspamd_cryptobox_HASHBYTES];
+ char *cksum_encoded, cksum[rspamd_cryptobox_HASHBYTES];
rspamd_cryptobox_hash_init(&st, NULL, 0);
GString *target)
{
gsize sz;
- const gchar *dline;
+ const char *dline;
if (ucl_object_type(elt) != UCL_STRING) {
msg_err_config("map has static backend but `data` is "
struct rspamd_map *
rspamd_map_add(struct rspamd_config *cfg,
- const gchar *map_line,
- const gchar *description,
+ const char *map_line,
+ const char *description,
map_cb_t read_callback,
map_fin_cb_t fin_callback,
map_dtor_t dtor,
map->cfg = cfg;
map->id = rspamd_random_uint64_fast();
map->locked =
- rspamd_mempool_alloc0_shared(cfg->cfg_pool, sizeof(gint));
+ rspamd_mempool_alloc0_shared(cfg->cfg_pool, sizeof(int));
map->backends = g_ptr_array_sized_new(1);
map->wrk = worker;
rspamd_mempool_add_destructor(cfg->cfg_pool, rspamd_ptr_array_free_hard,
struct rspamd_map *
rspamd_map_add_fake(struct rspamd_config *cfg,
- const gchar *description,
- const gchar *name)
+ const char *description,
+ const char *name)
{
struct rspamd_map *map;
struct rspamd_map *
rspamd_map_add_from_ucl(struct rspamd_config *cfg,
const ucl_object_t *obj,
- const gchar *description,
+ const char *description,
map_cb_t read_callback,
map_fin_cb_t fin_callback,
map_dtor_t dtor,
void **user_data,
struct rspamd_worker *worker,
- gint flags)
+ int flags)
{
ucl_object_iter_t it = NULL;
const ucl_object_t *cur, *elt;
struct rspamd_map *map;
struct rspamd_map_backend *bk;
- guint i;
+ unsigned int i;
g_assert(obj != NULL);
map->cfg = cfg;
map->id = rspamd_random_uint64_fast();
map->locked =
- rspamd_mempool_alloc0_shared(cfg->cfg_pool, sizeof(gint));
+ rspamd_mempool_alloc0_shared(cfg->cfg_pool, sizeof(int));
map->backends = g_ptr_array_new();
map->wrk = worker;
map->no_file_read = (flags & RSPAMD_MAP_FILE_NO_READ);
/**
* Callback types
*/
-typedef gchar *(*map_cb_t)(gchar *chunk, gint len,
- struct map_cb_data *data, gboolean final);
+typedef char *(*map_cb_t)(char *chunk, int len,
+ struct map_cb_data *data, gboolean final);
typedef void (*map_fin_cb_t)(struct map_cb_data *data, void **target);
*/
struct map_cb_data {
struct rspamd_map *map;
- gint state;
+ int state;
bool errored;
void *prev_data;
void *cur_data;
* @param map_line
* @return
*/
-gboolean rspamd_map_is_map(const gchar *map_line);
+gboolean rspamd_map_is_map(const char *map_line);
enum rspamd_map_flags {
RSPAMD_MAP_DEFAULT = 0,
* Add map from line
*/
struct rspamd_map *rspamd_map_add(struct rspamd_config *cfg,
- const gchar *map_line,
- const gchar *description,
+ const char *map_line,
+ const char *description,
map_cb_t read_callback,
map_fin_cb_t fin_callback,
map_dtor_t dtor,
*/
struct rspamd_map *rspamd_map_add_from_ucl(struct rspamd_config *cfg,
const ucl_object_t *obj,
- const gchar *description,
+ const char *description,
map_cb_t read_callback,
map_fin_cb_t fin_callback,
map_dtor_t dtor,
* @return
*/
struct rspamd_map *rspamd_map_add_fake(struct rspamd_config *cfg,
- const gchar *description,
- const gchar *name);
+ const char *description,
+ const char *name);
enum rspamd_map_watch_type {
static const uint64_t map_hash_seed = 0xdeadbabeULL;
-static const gchar *const hash_fill = "1";
+static const char *const hash_fill = "1";
struct rspamd_map_helper_value {
gsize hits;
gconstpointer key;
- gchar value[]; /* Null terminated */
+ char value[]; /* Null terminated */
};
#define rspamd_map_ftok_hash(t) (rspamd_icase_hash((t).begin, (t).len, rspamd_hash_seed()))
struct rspamd_regexp_map_helper {
rspamd_cryptobox_hash_state_t hst;
- guchar re_digest[rspamd_cryptobox_HASHBYTES];
+ unsigned char re_digest[rspamd_cryptobox_HASHBYTES];
rspamd_mempool_t *pool;
struct rspamd_map *map;
GPtrArray *regexps;
#ifdef WITH_HYPERSCAN
rspamd_hyperscan_t *hs_db;
hs_scratch_t *hs_scratch;
- gchar **patterns;
- gint *flags;
- gint *ids;
+ char **patterns;
+ int *flags;
+ int *ids;
#endif
};
stripped_value = g_strstrip(value); \
} while (0)
-gchar *
+char *
rspamd_parse_kv_list(
- gchar *chunk,
- gint len,
+ char *chunk,
+ int len,
struct map_cb_data *data,
rspamd_map_insert_func func,
- const gchar *default_value,
+ const char *default_value,
gboolean final)
{
enum {
map_read_eol,
};
- gchar *c, *p, *key = NULL, *value = NULL, *stripped_key, *stripped_value, *end;
+ char *c, *p, *key = NULL, *value = NULL, *stripped_key, *stripped_value, *end;
struct rspamd_map *map = data->map;
- guint line_number = 0;
+ unsigned int line_number = 0;
p = chunk;
c = p;
khiter_t k;
gconstpointer nk;
rspamd_ftok_t tok;
- gint res;
+ int res;
struct rspamd_map *map;
map = r->map;
khiter_t k;
gconstpointer nk;
rspamd_ftok_t tok;
- gint res;
+ int res;
struct rspamd_map *map;
map = r->map;
khiter_t k;
gconstpointer nk;
gsize vlen;
- gint r;
+ int r;
rspamd_ftok_t tok;
struct rspamd_map *map;
struct rspamd_regexp_map_helper *re_map = st;
struct rspamd_map *map;
rspamd_regexp_t *re;
- gchar *escaped;
+ char *escaped;
GError *err = NULL;
- gint pcre_flags;
+ int pcre_flags;
gsize escaped_len;
struct rspamd_map_helper_value *val;
khiter_t k;
rspamd_ftok_t tok;
gconstpointer nk;
gsize vlen;
- gint r;
+ int r;
map = re_map->map;
{
struct rspamd_radix_map_helper *r;
rspamd_mempool_t *pool;
- const gchar *name = "unnamed";
+ const char *name = "unnamed";
if (map) {
pool = rspamd_mempool_new(rspamd_mempool_suggest_size(),
void rspamd_map_helper_destroy_regexp(struct rspamd_regexp_map_helper *re_map)
{
rspamd_regexp_t *re;
- guint i;
+ unsigned int i;
if (!re_map || !re_map->regexps) {
return;
rspamd_mempool_delete(pool);
}
-gchar *
+char *
rspamd_kv_list_read(
- gchar *chunk,
- gint len,
+ char *chunk,
+ int len,
struct map_cb_data *data,
gboolean final)
{
}
}
-gchar *
+char *
rspamd_radix_read(
- gchar *chunk,
- gint len,
+ char *chunk,
+ int len,
struct map_cb_data *data,
gboolean final)
{
static gboolean
rspamd_try_load_re_map_cache(struct rspamd_regexp_map_helper *re_map)
{
- gchar fp[PATH_MAX];
+ char fp[PATH_MAX];
struct rspamd_map *map;
map = re_map->map;
rspamd_snprintf(fp, sizeof(fp), "%s/%*xs.hsmc",
map->cfg->hs_cache_dir,
- (gint) rspamd_cryptobox_HASHBYTES / 2, re_map->re_digest);
+ (int) rspamd_cryptobox_HASHBYTES / 2, re_map->re_digest);
re_map->hs_db = rspamd_hyperscan_maybe_load(fp, 0);
static gboolean
rspamd_try_save_re_map_cache(struct rspamd_regexp_map_helper *re_map)
{
- gchar fp[PATH_MAX], np[PATH_MAX];
+ char fp[PATH_MAX], np[PATH_MAX];
gsize len;
- gint fd;
+ int fd;
char *bytes = NULL;
struct rspamd_map *map;
rspamd_snprintf(np, sizeof(np), "%s/%*xs.hsmc",
re_map->map->cfg->hs_cache_dir,
- (gint) rspamd_cryptobox_HASHBYTES / 2, re_map->re_digest);
+ (int) rspamd_cryptobox_HASHBYTES / 2, re_map->re_digest);
if (rename(fp, np) == -1) {
msg_warn_map("cannot rename hyperscan cache from %s to %s: %s",
rspamd_re_map_finalize(struct rspamd_regexp_map_helper *re_map)
{
#ifdef WITH_HYPERSCAN
- guint i;
+ unsigned int i;
hs_platform_info_t plt;
hs_compile_error_t *err;
struct rspamd_map *map;
rspamd_regexp_t *re;
- gint pcre_flags;
+ int pcre_flags;
map = re_map->map;
return;
}
- re_map->patterns = g_new(gchar *, re_map->regexps->len);
- re_map->flags = g_new(gint, re_map->regexps->len);
- re_map->ids = g_new(gint, re_map->regexps->len);
+ re_map->patterns = g_new(char *, re_map->regexps->len);
+ re_map->flags = g_new(int, re_map->regexps->len);
+ re_map->ids = g_new(int, re_map->regexps->len);
for (i = 0; i < re_map->regexps->len; i++) {
- const gchar *pat;
- gchar *escaped;
- gint pat_flags;
+ const char *pat;
+ char *escaped;
+ int pat_flags;
re = g_ptr_array_index(re_map->regexps, i);
pcre_flags = rspamd_regexp_get_pcre_flags(re);
if (re_map->regexps->len > 0 && re_map->patterns) {
if (!rspamd_try_load_re_map_cache(re_map)) {
- gdouble ts1 = rspamd_get_ticks(FALSE);
+ double ts1 = rspamd_get_ticks(FALSE);
hs_database_t *hs_db = NULL;
- if (hs_compile_multi((const gchar **) re_map->patterns,
+ if (hs_compile_multi((const char **) re_map->patterns,
re_map->flags,
re_map->ids,
re_map->regexps->len,
char fpath[PATH_MAX];
rspamd_snprintf(fpath, sizeof(fpath), "%s/%*xs.hsmc",
re_map->map->cfg->hs_cache_dir,
- (gint) rspamd_cryptobox_HASHBYTES / 2, re_map->re_digest);
+ (int) rspamd_cryptobox_HASHBYTES / 2, re_map->re_digest);
re_map->hs_db = rspamd_hyperscan_from_raw_db(hs_db, fpath);
}
else {
#endif
}
-gchar *
+char *
rspamd_regexp_list_read_single(
- gchar *chunk,
- gint len,
+ char *chunk,
+ int len,
struct map_cb_data *data,
gboolean final)
{
final);
}
-gchar *
+char *
rspamd_glob_list_read_single(
- gchar *chunk,
- gint len,
+ char *chunk,
+ int len,
struct map_cb_data *data,
gboolean final)
{
final);
}
-gchar *
+char *
rspamd_regexp_list_read_multiple(
- gchar *chunk,
- gint len,
+ char *chunk,
+ int len,
struct map_cb_data *data,
gboolean final)
{
final);
}
-gchar *
+char *
rspamd_glob_list_read_multiple(
- gchar *chunk,
- gint len,
+ char *chunk,
+ int len,
struct map_cb_data *data,
gboolean final)
{
unsigned long long to,
unsigned int flags, void *context)
{
- guint *i = context;
+ unsigned int *i = context;
/* Always return non-zero as we need a single match here */
*i = id;
gconstpointer
rspamd_match_regexp_map_single(struct rspamd_regexp_map_helper *map,
- const gchar *in, gsize len)
+ const char *in, gsize len)
{
- guint i;
+ unsigned int i;
rspamd_regexp_t *re;
- gint res = 0;
+ int res = 0;
gpointer ret = NULL;
struct rspamd_map_helper_value *val;
gboolean validated = FALSE;
GPtrArray *
rspamd_match_regexp_map_all(struct rspamd_regexp_map_helper *map,
- const gchar *in, gsize len)
+ const char *in, gsize len)
{
- guint i;
+ unsigned int i;
rspamd_regexp_t *re;
GPtrArray *ret;
- gint res = 0;
+ int res = 0;
gboolean validated = FALSE;
struct rspamd_map_helper_value *val;
}
gconstpointer
-rspamd_match_hash_map(struct rspamd_hash_map_helper *map, const gchar *in,
+rspamd_match_hash_map(struct rspamd_hash_map_helper *map, const char *in,
gsize len)
{
khiter_t k;
gconstpointer
rspamd_match_radix_map(struct rspamd_radix_map_helper *map,
- const guchar *in, gsize inlen)
+ const unsigned char *in, gsize inlen)
{
struct rspamd_map_helper_value *val;
g_free(c);
}
-gchar *
-rspamd_cdb_list_read(gchar *chunk,
- gint len,
+char *
+rspamd_cdb_list_read(char *chunk,
+ int len,
struct map_cb_data *data,
gboolean final)
{
if (found == NULL) {
/* New cdb */
- gint fd;
+ int fd;
struct cdb *cdb;
fd = rspamd_file_xopen(chunk, O_RDONLY, 0, TRUE);
gconstpointer
rspamd_match_cdb_map(struct rspamd_cdb_map_helper *map,
- const gchar *in, gsize inlen)
+ const char *in, gsize inlen)
{
if (map == NULL || map->cdbs.head == NULL) {
return NULL;
/**
* Radix list is a list like ip/mask
*/
-gchar *rspamd_radix_read(
- gchar *chunk,
- gint len,
+char *rspamd_radix_read(
+ char *chunk,
+ int len,
struct map_cb_data *data,
gboolean final);
/**
* Kv list is an ordinal list of keys and values separated by whitespace
*/
-gchar *rspamd_kv_list_read(
- gchar *chunk,
- gint len,
+char *rspamd_kv_list_read(
+ char *chunk,
+ int len,
struct map_cb_data *data,
gboolean final);
* Cdb is a cdb mapped file with shared data
* chunk must be filename!
*/
-gchar *rspamd_cdb_list_read(
- gchar *chunk,
- gint len,
+char *rspamd_cdb_list_read(
+ char *chunk,
+ int len,
struct map_cb_data *data,
gboolean final);
void rspamd_cdb_list_fin(struct map_cb_data *data, void **target);
* Regexp list is a list of regular expressions
*/
-gchar *rspamd_regexp_list_read_single(
- gchar *chunk,
- gint len,
+char *rspamd_regexp_list_read_single(
+ char *chunk,
+ int len,
struct map_cb_data *data,
gboolean final);
-gchar *rspamd_regexp_list_read_multiple(
- gchar *chunk,
- gint len,
+char *rspamd_regexp_list_read_multiple(
+ char *chunk,
+ int len,
struct map_cb_data *data,
gboolean final);
-gchar *rspamd_glob_list_read_single(
- gchar *chunk,
- gint len,
+char *rspamd_glob_list_read_single(
+ char *chunk,
+ int len,
struct map_cb_data *data,
gboolean final);
-gchar *rspamd_glob_list_read_multiple(
- gchar *chunk,
- gint len,
+char *rspamd_glob_list_read_multiple(
+ char *chunk,
+ int len,
struct map_cb_data *data,
gboolean final);
/**
* FSM for lists parsing (support comments, blank lines and partial replies)
*/
-gchar *
+char *
rspamd_parse_kv_list(
- gchar *chunk,
- gint len,
+ char *chunk,
+ int len,
struct map_cb_data *data,
rspamd_map_insert_func func,
- const gchar *default_value,
+ const char *default_value,
gboolean final);
/**
* @return
*/
gconstpointer rspamd_match_regexp_map_single(struct rspamd_regexp_map_helper *map,
- const gchar *in, gsize len);
+ const char *in, gsize len);
/**
* Find a multiple (all) matching regexp for the specified text or NULL if
* @return
*/
GPtrArray *rspamd_match_regexp_map_all(struct rspamd_regexp_map_helper *map,
- const gchar *in, gsize len);
+ const char *in, gsize len);
/**
* Find value matching specific key in a hash map
* @return
*/
gconstpointer rspamd_match_hash_map(struct rspamd_hash_map_helper *map,
- const gchar *in, gsize len);
+ const char *in, gsize len);
/**
* Find value matching specific key in a cdb map
* @return rspamd_ftok_t pointer (allocated in a static buffer!)
*/
gconstpointer rspamd_match_cdb_map(struct rspamd_cdb_map_helper *map,
- const gchar *in, gsize len);
+ const char *in, gsize len);
/**
* Find value matching specific key in a hash map
* @return
*/
gconstpointer rspamd_match_radix_map(struct rspamd_radix_map_helper *map,
- const guchar *in, gsize inlen);
+ const unsigned char *in, gsize inlen);
gconstpointer rspamd_match_radix_map_addr(struct rspamd_radix_map_helper *map,
const rspamd_inet_addr_t *addr);
typedef void (*rspamd_map_tmp_dtor)(gpointer p);
-extern guint rspamd_map_log_id;
+extern unsigned int rspamd_map_log_id;
#define msg_err_map(...) rspamd_default_log_function(G_LOG_LEVEL_CRITICAL, \
"map", map->tag, \
RSPAMD_LOG_FUNC, \
* Data specific to file maps
*/
struct file_map_data {
- gchar *filename;
+ char *filename;
gboolean need_modify;
ev_stat st_ev;
};
};
struct rspamd_map_cachepoint {
- gint available;
+ int available;
gsize len;
time_t last_modified;
- gchar shmem_name[256];
+ char shmem_name[256];
};
/**
struct rspamd_map_cachepoint *cache;
/* Non-shared for cache owner, used to cleanup cache */
struct rspamd_http_map_cached_cbdata *cur_cache_cbd;
- gchar *userinfo;
- gchar *path;
- gchar *host;
- gchar *rest;
+ char *userinfo;
+ char *path;
+ char *host;
+ char *rest;
rspamd_fstring_t *etag;
time_t last_modified;
time_t last_checked;
gboolean request_sent;
uint64_t gen;
- guint16 port;
+ uint16_t port;
};
struct static_map_data {
- guchar *data;
+ unsigned char *data;
gsize len;
gboolean processed;
};
uint32_t id;
struct rspamd_cryptobox_pubkey *trusted_pubkey;
union rspamd_map_backend_data data;
- gchar *uri;
+ char *uri;
ref_entry_t ref;
};
void **user_data;
struct ev_loop *event_loop;
struct rspamd_worker *wrk;
- gchar *description;
- gchar *name;
+ char *description;
+ char *name;
uint32_t id;
struct map_periodic_cbdata *scheduled_check;
rspamd_map_tmp_dtor tmp_dtor;
uint64_t digest;
/* Should we check HTTP or just load cached data */
ev_tstamp timeout;
- gdouble poll_timeout;
+ double poll_timeout;
time_t next_check;
bool active_http;
bool non_trivial; /* E.g. has http backends in active mode */
bool no_file_read; /* Do not read files */
bool seen; /* This map has already been watched or pre-loaded */
/* Shared lock for temporary disabling of map reading (e.g. when this map is written by UI) */
- gint *locked;
- gchar tag[MEMPOOL_UID_LEN];
+ int *locked;
+ char tag[MEMPOOL_UID_LEN];
};
enum rspamd_map_http_stage {
gboolean need_modify;
gboolean errored;
gboolean locked;
- guint cur_backend;
+ unsigned int cur_backend;
ref_entry_t ref;
};
-static const gchar rspamd_http_file_magic[] =
+static const char rspamd_http_file_magic[] =
{'r', 'm', 'c', 'd', '2', '0', '0', '0'};
struct rspamd_http_file_data {
- guchar magic[sizeof(rspamd_http_file_magic)];
+ unsigned char magic[sizeof(rspamd_http_file_magic)];
goffset data_off;
gulong mtime;
gulong next_check;
-/*-
- * Copyright 2017 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
static void
rspamd_milter_session_reset(struct rspamd_milter_session *session,
- guint how)
+ unsigned int how)
{
struct rspamd_milter_outbuf *obuf, *obuf_tmp;
struct rspamd_milter_private *priv = session->priv;
struct rspamd_email_address *cur;
- guint i;
+ unsigned int i;
if (how & RSPAMD_MILTER_RESET_IO) {
msg_debug_milter("cleanup IO on abort");
}
msg_debug_milter("cleanup %d recipients on abort",
- (gint) session->rcpts->len);
+ (int) session->rcpts->len);
g_ptr_array_free(session->rcpts, TRUE);
session->rcpts = NULL;
if (priv->headers) {
msg_debug_milter("cleanup headers");
- gchar *k;
+ char *k;
GArray *ar;
kh_foreach(priv->headers, k, ar, {
}
if (priv->headers) {
- gchar *k;
+ char *k;
GArray *ar;
kh_foreach(priv->headers, k, ar, {
struct rspamd_milter_private *priv)
{
GError *err = NULL;
- static const gchar reply[] = "HTTP/1.1 200 OK\r\n"
- "Connection: close\r\n"
- "Server: rspamd/2.7 (milter mode)\r\n"
- "Content-Length: 6\r\n"
- "Content-Type: text/plain\r\n"
- "\r\n"
- "pong\r\n";
+ static const char reply[] = "HTTP/1.1 200 OK\r\n"
+ "Connection: close\r\n"
+ "Server: rspamd/2.7 (milter mode)\r\n"
+ "Content-Length: 6\r\n"
+ "Content-Type: text/plain\r\n"
+ "\r\n"
+ "pong\r\n";
if (write(priv->fd, reply, sizeof(reply)) == -1) {
- gint serrno = errno;
+ int serrno = errno;
msg_err_milter("cannot write pong reply: %s", strerror(serrno));
g_set_error(&err, rspamd_milter_quark(), serrno, "ping command IO error: %s",
strerror(serrno));
}
}
-static gint
-rspamd_milter_http_on_url(http_parser *parser, const gchar *at, size_t length)
+static int
+rspamd_milter_http_on_url(http_parser *parser, const char *at, size_t length)
{
GString *url = (GString *) parser->data;
}
static void
-rspamd_milter_io_handler(gint fd, gshort what, void *ud)
+rspamd_milter_io_handler(int fd, gshort what, void *ud)
{
struct rspamd_milter_session *session = ud;
struct rspamd_milter_private *priv;
{
GError *err;
rspamd_fstring_t *buf;
- const guchar *pos, *end, *zero;
- guint cmdlen;
+ const unsigned char *pos, *end, *zero;
+ unsigned int cmdlen;
uint32_t version, actions, protocol;
buf = priv->parser.buf;
*/
zero = memchr(pos, '\0', cmdlen);
- if (zero == NULL || zero > (end - sizeof(guint16) + 1)) {
+ if (zero == NULL || zero > (end - sizeof(uint16_t) + 1)) {
err = g_error_new(rspamd_milter_quark(), EINVAL, "invalid "
"connect command (no name)");
rspamd_milter_on_protocol_error(session, priv, err);
return FALSE;
}
else {
- guchar proto;
- guint16 port;
- gchar ip6_str[INET6_ADDRSTRLEN + 3];
+ unsigned char proto;
+ uint16_t port;
+ char ip6_str[INET6_ADDRSTRLEN + 3];
gsize r;
/*
else {
rspamd_fstring_t *name, *value;
rspamd_ftok_t *name_tok, *value_tok;
- const guchar *zero_val;
+ const unsigned char *zero_val;
zero_val = memchr(zero + 1, '\0', end - zero - 1);
else {
if (end > zero && *(end - 1) == '\0') {
khiter_t k;
- gint res;
+ int res;
- k = kh_get(milter_headers_hash_t, priv->headers, (gchar *) pos);
+ k = kh_get(milter_headers_hash_t, priv->headers, (char *) pos);
if (k == kh_end(priv->headers)) {
GArray *ar;
k = kh_put(milter_headers_hash_t, priv->headers,
g_strdup(pos), &res);
- ar = g_array_new(FALSE, FALSE, sizeof(gint));
+ ar = g_array_new(FALSE, FALSE, sizeof(int));
g_array_append_val(ar, priv->cur_hdr);
kh_value(priv->headers, k) = ar;
}
while (pos < end) {
struct rspamd_email_address *addr;
- gchar *cpy;
+ char *cpy;
zero = memchr(pos, '\0', end - pos);
while (pos < end) {
struct rspamd_email_address *addr;
- gchar *cpy;
+ char *cpy;
zero = memchr(pos, '\0', end - pos);
}
static gboolean
-rspamd_milter_is_valid_cmd(guchar c)
+rspamd_milter_is_valid_cmd(unsigned char c)
{
switch (c) {
case RSPAMD_MILTER_CMD_ABORT:
rspamd_milter_consume_input(struct rspamd_milter_session *session,
struct rspamd_milter_private *priv)
{
- const guchar *p, *end;
+ const unsigned char *p, *end;
GError *err;
p = priv->parser.buf->str + priv->parser.pos;
while (p < end) {
msg_debug_milter("offset: %d, state: %d",
- (gint) (p - (const guchar *) priv->parser.buf->str),
+ (int) (p - (const unsigned char *) priv->parser.buf->str),
priv->parser.state);
switch (priv->parser.state) {
}
p++;
- priv->parser.cmd_start = p - (const guchar *) priv->parser.buf->str;
+ priv->parser.cmd_start = p - (const unsigned char *) priv->parser.buf->str;
break;
case st_read_data:
/* We might need some more data in buffer for further steps */
return FALSE;
}
if (priv->parser.buf->allocated < priv->parser.datalen) {
- priv->parser.pos = p - (const guchar *) priv->parser.buf->str;
+ priv->parser.pos = p - (const unsigned char *) priv->parser.buf->str;
priv->parser.buf = rspamd_fstring_grow(priv->parser.buf,
priv->parser.buf->len + priv->parser.datalen);
/* This can realloc buffer */
}
else {
/* Need to read more */
- priv->parser.pos = p - (const guchar *) priv->parser.buf->str;
+ priv->parser.pos = p - (const unsigned char *) priv->parser.buf->str;
rspamd_milter_plan_io(session, priv, EV_READ);
goto end;
}
gboolean
-rspamd_milter_handle_socket(gint fd, ev_tstamp timeout,
+rspamd_milter_handle_socket(int fd, ev_tstamp timeout,
rspamd_mempool_t *pool,
struct ev_loop *ev_base, rspamd_milter_finish finish_cb,
rspamd_milter_error error_cb, void *ud)
{
struct rspamd_milter_session *session;
struct rspamd_milter_private *priv;
- gint nfd = dup(fd);
+ int nfd = dup(fd);
if (nfd == -1) {
GError *err = g_error_new(rspamd_milter_quark(), errno,
return ret;
}
-#define SET_COMMAND(cmd, sz, reply, pos) \
- do { \
- uint32_t _len; \
- _len = (sz) + 1; \
- (reply) = rspamd_fstring_sized_new(sizeof(_len) + _len); \
- (reply)->len = sizeof(_len) + _len; \
- _len = htonl(_len); \
- memcpy((reply)->str, &_len, sizeof(_len)); \
- (reply)->str[sizeof(_len)] = (cmd); \
- (pos) = (guchar *) (reply)->str + sizeof(_len) + 1; \
+#define SET_COMMAND(cmd, sz, reply, pos) \
+ do { \
+ uint32_t _len; \
+ _len = (sz) + 1; \
+ (reply) = rspamd_fstring_sized_new(sizeof(_len) + _len); \
+ (reply)->len = sizeof(_len) + _len; \
+ _len = htonl(_len); \
+ memcpy((reply)->str, &_len, sizeof(_len)); \
+ (reply)->str[sizeof(_len)] = (cmd); \
+ (pos) = (unsigned char *) (reply)->str + sizeof(_len) + 1; \
} while (0)
gboolean
{
uint32_t ver, actions, protocol, idx;
va_list ap;
- guchar cmd, *pos;
+ unsigned char cmd, *pos;
rspamd_fstring_t *reply = NULL;
gsize len;
GString *name, *value;
GString value;
uint32_t idx = 1;
- value.str = (gchar *) "";
+ value.str = (char *) "";
value.len = 0;
return rspamd_milter_send_action(session, RSPAMD_MILTER_CHGHEADER,
rspamd_milter_to_http(struct rspamd_milter_session *session)
{
struct rspamd_http_message *msg;
- guint i;
+ unsigned int i;
struct rspamd_email_address *rcpt;
struct rspamd_milter_private *priv = session->priv;
static void
rspamd_milter_remove_header_safe(struct rspamd_milter_session *session,
- const gchar *key, gint nhdr)
+ const char *key, int nhdr)
{
- gint i;
+ int i;
GString *hname, *hvalue;
struct rspamd_milter_private *priv = session->priv;
khiter_t k;
static void
rspamd_milter_extract_single_header(struct rspamd_milter_session *session,
- const gchar *hdr, const ucl_object_t *obj)
+ const char *hdr, const ucl_object_t *obj)
{
GString *hname, *hvalue;
struct rspamd_milter_private *priv = session->priv;
- gint idx = -1;
+ int idx = -1;
const ucl_object_t *val;
val = ucl_object_lookup(obj, "value");
void rspamd_milter_send_task_results(struct rspamd_milter_session *session,
const ucl_object_t *results,
- const gchar *new_body,
+ const char *new_body,
gsize bodylen)
{
const ucl_object_t *elt;
struct rspamd_milter_private *priv = session->priv;
- const gchar *str_action;
+ const char *str_action;
struct rspamd_action *action;
rspamd_fstring_t *xcode = NULL, *rcode = NULL, *reply = NULL;
GString *hname, *hvalue;
elt = ucl_object_lookup(results, "messages");
if (elt) {
const ucl_object_t *smtp_res;
- const gchar *msg;
+ const char *msg;
gsize len = 0;
smtp_res = ucl_object_lookup(elt, "smtp_message");
struct rspamd_config;
struct rspamd_milter_context {
- const gchar *spam_header;
- const gchar *client_ca_name;
- const gchar *reject_message;
+ const char *spam_header;
+ const char *client_ca_name;
+ const char *reject_message;
void *sessions_cache;
struct rspamd_config *cfg;
gboolean discard_on_reject;
ref_entry_t ref;
};
-typedef void (*rspamd_milter_finish)(gint fd,
+typedef void (*rspamd_milter_finish)(int fd,
struct rspamd_milter_session *session, void *ud);
-typedef void (*rspamd_milter_error)(gint fd,
+typedef void (*rspamd_milter_error)(int fd,
struct rspamd_milter_session *session,
void *ud, GError *err);
* @param ud
* @return
*/
-gboolean rspamd_milter_handle_socket(gint fd, ev_tstamp timeout,
+gboolean rspamd_milter_handle_socket(int fd, ev_tstamp timeout,
rspamd_mempool_t *pool,
struct ev_loop *ev_base, rspamd_milter_finish finish_cb,
rspamd_milter_error error_cb, void *ud);
*/
void rspamd_milter_send_task_results(struct rspamd_milter_session *session,
const ucl_object_t *results,
- const gchar *new_body,
+ const char *new_body,
gsize bodylen);
/**
goffset cmd_start;
gsize datalen;
enum rspamd_milter_state state;
- gchar cur_cmd;
+ char cur_cmd;
};
struct rspamd_milter_outbuf {
struct ev_loop *event_loop;
rspamd_mempool_t *pool;
khash_t(milter_headers_hash_t) * headers;
- gint cur_hdr;
+ int cur_hdr;
rspamd_milter_finish fin_cb;
rspamd_milter_error err_cb;
void *ud;
#include "logger.h"
#include "contrib/uthash/utlist.h"
-static const gdouble default_monitoring_interval = 60.0;
-static const guint default_max_errors = 2;
-static const gdouble default_max_monitored_mult = 32;
-static const gdouble default_min_monitored_mult = 0.1;
-static const gdouble default_initial_monitored_mult = default_min_monitored_mult;
-static const gdouble default_offline_monitored_mult = 8.0;
+static const double default_monitoring_interval = 60.0;
+static const unsigned int default_max_errors = 2;
+static const double default_max_monitored_mult = 32;
+static const double default_min_monitored_mult = 0.1;
+static const double default_initial_monitored_mult = default_min_monitored_mult;
+static const double default_offline_monitored_mult = 8.0;
struct rspamd_monitored_methods {
void *(*monitored_config)(struct rspamd_monitored *m,
GHashTable *helts;
mon_change_cb change_cb;
gpointer ud;
- gdouble monitoring_interval;
- gdouble max_monitored_mult;
- gdouble min_monitored_mult;
- gdouble initial_monitored_mult;
- gdouble offline_monitored_mult;
- guint max_errors;
+ double monitoring_interval;
+ double max_monitored_mult;
+ double min_monitored_mult;
+ double initial_monitored_mult;
+ double offline_monitored_mult;
+ unsigned int max_errors;
gboolean initialized;
};
struct rspamd_monitored {
- gchar *url;
- gdouble monitoring_mult;
- gdouble offline_time;
- gdouble total_offline_time;
- gdouble latency;
- guint nchecks;
- guint max_errors;
- guint cur_errors;
+ char *url;
+ double monitoring_mult;
+ double offline_time;
+ double total_offline_time;
+ double latency;
+ unsigned int nchecks;
+ unsigned int max_errors;
+ unsigned int cur_errors;
gboolean alive;
enum rspamd_monitored_type type;
enum rspamd_monitored_flags flags;
struct rspamd_monitored_ctx *ctx;
struct rspamd_monitored_methods proc;
ev_timer periodic;
- gchar tag[RSPAMD_MONITORED_TAG_LEN];
+ char tag[RSPAMD_MONITORED_TAG_LEN];
};
#define msg_err_mon(...) rspamd_default_log_function(G_LOG_LEVEL_CRITICAL, \
static inline void
rspamd_monitored_propagate_error(struct rspamd_monitored *m,
- const gchar *error)
+ const char *error)
{
if (m->alive) {
if (m->cur_errors < m->max_errors) {
}
static inline void
-rspamd_monitored_propagate_success(struct rspamd_monitored *m, gdouble lat)
+rspamd_monitored_propagate_success(struct rspamd_monitored *m, double lat)
{
- gdouble t;
+ double t;
m->cur_errors = 0;
rspamd_monitored_periodic(EV_P_ ev_timer *w, int revents)
{
struct rspamd_monitored *m = (struct rspamd_monitored *) w->data;
- gdouble jittered;
+ double jittered;
gboolean ret = FALSE;
if (m->proc.monitored_update) {
GString *request;
radix_compressed_t *expected;
struct rspamd_monitored *m;
- gint expected_code;
- gdouble check_tm;
+ int expected_code;
+ double check_tm;
};
static void
rspamd_monitored_dns_random(struct rspamd_monitored *m,
struct rspamd_dns_monitored_conf *conf)
{
- gchar random_prefix[32];
- const gchar dns_chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
- gint len;
+ char random_prefix[32];
+ const char dns_chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
+ int len;
len = rspamd_random_uint64_fast() % sizeof(random_prefix);
len = 8;
}
- for (guint i = 0; i < len; i++) {
- guint idx = rspamd_random_uint64_fast() % (sizeof(dns_chars) - 1);
+ for (unsigned int i = 0; i < len; i++) {
+ unsigned int idx = rspamd_random_uint64_fast() % (sizeof(dns_chars) - 1);
random_prefix[i] = dns_chars[idx];
}
{
struct rspamd_dns_monitored_conf *conf;
const ucl_object_t *elt;
- gint rt;
+ int rt;
GString *req = g_string_sized_new(127);
conf = g_malloc0(sizeof(*conf));
struct rspamd_monitored *m;
struct rdns_reply_entry *cur;
gboolean is_special_reply = FALSE;
- gdouble lat;
+ double lat;
m = conf->m;
lat = rspamd_get_calendar_ticks() - conf->check_tm;
gpointer ud)
{
struct rspamd_monitored *m;
- guint i;
+ unsigned int i;
g_assert(ctx != NULL);
ctx->event_loop = ev_base;
struct rspamd_monitored *
rspamd_monitored_create_(struct rspamd_monitored_ctx *ctx,
- const gchar *line,
+ const char *line,
enum rspamd_monitored_type type,
enum rspamd_monitored_flags flags,
const ucl_object_t *opts,
- const gchar *loc)
+ const char *loc)
{
struct rspamd_monitored *m;
rspamd_cryptobox_hash_state_t st;
- gchar *cksum_encoded, cksum[rspamd_cryptobox_HASHBYTES];
+ char *cksum_encoded, cksum[rspamd_cryptobox_HASHBYTES];
g_assert(ctx != NULL);
return st;
}
-gdouble
+double
rspamd_monitored_offline_time(struct rspamd_monitored *m)
{
g_assert(m != NULL);
return 0;
}
-gdouble
+double
rspamd_monitored_total_offline_time(struct rspamd_monitored *m)
{
g_assert(m != NULL);
return m->total_offline_time;
}
-gdouble
+double
rspamd_monitored_latency(struct rspamd_monitored *m)
{
g_assert(m != NULL);
void rspamd_monitored_start(struct rspamd_monitored *m)
{
- gdouble jittered;
+ double jittered;
g_assert(m != NULL);
jittered = rspamd_time_jitter(m->ctx->monitoring_interval * m->monitoring_mult,
void rspamd_monitored_ctx_destroy(struct rspamd_monitored_ctx *ctx)
{
struct rspamd_monitored *m;
- guint i;
+ unsigned int i;
g_assert(ctx != NULL);
struct rspamd_monitored *
rspamd_monitored_by_tag(struct rspamd_monitored_ctx *ctx,
- guchar tag[RSPAMD_MONITORED_TAG_LEN])
+ unsigned char tag[RSPAMD_MONITORED_TAG_LEN])
{
struct rspamd_monitored *res;
- gchar rtag[RSPAMD_MONITORED_TAG_LEN];
+ char rtag[RSPAMD_MONITORED_TAG_LEN];
rspamd_strlcpy(rtag, tag, sizeof(rtag));
res = g_hash_table_lookup(ctx->helts, rtag);
void rspamd_monitored_get_tag(struct rspamd_monitored *m,
- guchar tag_out[RSPAMD_MONITORED_TAG_LEN])
+ unsigned char tag_out[RSPAMD_MONITORED_TAG_LEN])
{
g_assert(m != NULL);
*/
struct rspamd_monitored *rspamd_monitored_create_(
struct rspamd_monitored_ctx *ctx,
- const gchar *line,
+ const char *line,
enum rspamd_monitored_type type,
enum rspamd_monitored_flags flags,
const ucl_object_t *opts,
- const gchar *loc);
+ const char *loc);
#define rspamd_monitored_create(ctx, line, type, flags, opts) \
rspamd_monitored_create_(ctx, line, type, flags, opts, G_STRFUNC)
* @return
*/
struct rspamd_monitored *rspamd_monitored_by_tag(struct rspamd_monitored_ctx *ctx,
- guchar tag[RSPAMD_MONITORED_TAG_LEN]);
+ unsigned char tag[RSPAMD_MONITORED_TAG_LEN]);
/**
* Sets `tag_out` to the monitored tag
* @param tag_out
*/
void rspamd_monitored_get_tag(struct rspamd_monitored *m,
- guchar tag_out[RSPAMD_MONITORED_TAG_LEN]);
+ unsigned char tag_out[RSPAMD_MONITORED_TAG_LEN]);
/**
* Return TRUE if monitored object is alive
* @param m
* @return
*/
-gdouble rspamd_monitored_offline_time(struct rspamd_monitored *m);
+double rspamd_monitored_offline_time(struct rspamd_monitored *m);
/**
* Returns the total offline time for a monitored object
* @param m
* @return
*/
-gdouble rspamd_monitored_total_offline_time(struct rspamd_monitored *m);
+double rspamd_monitored_total_offline_time(struct rspamd_monitored *m);
/**
* Returns the latency for monitored object (in seconds)
* @param m
* @return
*/
-gdouble rspamd_monitored_latency(struct rspamd_monitored *m);
+double rspamd_monitored_latency(struct rspamd_monitored *m);
/**
* Explicitly disable monitored object
/*
* Remove <> from the fixed string and copy it to the pool
*/
-static gchar *
+static char *
rspamd_protocol_escape_braces(struct rspamd_task *task, rspamd_ftok_t *in)
{
- guint nchars = 0;
- const gchar *p;
+ unsigned int nchars = 0;
+ const char *p;
rspamd_ftok_t tok;
gboolean has_obrace = FALSE;
GHashTable *query_args;
GHashTableIter it;
struct http_parser_url u;
- const gchar *p;
+ const char *p;
gsize pathlen;
rspamd_ftok_t *key, *value;
gpointer k, v;
g_hash_table_iter_init(&it, query_args);
while (g_hash_table_iter_next(&it, &k, &v)) {
- gchar *key_cpy;
+ char *key_cpy;
key = k;
value = v;
quoted_string,
normal_string,
} state = skip_spaces;
- const gchar *p, *end, *start_addr;
+ const char *p, *end, *start_addr;
struct rspamd_email_address *addr;
p = hdr->begin;
} while (0)
static void
-rspamd_protocol_handle_flag(struct rspamd_task *task, const gchar *str,
+rspamd_protocol_handle_flag(struct rspamd_task *task, const char *str,
gsize len)
{
gboolean known = FALSE;
CHECK_PROTOCOL_FLAG("groups", RSPAMD_TASK_PROTOCOL_FLAG_GROUPS);
if (!known) {
- msg_warn_protocol("unknown flag: %*s", (gint) len, str);
+ msg_warn_protocol("unknown flag: %*s", (int) len, str);
}
}
skip_spaces,
read_flag,
} state = skip_spaces;
- const gchar *p, *end, *start;
+ const char *p, *end, *start;
p = hdr->begin;
end = hdr->begin + hdr->len;
rspamd_ftok_t *hn_tok, *hv_tok, srch;
gboolean has_ip = FALSE, seen_settings_header = FALSE;
struct rspamd_http_header *header, *h;
- gchar *ntok;
+ char *ntok;
kh_foreach_value (msg->headers, header, {
DL_FOREACH (header, h) {
}
IF_HEADER(MTA_TAG_HEADER)
{
- gchar *mta_tag;
+ char *mta_tag;
mta_tag = rspamd_mempool_ftokdup(task->task_pool, hv_tok);
rspamd_mempool_set_variable(task->task_pool,
RSPAMD_MEMPOOL_MTA_TAG,
}
IF_HEADER(MTA_NAME_HEADER)
{
- gchar *mta_name;
+ char *mta_name;
mta_name = rspamd_mempool_ftokdup(task->task_pool, hv_tok);
rspamd_mempool_set_variable(task->task_pool,
RSPAMD_MEMPOOL_MTA_NAME,
GError **err)
{
struct rspamd_rcl_struct_parser *pd = ud;
- gint *target;
- const gchar *key;
+ int *target;
+ const char *key;
gboolean value;
- target = (gint *) (((gchar *) pd->user_struct) + pd->offset);
+ target = (int *) (((char *) pd->user_struct) + pd->offset);
key = ucl_object_key(obj);
value = ucl_object_toboolean(obj);
static ucl_object_t *
rspamd_protocol_extended_url(struct rspamd_task *task,
struct rspamd_url *url,
- const gchar *encoded, gsize enclen)
+ const char *encoded, gsize enclen)
{
ucl_object_t *obj, *elt;
{
ucl_object_t *obj;
struct rspamd_task *task = cb->task;
- const gchar *user_field = "unknown", *encoded = NULL;
+ const char *user_field = "unknown", *encoded = NULL;
gboolean has_user = FALSE;
- guint len = 0;
+ unsigned int len = 0;
gsize enclen = 0;
if (!(task->protocol_flags & RSPAMD_TASK_PROTOCOL_FLAG_EXT_URLS)) {
has_user ? "user" : "from",
len, user_field,
rspamd_inet_address_to_string(task->from_addr),
- (gint) enclen, encoded);
+ (int) enclen, encoded);
}
}
/* Write new subject */
-static const gchar *
+static const char *
rspamd_protocol_rewrite_subject(struct rspamd_task *task)
{
GString *subj_buf;
- gchar *res;
- const gchar *s, *c, *p;
+ char *res;
+ const char *s, *c, *p;
gsize slen = 0;
c = rspamd_mempool_get_variable(task->task_pool, "metric_subject");
rspamd_metric_symbol_ucl(struct rspamd_task *task, struct rspamd_symbol_result *sym)
{
ucl_object_t *obj = NULL, *ar;
- const gchar *description = NULL;
+ const char *description = NULL;
struct rspamd_symbol_option *opt;
if (sym->sym != NULL) {
static ucl_object_t *
rspamd_metric_group_ucl(struct rspamd_task *task,
- struct rspamd_symbols_group *gr, gdouble score)
+ struct rspamd_symbols_group *gr, double score)
{
ucl_object_t *obj = NULL;
gboolean is_spam;
struct rspamd_action *action;
ucl_object_t *obj = NULL, *sobj;
- const gchar *subject;
+ const char *subject;
struct rspamd_passthrough_result *pr = NULL;
action = rspamd_check_action_metric(task, &pr, NULL);
/* Handle groups if needed */
if (task->protocol_flags & RSPAMD_TASK_PROTOCOL_FLAG_GROUPS) {
struct rspamd_symbols_group *gr;
- gdouble gr_score;
+ double gr_score;
obj = ucl_object_typed_new(UCL_OBJECT);
ucl_object_reserve(obj, kh_size(mres->sym_groups));
GHashTableIter it;
gpointer k, v;
ucl_object_t *prof;
- gdouble val;
+ double val;
prof = ucl_object_typed_new(UCL_OBJECT);
tbl = rspamd_mempool_get_variable(task->task_pool, "profile");
g_hash_table_iter_init(&it, tbl);
while (g_hash_table_iter_next(&it, &k, &v)) {
- val = *(gdouble *) v;
+ val = *(double *) v;
ucl_object_insert_key(prof, ucl_object_fromdouble(val),
(const char *) k, 0, false);
}
ucl_object_t *top = NULL;
rspamd_fstring_t *reply;
- gint flags = RSPAMD_PROTOCOL_DEFAULT;
+ int flags = RSPAMD_PROTOCOL_DEFAULT;
struct rspamd_action *action;
/* Removed in 2.0 */
/* In case of milter, we append just body, otherwise - full message */
if (task->protocol_flags & RSPAMD_TASK_PROTOCOL_FLAG_MILTER) {
- const gchar *start;
+ const char *start;
goffset len, hdr_off;
start = task->msg.begin;
if (task->cfg->libs_ctx->out_dict &&
task->cfg->libs_ctx->out_dict->id != 0) {
- gchar dict_str[32];
+ char dict_str[32];
rspamd_snprintf(dict_str, sizeof(dict_str), "%ud",
task->cfg->libs_ctx->out_dict->id);
lua_State *L = task->cfg->lua_state;
struct rspamd_scan_result *mres;
struct rspamd_symbol_result *sym;
- gint id, i;
+ int id, i;
uint32_t n = 0, nextra = 0;
gsize sz;
GArray *extra;
void rspamd_protocol_write_reply(struct rspamd_task *task, ev_tstamp timeout)
{
struct rspamd_http_message *msg;
- const gchar *ctype = "application/json";
+ const char *ctype = "application/json";
rspamd_fstring_t *reply;
msg = rspamd_http_new_message(HTTP_RESPONSE);
/* We also need to validate utf8 */
if (out_type != UCL_EMIT_MSGPACK && rspamd_fast_utf8_validate(reply->str, reply->len) != 0) {
gsize valid_len;
- gchar *validated;
+ char *validated;
/* We copy reply several times here, but it should be a rare case */
validated = rspamd_str_make_utf_valid(reply->str, reply->len,
uint32_t nresults;
uint32_t nextra;
uint32_t settings_id;
- gdouble score;
- gdouble required_score;
+ double score;
+ double required_score;
struct rspamd_protocol_log_symbol_result results[];
};
#ifdef WITH_HYPERSCAN
#define RSPAMD_HS_MAGIC_LEN (sizeof(rspamd_hs_magic))
-static const guchar rspamd_hs_magic[] = {'r', 's', 'h', 's', 'r', 'e', '1', '1'},
- rspamd_hs_magic_vector[] = {'r', 's', 'h', 's', 'r', 'v', '1', '1'};
+static const unsigned char rspamd_hs_magic[] = {'r', 's', 'h', 's', 'r', 'e', '1', '1'},
+ rspamd_hs_magic_vector[] = {'r', 's', 'h', 's', 'r', 'v', '1', '1'};
#endif
GHashTable *re;
rspamd_cryptobox_hash_state_t *st;
- gchar hash[rspamd_cryptobox_HASHBYTES + 1];
+ char hash[rspamd_cryptobox_HASHBYTES + 1];
#ifdef WITH_HYPERSCAN
rspamd_hyperscan_t *hs_db;
hs_scratch_t *hs_scratch;
- gint *hs_ids;
- guint nhs;
+ int *hs_ids;
+ unsigned int nhs;
#endif
};
struct rspamd_re_cache_elt {
rspamd_regexp_t *re;
- gint lua_cbref;
+ int lua_cbref;
enum rspamd_re_cache_elt_match_type match_type;
};
-KHASH_INIT(lua_selectors_hash, gchar *, int, 1, kh_str_hash_func, kh_str_hash_equal);
+KHASH_INIT(lua_selectors_hash, char *, int, 1, kh_str_hash_func, kh_str_hash_equal);
struct rspamd_re_cache {
GHashTable *re_classes;
GPtrArray *re;
khash_t(lua_selectors_hash) * selectors;
ref_entry_t ref;
- guint nre;
- guint max_re_data;
- gchar hash[rspamd_cryptobox_HASHBYTES + 1];
+ unsigned int nre;
+ unsigned int max_re_data;
+ char hash[rspamd_cryptobox_HASHBYTES + 1];
lua_State *L;
#ifdef WITH_HYPERSCAN
enum rspamd_hyperscan_status hyperscan_loaded;
};
struct rspamd_re_selector_result {
- guchar **scvec;
- guint *lenvec;
- guint cnt;
+ unsigned char **scvec;
+ unsigned int *lenvec;
+ unsigned int cnt;
};
KHASH_INIT(selectors_results_hash, int, struct rspamd_re_selector_result, 1,
kh_int_hash_func, kh_int_hash_equal);
struct rspamd_re_runtime {
- guchar *checked;
- guchar *results;
+ unsigned char *checked;
+ unsigned char *results;
khash_t(selectors_results_hash) * sel_cache;
struct rspamd_re_cache *cache;
struct rspamd_re_cache_stat stat;
GHashTableIter it;
gpointer k, v;
struct rspamd_re_class *re_class;
- gchar *skey;
- gint sref;
+ char *skey;
+ int sref;
g_assert(cache != NULL);
g_hash_table_iter_init(&it, cache->re_classes);
});
struct rspamd_re_cache_elt *elt;
- guint i;
+ unsigned int i;
PTR_ARRAY_FOREACH(cache->re, i, elt)
{
rspamd_regexp_t *re,
enum rspamd_re_type type,
gconstpointer type_data, gsize datalen,
- gint lua_cbref)
+ int lua_cbref)
{
uint64_t class_id;
struct rspamd_re_class *re_class;
}
}
-static gint
+static int
rspamd_re_cache_sort_func(gconstpointer a, gconstpointer b)
{
struct rspamd_re_cache_elt *const *re1 = a, *const *re2 = b;
void rspamd_re_cache_init(struct rspamd_re_cache *cache, struct rspamd_config *cfg)
{
- guint i, fl;
+ unsigned int i, fl;
GHashTableIter it;
gpointer k, v;
struct rspamd_re_class *re_class;
rspamd_cryptobox_hash_state_t st_global;
rspamd_regexp_t *re;
struct rspamd_re_cache_elt *elt;
- guchar hash_out[rspamd_cryptobox_HASHBYTES];
+ unsigned char hash_out[rspamd_cryptobox_HASHBYTES];
g_assert(cache != NULL);
rspamd_cryptobox_HASHBYTES);
/* PCRE flags */
fl = rspamd_regexp_get_pcre_flags(re);
- rspamd_cryptobox_hash_update(re_class->st, (const guchar *) &fl,
+ rspamd_cryptobox_hash_update(re_class->st, (const unsigned char *) &fl,
sizeof(fl));
- rspamd_cryptobox_hash_update(&st_global, (const guchar *) &fl,
+ rspamd_cryptobox_hash_update(&st_global, (const unsigned char *) &fl,
sizeof(fl));
/* Rspamd flags */
fl = rspamd_regexp_get_flags(re);
- rspamd_cryptobox_hash_update(re_class->st, (const guchar *) &fl,
+ rspamd_cryptobox_hash_update(re_class->st, (const unsigned char *) &fl,
sizeof(fl));
- rspamd_cryptobox_hash_update(&st_global, (const guchar *) &fl,
+ rspamd_cryptobox_hash_update(&st_global, (const unsigned char *) &fl,
sizeof(fl));
/* Limit of hits */
fl = rspamd_regexp_get_maxhits(re);
- rspamd_cryptobox_hash_update(re_class->st, (const guchar *) &fl,
+ rspamd_cryptobox_hash_update(re_class->st, (const unsigned char *) &fl,
sizeof(fl));
- rspamd_cryptobox_hash_update(&st_global, (const guchar *) &fl,
+ rspamd_cryptobox_hash_update(&st_global, (const unsigned char *) &fl,
sizeof(fl));
/* Numeric order */
- rspamd_cryptobox_hash_update(re_class->st, (const guchar *) &i,
+ rspamd_cryptobox_hash_update(re_class->st, (const unsigned char *) &i,
sizeof(i));
- rspamd_cryptobox_hash_update(&st_global, (const guchar *) &i,
+ rspamd_cryptobox_hash_update(&st_global, (const unsigned char *) &i,
sizeof(i));
}
rspamd_cryptobox_hash_final(&st_global, hash_out);
rspamd_snprintf(cache->hash, sizeof(cache->hash), "%*xs",
- (gint) rspamd_cryptobox_HASHBYTES, hash_out);
+ (int) rspamd_cryptobox_HASHBYTES, hash_out);
/* Now finalize all classes */
g_hash_table_iter_init(&it, cache->re_classes);
sizeof(cache->re->len));
rspamd_cryptobox_hash_final(re_class->st, hash_out);
rspamd_snprintf(re_class->hash, sizeof(re_class->hash), "%*xs",
- (gint) rspamd_cryptobox_HASHBYTES, hash_out);
+ (int) rspamd_cryptobox_HASHBYTES, hash_out);
free(re_class->st); /* Due to posix_memalign */
re_class->st = NULL;
}
cache->L = cfg->lua_state;
#ifdef WITH_HYPERSCAN
- const gchar *platform = "generic";
+ const char *platform = "generic";
rspamd_fstring_t *features = rspamd_fstring_new();
cache->disable_hyperscan = cfg->disable_hyperscan;
rt = g_malloc0(sizeof(*rt) + NBYTES(cache->nre) + cache->nre);
rt->cache = cache;
REF_RETAIN(cache);
- rt->checked = ((guchar *) rt) + sizeof(*rt);
+ rt->checked = ((unsigned char *) rt) + sizeof(*rt);
rt->results = rt->checked + NBYTES(cache->nre);
rt->stat.regexp_total = cache->nre;
#ifdef WITH_HYPERSCAN
static gboolean
rspamd_re_cache_check_lua_condition(struct rspamd_task *task,
rspamd_regexp_t *re,
- const guchar *in, gsize len,
+ const unsigned char *in, gsize len,
goffset start, goffset end,
- gint lua_cbref)
+ int lua_cbref)
{
lua_State *L = (lua_State *) task->cfg->lua_state;
GError *err = NULL;
struct rspamd_lua_text __attribute__((unused)) * t;
- gint text_pos;
+ int text_pos;
if (G_LIKELY(lua_cbref == -1)) {
return TRUE;
return res;
}
-static guint
+static unsigned int
rspamd_re_cache_process_pcre(struct rspamd_re_runtime *rt,
rspamd_regexp_t *re, struct rspamd_task *task,
- const guchar *in, gsize len,
+ const unsigned char *in, gsize len,
gboolean is_raw,
- gint lua_cbref)
+ int lua_cbref)
{
- guint r = 0;
- const gchar *start = NULL, *end = NULL;
- guint max_hits = rspamd_regexp_get_maxhits(re);
+ unsigned int r = 0;
+ const char *start = NULL, *end = NULL;
+ unsigned int max_hits = rspamd_regexp_get_maxhits(re);
uint64_t id = rspamd_regexp_get_cache_id(re);
- gdouble t1 = NAN, t2, pr;
- const gdouble slow_time = 1e8;
+ double t1 = NAN, t2, pr;
+ const double slow_time = 1e8;
if (in == NULL) {
return rt->results[id];
is_raw,
NULL)) {
if (rspamd_re_cache_check_lua_condition(task, re, in, len,
- start - (const gchar *) in, end - (const gchar *) in, lua_cbref)) {
+ start - (const char *) in, end - (const char *) in, lua_cbref)) {
r++;
msg_debug_re_task("found regexp /%s/, total hits: %d",
rspamd_regexp_get_pattern(re), r);
#ifdef WITH_HYPERSCAN
struct rspamd_re_hyperscan_cbdata {
struct rspamd_re_runtime *rt;
- const guchar **ins;
- const guint *lens;
- guint count;
+ const unsigned char **ins;
+ const unsigned int *lens;
+ unsigned int count;
rspamd_regexp_t *re;
struct rspamd_task *task;
};
-static gint
+static int
rspamd_re_cache_hyperscan_cb(unsigned int id,
unsigned long long from,
unsigned long long to,
struct rspamd_re_hyperscan_cbdata *cbdata = ud;
struct rspamd_re_runtime *rt;
struct rspamd_re_cache_elt *cache_elt;
- guint ret, maxhits, i, processed;
+ unsigned int ret, maxhits, i, processed;
struct rspamd_task *task;
rt = cbdata->rt;
}
#endif
-static guint
+static unsigned int
rspamd_re_cache_process_regexp_data(struct rspamd_re_runtime *rt,
rspamd_regexp_t *re, struct rspamd_task *task,
- const guchar **in, guint *lens,
- guint count,
+ const unsigned char **in, unsigned int *lens,
+ unsigned int count,
gboolean is_raw,
gboolean *processed_hyperscan)
{
uint64_t re_id;
- guint ret = 0;
- guint i;
+ unsigned int ret = 0;
+ unsigned int i;
struct rspamd_re_cache_elt *cache_elt;
re_id = rspamd_regexp_get_cache_id(re);
rspamd_re_cache_finish_class(struct rspamd_task *task,
struct rspamd_re_runtime *rt,
struct rspamd_re_class *re_class,
- const gchar *class_name)
+ const char *class_name)
{
#ifdef WITH_HYPERSCAN
- guint i;
+ unsigned int i;
uint64_t re_id;
- guint found = 0;
+ unsigned int found = 0;
/* Set all bits that are not checked and included in hyperscan to 1 */
for (i = 0; i < re_class->nhs; i++) {
msg_debug_re_task("finished hyperscan for class %s; %d "
"matches found; %d hyperscan supported regexps; %d total regexps",
- class_name, found, re_class->nhs, (gint) g_hash_table_size(re_class->re));
+ class_name, found, re_class->nhs, (int) g_hash_table_size(re_class->re));
#endif
}
static gboolean
rspamd_re_cache_process_selector(struct rspamd_task *task,
struct rspamd_re_runtime *rt,
- const gchar *name,
- guchar ***svec,
- guint **lenvec,
- guint *n)
+ const char *name,
+ unsigned char ***svec,
+ unsigned int **lenvec,
+ unsigned int *n)
{
- gint ref;
+ int ref;
khiter_t k;
lua_State *L;
- gint err_idx, ret;
+ int err_idx, ret;
struct rspamd_task **ptask;
gboolean result = FALSE;
struct rspamd_re_cache *cache = rt->cache;
struct rspamd_re_selector_result *sr;
L = cache->L;
- k = kh_get(lua_selectors_hash, cache->selectors, (gchar *) name);
+ k = kh_get(lua_selectors_hash, cache->selectors, (char *) name);
if (k == kh_end(cache->selectors)) {
msg_err_task("cannot find selector %s, not registered", name);
else {
struct rspamd_lua_text *txt;
gsize slen;
- const gchar *sel_data;
+ const char *sel_data;
if (lua_type(L, -1) != LUA_TTABLE) {
txt = lua_check_text_or_string(L, -1);
sel_data = txt->start;
slen = txt->len;
*n = 1;
- *svec = g_malloc(sizeof(guchar *));
- *lenvec = g_malloc(sizeof(guint));
+ *svec = g_malloc(sizeof(unsigned char *));
+ *lenvec = g_malloc(sizeof(unsigned int));
(*svec)[0] = g_malloc(slen);
memcpy((*svec)[0], sel_data, slen);
(*lenvec)[0] = slen;
msg_debug_re_cache("re selector %s returned %d elements", name, *n);
if (*n > 0) {
- *svec = g_malloc(sizeof(guchar *) * (*n));
- *lenvec = g_malloc(sizeof(guint) * (*n));
+ *svec = g_malloc(sizeof(unsigned char *) * (*n));
+ *lenvec = g_malloc(sizeof(unsigned int) * (*n));
for (int i = 0; i < *n; i++) {
lua_rawgeti(L, -1, i + 1);
return result;
}
-static inline guint
+static inline unsigned int
rspamd_process_words_vector(GArray *words,
- const guchar **scvec,
- guint *lenvec,
+ const unsigned char **scvec,
+ unsigned int *lenvec,
struct rspamd_re_class *re_class,
- guint cnt,
+ unsigned int cnt,
gboolean *raw)
{
- guint j;
+ unsigned int j;
rspamd_stat_token_t *tok;
if (words) {
return cnt;
}
-static guint
+static unsigned int
rspamd_re_cache_process_headers_list(struct rspamd_task *task,
struct rspamd_re_runtime *rt,
rspamd_regexp_t *re,
gboolean is_strong,
gboolean *processed_hyperscan)
{
- const guchar **scvec, *in;
+ const unsigned char **scvec, *in;
gboolean raw = FALSE;
- guint *lenvec;
+ unsigned int *lenvec;
struct rspamd_mime_header *cur;
- guint cnt = 0, i = 0, ret = 0;
+ unsigned int cnt = 0, i = 0, ret = 0;
DL_COUNT(rh, cur, cnt);
}
if (re_class->type == RSPAMD_RE_RAWHEADER) {
- in = (const guchar *) cur->value;
+ in = (const unsigned char *) cur->value;
lenvec[i] = strlen(cur->value);
if (rspamd_fast_utf8_validate(in, lenvec[i]) != 0) {
}
}
else {
- in = (const guchar *) cur->decoded;
+ in = (const unsigned char *) cur->decoded;
/* Validate input^W^WNo need to validate as it is already valid */
if (!in) {
lenvec[i] = 0;
- scvec[i] = (guchar *) "";
+ scvec[i] = (unsigned char *) "";
continue;
}
/*
* Calculates the specified regexp for the specified class if it's not calculated
*/
-static guint
+static unsigned int
rspamd_re_cache_exec_re(struct rspamd_task *task,
struct rspamd_re_runtime *rt,
rspamd_regexp_t *re,
struct rspamd_re_class *re_class,
gboolean is_strong)
{
- guint ret = 0, i, re_id;
+ unsigned int ret = 0, i, re_id;
struct rspamd_mime_header *rh;
- const gchar *in;
- const guchar **scvec = NULL;
- guint *lenvec = NULL;
+ const char *in;
+ const unsigned char **scvec = NULL;
+ unsigned int *lenvec = NULL;
gboolean raw = FALSE, processed_hyperscan = FALSE;
struct rspamd_mime_text_part *text_part;
struct rspamd_mime_part *mime_part;
struct rspamd_url *url;
- guint len = 0, cnt = 0;
- const gchar *class_name;
+ unsigned int len = 0, cnt = 0;
+ const char *class_name;
class_name = rspamd_re_cache_type_to_string(re_class->type);
msg_debug_re_task("start check re type: %s: /%s/",
in = MESSAGE_FIELD(task, raw_headers_content).begin;
len = MESSAGE_FIELD(task, raw_headers_content).len;
ret = rspamd_re_cache_process_regexp_data(rt, re,
- task, (const guchar **) &in, &len, 1, raw, &processed_hyperscan);
+ task, (const unsigned char **) &in, &len, 1, raw, &processed_hyperscan);
msg_debug_re_task("checked allheader regexp: %s -> %d",
rspamd_regexp_get_pattern(re), ret);
break;
}
}
- scvec[i] = (guchar *) in;
+ scvec[i] = (unsigned char *) in;
lenvec[i] = len;
}
len = url->urllen;
if (len > 0 && !(url->flags & RSPAMD_URL_FLAG_IMAGE)) {
- scvec[i] = (guchar *) in;
+ scvec[i] = (unsigned char *) in;
lenvec[i++] = len;
}
});
len = url->urllen;
if (len > 0 && !(url->flags & RSPAMD_URL_FLAG_IMAGE)) {
- scvec[i] = (guchar *) in;
+ scvec[i] = (unsigned char *) in;
lenvec[i++] = len;
}
}
in = rspamd_url_user_unsafe(url);
len = url->userlen + 1 + url->hostlen;
- scvec[i] = (guchar *) in;
+ scvec[i] = (unsigned char *) in;
lenvec[i++] = len;
});
len = task->msg.len;
ret = rspamd_re_cache_process_regexp_data(rt, re, task,
- (const guchar **) &in, &len, 1, raw, &processed_hyperscan);
+ (const unsigned char **) &in, &len, 1, raw, &processed_hyperscan);
msg_debug_re_task("checked rawbody regexp: %s -> %d",
rspamd_regexp_get_pattern(re), ret);
break;
rh = rspamd_message_get_header_array(task, "Subject", FALSE);
if (rh) {
- scvec[0] = (guchar *) rh->decoded;
+ scvec[0] = (unsigned char *) rh->decoded;
lenvec[0] = strlen(rh->decoded);
}
else {
- scvec[0] = (guchar *) "";
+ scvec[0] = (unsigned char *) "";
lenvec[0] = 0;
}
PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, text_parts), i, text_part)
{
if (text_part->utf_stripped_content) {
- scvec[i + 1] = (guchar *) text_part->utf_stripped_content->data;
+ scvec[i + 1] = (unsigned char *) text_part->utf_stripped_content->data;
lenvec[i + 1] = text_part->utf_stripped_content->len;
if (!IS_TEXT_PART_UTF(text_part)) {
}
}
else {
- scvec[i + 1] = (guchar *) "";
+ scvec[i + 1] = (unsigned char *) "";
lenvec[i + 1] = 0;
}
}
text_part = g_ptr_array_index(MESSAGE_FIELD(task, text_parts), i);
if (text_part->parsed.len > 0) {
- scvec[i] = (guchar *) text_part->parsed.begin;
+ scvec[i] = (unsigned char *) text_part->parsed.begin;
lenvec[i] = text_part->parsed.len;
if (!IS_TEXT_PART_UTF(text_part)) {
}
}
else {
- scvec[i] = (guchar *) "";
+ scvec[i] = (unsigned char *) "";
lenvec[i] = 0;
}
}
case RSPAMD_RE_SELECTOR:
if (rspamd_re_cache_process_selector(task, rt,
re_class->type_data,
- (guchar ***) &scvec,
+ (unsigned char ***) &scvec,
&lenvec, &cnt)) {
ret = rspamd_re_cache_process_regexp_data(rt, re,
return rt->results[re_id];
}
-gint rspamd_re_cache_process(struct rspamd_task *task,
- rspamd_regexp_t *re,
- enum rspamd_re_type type,
- gconstpointer type_data,
- gsize datalen,
- gboolean is_strong)
+int rspamd_re_cache_process(struct rspamd_task *task,
+ rspamd_regexp_t *re,
+ enum rspamd_re_type type,
+ gconstpointer type_data,
+ gsize datalen,
+ gboolean is_strong)
{
uint64_t re_id;
struct rspamd_re_class *re_class;
struct rspamd_re_selector_result sr;
kh_foreach_value(rt->sel_cache, sr, {
- for (guint i = 0; i < sr.cnt; i++) {
+ for (unsigned int i = 0; i < sr.cnt; i++) {
g_free((gpointer) sr.scvec[i]);
}
return cache;
}
-guint rspamd_re_cache_set_limit(struct rspamd_re_cache *cache, guint limit)
+unsigned int rspamd_re_cache_set_limit(struct rspamd_re_cache *cache, unsigned int limit)
{
- guint old;
+ unsigned int old;
g_assert(cache != NULL);
return old;
}
-const gchar *
+const char *
rspamd_re_cache_type_to_string(enum rspamd_re_type type)
{
- const gchar *ret = "unknown";
+ const char *ret = "unknown";
switch (type) {
case RSPAMD_RE_HEADER:
}
#ifdef WITH_HYPERSCAN
-static gchar *
+static char *
rspamd_re_cache_hs_pattern_from_pcre(rspamd_regexp_t *re)
{
/*
* Workaround for bug in ragel 7.0.0.11
* https://github.com/intel/hyperscan/issues/133
*/
- const gchar *pat = rspamd_regexp_get_pattern(re);
- guint flags = rspamd_regexp_get_flags(re), esc_flags = RSPAMD_REGEXP_ESCAPE_RE;
- gchar *escaped;
+ const char *pat = rspamd_regexp_get_pattern(re);
+ unsigned int flags = rspamd_regexp_get_flags(re), esc_flags = RSPAMD_REGEXP_ESCAPE_RE;
+ char *escaped;
gsize esc_len;
if (flags & RSPAMD_REGEXP_FLAG_UTF) {
static gboolean
rspamd_re_cache_is_finite(struct rspamd_re_cache *cache,
- rspamd_regexp_t *re, gint flags, gdouble max_time)
+ rspamd_regexp_t *re, int flags, double max_time)
{
pid_t cld;
- gint status;
+ int status;
struct timespec ts;
hs_compile_error_t *hs_errors;
hs_database_t *test_db;
- gdouble wait_time;
- const gint max_tries = 10;
- gint tries = 0, rc;
+ double wait_time;
+ const int max_tries = 10;
+ int tries = 0, rc;
void (*old_hdl)(int);
wait_time = max_time / max_tries;
if (cld == 0) {
/* Try to compile pattern */
- gchar *pat = rspamd_re_cache_hs_pattern_from_pcre(re);
+ char *pat = rspamd_re_cache_hs_pattern_from_pcre(re);
if (hs_compile(pat,
flags | HS_FLAG_PREFILTER,
GHashTableIter it;
struct rspamd_re_cache *cache;
const char *cache_dir;
- gdouble max_time;
+ double max_time;
gboolean silent;
- guint total;
- void (*cb)(guint ncompiled, GError *err, void *cbd);
+ unsigned int total;
+ void (*cb)(unsigned int ncompiled, GError *err, void *cbd);
void *cbd;
};
GHashTableIter cit;
gpointer k, v;
struct rspamd_re_class *re_class;
- gchar path[PATH_MAX], npath[PATH_MAX];
+ char path[PATH_MAX], npath[PATH_MAX];
hs_database_t *test_db;
- gint fd, i, n, *hs_ids = NULL, pcre_flags, re_flags;
+ int fd, i, n, *hs_ids = NULL, pcre_flags, re_flags;
rspamd_cryptobox_fast_hash_state_t crc_st;
uint64_t crc;
rspamd_regexp_t *re;
hs_compile_error_t *hs_errors = NULL;
- guint *hs_flags = NULL;
+ unsigned int *hs_flags = NULL;
const hs_expr_ext_t **hs_exts = NULL;
- gchar **hs_pats = NULL;
- gchar *hs_serialized = NULL;
+ char **hs_pats = NULL;
+ char *hs_serialized = NULL;
gsize serialized_len;
struct iovec iov[7];
struct rspamd_re_cache *cache;
msg_info_re_cache(
"skip already valid class %s(%*s) to cache %6s, %d regexps",
rspamd_re_cache_type_to_string(re_class->type),
- (gint) re_class->type_len - 1,
+ (int) re_class->type_len - 1,
re_class->type_data,
re_class->hash,
n);
g_hash_table_iter_init(&cit, re_class->re);
n = g_hash_table_size(re_class->re);
- hs_flags = g_new0(guint, n);
- hs_ids = g_new0(guint, n);
+ hs_flags = g_new0(unsigned int, n);
+ hs_ids = g_new0(unsigned int, n);
hs_pats = g_new0(char *, n);
hs_exts = g_new0(const hs_expr_ext_t *, n);
i = 0;
hs_flags[i] |= HS_FLAG_SINGLEMATCH;
}
- gchar *pat = rspamd_re_cache_hs_pattern_from_pcre(re);
+ char *pat = rspamd_re_cache_hs_pattern_from_pcre(re);
if (hs_compile(pat,
hs_flags[i],
do { \
g_free(hs_flags); \
g_free(hs_ids); \
- for (guint j = 0; j < i; j++) { \
+ for (unsigned int j = 0; j < i; j++) { \
g_free(hs_pats[j]); \
} \
g_free(hs_pats); \
msg_info_re_cache(
"compiled class %s(%*s) to cache %6s, %d/%d regexps",
rspamd_re_cache_type_to_string(re_class->type),
- (gint) re_class->type_len - 1,
+ (int) re_class->type_len - 1,
re_class->type_data,
re_class->hash,
n,
- (gint) g_hash_table_size(re_class->re));
+ (int) g_hash_table_size(re_class->re));
}
else {
msg_info_re_cache(
rspamd_re_cache_type_to_string(re_class->type),
re_class->hash,
n,
- (gint) g_hash_table_size(re_class->re));
+ (int) g_hash_table_size(re_class->re));
}
cbdata->total += n;
"no suitable regular expressions %s (%d original): "
"remove temporary file %s",
rspamd_re_cache_type_to_string(re_class->type),
- (gint) g_hash_table_size(re_class->re),
+ (int) g_hash_table_size(re_class->re),
path);
CLEANUP_ALLOCATED(true);
#endif
-gint rspamd_re_cache_compile_hyperscan(struct rspamd_re_cache *cache,
- const char *cache_dir,
- gdouble max_time,
- gboolean silent,
- struct ev_loop *event_loop,
- void (*cb)(guint ncompiled, GError *err, void *cbd),
- void *cbd)
+int rspamd_re_cache_compile_hyperscan(struct rspamd_re_cache *cache,
+ const char *cache_dir,
+ double max_time,
+ gboolean silent,
+ struct ev_loop *event_loop,
+ void (*cb)(unsigned int ncompiled, GError *err, void *cbd),
+ void *cbd)
{
g_assert(cache != NULL);
g_assert(cache_dir != NULL);
#ifndef WITH_HYPERSCAN
return FALSE;
#else
- gint fd, n, ret;
- guchar magicbuf[RSPAMD_HS_MAGIC_LEN];
- const guchar *mb;
+ int fd, n, ret;
+ unsigned char magicbuf[RSPAMD_HS_MAGIC_LEN];
+ const unsigned char *mb;
GHashTableIter it;
gpointer k, v;
struct rspamd_re_class *re_class;
gsize len;
- const gchar *hash_pos;
+ const char *hash_pos;
hs_platform_info_t test_plt;
hs_database_t *test_db = NULL;
- guchar *map, *p, *end;
+ unsigned char *map, *p, *end;
rspamd_cryptobox_fast_hash_state_t crc_st;
uint64_t crc, valid_crc;
p = map + RSPAMD_HS_MAGIC_LEN + sizeof(test_plt);
end = map + len;
memcpy(&n, p, sizeof(n));
- p += sizeof(gint);
+ p += sizeof(int);
- if (n <= 0 || 2 * n * sizeof(gint) + /* IDs + flags */
+ if (n <= 0 || 2 * n * sizeof(int) + /* IDs + flags */
sizeof(uint64_t) + /* crc */
RSPAMD_HS_MAGIC_LEN + /* header */
sizeof(cache->plt) >
* <hyperscan blob>
*/
- memcpy(&crc, p + n * 2 * sizeof(gint), sizeof(crc));
+ memcpy(&crc, p + n * 2 * sizeof(int), sizeof(crc));
rspamd_cryptobox_fast_hash_init(&crc_st, 0xdeadbabe);
/* IDs */
- rspamd_cryptobox_fast_hash_update(&crc_st, p, n * sizeof(gint));
+ rspamd_cryptobox_fast_hash_update(&crc_st, p, n * sizeof(int));
/* Flags */
- rspamd_cryptobox_fast_hash_update(&crc_st, p + n * sizeof(gint),
- n * sizeof(gint));
+ rspamd_cryptobox_fast_hash_update(&crc_st, p + n * sizeof(int),
+ n * sizeof(int));
/* HS database */
- p += n * sizeof(gint) * 2 + sizeof(uint64_t);
+ p += n * sizeof(int) * 2 + sizeof(uint64_t);
rspamd_cryptobox_fast_hash_update(&crc_st, p, end - p);
valid_crc = rspamd_cryptobox_fast_hash_final(&crc_st);
#ifndef WITH_HYPERSCAN
return RSPAMD_HYPERSCAN_UNSUPPORTED;
#else
- gchar path[PATH_MAX];
- gint fd, i, n, *hs_ids = NULL, *hs_flags = NULL, total = 0, ret;
+ char path[PATH_MAX];
+ int fd, i, n, *hs_ids = NULL, *hs_flags = NULL, total = 0, ret;
GHashTableIter it;
gpointer k, v;
- guint8 *map, *p;
+ uint8_t *map, *p;
struct rspamd_re_class *re_class;
struct rspamd_re_cache_elt *elt;
struct stat st;
close(fd);
p = map + RSPAMD_HS_MAGIC_LEN + sizeof(cache->plt);
- n = *(gint *) p;
+ n = *(int *) p;
- if (n <= 0 || 2 * n * sizeof(gint) + /* IDs + flags */
+ if (n <= 0 || 2 * n * sizeof(int) + /* IDs + flags */
sizeof(uint64_t) + /* crc */
RSPAMD_HS_MAGIC_LEN + /* header */
sizeof(cache->plt) >
* specify that they should be matched using hyperscan
*/
for (i = 0; i < n; i++) {
- g_assert((gint) cache->re->len > hs_ids[i] && hs_ids[i] >= 0);
+ g_assert((int) cache->re->len > hs_ids[i] && hs_ids[i] >= 0);
elt = g_ptr_array_index(cache->re, hs_ids[i]);
if (hs_flags[i] & HS_FLAG_PREFILTER) {
}
void rspamd_re_cache_add_selector(struct rspamd_re_cache *cache,
- const gchar *sname,
- gint ref)
+ const char *sname,
+ int ref)
{
khiter_t k;
- k = kh_get(lua_selectors_hash, cache->selectors, (gchar *) sname);
+ k = kh_get(lua_selectors_hash, cache->selectors, (char *) sname);
if (k == kh_end(cache->selectors)) {
- gchar *cpy = g_strdup(sname);
- gint res;
+ char *cpy = g_strdup(sname);
+ int res;
k = kh_put(lua_selectors_hash, cache->selectors, cpy, &res);
struct rspamd_re_cache_stat {
uint64_t bytes_scanned;
uint64_t bytes_scanned_pcre;
- guint regexp_checked;
- guint regexp_matched;
- guint regexp_total;
- guint regexp_fast_cached;
+ unsigned int regexp_checked;
+ unsigned int regexp_matched;
+ unsigned int regexp_total;
+ unsigned int regexp_fast_cached;
};
/**
rspamd_re_cache_add(struct rspamd_re_cache *cache, rspamd_regexp_t *re,
enum rspamd_re_type type,
gconstpointer type_data, gsize datalen,
- gint lua_cbref);
+ int lua_cbref);
/**
* Replace regexp in the cache with another regexp
* @param datalen associated data length
* @param is_strong use case sensitive match when looking for headers
*/
-gint rspamd_re_cache_process(struct rspamd_task *task,
- rspamd_regexp_t *re,
- enum rspamd_re_type type,
- gconstpointer type_data,
- gsize datalen,
- gboolean is_strong);
+int rspamd_re_cache_process(struct rspamd_task *task,
+ rspamd_regexp_t *re,
+ enum rspamd_re_type type,
+ gconstpointer type_data,
+ gsize datalen,
+ gboolean is_strong);
int rspamd_re_cache_process_ffi(void *ptask,
void *pre,
/**
* Set limit for all regular expressions in the cache, returns previous limit
*/
-guint rspamd_re_cache_set_limit(struct rspamd_re_cache *cache, guint limit);
+unsigned int rspamd_re_cache_set_limit(struct rspamd_re_cache *cache, unsigned int limit);
/**
* Convert re type to a human readable string (constant one)
*/
-const gchar *rspamd_re_cache_type_to_string(enum rspamd_re_type type);
+const char *rspamd_re_cache_type_to_string(enum rspamd_re_type type);
/**
* Convert re type string to the type enum
/**
* Compile expressions to the hyperscan tree and store in the `cache_dir`
*/
-gint rspamd_re_cache_compile_hyperscan(struct rspamd_re_cache *cache,
- const char *cache_dir,
- gdouble max_time,
- gboolean silent,
- struct ev_loop *event_loop,
- void (*cb)(guint ncompiled, GError *err, void *cbd),
- void *cbd);
+int rspamd_re_cache_compile_hyperscan(struct rspamd_re_cache *cache,
+ const char *cache_dir,
+ double max_time,
+ gboolean silent,
+ struct ev_loop *event_loop,
+ void (*cb)(unsigned int ncompiled, GError *err, void *cbd),
+ void *cbd);
/**
* Returns TRUE if the specified file is valid hyperscan cache
* Registers lua selector in the cache
*/
void rspamd_re_cache_add_selector(struct rspamd_re_cache *cache,
- const gchar *sname, gint ref);
+ const char *sname, int ref);
#ifdef __cplusplus
}
redis_pool *pool;
conn_iter_t elt_pos;
ev_timer timeout;
- gchar tag[MEMPOOL_UID_LEN];
+ char tag[MEMPOOL_UID_LEN];
rspamd_redis_pool_connection_state state;
auto schedule_timeout() -> void;
redis_pool_elt(redis_pool_elt &&other) = default;
explicit redis_pool_elt(redis_pool *_pool,
- const gchar *_db, const gchar *_username,
- const gchar *_password,
+ const char *_db, const char *_username,
+ const char *_password,
const char *_ip, int _port)
: pool(_pool), ip(_ip), port(_port),
key(redis_pool_elt::make_key(_db, _username, _password, _ip, _port))
conn->elt_pos = std::prev(std::end(terminating));
}
- inline static auto make_key(const gchar *db, const gchar *username,
- const gchar *password, const char *ip, int port) -> redis_pool_key_t
+ inline static auto make_key(const char *db, const char *username,
+ const char *password, const char *ip, int port) -> redis_pool_key_t
{
rspamd_cryptobox_fast_hash_state_t st;
cfg = _cfg;
}
- auto new_connection(const gchar *db, const gchar *username,
- const gchar *password, const char *ip, int port) -> redisAsyncContext *;
+ auto new_connection(const char *db, const char *username,
+ const char *password, const char *ip, int port) -> redisAsyncContext *;
auto release_connection(redisAsyncContext *ctx,
enum rspamd_redis_pool_release_type how) -> void;
g_assert(conn->state != rspamd_redis_pool_connection_state::RSPAMD_REDIS_POOL_CONN_ACTIVE);
if (conn->ctx->err == REDIS_OK) {
/* Also check SO_ERROR */
- gint err;
- socklen_t len = sizeof(gint);
+ int err;
+ socklen_t len = sizeof(int);
if (getsockopt(conn->ctx->c.fd, SOL_SOCKET, SO_ERROR,
(void *) &err, &len) == -1) {
RSPAMD_UNREACHABLE;
}
-auto redis_pool::new_connection(const gchar *db, const gchar *username,
- const gchar *password, const char *ip, int port) -> redisAsyncContext *
+auto redis_pool::new_connection(const char *db, const char *username,
+ const char *password, const char *ip, int port) -> redisAsyncContext *
{
if (!wanna_die) {
struct redisAsyncContext *
rspamd_redis_pool_connect(void *p,
- const gchar *db, const gchar *username,
- const gchar *password, const char *ip, int port)
+ const char *db, const char *username,
+ const char *password, const char *ip, int port)
{
g_assert(p != NULL);
auto *pool = reinterpret_cast<class rspamd::redis_pool *>(p);
delete pool;
}
-const gchar *
+const char *
rspamd_redis_type_to_string(int type)
{
- const gchar *ret = "unknown";
+ const char *ret = "unknown";
switch (type) {
case REDIS_REPLY_STRING:
*/
struct redisAsyncContext *rspamd_redis_pool_connect(
void *pool,
- const gchar *db, const gchar *username, const gchar *password,
+ const char *db, const char *username, const char *password,
const char *ip, int port);
enum rspamd_redis_pool_release_type {
* @param type
* @return
*/
-const gchar *rspamd_redis_type_to_string(int type);
+const char *rspamd_redis_type_to_string(int type);
#ifdef __cplusplus
}
#include "unix-std.h"
#include "cfg_file_private.h"
-static const gchar rspamd_history_magic_old[] = {'r', 's', 'h', '1'};
+static const char rspamd_history_magic_old[] = {'r', 's', 'h', '1'};
/**
* Returns new roll history
* @return new structure
*/
struct roll_history *
-rspamd_roll_history_new(rspamd_mempool_t *pool, guint max_rows,
+rspamd_roll_history_new(rspamd_mempool_t *pool, unsigned int max_rows,
struct rspamd_config *cfg)
{
struct roll_history *history;
}
struct history_metric_callback_data {
- gchar *pos;
- gint remain;
+ char *pos;
+ int remain;
};
static void
{
struct history_metric_callback_data *cb = user_data;
struct rspamd_symbol_result *s = value;
- guint wr;
+ unsigned int wr;
if (s->flags & RSPAMD_SYMBOL_RESULT_IGNORED) {
return;
void rspamd_roll_history_update(struct roll_history *history,
struct rspamd_task *task)
{
- guint row_num;
+ unsigned int row_num;
struct roll_history_row *row;
struct rspamd_scan_result *metric_res;
struct history_metric_callback_data cbdata;
* @return TRUE if history has been loaded
*/
gboolean
-rspamd_roll_history_load(struct roll_history *history, const gchar *filename)
+rspamd_roll_history_load(struct roll_history *history, const char *filename)
{
- gint fd;
+ int fd;
struct stat st;
- gchar magic[sizeof(rspamd_history_magic_old)];
+ char magic[sizeof(rspamd_history_magic_old)];
ucl_object_t *top;
const ucl_object_t *cur, *elt;
struct ucl_parser *parser;
struct roll_history_row *row;
- guint n, i;
+ unsigned int n, i;
g_assert(history != NULL);
if (history->disabled) {
* @return TRUE if history has been saved
*/
gboolean
-rspamd_roll_history_save(struct roll_history *history, const gchar *filename)
+rspamd_roll_history_save(struct roll_history *history, const char *filename)
{
- gint fd;
+ int fd;
FILE *fp;
ucl_object_t *obj, *elt;
- guint i;
+ unsigned int i;
struct roll_history_row *row;
struct ucl_emitter_functions *emitter_func;
struct roll_history_row {
ev_tstamp timestamp;
- gchar message_id[HISTORY_MAX_ID];
- gchar symbols[HISTORY_MAX_SYMBOLS];
- gchar user[HISTORY_MAX_USER];
- gchar from_addr[HISTORY_MAX_ADDR];
+ char message_id[HISTORY_MAX_ID];
+ char symbols[HISTORY_MAX_SYMBOLS];
+ char user[HISTORY_MAX_USER];
+ char from_addr[HISTORY_MAX_ADDR];
gsize len;
- gdouble scan_time;
- gdouble score;
- gdouble required_score;
- gint action;
- guint completed;
+ double scan_time;
+ double score;
+ double required_score;
+ int action;
+ unsigned int completed;
};
struct roll_history {
struct roll_history_row *rows;
gboolean disabled;
- guint nrows;
- guint cur_row;
+ unsigned int nrows;
+ unsigned int cur_row;
};
/**
* @return new structure
*/
struct roll_history *rspamd_roll_history_new(rspamd_mempool_t *pool,
- guint max_rows, struct rspamd_config *cfg);
+ unsigned int max_rows, struct rspamd_config *cfg);
/**
* Update roll history with data from task
* @return TRUE if history has been loaded
*/
gboolean rspamd_roll_history_load(struct roll_history *history,
- const gchar *filename);
+ const char *filename);
/**
* Save history to file
* @return TRUE if history has been saved
*/
gboolean rspamd_roll_history_save(struct roll_history *history,
- const gchar *filename);
+ const char *filename);
#ifdef __cplusplus
}
GQuark wrk_type;
pid_t wrk_pid;
gpointer ud;
- gint attached_fd;
+ int attached_fd;
GHashTable *pending_elts;
struct rspamd_control_reply_elt *prev, *next;
};
struct rspamd_control_session {
- gint fd;
+ int fd;
struct ev_loop *event_loop;
struct rspamd_main *rspamd_main;
struct rspamd_http_connection *conn;
struct rspamd_control_command cmd;
struct rspamd_control_reply_elt *replies;
rspamd_inet_addr_t *addr;
- guint replies_remain;
+ unsigned int replies_remain;
gboolean is_reply;
};
}
void rspamd_control_send_error(struct rspamd_control_session *session,
- gint code, const gchar *error_msg, ...)
+ int code, const char *error_msg, ...)
{
struct rspamd_http_message *msg;
rspamd_fstring_t *reply;
{
ucl_object_t *rep, *cur, *workers;
struct rspamd_control_reply_elt *elt;
- gchar tmpbuf[64];
- gdouble total_utime = 0, total_systime = 0;
+ char tmpbuf[64];
+ double total_utime = 0, total_systime = 0;
struct ucl_parser *parser;
- guint total_conns = 0;
+ unsigned int total_conns = 0;
rep = ucl_object_typed_new(UCL_OBJECT);
workers = ucl_object_typed_new(UCL_OBJECT);
}
static void
-rspamd_control_wrk_io(gint fd, short what, gpointer ud)
+rspamd_control_wrk_io(int fd, short what, gpointer ud)
{
struct rspamd_control_reply_elt *elt = ud;
struct rspamd_control_session *session;
- guchar fdspace[CMSG_SPACE(sizeof(int))];
+ unsigned char fdspace[CMSG_SPACE(sizeof(int))];
struct iovec iov;
struct msghdr msg;
gssize r;
static struct rspamd_control_reply_elt *
rspamd_control_broadcast_cmd(struct rspamd_main *rspamd_main,
struct rspamd_control_command *cmd,
- gint attached_fd,
+ int attached_fd,
rspamd_ev_cb handler,
gpointer ud,
pid_t except_pid)
struct msghdr msg;
struct cmsghdr *cmsg;
struct iovec iov;
- guchar fdspace[CMSG_SPACE(sizeof(int))];
+ unsigned char fdspace[CMSG_SPACE(sizeof(int))];
gssize r;
g_hash_table_iter_init(&it, rspamd_main->workers);
rspamd_control_ignore_io_handler, NULL, except_pid);
}
-static gint
+static int
rspamd_control_finish_handler(struct rspamd_http_connection *conn,
struct rspamd_http_message *msg)
{
struct rspamd_control_session *session = conn->ud;
rspamd_ftok_t srch;
- guint i;
+ unsigned int i;
gboolean found = FALSE;
struct rspamd_control_reply_elt *cur;
}
void rspamd_control_process_client_socket(struct rspamd_main *rspamd_main,
- gint fd, rspamd_inet_addr_t *addr)
+ int fd, rspamd_inet_addr_t *addr)
{
struct rspamd_control_session *session;
};
static void
-rspamd_control_default_cmd_handler(gint fd,
- gint attached_fd,
+rspamd_control_default_cmd_handler(int fd,
+ int attached_fd,
struct rspamd_worker_control_data *cd,
struct rspamd_control_command *cmd)
{
static struct rspamd_control_command cmd;
static struct msghdr msg;
static struct iovec iov;
- static guchar fdspace[CMSG_SPACE(sizeof(int))];
- gint rfd = -1;
+ static unsigned char fdspace[CMSG_SPACE(sizeof(int))];
+ int rfd = -1;
gssize r;
iov.iov_base = &cmd;
close(w->fd);
}
}
- else if (r < (gint) sizeof(cmd)) {
- msg_err("short read of control command: %d of %d", (gint) r,
- (gint) sizeof(cmd));
+ else if (r < (int) sizeof(cmd)) {
+ msg_err("short read of control command: %d of %d", (int) r,
+ (int) sizeof(cmd));
if (r == 0) {
ev_io_stop(cd->ev_base, &cd->io_ev);
close(w->fd);
}
}
- else if ((gint) cmd.type >= 0 && cmd.type < RSPAMD_CONTROL_MAX) {
+ else if ((int) cmd.type >= 0 && cmd.type < RSPAMD_CONTROL_MAX) {
if (msg.msg_controllen >= CMSG_LEN(sizeof(int))) {
rfd = *(int *) CMSG_DATA(CMSG_FIRSTHDR(&msg));
}
}
else {
- msg_err("unknown command: %d", (gint) cmd.type);
+ msg_err("unknown command: %d", (int) cmd.type);
}
}
struct rspamd_srv_reply_data {
struct rspamd_worker *worker;
struct rspamd_main *srv;
- gint fd;
+ int fd;
struct rspamd_srv_reply rep;
};
struct msghdr msg;
struct cmsghdr *cmsg;
static struct iovec iov;
- static guchar fdspace[CMSG_SPACE(sizeof(int))];
- gint *spair, rfd = -1;
- gchar *nid;
+ static unsigned char fdspace[CMSG_SPACE(sizeof(int))];
+ int *spair, rfd = -1;
+ char *nid;
struct rspamd_control_command wcmd;
gssize r;
}
else if (r != sizeof(cmd)) {
msg_err_main("cannot read from worker's srv pipe incomplete command: %d != %d; command = %s",
- (gint) r, (gint) sizeof(cmd), rspamd_srv_command_to_string(cmd.type));
+ (int) r, (int) sizeof(cmd), rspamd_srv_command_to_string(cmd.type));
}
else {
rdata = g_malloc0(sizeof(*rdata));
case RSPAMD_SRV_SOCKETPAIR:
spair = g_hash_table_lookup(rspamd_main->spairs, cmd.cmd.spair.pair_id);
if (spair == NULL) {
- spair = g_malloc(sizeof(gint) * 2);
+ spair = g_malloc(sizeof(int) * 2);
if (rspamd_socketpair(spair, cmd.cmd.spair.af) == -1) {
rdata->rep.reply.spair.code = errno;
struct rspamd_srv_request_data {
struct rspamd_worker *worker;
struct rspamd_srv_command cmd;
- gint attached_fd;
+ int attached_fd;
struct rspamd_srv_reply rep;
rspamd_srv_reply_handler handler;
ev_io io_ev;
struct rspamd_srv_request_data *rd = (struct rspamd_srv_request_data *) w->data;
struct msghdr msg;
struct iovec iov;
- guchar fdspace[CMSG_SPACE(sizeof(int))];
+ unsigned char fdspace[CMSG_SPACE(sizeof(int))];
struct cmsghdr *cmsg;
gssize r;
- gint rfd = -1;
+ int rfd = -1;
if (revents == EV_WRITE) {
/* Send request to server */
goto cleanup;
}
- if (r != (gint) sizeof(rd->rep)) {
+ if (r != (int) sizeof(rd->rep)) {
msg_err("cannot read from server pipe, invalid length: %d != %d; command = %s",
- (gint) r, (int) sizeof(rd->rep), rspamd_srv_command_to_string(rd->cmd.type));
+ (int) r, (int) sizeof(rd->rep), rspamd_srv_command_to_string(rd->cmd.type));
goto cleanup;
}
void rspamd_srv_send_command(struct rspamd_worker *worker,
struct ev_loop *ev_base,
struct rspamd_srv_command *cmd,
- gint attached_fd,
+ int attached_fd,
rspamd_srv_reply_handler handler,
gpointer ud)
{
}
enum rspamd_control_type
-rspamd_control_command_from_string(const gchar *str)
+rspamd_control_command_from_string(const char *str)
{
enum rspamd_control_type ret = RSPAMD_CONTROL_MAX;
return ret;
}
-const gchar *
+const char *
rspamd_control_command_to_string(enum rspamd_control_type cmd)
{
- const gchar *reply = "unknown";
+ const char *reply = "unknown";
switch (cmd) {
case RSPAMD_CONTROL_STAT:
return reply;
}
-const gchar *rspamd_srv_command_to_string(enum rspamd_srv_type cmd)
+const char *rspamd_srv_command_to_string(enum rspamd_srv_type cmd)
{
- const gchar *reply = "unknown";
+ const char *reply = "unknown";
switch (cmd) {
case RSPAMD_SRV_SOCKETPAIR:
enum rspamd_control_type type;
union {
struct {
- guint unused;
+ unsigned int unused;
} stat;
struct {
- guint unused;
+ unsigned int unused;
} reload;
struct {
- guint unused;
+ unsigned int unused;
} reresolve;
struct {
- guint unused;
+ unsigned int unused;
} recompile;
struct {
gboolean forced;
- gchar cache_dir[CONTROL_PATHLEN];
+ char cache_dir[CONTROL_PATHLEN];
} hs_loaded;
struct {
- gchar tag[32];
+ char tag[32];
gboolean alive;
pid_t sender;
} monitored_change;
enum rspamd_log_pipe_type type;
} log_pipe;
struct {
- guint unused;
+ unsigned int unused;
} fuzzy_stat;
struct {
- guint unused;
+ unsigned int unused;
} fuzzy_sync;
struct {
enum {
rspamd_child_terminated,
} what;
pid_t pid;
- guint additional;
+ unsigned int additional;
} child_change;
struct {
union {
enum rspamd_control_type type;
union {
struct {
- guint conns;
- gdouble uptime;
- gdouble utime;
- gdouble systime;
+ unsigned int conns;
+ double uptime;
+ double utime;
+ double systime;
gulong maxrss;
} stat;
struct {
- guint status;
+ unsigned int status;
} reload;
struct {
- guint status;
+ unsigned int status;
} reresolve;
struct {
- guint status;
+ unsigned int status;
} recompile;
struct {
- guint status;
+ unsigned int status;
} hs_loaded;
struct {
- guint status;
+ unsigned int status;
} monitored_change;
struct {
- guint status;
+ unsigned int status;
} log_pipe;
struct {
- guint status;
- gchar storage_id[MEMPOOL_UID_LEN];
+ unsigned int status;
+ char storage_id[MEMPOOL_UID_LEN];
} fuzzy_stat;
struct {
- guint status;
+ unsigned int status;
} fuzzy_sync;
struct {
- guint status;
+ unsigned int status;
} fuzzy_blocked;
} reply;
};
uint64_t id;
union {
struct {
- gint af;
- gchar pair_id[PAIR_ID_LEN];
- guint pair_num;
+ int af;
+ char pair_id[PAIR_ID_LEN];
+ unsigned int pair_num;
} spair;
struct {
gboolean forced;
- gchar cache_dir[CONTROL_PATHLEN];
+ char cache_dir[CONTROL_PATHLEN];
} hs_loaded;
struct {
- gchar tag[32];
+ char tag[32];
gboolean alive;
pid_t sender;
} monitored_change;
} state;
} on_fork;
struct {
- guint status;
+ unsigned int status;
/* TODO: add more fields */
} heartbeat;
struct {
- guint status;
+ unsigned int status;
} health;
/* Used when a worker loads a valid hyperscan file */
struct {
uint64_t id;
union {
struct {
- gint code;
+ int code;
} spair;
struct {
- gint forced;
+ int forced;
} hs_loaded;
struct {
- gint status;
+ int status;
};
struct {
enum rspamd_log_pipe_type type;
} log_pipe;
struct {
- gint status;
+ int status;
} on_fork;
struct {
- gint status;
+ int status;
} heartbeat;
struct {
- guint status;
- guint workers_count;
- guint scanners_count;
- guint workers_hb_lost;
+ unsigned int status;
+ unsigned int workers_count;
+ unsigned int scanners_count;
+ unsigned int workers_hb_lost;
} health;
struct {
int unused;
typedef gboolean (*rspamd_worker_control_handler)(struct rspamd_main *rspamd_main,
struct rspamd_worker *worker,
- gint fd,
- gint attached_fd,
+ int fd,
+ int attached_fd,
struct rspamd_control_command *cmd,
gpointer ud);
typedef void (*rspamd_srv_reply_handler)(struct rspamd_worker *worker,
- struct rspamd_srv_reply *rep, gint rep_fd,
+ struct rspamd_srv_reply *rep, int rep_fd,
gpointer ud);
/**
* Process client socket connection
*/
void rspamd_control_process_client_socket(struct rspamd_main *rspamd_main,
- gint fd, rspamd_inet_addr_t *addr);
+ int fd, rspamd_inet_addr_t *addr);
/**
* Register default handlers for a worker
void rspamd_srv_send_command(struct rspamd_worker *worker,
struct ev_loop *ev_base,
struct rspamd_srv_command *cmd,
- gint attached_fd,
+ int attached_fd,
rspamd_srv_reply_handler handler,
gpointer ud);
* @param str
* @return
*/
-enum rspamd_control_type rspamd_control_command_from_string(const gchar *str);
+enum rspamd_control_type rspamd_control_command_from_string(const char *str);
/**
* Returns command name from it's type
* @param cmd
* @return
*/
-const gchar *rspamd_control_command_to_string(enum rspamd_control_type cmd);
+const char *rspamd_control_command_to_string(enum rspamd_control_type cmd);
-const gchar *rspamd_srv_command_to_string(enum rspamd_srv_type cmd);
+const char *rspamd_srv_command_to_string(enum rspamd_srv_type cmd);
/**
* Used to cleanup pending events
*/
struct rspamd_symcache_item_stat {
struct rspamd_counter_data time_counter;
- gdouble avg_time;
- gdouble weight;
- guint hits;
+ double avg_time;
+ double weight;
+ unsigned int hits;
uint64_t total_hits;
struct rspamd_counter_data frequency_counter;
- gdouble avg_frequency;
- gdouble stddev_frequency;
+ double avg_frequency;
+ double stddev_frequency;
};
/**
* @param type
* @param parent
*/
-gint rspamd_symcache_add_symbol(struct rspamd_symcache *cache,
- const gchar *name,
- gint priority,
- symbol_func_t func,
- gpointer user_data,
- int type,
- gint parent);
+int rspamd_symcache_add_symbol(struct rspamd_symcache *cache,
+ const char *name,
+ int priority,
+ symbol_func_t func,
+ gpointer user_data,
+ int type,
+ int parent);
/**
* Adds augmentation to the symbol
* @param cbref
*/
void rspamd_symcache_set_peak_callback(struct rspamd_symcache *cache,
- gint cbref);
+ int cbref);
/**
* Add delayed condition to the specific symbol in cache. So symbol can be absent
* @return TRUE if condition has been added
*/
gboolean rspamd_symcache_add_condition_delayed(struct rspamd_symcache *cache,
- const gchar *sym,
- lua_State *L, gint cbref);
+ const char *sym,
+ lua_State *L, int cbref);
/**
* Find symbol in cache by id and returns its id resolving virtual symbols if
* @param name
* @return id of symbol or (-1) if a symbol has not been found
*/
-gint rspamd_symcache_find_symbol(struct rspamd_symcache *cache,
- const gchar *name);
+int rspamd_symcache_find_symbol(struct rspamd_symcache *cache,
+ const char *name);
/**
* Get statistics for a specific symbol
* @return
*/
gboolean rspamd_symcache_stat_symbol(struct rspamd_symcache *cache,
- const gchar *name,
- gdouble *frequency,
- gdouble *freq_stddev,
- gdouble *tm,
- guint *nhits);
+ const char *name,
+ double *frequency,
+ double *freq_stddev,
+ double *tm,
+ unsigned int *nhits);
/**
* Returns number of symbols registered in symbols cache
* @param cache
* @return number of symbols in the cache
*/
-guint rspamd_symcache_stats_symbols_count(struct rspamd_symcache *cache);
+unsigned int rspamd_symcache_stats_symbols_count(struct rspamd_symcache *cache);
/**
* Validate cache items against theirs weights defined in metrics
*/
gboolean rspamd_symcache_process_symbols(struct rspamd_task *task,
struct rspamd_symcache *cache,
- guint stage);
+ unsigned int stage);
/**
* Return statistics about the cache as ucl object (array of objects one per item)
*/
void rspamd_symcache_inc_frequency(struct rspamd_symcache *_cache,
struct rspamd_symcache_item *item,
- const gchar *sym_name);
+ const char *sym_name);
/**
* Add delayed dependency that is resolved on cache post-load routine
* @param to
*/
void rspamd_symcache_add_delayed_dependency(struct rspamd_symcache *cache,
- const gchar *from, const gchar *to);
+ const char *from, const char *to);
/**
* Get abstract callback data for a symbol (or its parent symbol)
* @return abstract callback data or NULL if symbol is absent or has no data attached
*/
struct rspamd_abstract_callback_data *rspamd_symcache_get_cbdata(
- struct rspamd_symcache *cache, const gchar *symbol);
+ struct rspamd_symcache *cache, const char *symbol);
/**
* Returns symbol's parent name (or symbol name itself)
* @param symbol
* @return
*/
-const gchar *rspamd_symcache_get_parent(struct rspamd_symcache *cache,
- const gchar *symbol);
+const char *rspamd_symcache_get_parent(struct rspamd_symcache *cache,
+ const char *symbol);
-guint rspamd_symcache_get_symbol_flags(struct rspamd_symcache *cache,
- const gchar *symbol);
+unsigned int rspamd_symcache_get_symbol_flags(struct rspamd_symcache *cache,
+ const char *symbol);
void rspamd_symcache_get_symbol_details(struct rspamd_symcache *cache,
- const gchar *symbol,
+ const char *symbol,
ucl_object_t *this_sym_ucl);
*/
gboolean rspamd_symcache_is_checked(struct rspamd_task *task,
struct rspamd_symcache *cache,
- const gchar *symbol);
+ const char *symbol);
/**
* Returns checksum for all cache items
*/
gboolean rspamd_symcache_is_symbol_enabled(struct rspamd_task *task,
struct rspamd_symcache *cache,
- const gchar *symbol);
+ const char *symbol);
/**
* Enable this symbol for task
*/
gboolean rspamd_symcache_enable_symbol(struct rspamd_task *task,
struct rspamd_symcache *cache,
- const gchar *symbol);
+ const char *symbol);
/**
* Enable this symbol for task
*/
gboolean rspamd_symcache_disable_symbol(struct rspamd_task *task,
struct rspamd_symcache *cache,
- const gchar *symbol);
+ const char *symbol);
/**
* Disable execution of a symbol or a pattern (a string enclosed in `//`) permanently
* @return
*/
void rspamd_symcache_disable_symbol_static(struct rspamd_symcache *cache,
- const gchar *symbol);
+ const char *symbol);
/**
* Add a symbol or a pattern to the list of explicitly and statically enabled symbols
* @param cache
* @return
*/
void rspamd_symcache_enable_symbol_static(struct rspamd_symcache *cache,
- const gchar *symbol);
+ const char *symbol);
/**
* Process specific function for each cache element (in order they are added)
/*
* Increase number of async events pending for an item
*/
-guint rspamd_symcache_item_async_inc_full(struct rspamd_task *task,
- struct rspamd_symcache_dynamic_item *item,
- const gchar *subsystem,
- const gchar *loc);
+unsigned int rspamd_symcache_item_async_inc_full(struct rspamd_task *task,
+ struct rspamd_symcache_dynamic_item *item,
+ const char *subsystem,
+ const char *loc);
#define rspamd_symcache_item_async_inc(task, item, subsystem) \
rspamd_symcache_item_async_inc_full(task, item, subsystem, G_STRLOC)
/*
* Decrease number of async events pending for an item, asserts if no events pending
*/
-guint rspamd_symcache_item_async_dec_full(struct rspamd_task *task,
- struct rspamd_symcache_dynamic_item *item,
- const gchar *subsystem,
- const gchar *loc);
+unsigned int rspamd_symcache_item_async_dec_full(struct rspamd_task *task,
+ struct rspamd_symcache_dynamic_item *item,
+ const char *subsystem,
+ const char *loc);
#define rspamd_symcache_item_async_dec(task, item, subsystem) \
rspamd_symcache_item_async_dec_full(task, item, subsystem, G_STRLOC)
*/
gboolean rspamd_symcache_item_async_dec_check_full(struct rspamd_task *task,
struct rspamd_symcache_dynamic_item *item,
- const gchar *subsystem,
- const gchar *loc);
+ const char *subsystem,
+ const char *loc);
#define rspamd_symcache_item_async_dec_check(task, item, subsystem) \
rspamd_symcache_item_async_dec_check_full(task, item, subsystem, G_STRLOC)
*/
void rspamd_symcache_disable_all_symbols(struct rspamd_task *task,
struct rspamd_symcache *cache,
- guint skip_mask);
+ unsigned int skip_mask);
/**
* Iterates over the list of the enabled composites calling specified function
* @param nids
*/
bool rspamd_symcache_set_allowed_settings_ids(struct rspamd_symcache *cache,
- const gchar *symbol,
+ const char *symbol,
const uint32_t *ids,
- guint nids);
+ unsigned int nids);
/**
* Sets denied settings ids for a symbol
* @param cache
* @param nids
*/
bool rspamd_symcache_set_forbidden_settings_ids(struct rspamd_symcache *cache,
- const gchar *symbol,
+ const char *symbol,
const uint32_t *ids,
- guint nids);
+ unsigned int nids);
/**
* Returns allowed ids for a symbol as a constant array
* @return
*/
const uint32_t *rspamd_symcache_get_allowed_settings_ids(struct rspamd_symcache *cache,
- const gchar *symbol,
- guint *nids);
+ const char *symbol,
+ unsigned int *nids);
/**
* Returns denied ids for a symbol as a constant array
* @return
*/
const uint32_t *rspamd_symcache_get_forbidden_settings_ids(struct rspamd_symcache *cache,
- const gchar *symbol,
- guint *nids);
+ const char *symbol,
+ unsigned int *nids);
/**
* @param item
* @return
*/
-gint rspamd_symcache_dyn_item_flags(struct rspamd_task *task,
- struct rspamd_symcache_dynamic_item *dyn_item);
-gint rspamd_symcache_item_flags(struct rspamd_symcache_item *item);
+int rspamd_symcache_dyn_item_flags(struct rspamd_task *task,
+ struct rspamd_symcache_dynamic_item *dyn_item);
+int rspamd_symcache_item_flags(struct rspamd_symcache_item *item);
/**
* Returns cache item name
* @param item
* @return
*/
-const gchar *rspamd_symcache_dyn_item_name(struct rspamd_task *task,
- struct rspamd_symcache_dynamic_item *dyn_item);
-const gchar *rspamd_symcache_item_name(struct rspamd_symcache_item *item);
+const char *rspamd_symcache_dyn_item_name(struct rspamd_task *task,
+ struct rspamd_symcache_dynamic_item *dyn_item);
+const char *rspamd_symcache_item_name(struct rspamd_symcache_item *item);
/**
* Returns the current item stat
struct spf_resolved_element {
GPtrArray *elts;
- gchar *cur_domain;
+ char *cur_domain;
gboolean redirected; /* Ignore level, it's redirected */
};
struct spf_record {
- gint nested;
- gint dns_requests;
- gint requests_inflight;
+ int nested;
+ int dns_requests;
+ int requests_inflight;
- guint ttl;
+ unsigned int ttl;
GPtrArray *resolved;
/* Array of struct spf_resolved_element */
- const gchar *sender;
- const gchar *sender_domain;
- const gchar *top_record;
- gchar *local_part;
+ const char *sender;
+ const char *sender_domain;
+ const char *top_record;
+ char *local_part;
struct rspamd_task *task;
spf_cb_t callback;
gpointer cbdata;
};
struct rspamd_spf_library_ctx {
- guint max_dns_nesting;
- guint max_dns_requests;
- guint min_cache_ttl;
+ unsigned int max_dns_nesting;
+ unsigned int max_dns_requests;
+ unsigned int min_cache_ttl;
gboolean disable_ipv6;
rspamd_lru_hash_t *spf_hash;
};
struct spf_record *rec;
struct spf_addr *addr;
struct spf_resolved_element *resolved;
- const gchar *ptr_host;
+ const char *ptr_host;
spf_action_t cur_action;
gboolean in_include;
};
}
static gboolean start_spf_parse(struct spf_record *rec,
- struct spf_resolved_element *resolved, gchar *begin);
+ struct spf_resolved_element *resolved, char *begin);
/* Determine spf mech */
static spf_mech_t
-check_spf_mech(const gchar *elt, gboolean *need_shift)
+check_spf_mech(const char *elt, gboolean *need_shift)
{
g_assert(elt != NULL);
}
}
-static const gchar *
+static const char *
rspamd_spf_dns_action_to_str(spf_action_t act)
{
const char *ret = "unknown";
static struct spf_addr *
rspamd_spf_new_addr(struct spf_record *rec,
- struct spf_resolved_element *resolved, const gchar *elt)
+ struct spf_resolved_element *resolved, const char *elt)
{
gboolean need_shift = FALSE;
struct spf_addr *naddr;
}
static struct spf_resolved_element *
-rspamd_spf_new_addr_list(struct spf_record *rec, const gchar *domain)
+rspamd_spf_new_addr_list(struct spf_record *rec, const char *domain)
{
struct spf_resolved_element *resolved;
{
struct spf_record *rec = r;
struct spf_resolved_element *elt;
- guint i;
+ unsigned int i;
if (rec) {
for (i = 0; i < rec->resolved->len; i++) {
rspamd_flatten_record_dtor(struct spf_resolved *r)
{
struct spf_addr *addr;
- guint i;
+ unsigned int i;
for (i = 0; i < r->elts->len; i++) {
addr = &g_array_index(r->elts, struct spf_addr, i);
{
struct spf_resolved_element *elt, *relt;
struct spf_addr *cur = NULL, taddr, *cur_addr;
- guint i;
+ unsigned int i;
if (addr) {
g_assert(addr->m.idx < rec->resolved->len);
return res;
}
-static gint
+static int
rspamd_spf_elts_cmp(gconstpointer a, gconstpointer b)
{
struct spf_addr *addr_a, *addr_b;
{
g_array_sort(rec->elts, rspamd_spf_elts_cmp);
- for (guint i = 0; i < rec->elts->len; i++) {
+ for (unsigned int i = 0; i < rec->elts->len; i++) {
struct spf_addr *cur_addr = &g_array_index(rec->elts, struct spf_addr, i);
if (cur_addr->flags & RSPAMD_SPF_FLAG_IPV6) {
t[2] = ((uint64_t) (cur_addr->mech)) << 48u;
t[2] |= cur_addr->m.dual.mask_v6;
- for (guint j = 0; j < G_N_ELEMENTS(t); j++) {
+ for (unsigned int j = 0; j < G_N_ELEMENTS(t); j++) {
rec->digest = mum_hash_step(rec->digest, t[j]);
}
}
static void
spf_record_addr_set(struct spf_addr *addr, gboolean allow_any)
{
- guchar fill;
+ unsigned char fill;
if (!(addr->flags & RSPAMD_SPF_FLAG_PROCESSED)) {
if (allow_any) {
LL_FOREACH(reply->entries, elt_data)
{
/* Adjust ttl if a resolved record has lower ttl than spf record itself */
- if ((guint) elt_data->ttl < rec->ttl) {
+ if ((unsigned int) elt_data->ttl < rec->ttl) {
msg_debug_spf("reducing ttl from %d to %d after DNS resolving",
rec->ttl, elt_data->ttl);
rec->ttl = elt_data->ttl;
* ip6-cidr-length = "/" 1*DIGIT
* dual-cidr-length = [ ip4-cidr-length ] [ "/" ip6-cidr-length ]
*/
-static const gchar *
+static const char *
parse_spf_domain_mask(struct spf_record *rec, struct spf_addr *addr,
struct spf_resolved_element *resolved,
gboolean allow_mask)
parse_ipv6_mask,
skip_garbage
} state = 0;
- const gchar *p = addr->spf_string, *host, *c;
- gchar *hostbuf;
- gchar t;
- guint16 cur_mask = 0;
+ const char *p = addr->spf_string, *host, *c;
+ char *hostbuf;
+ char t;
+ uint16_t cur_mask = 0;
host = resolved->cur_domain;
c = p;
struct spf_resolved_element *resolved, struct spf_addr *addr)
{
struct spf_dns_cb *cb;
- const gchar *host = NULL;
+ const char *host = NULL;
struct rspamd_task *task = rec->task;
CHECK_REC(rec);
struct spf_resolved_element *resolved, struct spf_addr *addr)
{
struct spf_dns_cb *cb;
- const gchar *host;
- gchar *ptr;
+ const char *host;
+ char *ptr;
struct rspamd_task *task = rec->task;
CHECK_REC(rec);
struct spf_resolved_element *resolved, struct spf_addr *addr)
{
struct spf_dns_cb *cb;
- const gchar *host;
+ const char *host;
struct rspamd_task *task = rec->task;
CHECK_REC(rec);
parse_spf_ip4(struct spf_record *rec, struct spf_addr *addr)
{
/* ip4:addr[/mask] */
- const gchar *semicolon, *slash;
+ const char *semicolon, *slash;
gsize len;
- gchar ipbuf[INET_ADDRSTRLEN + 1];
+ char ipbuf[INET_ADDRSTRLEN + 1];
uint32_t mask;
static const uint32_t min_valid_mask = 8;
}
if (slash) {
- gchar *end = NULL;
+ char *end = NULL;
mask = strtoul(slash + 1, &end, 10);
if (mask > 32) {
parse_spf_ip6(struct spf_record *rec, struct spf_addr *addr)
{
/* ip6:addr[/mask] */
- const gchar *semicolon, *slash;
+ const char *semicolon, *slash;
gsize len;
- gchar ipbuf[INET6_ADDRSTRLEN + 1];
+ char ipbuf[INET6_ADDRSTRLEN + 1];
uint32_t mask;
static const uint32_t min_valid_mask = 8;
}
if (slash) {
- gchar *end = NULL;
+ char *end = NULL;
mask = strtoul(slash + 1, &end, 10);
if (mask > 128) {
msg_notice_spf("invalid mask for ip6 element for %s: %s", addr->spf_string,
parse_spf_include(struct spf_record *rec, struct spf_addr *addr)
{
struct spf_dns_cb *cb;
- const gchar *domain;
+ const char *domain;
struct rspamd_task *task = rec->task;
CHECK_REC(rec);
struct spf_resolved_element *resolved, struct spf_addr *addr)
{
struct spf_dns_cb *cb;
- const gchar *domain;
+ const char *domain;
struct rspamd_task *task = rec->task;
CHECK_REC(rec);
parse_spf_exists(struct spf_record *rec, struct spf_addr *addr)
{
struct spf_dns_cb *cb;
- const gchar *host;
+ const char *host;
struct rspamd_task *task = rec->task;
struct spf_resolved_element *resolved;
}
static gsize
-rspamd_spf_split_elt(const gchar *val, gsize len, gint *pos,
- gsize poslen, gchar delim)
+rspamd_spf_split_elt(const char *val, gsize len, int *pos,
+ gsize poslen, char delim)
{
- const gchar *p, *end;
- guint cur_pos = 0, cur_st = 0, nsub = 0;
+ const char *p, *end;
+ unsigned int cur_pos = 0, cur_st = 0, nsub = 0;
p = val;
end = val + len;
}
static gsize
-rspamd_spf_process_substitution(const gchar *macro_value,
- gsize macro_len, guint ndelim, gchar delim, gboolean reversed,
- gchar *dest)
+rspamd_spf_process_substitution(const char *macro_value,
+ gsize macro_len, unsigned int ndelim, char delim, gboolean reversed,
+ char *dest)
{
- gchar *d = dest;
- const gchar canon_delim = '.';
- guint vlen, i;
- gint pos[49 * 2], tlen;
+ char *d = dest;
+ const char canon_delim = '.';
+ unsigned int vlen, i;
+ int pos[49 * 2], tlen;
if (!reversed && ndelim == 0 && delim == canon_delim) {
/* Trivial case */
return (d - dest);
}
-static const gchar *
+static const char *
expand_spf_macro(struct spf_record *rec, struct spf_resolved_element *resolved,
- const gchar *begin)
+ const char *begin)
{
- const gchar *p, *macro_value = NULL;
- gchar *c, *new, *tmp, delim = '.';
+ const char *p, *macro_value = NULL;
+ char *c, *new, *tmp, delim = '.';
gsize len = 0, macro_len = 0;
- gint state = 0, ndelim = 0;
- gchar ip_buf[64 + 1]; /* cannot use INET6_ADDRSTRLEN as we use ptr lookup */
+ int state = 0, ndelim = 0;
+ char ip_buf[64 + 1]; /* cannot use INET6_ADDRSTRLEN as we use ptr lookup */
gboolean need_expand = FALSE, reversed;
struct rspamd_task *task;
static gboolean
spf_process_element(struct spf_record *rec,
struct spf_resolved_element *resolved,
- const gchar *elt,
- const gchar **elts)
+ const char *elt,
+ const char **elts)
{
struct spf_addr *addr = NULL;
gboolean res = FALSE;
- const gchar *begin;
- gchar t;
+ const char *begin;
+ char t;
g_assert(elt != NULL);
g_assert(rec != NULL);
*/
gboolean ignore_redirect = FALSE;
- for (const gchar **tmp = elts; *tmp != NULL; tmp++) {
+ for (const char **tmp = elts; *tmp != NULL; tmp++) {
if (g_ascii_strcasecmp((*tmp) + 1, "all") == 0) {
ignore_redirect = TRUE;
break;
}
static void
-parse_spf_scopes(struct spf_record *rec, gchar **begin)
+parse_spf_scopes(struct spf_record *rec, char **begin)
{
for (;;) {
if (g_ascii_strncasecmp(*begin, SPF_SCOPE_PRA, sizeof(SPF_SCOPE_PRA) - 1) == 0) {
static gboolean
start_spf_parse(struct spf_record *rec, struct spf_resolved_element *resolved,
- gchar *begin)
+ char *begin)
{
- gchar **elts, **cur_elt;
+ char **elts, **cur_elt;
gsize len;
/* Skip spaces */
msg_debug_spf(
"spf error for domain %s: bad spf record start: %*s",
rec->sender_domain,
- (gint) len,
+ (int) len,
begin);
return FALSE;
cur_elt = elts;
while (*cur_elt) {
- spf_process_element(rec, resolved, *cur_elt, (const gchar **) elts);
+ spf_process_element(rec, resolved, *cur_elt, (const char **) elts);
cur_elt++;
}
return cred;
}
-const gchar *
+const char *
rspamd_spf_get_domain(struct rspamd_task *task)
{
- gchar *domain = NULL;
+ char *domain = NULL;
struct rspamd_spf_cred *cred;
cred = rspamd_spf_get_cred(task);
}
struct spf_resolved *
-_spf_record_ref(struct spf_resolved *flat, const gchar *loc)
+_spf_record_ref(struct spf_resolved *flat, const char *loc)
{
REF_RETAIN(flat);
return flat;
}
-void _spf_record_unref(struct spf_resolved *flat, const gchar *loc)
+void _spf_record_unref(struct spf_resolved *flat, const char *loc)
{
REF_RELEASE(flat);
}
-gchar *
+char *
spf_addr_mask_to_string(struct spf_addr *addr)
{
GString *res;
- gchar *s, ipstr[INET6_ADDRSTRLEN + 1];
+ char *s, ipstr[INET6_ADDRSTRLEN + 1];
if (addr->flags & RSPAMD_SPF_FLAG_ANY) {
res = g_string_new("any");
struct spf_addr *
spf_addr_match_task(struct rspamd_task *task, struct spf_resolved *rec)
{
- const guint8 *s, *d;
- guint af, mask, bmask, addrlen;
+ const uint8_t *s, *d;
+ unsigned int af, mask, bmask, addrlen;
struct spf_addr *selected = NULL, *addr, *any_addr = NULL;
- guint i;
+ unsigned int i;
if (task->from_addr == NULL) {
return FALSE;
d = rspamd_inet_address_get_hash_key(task->from_addr, &addrlen);
if (af == AF_INET6) {
- s = (const guint8 *) addr->addr6;
+ s = (const uint8_t *) addr->addr6;
mask = addr->m.dual.mask_v6;
}
else {
- s = (const guint8 *) addr->addr4;
+ s = (const uint8_t *) addr->addr4;
mask = addr->m.dual.mask_v4;
}
+/*
+ * Copyright 2024 Vsevolod Stakhov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
#ifndef RSPAMD_SPF_H
#define RSPAMD_SPF_H
SPF_NEUTRAL
} spf_mech_t;
-static inline gchar spf_mech_char(spf_mech_t mech)
+static inline char spf_mech_char(spf_mech_t mech)
{
switch (mech) {
case SPF_FAIL:
#define SPF_MIN_CACHE_TTL (60 * 5) /* 5 minutes */
struct spf_addr {
- guchar addr6[sizeof(struct in6_addr)];
- guchar addr4[sizeof(struct in_addr)];
+ unsigned char addr6[sizeof(struct in6_addr)];
+ unsigned char addr4[sizeof(struct in_addr)];
union {
struct {
- guint16 mask_v4;
- guint16 mask_v6;
+ uint16_t mask_v4;
+ uint16_t mask_v6;
} dual;
uint32_t idx;
} m;
- guint flags;
+ unsigned int flags;
spf_mech_t mech;
- gchar *spf_string;
+ char *spf_string;
struct spf_addr *prev, *next;
};
};
struct spf_resolved {
- gchar *domain;
- gchar *top_record;
- guint ttl;
- gint flags;
- gdouble timestamp;
+ char *domain;
+ char *top_record;
+ unsigned int ttl;
+ int flags;
+ double timestamp;
uint64_t digest;
GArray *elts; /* Flat list of struct spf_addr */
ref_entry_t ref; /* Refcounting */
};
struct rspamd_spf_cred {
- gchar *local_part;
- gchar *domain;
- gchar *sender;
+ char *local_part;
+ char *domain;
+ char *sender;
};
/*
/*
* Get a domain for spf for specified task
*/
-const gchar *rspamd_spf_get_domain(struct rspamd_task *task);
+const char *rspamd_spf_get_domain(struct rspamd_task *task);
struct rspamd_spf_cred *rspamd_spf_get_cred(struct rspamd_task *task);
/*
* Increase refcount
*/
-struct spf_resolved *_spf_record_ref(struct spf_resolved *rec, const gchar *loc);
+struct spf_resolved *_spf_record_ref(struct spf_resolved *rec, const char *loc);
#define spf_record_ref(rec) \
_spf_record_ref((rec), G_STRLOC)
/*
* Decrease refcount
*/
-void _spf_record_unref(struct spf_resolved *rec, const gchar *loc);
+void _spf_record_unref(struct spf_resolved *rec, const char *loc);
#define spf_record_unref(rec) \
_spf_record_unref((rec), G_STRLOC)
* @param addr
* @return
*/
-gchar *spf_addr_mask_to_string(struct spf_addr *addr);
+char *spf_addr_mask_to_string(struct spf_addr *addr);
/**
* Returns spf address that matches the specific task (or nil if not matched)
};
struct rspamd_ssl_connection {
- gint fd;
+ int fd;
enum rspamd_ssl_state state;
enum rspamd_ssl_shutdown shut;
gboolean verify_peer;
SSL *ssl;
struct rspamd_ssl_ctx *ssl_ctx;
- gchar *hostname;
+ char *hostname;
struct rspamd_io_ev *ev;
struct rspamd_io_ev *shut_ev;
struct ev_loop *event_loop;
rspamd_ssl_handler_t handler;
rspamd_ssl_error_handler_t err_handler;
gpointer handler_data;
- gchar log_tag[8];
+ char log_tag[8];
};
#define msg_debug_ssl(...) rspamd_conditional_debug_fast(NULL, NULL, \
RSPAMD_LOG_FUNC, \
__VA_ARGS__)
-static void rspamd_ssl_event_handler(gint fd, short what, gpointer ud);
+static void rspamd_ssl_event_handler(int fd, short what, gpointer ud);
INIT_LOG_MODULE(ssl)
data = (const char *) ASN1_STRING_data(altname->d.dNSName);
len = ASN1_STRING_length(altname->d.dNSName);
- if (len < 0 || len != (gint) strlen(data)) {
+ if (len < 0 || len != (int) strlen(data)) {
ret = FALSE;
break;
}
common_name_len + 1);
/* NUL bytes in CN? */
- if (common_name_len != (gint) strlen(common_name)) {
+ if (common_name_len != (int) strlen(common_name)) {
goto out;
}
}
static void
-rspamd_tls_set_error(gint retcode, const gchar *stage, GError **err)
+rspamd_tls_set_error(int retcode, const char *stage, GError **err)
{
GString *reason;
- gchar buf[120];
- gint err_code = 0;
+ char buf[120];
+ int err_code = 0;
reason = g_string_sized_new(sizeof(buf));
static void
rspamd_ssl_shutdown(struct rspamd_ssl_connection *conn)
{
- gint ret = 0, nret, retries;
- static const gint max_retries = 5;
+ int ret = 0, nret, retries;
+ static const int max_retries = 5;
/*
* Fucking openssl...
}
static void
-rspamd_ssl_event_handler(gint fd, short what, gpointer ud)
+rspamd_ssl_event_handler(int fd, short what, gpointer ud)
{
struct rspamd_ssl_connection *conn = ud;
- gint ret;
+ int ret;
GError *err = NULL;
if (what == EV_TIMER) {
struct rspamd_ssl_connection *
rspamd_ssl_connection_new(gpointer ssl_ctx, struct ev_loop *ev_base,
- gboolean verify_peer, const gchar *log_tag)
+ gboolean verify_peer, const char *log_tag)
{
struct rspamd_ssl_connection *conn;
struct rspamd_ssl_ctx *ctx = (struct rspamd_ssl_ctx *) ssl_ctx;
gboolean
-rspamd_ssl_connect_fd(struct rspamd_ssl_connection *conn, gint fd,
- const gchar *hostname, struct rspamd_io_ev *ev, ev_tstamp timeout,
+rspamd_ssl_connect_fd(struct rspamd_ssl_connection *conn, int fd,
+ const char *hostname, struct rspamd_io_ev *ev, ev_tstamp timeout,
rspamd_ssl_handler_t handler, rspamd_ssl_error_handler_t err_handler,
gpointer handler_data)
{
- gint ret;
+ int ret;
SSL_SESSION *session = NULL;
g_assert(conn != NULL);
}
/* We dup fd to allow graceful closing */
- gint nfd = dup(fd);
+ int nfd = dup(fd);
if (nfd == -1) {
return FALSE;
rspamd_ssl_read(struct rspamd_ssl_connection *conn, gpointer buf,
gsize buflen)
{
- gint ret;
+ int ret;
short what;
GError *err = NULL;
rspamd_ssl_write(struct rspamd_ssl_connection *conn, gconstpointer buf,
gsize buflen)
{
- gint ret;
+ int ret;
short what;
GError *err = NULL;
* Static is needed to avoid issue:
* https://github.com/openssl/openssl/issues/6865
*/
- static guchar ssl_buf[16384];
- guchar *p;
+ static unsigned char ssl_buf[16384];
+ unsigned char *p;
struct iovec *cur;
gsize i, remain;
{
struct rspamd_ssl_ctx *ret;
SSL_CTX *ssl_ctx;
- gint ssl_options;
- static const guint client_cache_size = 1024;
+ int ssl_options;
+ static const unsigned int client_cache_size = 1024;
rspamd_openssl_maybe_init();
OPENSSL_config(NULL);
#endif
if (RAND_status() == 0) {
- guchar seed[128];
+ unsigned char seed[128];
/* Try to use ottery to seed rand */
ottery_rand_bytes(seed, sizeof(seed));
struct rspamd_ssl_connection;
-typedef void (*rspamd_ssl_handler_t)(gint fd, short what, gpointer d);
+typedef void (*rspamd_ssl_handler_t)(int fd, short what, gpointer d);
typedef void (*rspamd_ssl_error_handler_t)(gpointer d, GError *err);
struct rspamd_ssl_connection *rspamd_ssl_connection_new(gpointer ssl_ctx,
struct ev_loop *ev_base,
gboolean verify_peer,
- const gchar *log_tag);
+ const char *log_tag);
/**
* Connects SSL session using the specified (connected) FD
* @param handler_data opaque data
* @return TRUE if a session has been connected
*/
-gboolean rspamd_ssl_connect_fd(struct rspamd_ssl_connection *conn, gint fd,
- const gchar *hostname, struct rspamd_io_ev *ev, ev_tstamp timeout,
+gboolean rspamd_ssl_connect_fd(struct rspamd_ssl_connection *conn, int fd,
+ const char *hostname, struct rspamd_io_ev *ev, ev_tstamp timeout,
rspamd_ssl_handler_t handler, rspamd_ssl_error_handler_t err_handler,
gpointer handler_data);
real_cache->save_items();
}
-gint rspamd_symcache_add_symbol(struct rspamd_symcache *cache,
- const gchar *name,
- gint priority,
- symbol_func_t func,
- gpointer user_data,
- int type,
- gint parent)
+int rspamd_symcache_add_symbol(struct rspamd_symcache *cache,
+ const char *name,
+ int priority,
+ symbol_func_t func,
+ gpointer user_data,
+ int type,
+ int parent)
{
auto *real_cache = C_API_SYMCACHE(cache);
return item->add_augmentation(*real_cache, augmentation, value);
}
-void rspamd_symcache_set_peak_callback(struct rspamd_symcache *cache, gint cbref)
+void rspamd_symcache_set_peak_callback(struct rspamd_symcache *cache, int cbref)
{
auto *real_cache = C_API_SYMCACHE(cache);
gboolean
rspamd_symcache_add_condition_delayed(struct rspamd_symcache *cache,
- const gchar *sym, lua_State *L, gint cbref)
+ const char *sym, lua_State *L, int cbref)
{
auto *real_cache = C_API_SYMCACHE(cache);
return TRUE;
}
-gint rspamd_symcache_find_symbol(struct rspamd_symcache *cache,
- const gchar *name)
+int rspamd_symcache_find_symbol(struct rspamd_symcache *cache,
+ const char *name)
{
auto *real_cache = C_API_SYMCACHE(cache);
gboolean
rspamd_symcache_stat_symbol(struct rspamd_symcache *cache,
- const gchar *name,
- gdouble *frequency,
- gdouble *freq_stddev,
- gdouble *tm,
- guint *nhits)
+ const char *name,
+ double *frequency,
+ double *freq_stddev,
+ double *tm,
+ unsigned int *nhits)
{
auto *real_cache = C_API_SYMCACHE(cache);
}
-guint rspamd_symcache_stats_symbols_count(struct rspamd_symcache *cache)
+unsigned int rspamd_symcache_stats_symbols_count(struct rspamd_symcache *cache)
{
auto *real_cache = C_API_SYMCACHE(cache);
return real_cache->get_stats_symbols_count();
}
void rspamd_symcache_add_delayed_dependency(struct rspamd_symcache *cache,
- const gchar *from, const gchar *to)
+ const char *from, const char *to)
{
auto *real_cache = C_API_SYMCACHE(cache);
real_cache->add_delayed_dependency(from, to);
}
-const gchar *
+const char *
rspamd_symcache_get_parent(struct rspamd_symcache *cache,
- const gchar *symbol)
+ const char *symbol)
{
auto *real_cache = C_API_SYMCACHE(cache);
return nullptr;
}
-const gchar *
+const char *
rspamd_symcache_item_name(struct rspamd_symcache_item *item)
{
auto *real_item = C_API_SYMCACHE_ITEM(item);
return real_item->get_name().c_str();
}
-gint rspamd_symcache_item_flags(struct rspamd_symcache_item *item)
+int rspamd_symcache_item_flags(struct rspamd_symcache_item *item)
{
auto *real_item = C_API_SYMCACHE_ITEM(item);
}
-const gchar *
+const char *
rspamd_symcache_dyn_item_name(struct rspamd_task *task,
struct rspamd_symcache_dynamic_item *dyn_item)
{
return static_item->get_name().c_str();
}
-gint rspamd_symcache_item_flags(struct rspamd_task *task,
- struct rspamd_symcache_dynamic_item *dyn_item)
+int rspamd_symcache_item_flags(struct rspamd_task *task,
+ struct rspamd_symcache_dynamic_item *dyn_item)
{
auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
auto *real_dyn_item = C_API_SYMCACHE_DYN_ITEM(dyn_item);
return static_item->get_flags();
}
-guint rspamd_symcache_get_symbol_flags(struct rspamd_symcache *cache,
- const gchar *symbol)
+unsigned int rspamd_symcache_get_symbol_flags(struct rspamd_symcache *cache,
+ const char *symbol)
{
auto *real_cache = C_API_SYMCACHE(cache);
}
void rspamd_symcache_get_symbol_details(struct rspamd_symcache *cache,
- const gchar *symbol,
+ const char *symbol,
ucl_object_t *this_sym_ucl)
{
auto *real_cache = C_API_SYMCACHE(cache);
}
bool rspamd_symcache_set_allowed_settings_ids(struct rspamd_symcache *cache,
- const gchar *symbol,
+ const char *symbol,
const uint32_t *ids,
- guint nids)
+ unsigned int nids)
{
auto *real_cache = C_API_SYMCACHE(cache);
}
bool rspamd_symcache_set_forbidden_settings_ids(struct rspamd_symcache *cache,
- const gchar *symbol,
+ const char *symbol,
const uint32_t *ids,
- guint nids)
+ unsigned int nids)
{
auto *real_cache = C_API_SYMCACHE(cache);
const uint32_t *
rspamd_symcache_get_allowed_settings_ids(struct rspamd_symcache *cache,
- const gchar *symbol,
- guint *nids)
+ const char *symbol,
+ unsigned int *nids)
{
auto *real_cache = C_API_SYMCACHE(cache);
const uint32_t *
rspamd_symcache_get_forbidden_settings_ids(struct rspamd_symcache *cache,
- const gchar *symbol,
- guint *nids)
+ const char *symbol,
+ unsigned int *nids)
{
auto *real_cache = C_API_SYMCACHE(cache);
void rspamd_symcache_disable_all_symbols(struct rspamd_task *task,
struct rspamd_symcache *_cache,
- guint skip_mask)
+ unsigned int skip_mask)
{
auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
gboolean
rspamd_symcache_disable_symbol(struct rspamd_task *task,
struct rspamd_symcache *cache,
- const gchar *symbol)
+ const char *symbol)
{
auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
auto *real_cache = C_API_SYMCACHE(cache);
gboolean
rspamd_symcache_enable_symbol(struct rspamd_task *task,
struct rspamd_symcache *cache,
- const gchar *symbol)
+ const char *symbol)
{
auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
auto *real_cache = C_API_SYMCACHE(cache);
}
void rspamd_symcache_disable_symbol_static(struct rspamd_symcache *cache,
- const gchar *symbol)
+ const char *symbol)
{
auto *real_cache = C_API_SYMCACHE(cache);
}
void rspamd_symcache_enable_symbol_static(struct rspamd_symcache *cache,
- const gchar *symbol)
+ const char *symbol)
{
auto *real_cache = C_API_SYMCACHE(cache);
gboolean
rspamd_symcache_is_checked(struct rspamd_task *task,
struct rspamd_symcache *cache,
- const gchar *symbol)
+ const char *symbol)
{
auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
auto *real_cache = C_API_SYMCACHE(cache);
gboolean
rspamd_symcache_is_symbol_enabled(struct rspamd_task *task,
struct rspamd_symcache *cache,
- const gchar *symbol)
+ const char *symbol)
{
auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
auto *real_cache = C_API_SYMCACHE(cache);
cache_runtime->set_profile_mode(true);
}
-guint rspamd_symcache_item_async_inc_full(struct rspamd_task *task,
- struct rspamd_symcache_dynamic_item *item,
- const gchar *subsystem,
- const gchar *loc)
+unsigned int rspamd_symcache_item_async_inc_full(struct rspamd_task *task,
+ struct rspamd_symcache_dynamic_item *item,
+ const char *subsystem,
+ const char *loc)
{
auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
auto *real_dyn_item = C_API_SYMCACHE_DYN_ITEM(item);
return ++real_dyn_item->async_events;
}
-guint rspamd_symcache_item_async_dec_full(struct rspamd_task *task,
- struct rspamd_symcache_dynamic_item *item,
- const gchar *subsystem,
- const gchar *loc)
+unsigned int rspamd_symcache_item_async_dec_full(struct rspamd_task *task,
+ struct rspamd_symcache_dynamic_item *item,
+ const char *subsystem,
+ const char *loc)
{
auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
auto *real_dyn_item = C_API_SYMCACHE_DYN_ITEM(item);
gboolean
rspamd_symcache_item_async_dec_check_full(struct rspamd_task *task,
struct rspamd_symcache_dynamic_item *item,
- const gchar *subsystem,
- const gchar *loc)
+ const char *subsystem,
+ const char *loc)
{
if (rspamd_symcache_item_async_dec_full(task, item, subsystem, loc) == 0) {
rspamd_symcache_finalize_item(task, item);
struct rspamd_abstract_callback_data *
rspamd_symcache_get_cbdata(struct rspamd_symcache *cache,
- const gchar *symbol)
+ const char *symbol)
{
auto *real_cache = C_API_SYMCACHE(cache);
gboolean
rspamd_symcache_process_symbols(struct rspamd_task *task,
struct rspamd_symcache *cache,
- guint stage)
+ unsigned int stage)
{
auto *real_cache = C_API_SYMCACHE(cache);
}
- if (cached_map->get_size() < (gint) sizeof(symcache_header)) {
+ if (cached_map->get_size() < (int) sizeof(symcache_header)) {
msg_info_cache("cannot use file %s, truncated: %z", cfg->cache_filename,
errno, strerror(errno));
return false;
auto symcache::add_dependency(int id_from, std::string_view to, int virtual_id_from) -> void
{
- g_assert(id_from >= 0 && id_from < (gint) items_by_id.size());
+ g_assert(id_from >= 0 && id_from < (int) items_by_id.size());
const auto &source = items_by_id[id_from];
g_assert(source.get() != nullptr);
if (virtual_id_from >= 0) {
- g_assert(virtual_id_from < (gint) items_by_id.size());
+ g_assert(virtual_id_from < (int) items_by_id.size());
/* We need that for settings id propagation */
const auto &vsource = items_by_id[virtual_id_from];
g_assert(vsource.get() != nullptr);
auto symcache_runtime::finalize_item(struct rspamd_task *task, cache_dynamic_item *dyn_item) -> void
{
/* Limit to consider a rule as slow (in milliseconds) */
- constexpr const gdouble slow_diff_limit = 300;
+ constexpr const double slow_diff_limit = 300;
auto *item = get_item_by_dynamic_item(dyn_item);
/* Sanity checks */
g_assert(items_inflight > 0);
{
struct rspamd_task *new_task;
rspamd_mempool_t *task_pool;
- guint flags = 0;
+ unsigned int flags = 0;
if (pool == NULL) {
task_pool = rspamd_mempool_new(rspamd_mempool_suggest_size(),
void rspamd_task_free(struct rspamd_task *task)
{
struct rspamd_email_address *addr;
- static guint free_iters = 0;
- guint i;
+ static unsigned int free_iters = 0;
+ unsigned int i;
if (task) {
debug_task("free pointer %p", task);
/* Perform more expensive cleanup cycle */
gsize allocated = 0, active = 0, metadata = 0,
resident = 0, mapped = 0, old_lua_mem = 0;
- gdouble t1, t2;
+ double t1, t2;
old_lua_mem = lua_gc(task->cfg->lua_state, LUA_GCCOUNT, 0);
t1 = rspamd_get_ticks(FALSE);
old_lua_mem, lua_gc(task->cfg->lua_state, LUA_GCCOUNT, 0),
(t2 - t1) * 1000.0);
free_iters = rspamd_time_jitter(0,
- (gdouble) task->cfg->full_gc_iters / 2);
+ (double) task->cfg->full_gc_iters / 2);
}
REF_RELEASE(task->cfg);
struct rspamd_task_map {
gpointer begin;
gulong len;
- gint fd;
+ int fd;
};
static void
gboolean
rspamd_task_load_message(struct rspamd_task *task,
- struct rspamd_http_message *msg, const gchar *start, gsize len)
+ struct rspamd_http_message *msg, const char *start, gsize len)
{
- guint control_len, r;
+ unsigned int control_len, r;
struct ucl_parser *parser;
ucl_object_t *control_obj;
- gchar filepath[PATH_MAX], *fp;
- gint fd, flen;
+ char filepath[PATH_MAX], *fp;
+ int fd, flen;
gulong offset = 0, shmem_size = 0;
rspamd_ftok_t *tok;
gpointer map;
struct stat st;
struct rspamd_task_map *m;
- const gchar *ft;
+ const char *ft;
#ifdef HAVE_SANE_SHMEM
ft = "shm";
}
}
- task->msg.begin = ((guchar *) map) + offset;
+ task->msg.begin = ((unsigned char *) map) + offset;
task->msg.len = shmem_size;
m = rspamd_mempool_alloc(task->task_pool, sizeof(*m));
m->begin = map;
ZSTD_DStream *zstream;
ZSTD_inBuffer zin;
ZSTD_outBuffer zout;
- guchar *out;
+ unsigned char *out;
gsize outlen, r;
gulong dict_id;
return TRUE;
}
-static guint
-rspamd_task_select_processing_stage(struct rspamd_task *task, guint stages)
+static unsigned int
+rspamd_task_select_processing_stage(struct rspamd_task *task, unsigned int stages)
{
- guint st, mask;
+ unsigned int st, mask;
mask = task->processed_stages;
}
gboolean
-rspamd_task_process(struct rspamd_task *task, guint stages)
+rspamd_task_process(struct rspamd_task *task, unsigned int stages)
{
- guint st;
+ unsigned int st;
gboolean ret = TRUE, all_done = TRUE;
GError *stat_error = NULL;
return task->from_envelope;
}
-static const gchar *
+static const char *
rspamd_task_cache_principal_recipient(struct rspamd_task *task,
- const gchar *rcpt, gsize len)
+ const char *rcpt, gsize len)
{
- gchar *rcpt_lc;
+ char *rcpt_lc;
if (rcpt == NULL) {
return NULL;
return rcpt_lc;
}
-const gchar *
+const char *
rspamd_task_get_principal_recipient(struct rspamd_task *task)
{
- const gchar *val;
+ const char *val;
struct rspamd_email_address *addr;
- guint i;
+ unsigned int i;
val = rspamd_mempool_get_variable(task->task_pool,
RSPAMD_MEMPOOL_PRINCIPAL_RECIPIENT);
gboolean
rspamd_learn_task_spam(struct rspamd_task *task,
gboolean is_spam,
- const gchar *classifier,
+ const char *classifier,
GError **err)
{
if (is_spam) {
/*
* Sort by symbol's score -> name
*/
-static gint
+static int
rspamd_task_compare_log_sym(gconstpointer a, gconstpointer b)
{
const struct rspamd_symbol_result *s1 = *(const struct rspamd_symbol_result **) a,
*s2 = *(const struct rspamd_symbol_result **) b;
- gdouble w1, w2;
+ double w1, w2;
w1 = fabs(s1->score);
return (w2 - w1) * 1000.0;
}
-static gint
+static int
rspamd_task_compare_log_group(gconstpointer a, gconstpointer b)
{
const struct rspamd_symbols_group *s1 = *(const struct rspamd_symbols_group **) a,
rspamd_task_log_metric_res(struct rspamd_task *task,
struct rspamd_log_format *lf)
{
- static gchar scorebuf[32];
+ static char scorebuf[32];
rspamd_ftok_t res = {.begin = NULL, .len = 0};
struct rspamd_scan_result *mres;
gboolean first = TRUE;
GPtrArray *sorted_symbols;
struct rspamd_action *act;
struct rspamd_symbols_group *gr;
- guint i, j;
+ unsigned int i, j;
khiter_t k;
- guint max_log_elts = task->cfg->log_task_max_elts;
+ unsigned int max_log_elts = task->cfg->log_task_max_elts;
mres = task->result;
act = rspamd_check_action_metric(task, NULL, NULL);
DL_FOREACH(sym->opts_head, opt)
{
rspamd_printf_fstring(&symbuf, "%*s;",
- (gint) opt->optlen, opt->option);
+ (int) opt->optlen, opt->option);
if (j >= max_log_elts && opt->next) {
rspamd_printf_fstring(&symbuf, "...;");
const rspamd_ftok_t *var, const rspamd_ftok_t *content)
{
rspamd_fstring_t *res = logbuf;
- const gchar *p, *c, *end;
+ const char *p, *c, *end;
if (content == NULL) {
/* Just output variable */
static rspamd_fstring_t *
rspamd_task_write_ialist(struct rspamd_task *task,
- GPtrArray *addrs, gint lim,
+ GPtrArray *addrs, int lim,
struct rspamd_log_format *lf,
rspamd_fstring_t *logbuf)
{
rspamd_fstring_t *res = logbuf, *varbuf;
rspamd_ftok_t var = {.begin = NULL, .len = 0};
struct rspamd_email_address *addr;
- gint i, nchars = 0, wr = 0, cur_chars;
+ int i, nchars = 0, wr = 0, cur_chars;
gboolean has_orig = FALSE;
- guint max_log_elts = task->cfg->log_task_max_elts;
+ unsigned int max_log_elts = task->cfg->log_task_max_elts;
if (addrs && lim <= 0) {
lim = addrs->len;
static rspamd_fstring_t *
rspamd_task_write_addr_list(struct rspamd_task *task,
- GPtrArray *addrs, gint lim,
+ GPtrArray *addrs, int lim,
struct rspamd_log_format *lf,
rspamd_fstring_t *logbuf)
{
rspamd_fstring_t *res = logbuf, *varbuf;
rspamd_ftok_t var = {.begin = NULL, .len = 0};
struct rspamd_email_address *addr;
- guint max_log_elts = task->cfg->log_task_max_elts;
- guint i;
+ unsigned int max_log_elts = task->cfg->log_task_max_elts;
+ unsigned int i;
if (lim <= 0) {
lim = addrs->len;
{
rspamd_fstring_t *res = logbuf;
rspamd_ftok_t var = {.begin = NULL, .len = 0};
- static gchar numbuf[128];
- static const gchar undef[] = "undef";
+ static char numbuf[128];
+ static const char undef[] = "undef";
switch (lf->type) {
/* String vars */
case RSPAMD_LOG_DIGEST:
if (task->message) {
var.len = rspamd_snprintf(numbuf, sizeof(numbuf), "%*xs",
- (gint) sizeof(MESSAGE_FIELD(task, digest)),
+ (int) sizeof(MESSAGE_FIELD(task, digest)),
MESSAGE_FIELD(task, digest));
var.begin = numbuf;
}
rspamd_fstring_t *logbuf;
struct rspamd_log_format *lf;
struct rspamd_task **ptask;
- const gchar *lua_str;
+ const char *lua_str;
gsize lua_str_len;
lua_State *L;
rspamd_fstring_free(logbuf);
}
-gdouble
+double
rspamd_task_get_required_score(struct rspamd_task *task, struct rspamd_scan_result *m)
{
if (m == NULL) {
}
}
- for (guint i = m->nactions; i-- > 0;) {
+ for (unsigned int i = m->nactions; i-- > 0;) {
struct rspamd_action_config *action_lim = &m->actions_config[i];
rspamd_ftok_t *
rspamd_task_get_request_header(struct rspamd_task *task,
- const gchar *name)
+ const char *name)
{
struct rspamd_request_header_chain *ret =
rspamd_task_get_request_header_multiple(task, name);
struct rspamd_request_header_chain *
rspamd_task_get_request_header_multiple(struct rspamd_task *task,
- const gchar *name)
+ const char *name)
{
struct rspamd_request_header_chain *ret = NULL;
rspamd_ftok_t srch;
khiter_t k;
- srch.begin = (gchar *) name;
+ srch.begin = (char *) name;
srch.len = strlen(name);
k = kh_get(rspamd_req_headers_hash, task->request_headers,
{
khiter_t k;
- gint res;
+ int res;
struct rspamd_request_header_chain *chain, *nchain;
k = kh_put(rspamd_req_headers_hash, task->request_headers,
}
-void rspamd_task_profile_set(struct rspamd_task *task, const gchar *key,
- gdouble value)
+void rspamd_task_profile_set(struct rspamd_task *task, const char *key,
+ double value)
{
GHashTable *tbl;
- gdouble *pval;
+ double *pval;
if (key == NULL) {
return;
}
}
-gdouble *
-rspamd_task_profile_get(struct rspamd_task *task, const gchar *key)
+double *
+rspamd_task_profile_get(struct rspamd_task *task, const char *key)
{
GHashTable *tbl;
- gdouble *pval = NULL;
+ double *pval = NULL;
tbl = rspamd_mempool_get_variable(task->task_pool, RSPAMD_MEMPOOL_PROFILE);
return FALSE;
}
-const gchar *
+const char *
rspamd_task_stage_name(enum rspamd_task_stage stg)
{
- const gchar *ret = "unknown stage";
+ const char *ret = "unknown stage";
switch (stg) {
case RSPAMD_TASK_STAGE_CONNECT:
void rspamd_worker_guard_handler(EV_P_ ev_io *w, int revents)
{
struct rspamd_task *task = (struct rspamd_task *) w->data;
- gchar fake_buf[1024];
+ char fake_buf[1024];
gssize r;
r = read(w->fd, fake_buf, sizeof(fake_buf));
struct rspamd_message;
struct rspamd_task_data_storage {
- const gchar *begin;
+ const char *begin;
gsize len;
- gchar *fpath;
+ char *fpath;
};
struct rspamd_request_header_chain {
__KHASH_TYPE(rspamd_req_headers_hash, rspamd_ftok_t *, struct rspamd_request_header_chain *);
struct rspamd_lua_cached_entry {
- gint ref;
- guint id;
+ int ref;
+ unsigned int id;
};
KHASH_INIT(rspamd_task_lua_cache, char *, struct rspamd_lua_cached_entry, 1, kh_str_hash_func, kh_str_hash_equal);
struct rspamd_task {
struct rspamd_worker *worker; /**< pointer to worker object */
enum rspamd_command cmd; /**< command */
- gint sock; /**< socket descriptor */
+ int sock; /**< socket descriptor */
uint32_t dns_requests; /**< number of DNS requests per this task */
uint32_t flags; /**< Bit flags */
uint32_t protocol_flags;
uint32_t processed_stages; /**< bits of stages that are processed */
- gchar *helo; /**< helo header value */
- gchar *queue_id; /**< queue id if specified */
+ char *helo; /**< helo header value */
+ char *queue_id; /**< queue id if specified */
rspamd_inet_addr_t *from_addr; /**< from addr for a task */
rspamd_inet_addr_t *client_addr; /**< address of connected socket */
- gchar *deliver_to; /**< address to deliver */
- gchar *auth_user; /**< SMTP authenticated user */
- const gchar *hostname; /**< hostname reported by MTA */
+ char *deliver_to; /**< address to deliver */
+ char *auth_user; /**< SMTP authenticated user */
+ const char *hostname; /**< hostname reported by MTA */
khash_t(rspamd_req_headers_hash) * request_headers; /**< HTTP headers in a request */
struct rspamd_task_data_storage msg; /**< message buffer */
struct rspamd_http_connection *http_conn; /**< HTTP server connection */
ucl_object_t *settings; /**< Settings applied to task */
struct rspamd_config_settings_elt *settings_elt; /**< preprocessed settings id elt */
- const gchar *classifier; /**< Classifier to learn (if needed) */
+ const char *classifier; /**< Classifier to learn (if needed) */
struct rspamd_lang_detector *lang_det; /**< Languages detector */
struct rspamd_message *message;
};
*/
gboolean rspamd_task_load_message(struct rspamd_task *task,
struct rspamd_http_message *msg,
- const gchar *start, gsize len);
+ const char *start, gsize len);
/**
* Process task
* @param task task to process
* @return task has been successfully parsed and processed
*/
-gboolean rspamd_task_process(struct rspamd_task *task, guint stages);
+gboolean rspamd_task_process(struct rspamd_task *task, unsigned int stages);
/**
* Return address of sender or NULL
* @param task
* @return
*/
-const gchar *rspamd_task_get_principal_recipient(struct rspamd_task *task);
+const char *rspamd_task_get_principal_recipient(struct rspamd_task *task);
/**
* Add a recipient for a task
* @param rcpt string representation of recipient address
* @return TRUE if an address has been parsed and added
*/
-gboolean rspamd_task_add_recipient(struct rspamd_task *task, const gchar *rcpt);
+gboolean rspamd_task_add_recipient(struct rspamd_task *task, const char *rcpt);
/**
* Learn specified statfile with message in a task
*/
gboolean rspamd_learn_task_spam(struct rspamd_task *task,
gboolean is_spam,
- const gchar *classifier,
+ const char *classifier,
GError **err);
/**
*/
struct rspamd_scan_result;
-gdouble rspamd_task_get_required_score(struct rspamd_task *task,
- struct rspamd_scan_result *m);
+double rspamd_task_get_required_score(struct rspamd_task *task,
+ struct rspamd_scan_result *m);
/**
* Returns the first header as value for a header
* @return
*/
rspamd_ftok_t *rspamd_task_get_request_header(struct rspamd_task *task,
- const gchar *name);
+ const char *name);
/**
* Returns all headers with the specific name
*/
struct rspamd_request_header_chain *rspamd_task_get_request_header_multiple(
struct rspamd_task *task,
- const gchar *name);
+ const char *name);
/**
* Adds a new request header to task (name and value should be mapped to fstring)
* @param key
* @param value
*/
-void rspamd_task_profile_set(struct rspamd_task *task, const gchar *key,
- gdouble value);
+void rspamd_task_profile_set(struct rspamd_task *task, const char *key,
+ double value);
/**
* Get value for a specific profiling key
* @param key
* @return
*/
-gdouble *rspamd_task_profile_get(struct rspamd_task *task, const gchar *key);
+double *rspamd_task_profile_get(struct rspamd_task *task, const char *key);
/**
* Sets finishing time for a task if not yet set
* @param stg
* @return
*/
-const gchar *rspamd_task_stage_name(enum rspamd_task_stage stg);
+const char *rspamd_task_stage_name(enum rspamd_task_stage stg);
/*
* Called on forced timeout
#include <unicode/ucnv.h>
typedef struct url_match_s {
- const gchar *m_begin;
+ const char *m_begin;
gsize m_len;
- const gchar *pattern;
- const gchar *prefix;
- const gchar *newline_pos;
- const gchar *prev_newline_pos;
+ const char *pattern;
+ const char *prefix;
+ const char *newline_pos;
+ const char *prev_newline_pos;
gboolean add_prefix;
- gchar st;
+ char st;
} url_match_t;
#define URL_MATCHER_FLAG_NOHTML (1u << 0u)
static const struct {
enum rspamd_url_protocol proto;
- const gchar *name;
+ const char *name;
gsize len;
} rspamd_url_protocols[] = {
{.proto = PROTOCOL_FILE,
.name = NULL,
.len = 0}};
struct url_matcher {
- const gchar *pattern;
- const gchar *prefix;
+ const char *pattern;
+ const char *prefix;
gboolean (*start)(struct url_callback_data *cb,
- const gchar *pos,
+ const char *pos,
url_match_t *match);
gboolean (*end)(struct url_callback_data *cb,
- const gchar *pos,
+ const char *pos,
url_match_t *match);
- gint flags;
+ int flags;
};
static gboolean url_file_start(struct url_callback_data *cb,
- const gchar *pos,
+ const char *pos,
url_match_t *match);
static gboolean url_file_end(struct url_callback_data *cb,
- const gchar *pos,
+ const char *pos,
url_match_t *match);
static gboolean url_web_start(struct url_callback_data *cb,
- const gchar *pos,
+ const char *pos,
url_match_t *match);
static gboolean url_web_end(struct url_callback_data *cb,
- const gchar *pos,
+ const char *pos,
url_match_t *match);
static gboolean url_tld_start(struct url_callback_data *cb,
- const gchar *pos,
+ const char *pos,
url_match_t *match);
static gboolean url_tld_end(struct url_callback_data *cb,
- const gchar *pos,
+ const char *pos,
url_match_t *match);
static gboolean url_email_start(struct url_callback_data *cb,
- const gchar *pos,
+ const char *pos,
url_match_t *match);
static gboolean url_email_end(struct url_callback_data *cb,
- const gchar *pos,
+ const char *pos,
url_match_t *match);
static gboolean url_tel_start(struct url_callback_data *cb,
- const gchar *pos,
+ const char *pos,
url_match_t *match);
static gboolean url_tel_end(struct url_callback_data *cb,
- const gchar *pos,
+ const char *pos,
url_match_t *match);
struct url_matcher static_matchers[] = {
0}};
struct rspamd_url_flag_name {
- const gchar *name;
- gint flag;
- gint hash;
+ const char *name;
+ int flag;
+ int hash;
} url_flag_names[] = {
{"phished", RSPAMD_URL_FLAG_PHISHED, -1},
{"numeric", RSPAMD_URL_FLAG_NUMERIC, -1},
rspamd_url_host_hash, rspamd_urls_host_cmp);
struct url_callback_data {
- const gchar *begin;
- gchar *url_str;
+ const char *begin;
+ char *url_str;
rspamd_mempool_t *pool;
- gint len;
+ int len;
enum rspamd_url_find_type how;
gboolean prefix_added;
- guint newline_idx;
+ unsigned int newline_idx;
GArray *matchers;
GPtrArray *newlines;
- const gchar *start;
- const gchar *fin;
- const gchar *end;
- const gchar *last_at;
+ const char *start;
+ const char *fin;
+ const char *end;
+ const char *last_at;
url_insert_function func;
void *funcd;
};
IS_URLSAFE | IS_DOMAIN, IS_URLSAFE | IS_DOMAIN, IS_URLSAFE | IS_DOMAIN,
IS_URLSAFE | IS_DOMAIN};
-#define is_lwsp(x) ((url_scanner_table[(guchar) (x)] & IS_LWSP) != 0)
-#define is_mailsafe(x) ((url_scanner_table[(guchar) (x)] & (IS_MAILSAFE)) != 0)
-#define is_domain(x) ((url_scanner_table[(guchar) (x)] & IS_DOMAIN) != 0)
-#define is_urlsafe(x) ((url_scanner_table[(guchar) (x)] & (IS_URLSAFE)) != 0)
+#define is_lwsp(x) ((url_scanner_table[(unsigned char) (x)] & IS_LWSP) != 0)
+#define is_mailsafe(x) ((url_scanner_table[(unsigned char) (x)] & (IS_MAILSAFE)) != 0)
+#define is_domain(x) ((url_scanner_table[(unsigned char) (x)] & IS_DOMAIN) != 0)
+#define is_urlsafe(x) ((url_scanner_table[(unsigned char) (x)] & (IS_URLSAFE)) != 0)
-const gchar *
+const char *
rspamd_url_strerror(int err)
{
switch (err) {
}
static gboolean
-rspamd_url_parse_tld_file(const gchar *fname,
+rspamd_url_parse_tld_file(const char *fname,
struct url_match_scanner *scanner)
{
FILE *f;
struct url_matcher m;
- gchar *linebuf = NULL, *p;
+ char *linebuf = NULL, *p;
gsize buflen = 0;
gssize r;
- gint flags;
+ int flags;
f = fopen(fname, "r");
static void
rspamd_url_add_static_matchers(struct url_match_scanner *sc)
{
- gint n = G_N_ELEMENTS(static_matchers), i;
+ int n = G_N_ELEMENTS(static_matchers), i;
for (i = 0; i < n; i++) {
if (static_matchers[i].flags & URL_MATCHER_FLAG_REGEXP) {
}
}
-void rspamd_url_init(const gchar *tld_file)
+void rspamd_url_init(const char *tld_file)
{
GError *err = NULL;
gboolean ret = TRUE;
}
/* Generate hashes for flags */
- for (gint i = 0; i < G_N_ELEMENTS(url_flag_names); i++) {
+ for (int i = 0; i < G_N_ELEMENTS(url_flag_names); i++) {
url_flag_names[i].hash =
rspamd_cryptobox_fast_hash_specific(RSPAMD_CRYPTOBOX_HASHFAST_INDEPENDENT,
url_flag_names[i].name,
strlen(url_flag_names[i].name), 0);
}
/* Ensure that we have no hashes collisions O(N^2) but this array is small */
- for (gint i = 0; i < G_N_ELEMENTS(url_flag_names) - 1; i++) {
- for (gint j = i + 1; j < G_N_ELEMENTS(url_flag_names); j++) {
+ for (int i = 0; i < G_N_ELEMENTS(url_flag_names) - 1; i++) {
+ for (int j = i + 1; j < G_N_ELEMENTS(url_flag_names); j++) {
if (url_flag_names[i].hash == url_flag_names[j].hash) {
msg_err("collision: both %s and %s map to %d",
url_flag_names[i].name, url_flag_names[j].name,
} while (0)
static bool
-is_url_start(gchar c)
+is_url_start(char c)
{
if (c == '(' ||
c == '{' ||
}
static bool
-is_url_end(gchar c)
+is_url_end(char c)
{
if (c == ')' ||
c == '}' ||
return FALSE;
}
-static const guint max_domain_length = 253;
-static const guint max_dns_label = 63;
-static const guint max_email_user = 64;
+static const unsigned int max_domain_length = 253;
+static const unsigned int max_dns_label = 63;
+static const unsigned int max_email_user = 64;
-static gint
+static int
rspamd_mailto_parse(struct http_parser_url *u,
- const gchar *str, gsize len,
- gchar const **end,
- enum rspamd_url_parse_flags parse_flags, guint *flags)
+ const char *str, gsize len,
+ char const **end,
+ enum rspamd_url_parse_flags parse_flags, unsigned int *flags)
{
- const gchar *p = str, *c = str, *last = str + len;
- gchar t;
- gint ret = 1;
+ const char *p = str, *c = str, *last = str + len;
+ char t;
+ int ret = 1;
enum {
parse_mailto,
parse_slash,
return ret;
}
-static gint
+static int
rspamd_telephone_parse(struct http_parser_url *u,
- const gchar *str, gsize len,
- gchar const **end,
+ const char *str, gsize len,
+ char const **end,
enum rspamd_url_parse_flags parse_flags,
- guint *flags)
+ unsigned int *flags)
{
enum {
parse_protocol,
parse_phone,
} st = parse_protocol;
- const gchar *p = str, *c = str, *last = str + len;
- gchar t;
- gint ret = 1, i;
+ const char *p = str, *c = str, *last = str + len;
+ char t;
+ int ret = 1, i;
UChar32 uc;
if (u != NULL) {
return ret;
}
-static gint
-rspamd_web_parse(struct http_parser_url *u, const gchar *str, gsize len,
- gchar const **end,
+static int
+rspamd_web_parse(struct http_parser_url *u, const char *str, gsize len,
+ char const **end,
enum rspamd_url_parse_flags parse_flags,
- guint *flags)
+ unsigned int *flags)
{
- const gchar *p = str, *c = str, *last = str + len, *slash = NULL,
- *password_start = NULL, *user_start = NULL;
- gchar t = 0;
+ const char *p = str, *c = str, *last = str + len, *slash = NULL,
+ *password_start = NULL, *user_start = NULL;
+ char t = 0;
UChar32 uc;
glong pt;
- gint ret = 1;
+ int ret = 1;
gboolean user_seen = FALSE;
enum {
parse_protocol,
}
else if (*p != '.' && *p != '-' && *p != '_' && *p != '%') {
if (*p & 0x80) {
- guint i = 0;
+ unsigned int i = 0;
- U8_NEXT(((const guchar *) p), i, last - p, uc);
+ U8_NEXT(((const unsigned char *) p), i, last - p, uc);
if (uc < 0) {
/* Bad utf8 */
break;
case parse_port_password:
if (g_ascii_isdigit(t)) {
- const gchar *tmp = p;
+ const char *tmp = p;
while (tmp < last) {
if (!g_ascii_isdigit(*tmp)) {
#undef SET_U
-static gint
+static int
rspamd_tld_trie_callback(struct rspamd_multipattern *mp,
- guint strnum,
- gint match_start,
- gint match_pos,
- const gchar *text,
+ unsigned int strnum,
+ int match_start,
+ int match_pos,
+ const char *text,
gsize len,
void *context)
{
struct url_matcher *matcher;
- const gchar *start, *pos, *p;
+ const char *start, *pos, *p;
struct rspamd_url *url = context;
- gint ndots;
+ int ndots;
matcher = &g_array_index(url_scanner->matchers_full, struct url_matcher,
strnum);
p = pos - 1;
start = rspamd_url_host_unsafe(url);
- if (*pos != '.' || match_pos != (gint) url->hostlen) {
+ if (*pos != '.' || match_pos != (int) url->hostlen) {
/* Something weird has been found */
- if (match_pos == (gint) url->hostlen - 1) {
+ if (match_pos == (int) url->hostlen - 1) {
pos = rspamd_url_host_unsafe(url) + match_pos;
if (*pos == '.') {
/* This is dot at the end of domain */
rspamd_url_regen_from_inet_addr(struct rspamd_url *uri, const void *addr, int af,
rspamd_mempool_t *pool)
{
- gchar *strbuf, *p;
- const gchar *start_offset;
+ char *strbuf, *p;
+ const char *start_offset;
gsize slen = uri->urllen - uri->hostlen;
goffset r = 0;
/* Allocate new string to build it from IP */
strbuf = rspamd_mempool_alloc(pool, slen + 1);
r += rspamd_snprintf(strbuf + r, slen - r, "%*s",
- (gint) (uri->hostshift),
+ (int) (uri->hostshift),
uri->string);
uri->hostshift = r;
p = strbuf + r;
start_offset = p + 1;
r += rspamd_snprintf(strbuf + r, slen - r, "/%*s",
- (gint) uri->datalen,
+ (int) uri->datalen,
rspamd_url_data_unsafe(uri));
uri->datashift = start_offset - strbuf;
}
p = strbuf + r;
start_offset = p + 1;
r += rspamd_snprintf(strbuf + r, slen - r, "?%*s",
- (gint) uri->querylen,
+ (int) uri->querylen,
rspamd_url_query_unsafe(uri));
uri->queryshift = start_offset - strbuf;
}
p = strbuf + r;
start_offset = p + 1;
r += rspamd_snprintf(strbuf + r, slen - r, "#%*s",
- (gint) uri->fragmentlen,
+ (int) uri->fragmentlen,
rspamd_url_fragment_unsafe(uri));
uri->fragmentshift = start_offset - strbuf;
}
static gboolean
rspamd_url_maybe_regenerate_from_ip(struct rspamd_url *uri, rspamd_mempool_t *pool)
{
- const gchar *p, *end, *c;
- gchar *errstr;
+ const char *p, *end, *c;
+ char *errstr;
struct in_addr in4;
struct in6_addr in6;
gboolean ret = FALSE, check_num = TRUE;
}
else {
/* Heuristics for broken urls */
- gchar buf[INET6_ADDRSTRLEN + 1];
+ char buf[INET6_ADDRSTRLEN + 1];
/* Try also numeric notation */
c = p;
n = 0;
while (p <= end && check_num) {
if (shift < 32 &&
((*p == '.' && dots < 3) || (p == end && dots <= 3))) {
- if (p - c + 1 >= (gint) sizeof(buf)) {
+ if (p - c + 1 >= (int) sizeof(buf)) {
msg_debug_pool("invalid numeric url %*.s...: too long",
INET6_ADDRSTRLEN, c);
return FALSE;
uri->flags |= RSPAMD_URL_FLAG_OBSCURED;
ret = TRUE;
}
- else if (end - c > (gint) sizeof(buf) - 1) {
+ else if (end - c > (int) sizeof(buf) - 1) {
rspamd_strlcpy(buf, c, end - c + 1);
if (inet_pton(AF_INET6, buf, &in6) == 1) {
rspamd_url_shift(struct rspamd_url *uri, gsize nlen,
enum http_parser_url_fields field)
{
- guint old_shift, shift = 0;
- gint remain;
+ unsigned int old_shift, shift = 0;
+ int remain;
/* Shift remaining data */
switch (field) {
static void
rspamd_telephone_normalise_inplace(struct rspamd_url *uri)
{
- gchar *t, *h, *end;
- gint i = 0, w, orig_len;
+ char *t, *h, *end;
+ int i = 0, w, orig_len;
UChar32 uc;
t = rspamd_url_host_unsafe(uri);
static bool
rspamd_url_remove_dots(struct rspamd_url *uri)
{
- const gchar *hstart = rspamd_url_host_unsafe(uri);
- gchar *t;
+ const char *hstart = rspamd_url_host_unsafe(uri);
+ char *t;
UChar32 uc;
- gint i = 0, hlen;
+ int i = 0, hlen;
bool ret = false;
if (uri->hostlen == 0) {
t = rspamd_url_host_unsafe(uri);
while (i < hlen) {
- gint prev_i = i;
+ int prev_i = i;
U8_NEXT(hstart, i, hlen, uc);
if (is_idna_label_dot(uc)) {
enum uri_errno
rspamd_url_parse(struct rspamd_url *uri,
- gchar *uristring, gsize len,
+ char *uristring, gsize len,
rspamd_mempool_t *pool,
enum rspamd_url_parse_flags parse_flags)
{
struct http_parser_url u;
- gchar *p;
- const gchar *end;
- guint complen, ret, flags = 0;
+ char *p;
+ const char *end;
+ unsigned int complen, ret, flags = 0;
gsize unquoted_len = 0;
memset(uri, 0, sizeof(*uri));
return URI_ERRNO_BAD_FORMAT;
}
- if (end > uristring && (guint) (end - uristring) != len) {
+ if (end > uristring && (unsigned int) (end - uristring) != len) {
len = end - uristring;
}
uri->urllen = len;
uri->flags = flags;
- for (guint i = 0; i < UF_MAX; i++) {
+ for (unsigned int i = 0; i < UF_MAX; i++) {
if (u.field_set & (1 << i)) {
- guint shift = u.field_data[i].off;
+ unsigned int shift = u.field_data[i].off;
complen = u.field_data[i].len;
if (complen >= G_MAXUINT16) {
if (uri->protocol & (PROTOCOL_HTTP | PROTOCOL_HTTPS | PROTOCOL_MAILTO | PROTOCOL_FTP | PROTOCOL_FILE)) {
/* Ensure that hostname starts with something sane (exclude numeric urls) */
- const gchar *host = rspamd_url_host_unsafe(uri);
+ const char *host = rspamd_url_host_unsafe(uri);
if (!(is_domain_start(host[0]) || host[0] == ':')) {
return URI_ERRNO_BAD_FORMAT;
if (uri->protocol & (PROTOCOL_HTTP | PROTOCOL_HTTPS | PROTOCOL_FTP) &&
uri->protocollen > 0 && uri->urllen > uri->protocollen + 2) {
- gchar *pos = &uri->string[uri->protocollen],
- *host_start = rspamd_url_host_unsafe(uri);
+ char *pos = &uri->string[uri->protocollen],
+ *host_start = rspamd_url_host_unsafe(uri);
while (pos < host_start) {
if (*pos == '\\') {
}
struct tld_trie_cbdata {
- const gchar *begin;
+ const char *begin;
gsize len;
rspamd_ftok_t *out;
};
-static gint
+static int
rspamd_tld_trie_find_callback(struct rspamd_multipattern *mp,
- guint strnum,
- gint match_start,
- gint match_pos,
- const gchar *text,
+ unsigned int strnum,
+ int match_start,
+ int match_pos,
+ const char *text,
gsize len,
void *context)
{
struct url_matcher *matcher;
- const gchar *start, *pos, *p;
+ const char *start, *pos, *p;
struct tld_trie_cbdata *cbdata = context;
- gint ndots = 1;
+ int ndots = 1;
matcher = &g_array_index(url_scanner->matchers_full, struct url_matcher,
strnum);
p = pos - 1;
start = text;
- if (*pos != '.' || match_pos != (gint) cbdata->len) {
+ if (*pos != '.' || match_pos != (int) cbdata->len) {
/* Something weird has been found */
- if (match_pos != (gint) cbdata->len - 1) {
+ if (match_pos != (int) cbdata->len - 1) {
/* Search more */
return 0;
}
}
gboolean
-rspamd_url_find_tld(const gchar *in, gsize inlen, rspamd_ftok_t *out)
+rspamd_url_find_tld(const char *in, gsize inlen, rspamd_ftok_t *out)
{
struct tld_trie_cbdata cbdata;
return FALSE;
}
-static const gchar url_braces[] = {
+static const char url_braces[] = {
'(', ')',
'{', '}',
'[', ']',
static gboolean
url_file_start(struct url_callback_data *cb,
- const gchar *pos,
+ const char *pos,
url_match_t *match)
{
match->m_begin = pos;
static gboolean
url_file_end(struct url_callback_data *cb,
- const gchar *pos,
+ const char *pos,
url_match_t *match)
{
- const gchar *p;
- gchar stop;
- guint i;
+ const char *p;
+ char stop;
+ unsigned int i;
p = pos + strlen(match->pattern);
stop = *p;
static gboolean
url_tld_start(struct url_callback_data *cb,
- const gchar *pos,
+ const char *pos,
url_match_t *match)
{
- const gchar *p = pos;
- guint processed = 0;
- static const guint max_shift = 253 + sizeof("https://");
+ const char *p = pos;
+ unsigned int processed = 0;
+ static const unsigned int max_shift = 253 + sizeof("https://");
/* Try to find the start of the url by finding any non-urlsafe character or whitespace/punctuation */
while (p >= cb->begin) {
static gboolean
url_tld_end(struct url_callback_data *cb,
- const gchar *pos,
+ const char *pos,
url_match_t *match)
{
- const gchar *p;
+ const char *p;
gboolean ret = FALSE;
p = pos + match->m_len;
static gboolean
url_web_start(struct url_callback_data *cb,
- const gchar *pos,
+ const char *pos,
url_match_t *match)
{
/* Check what we have found */
}
}
else {
- guchar prev = *(pos - 1);
+ unsigned char prev = *(pos - 1);
if (g_ascii_isalnum(prev)) {
/* Part of another url */
static gboolean
url_web_end(struct url_callback_data *cb,
- const gchar *pos,
+ const char *pos,
url_match_t *match)
{
- const gchar *last = NULL;
- gint len = cb->end - pos;
- guint flags = 0;
+ const char *last = NULL;
+ int len = cb->end - pos;
+ unsigned int flags = 0;
if (match->newline_pos && match->st != '<') {
/* We should also limit our match end to the newline */
static gboolean
url_email_start(struct url_callback_data *cb,
- const gchar *pos,
+ const char *pos,
url_match_t *match)
{
if (!match->prefix || match->prefix[0] == '\0') {
static gboolean
url_email_end(struct url_callback_data *cb,
- const gchar *pos,
+ const char *pos,
url_match_t *match)
{
- const gchar *last = NULL;
+ const char *last = NULL;
struct http_parser_url u;
- gint len = cb->end - pos;
- guint flags = 0;
+ int len = cb->end - pos;
+ unsigned int flags = 0;
if (match->newline_pos && match->st != '<') {
/* We should also limit our match end to the newline */
return TRUE;
}
else {
- const gchar *c, *p;
+ const char *c, *p;
/*
* Here we have just '@', so we need to find both start and end of the
* pattern
static gboolean
url_tel_start(struct url_callback_data *cb,
- const gchar *pos,
+ const char *pos,
url_match_t *match)
{
match->m_begin = pos;
static gboolean
url_tel_end(struct url_callback_data *cb,
- const gchar *pos,
+ const char *pos,
url_match_t *match)
{
- const gchar *last = NULL;
+ const char *last = NULL;
struct http_parser_url u;
- gint len = cb->end - pos;
- guint flags = 0;
+ int len = cb->end - pos;
+ unsigned int flags = 0;
if (match->newline_pos && match->st != '<') {
/* We should also limit our match end to the newline */
static gboolean
-rspamd_url_trie_is_match(struct url_matcher *matcher, const gchar *pos,
- const gchar *end, const gchar *newline_pos)
+rspamd_url_trie_is_match(struct url_matcher *matcher, const char *pos,
+ const char *end, const char *newline_pos)
{
if (matcher->flags & URL_MATCHER_FLAG_TLD_MATCH) {
/* Immediately check pos for valid chars */
return TRUE;
}
-static gint
+static int
rspamd_url_trie_callback(struct rspamd_multipattern *mp,
- guint strnum,
- gint match_start,
- gint match_pos,
- const gchar *text,
+ unsigned int strnum,
+ int match_start,
+ int match_pos,
+ const char *text,
gsize len,
void *context)
{
struct url_matcher *matcher;
url_match_t m;
- const gchar *pos, *newline_pos = NULL;
+ const char *pos, *newline_pos = NULL;
struct url_callback_data *cb = context;
pos = text + match_pos;
cb->len + 1,
"%s%*s",
m.prefix,
- (gint) m.m_len,
+ (int) m.m_len,
m.m_begin);
cb->prefix_added = TRUE;
}
gboolean
rspamd_url_find(rspamd_mempool_t *pool,
- const gchar *begin, gsize len,
- gchar **url_str,
+ const char *begin, gsize len,
+ char **url_str,
enum rspamd_url_find_type how,
goffset *url_pos,
gboolean *prefix_added)
{
struct url_callback_data cb;
- gint ret;
+ int ret;
memset(&cb, 0, sizeof(cb));
cb.begin = begin;
return FALSE;
}
-static gint
+static int
rspamd_url_trie_generic_callback_common(struct rspamd_multipattern *mp,
- guint strnum,
- gint match_start,
- gint match_pos,
- const gchar *text,
+ unsigned int strnum,
+ int match_start,
+ int match_pos,
+ const char *text,
gsize len,
void *context,
gboolean multiple)
struct rspamd_url *url;
struct url_matcher *matcher;
url_match_t m;
- const gchar *pos, *newline_pos = NULL;
+ const char *pos, *newline_pos = NULL;
struct url_callback_data *cb = context;
- gint rc;
+ int rc;
rspamd_mempool_t *pool;
pos = text + match_pos;
cb->len + 1,
"%s%*s",
m.prefix,
- (gint) m.m_len,
+ (int) m.m_len,
m.m_begin);
cb->prefix_added = TRUE;
}
return !multiple;
}
-static gint
+static int
rspamd_url_trie_generic_callback_multiple(struct rspamd_multipattern *mp,
- guint strnum,
- gint match_start,
- gint match_pos,
- const gchar *text,
+ unsigned int strnum,
+ int match_start,
+ int match_pos,
+ const char *text,
gsize len,
void *context)
{
match_pos, text, len, context, TRUE);
}
-static gint
+static int
rspamd_url_trie_generic_callback_single(struct rspamd_multipattern *mp,
- guint strnum,
- gint match_start,
- gint match_pos,
- const gchar *text,
+ unsigned int strnum,
+ int match_start,
+ int match_pos,
+ const char *text,
gsize len,
void *context)
{
if (kh_size(MESSAGE_FIELD(task, urls)) > cbd->task->cfg->max_urls) {
msg_err_task("part has too many URLs, we cannot process more: "
"%d urls extracted ",
- (guint) kh_size(MESSAGE_FIELD(task, urls)));
+ (unsigned int) kh_size(MESSAGE_FIELD(task, urls)));
return FALSE;
}
if (kh_size(MESSAGE_FIELD(task, urls)) > cbd->task->cfg->max_urls) {
msg_err_task("part has too many URLs, we cannot process more: "
"%d urls extracted ",
- (guint) kh_size(MESSAGE_FIELD(task, urls)));
+ (unsigned int) kh_size(MESSAGE_FIELD(task, urls)));
return FALSE;
}
}
void rspamd_url_find_multiple(rspamd_mempool_t *pool,
- const gchar *in,
+ const char *in,
gsize inlen,
enum rspamd_url_find_type how,
GPtrArray *nlines,
}
void rspamd_url_find_single(rspamd_mempool_t *pool,
- const gchar *in,
+ const char *in,
gsize inlen,
enum rspamd_url_find_type how,
url_insert_function func,
gsize end_offset, gpointer ud)
{
struct rspamd_task *task = ud;
- gchar *url_str = NULL;
+ char *url_str = NULL;
struct rspamd_url *query_url;
- gint rc;
+ int rc;
gboolean prefix_added;
/* It is just a displayed URL, we should not check it for certain things */
static inline bool
rspamd_emails_cmp(struct rspamd_url *u1, struct rspamd_url *u2)
{
- gint r;
+ int r;
if (u1->hostlen != u2->hostlen || u1->hostlen == 0) {
return FALSE;
return r == 0;
}
-gsize rspamd_url_decode(gchar *dst, const gchar *src, gsize size)
+gsize rspamd_url_decode(char *dst, const char *src, gsize size)
{
- gchar *d, ch, c, decoded;
- const gchar *s;
+ char *d, ch, c, decoded;
+ const char *s;
enum {
sw_usual = 0,
sw_quoted,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0};
-#define CHECK_URL_COMPONENT(beg, len, flags) \
- do { \
- for (i = 0; i < (len); i++) { \
- if ((rspamd_url_encoding_classes[(guchar) (beg)[i]] & (flags)) == 0) { \
- dlen += 2; \
- } \
- } \
+#define CHECK_URL_COMPONENT(beg, len, flags) \
+ do { \
+ for (i = 0; i < (len); i++) { \
+ if ((rspamd_url_encoding_classes[(unsigned char) (beg)[i]] & (flags)) == 0) { \
+ dlen += 2; \
+ } \
+ } \
} while (0)
-#define ENCODE_URL_COMPONENT(beg, len, flags) \
- do { \
- for (i = 0; i < (len) && dend > d; i++) { \
- if ((rspamd_url_encoding_classes[(guchar) (beg)[i]] & (flags)) == 0) { \
- *d++ = '%'; \
- *d++ = hexdigests[(guchar) ((beg)[i] >> 4) & 0xf]; \
- *d++ = hexdigests[(guchar) (beg)[i] & 0xf]; \
- } \
- else { \
- *d++ = (beg)[i]; \
- } \
- } \
+#define ENCODE_URL_COMPONENT(beg, len, flags) \
+ do { \
+ for (i = 0; i < (len) && dend > d; i++) { \
+ if ((rspamd_url_encoding_classes[(unsigned char) (beg)[i]] & (flags)) == 0) { \
+ *d++ = '%'; \
+ *d++ = hexdigests[(unsigned char) ((beg)[i] >> 4) & 0xf]; \
+ *d++ = hexdigests[(unsigned char) (beg)[i] & 0xf]; \
+ } \
+ else { \
+ *d++ = (beg)[i]; \
+ } \
+ } \
} while (0)
-const gchar *
+const char *
rspamd_url_encode(struct rspamd_url *url, gsize *pdlen,
rspamd_mempool_t *pool)
{
- guchar *dest, *d, *dend;
- static const gchar hexdigests[16] = "0123456789ABCDEF";
- guint i;
+ unsigned char *dest, *d, *dend;
+ static const char hexdigests[16] = "0123456789ABCDEF";
+ unsigned int i;
gsize dlen = 0;
g_assert(pdlen != NULL && url != NULL && pool != NULL);
if (url->protocollen > 0) {
if (!(url->protocol & PROTOCOL_UNKNOWN)) {
- const gchar *known_proto = rspamd_url_protocol_name(url->protocol);
- d += rspamd_snprintf((gchar *) d, dend - d,
+ const char *known_proto = rspamd_url_protocol_name(url->protocol);
+ d += rspamd_snprintf((char *) d, dend - d,
"%s://",
known_proto);
}
else {
- d += rspamd_snprintf((gchar *) d, dend - d,
+ d += rspamd_snprintf((char *) d, dend - d,
"%*s://",
- (gint) url->protocollen, url->string);
+ (int) url->protocollen, url->string);
}
}
else {
- d += rspamd_snprintf((gchar *) d, dend - d, "http://");
+ d += rspamd_snprintf((char *) d, dend - d, "http://");
}
if (url->userlen > 0) {
*pdlen = (d - dest);
- return (const gchar *) dest;
+ return (const char *) dest;
}
gboolean
rspamd_url_is_domain(int c)
{
- return is_domain((guchar) c);
+ return is_domain((unsigned char) c);
}
-const gchar *
+const char *
rspamd_url_protocol_name(enum rspamd_url_protocol proto)
{
- const gchar *ret = "unknown";
+ const char *ret = "unknown";
switch (proto) {
case PROTOCOL_HTTP:
}
enum rspamd_url_protocol
-rspamd_url_protocol_from_string(const gchar *str)
+rspamd_url_protocol_from_string(const char *str)
{
enum rspamd_url_protocol ret = PROTOCOL_UNKNOWN;
bool enforce_replace)
{
khiter_t k;
- gint r;
+ int r;
k = kh_get(rspamd_url_hash, set, u);
struct rspamd_url *u)
{
khiter_t k;
- gint r;
+ int r;
if (set) {
k = kh_get(rspamd_url_hash, set, u);
bool rspamd_url_host_set_add(khash_t(rspamd_url_host_hash) * set,
struct rspamd_url *u)
{
- gint r;
+ int r;
if (set) {
kh_put(rspamd_url_host_hash, set, u, &r);
return false;
}
-bool rspamd_url_flag_from_string(const gchar *str, gint *flag)
+bool rspamd_url_flag_from_string(const char *str, int *flag)
{
- gint h = rspamd_cryptobox_fast_hash_specific(RSPAMD_CRYPTOBOX_HASHFAST_INDEPENDENT,
- str, strlen(str), 0);
+ int h = rspamd_cryptobox_fast_hash_specific(RSPAMD_CRYPTOBOX_HASHFAST_INDEPENDENT,
+ str, strlen(str), 0);
for (int i = 0; i < G_N_ELEMENTS(url_flag_names); i++) {
if (url_flag_names[i].hash == h) {
}
-const gchar *
+const char *
rspamd_url_flag_to_string(int flag)
{
for (int i = 0; i < G_N_ELEMENTS(url_flag_names); i++) {
+/*
+ * Copyright 2024 Vsevolod Stakhov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
/* URL check functions */
#ifndef URL_H
#define URL_H
#define RSPAMD_URL_MAX_FLAG_SHIFT (26u)
struct rspamd_url_tag {
- const gchar *data;
+ const char *data;
struct rspamd_url_tag *prev, *next;
};
uint16_t queryshift;
uint16_t fragmentshift;
uint16_t tldshift;
- guint16 usershift;
- guint16 userlen;
+ uint16_t usershift;
+ uint16_t userlen;
uint16_t hostlen;
uint16_t datalen;
* Rarely used url fields
*/
struct rspamd_url_ext {
- gchar *visible_part;
+ char *visible_part;
struct rspamd_url *linked_url;
- guint16 port;
+ uint16_t port;
};
#define rspamd_url_user(u) ((u)->userlen > 0 ? (u)->string + (u)->usershift : NULL)
* Initialize url library
* @param cfg
*/
-void rspamd_url_init(const gchar *tld_file);
+void rspamd_url_init(const char *tld_file);
void rspamd_url_deinit(void);
* @param uri url object, must be pre allocated
*/
enum uri_errno rspamd_url_parse(struct rspamd_url *uri,
- gchar *uristring,
+ char *uristring,
gsize len,
rspamd_mempool_t *pool,
enum rspamd_url_parse_flags flags);
* @return TRUE if url is found in specified text
*/
gboolean rspamd_url_find(rspamd_mempool_t *pool,
- const gchar *begin, gsize len,
- gchar **url_str,
+ const char *begin, gsize len,
+ char **url_str,
enum rspamd_url_find_type how,
goffset *url_pos,
gboolean *prefix_added);
/*
* Return text representation of url parsing error
*/
-const gchar *rspamd_url_strerror(int err);
+const char *rspamd_url_strerror(int err);
/**
* @param out output rspamd_ftok_t with tld position
* @return TRUE if tld has been found
*/
-gboolean rspamd_url_find_tld(const gchar *in, gsize inlen, rspamd_ftok_t *out);
+gboolean rspamd_url_find_tld(const char *in, gsize inlen, rspamd_ftok_t *out);
typedef gboolean (*url_insert_function)(struct rspamd_url *url,
gsize start_offset, gsize end_offset, void *ud);
* @param ud
*/
void rspamd_url_find_multiple(rspamd_mempool_t *pool,
- const gchar *in, gsize inlen,
+ const char *in, gsize inlen,
enum rspamd_url_find_type how,
GPtrArray *nlines,
url_insert_function func,
* @param ud
*/
void rspamd_url_find_single(rspamd_mempool_t *pool,
- const gchar *in, gsize inlen,
+ const char *in, gsize inlen,
enum rspamd_url_find_type how,
url_insert_function func,
gpointer ud);
* @param size
* @return
*/
-gsize rspamd_url_decode(gchar *dst, const gchar *src, gsize size);
+gsize rspamd_url_decode(char *dst, const char *src, gsize size);
/**
* Encode url if needed. In this case, memory is allocated from the specific pool.
* @param pool
* @return
*/
-const gchar *rspamd_url_encode(struct rspamd_url *url, gsize *dlen,
- rspamd_mempool_t *pool);
+const char *rspamd_url_encode(struct rspamd_url *url, gsize *dlen,
+ rspamd_mempool_t *pool);
/**
* @param proto
* @return
*/
-const gchar *rspamd_url_protocol_name(enum rspamd_url_protocol proto);
+const char *rspamd_url_protocol_name(enum rspamd_url_protocol proto);
/**
* @param str
* @return
*/
-enum rspamd_url_protocol rspamd_url_protocol_from_string(const gchar *str);
+enum rspamd_url_protocol rspamd_url_protocol_from_string(const char *str);
/**
* Converts string to a url flag
* @param flag
* @return
*/
-bool rspamd_url_flag_from_string(const gchar *str, gint *flag);
+bool rspamd_url_flag_from_string(const char *str, int *flag);
/**
* Converts url flag to a string
* @param flag
* @return
*/
-const gchar *rspamd_url_flag_to_string(int flag);
+const char *rspamd_url_flag_to_string(int flag);
/* Defines sets of urls indexed by url as is */
KHASH_DECLARE(rspamd_url_hash, struct rspamd_url *, char);
}
void rspamd_controller_send_error(struct rspamd_http_connection_entry *entry,
- gint code, const gchar *error_msg, ...)
+ int code, const char *error_msg, ...)
{
struct rspamd_http_message *msg;
va_list args;
}
void rspamd_controller_send_string(struct rspamd_http_connection_entry *entry,
- const gchar *str)
+ const char *str)
{
struct rspamd_http_message *msg;
rspamd_fstring_t *reply;
if (rspamd_main->is_privileged) {
if (setgid(rspamd_main->workers_gid) == -1) {
msg_err_main("cannot setgid to %d (%s), aborting",
- (gint) rspamd_main->workers_gid,
+ (int) rspamd_main->workers_gid,
strerror(errno));
exit(-errno);
}
if (setuid(rspamd_main->workers_uid) == -1) {
msg_err_main("cannot setuid to %d (%s), aborting",
- (gint) rspamd_main->workers_uid,
+ (int) rspamd_main->workers_uid,
strerror(errno));
exit(-errno);
}
rspamd_main_heartbeat_cb(EV_P_ ev_timer *w, int revents)
{
struct rspamd_worker *wrk = (struct rspamd_worker *) w->data;
- gdouble time_from_last = ev_time();
+ double time_from_last = ev_time();
struct rspamd_main *rspamd_main;
static struct rspamd_control_command cmd;
struct tm tm;
- gchar timebuf[64];
- gchar usec_buf[16];
- gint r;
+ char timebuf[64];
+ char usec_buf[16];
+ int r;
time_from_last -= wrk->hb.last_event;
rspamd_main = wrk->srv;
rspamd_localtime(wrk->hb.last_event, &tm);
r = strftime(timebuf, sizeof(timebuf), "%F %H:%M:%S", &tm);
rspamd_snprintf(usec_buf, sizeof(usec_buf), "%.5f",
- wrk->hb.last_event - (gdouble) (time_t) wrk->hb.last_event);
+ wrk->hb.last_event - (double) (time_t) wrk->hb.last_event);
rspamd_snprintf(timebuf + r, sizeof(timebuf) - r,
"%s", usec_buf + 1);
rspamd_localtime(wrk->hb.last_event, &tm);
r = strftime(timebuf, sizeof(timebuf), "%F %H:%M:%S", &tm);
rspamd_snprintf(usec_buf, sizeof(usec_buf), "%.5f",
- wrk->hb.last_event - (gdouble) (time_t) wrk->hb.last_event);
+ wrk->hb.last_event - (double) (time_t) wrk->hb.last_event);
rspamd_snprintf(timebuf + r, sizeof(timebuf) - r,
"%s", usec_buf + 1);
}
#if defined(SO_REUSEPORT) && defined(SO_REUSEADDR) && defined(LINUX)
- gint nfd = -1;
+ int nfd = -1;
if (ls->type == RSPAMD_WORKER_SOCKET_UDP) {
nfd = rspamd_inet_address_listen(ls->addr,
struct rspamd_worker_conf *cf,
GHashTable *listen_sockets)
{
- gint rc;
+ int rc;
struct rlimit rlim;
/* Update pid for logging */
struct rspamd_worker *
rspamd_fork_worker(struct rspamd_main *rspamd_main,
struct rspamd_worker_conf *cf,
- guint index,
+ unsigned int index,
struct ev_loop *ev_base,
rspamd_worker_term_cb term_handler,
GHashTable *listen_sockets)
struct rspamd_worker_session_elt {
void *ptr;
- guint *pref;
- const gchar *tag;
+ unsigned int *pref;
+ const char *tag;
time_t when;
};
struct ev_timer periodic;
};
-static gint
+static int
rspamd_session_cache_sort_cmp(gconstpointer pa, gconstpointer pb)
{
const struct rspamd_worker_session_elt
struct rspamd_worker_session_cache *c =
(struct rspamd_worker_session_cache *) w->data;
GHashTableIter it;
- gchar timebuf[32];
+ char timebuf[32];
gpointer k, v;
struct rspamd_worker_session_elt *elt;
struct tm tms;
GPtrArray *res;
- guint i;
+ unsigned int i;
if (g_hash_table_size(c->cache) > c->cfg->max_sessions_cache) {
res = g_ptr_array_sized_new(g_hash_table_size(c->cache));
}
msg_err("sessions cache is overflowed %d elements where %d is limit",
- (gint) res->len, (gint) c->cfg->max_sessions_cache);
+ (int) res->len, (int) c->cfg->max_sessions_cache);
g_ptr_array_sort(res, rspamd_session_cache_sort_cmp);
PTR_ARRAY_FOREACH(res, i, elt)
struct ev_loop *ev_base)
{
struct rspamd_worker_session_cache *c;
- static const gdouble periodic_interval = 60.0;
+ static const double periodic_interval = 60.0;
c = g_malloc0(sizeof(*c));
c->ev_base = ev_base;
}
-void rspamd_worker_session_cache_add(void *cache, const gchar *tag,
- guint *pref, void *ptr)
+void rspamd_worker_session_cache_add(void *cache, const char *tag,
+ unsigned int *pref, void *ptr)
{
struct rspamd_worker_session_cache *c = cache;
struct rspamd_worker_session_elt *elt;
struct rspamd_worker *worker = ud;
struct rspamd_config *cfg = worker->srv->cfg;
struct ev_loop *ev_base;
- guchar tag[RSPAMD_MONITORED_TAG_LEN];
+ unsigned char tag[RSPAMD_MONITORED_TAG_LEN];
static struct rspamd_srv_command srv_cmd;
rspamd_monitored_get_tag(m, tag);
ev_io_start(EV_A_ & ac_ev->accept_ev);
}
-void rspamd_worker_throttle_accept_events(gint sock, void *data)
+void rspamd_worker_throttle_accept_events(int sock, void *data)
{
struct rspamd_worker_accept_event *head, *cur;
- const gdouble throttling = 0.5;
+ const double throttling = 0.5;
head = (struct rspamd_worker_accept_event *) data;
#ifdef WITH_HYPERSCAN
gboolean
rspamd_worker_hyperscan_ready(struct rspamd_main *rspamd_main,
- struct rspamd_worker *worker, gint fd,
- gint attached_fd,
+ struct rspamd_worker *worker, int fd,
+ int attached_fd,
struct rspamd_control_command *cmd,
gpointer ud)
{
static gboolean
rspamd_worker_log_pipe_handler(struct rspamd_main *rspamd_main,
- struct rspamd_worker *worker, gint fd,
- gint attached_fd,
+ struct rspamd_worker *worker, int fd,
+ int attached_fd,
struct rspamd_control_command *cmd,
gpointer ud)
{
static gboolean
rspamd_worker_monitored_handler(struct rspamd_main *rspamd_main,
- struct rspamd_worker *worker, gint fd,
- gint attached_fd,
+ struct rspamd_worker *worker, int fd,
+ int attached_fd,
struct rspamd_control_command *cmd,
gpointer ud)
{
struct rspamd_stat *stat;
ucl_object_t *top, *sub;
struct ucl_emitter_functions *efuncs;
- gint i, fd;
+ int i, fd;
FILE *fp;
- gchar fpath[PATH_MAX];
+ char fpath[PATH_MAX];
if (cfg->stats_file == NULL) {
return;
ucl_object_t *obj;
const ucl_object_t *elt, *subelt;
struct rspamd_stat *stat, stat_copy;
- gint i;
+ int i;
if (cfg->stats_file == NULL) {
return;
(struct rspamd_controller_periodics_cbdata *) w->data;
struct rspamd_stat *stat;
GArray ar;
- gdouble points[METRIC_ACTION_MAX];
+ double points[METRIC_ACTION_MAX];
GError *err = NULL;
- guint i;
+ unsigned int i;
g_assert(cbd->rrd != NULL);
stat = cbd->stat;
points[i] = stat->actions_stat[i];
}
- ar.data = (gchar *) points;
+ ar.data = (char *) points;
ar.len = sizeof(points);
if (!rspamd_rrd_add_record(cbd->rrd, &ar, rspamd_get_calendar_ticks(),
}
}
-gdouble
-rspamd_worker_check_and_adjust_timeout(struct rspamd_config *cfg, gdouble timeout)
+double
+rspamd_worker_check_and_adjust_timeout(struct rspamd_config *cfg, double timeout)
{
if (isnan(timeout)) {
/* Use implicit timeout from cfg->task_timeout */
#endif
#ifndef HAVE_SA_SIGINFO
-typedef void (*rspamd_sig_handler_t)(gint);
+typedef void (*rspamd_sig_handler_t)(int);
#else
-typedef void (*rspamd_sig_handler_t)(gint, siginfo_t *, void *);
+typedef void (*rspamd_sig_handler_t)(int, siginfo_t *, void *);
#endif
*/
void rspamd_worker_stop_accept(struct rspamd_worker *worker);
-typedef gint (*rspamd_controller_func_t)(
+typedef int (*rspamd_controller_func_t)(
struct rspamd_http_connection_entry *conn_ent,
struct rspamd_http_message *msg,
struct module_ctx *ctx);
struct rspamd_custom_controller_command {
- const gchar *command;
+ const char *command;
struct module_ctx *ctx;
gboolean privileged;
gboolean require_message;
struct rspamd_worker *wrk;
rspamd_mempool_t *pool;
struct rspamd_task *task;
- gchar *classifier;
+ char *classifier;
rspamd_inet_addr_t *from_addr;
struct rspamd_config *cfg;
struct rspamd_lang_detector *lang_det;
* @param error_msg error message
*/
void rspamd_controller_send_error(struct rspamd_http_connection_entry *entry,
- gint code, const gchar *error_msg, ...);
+ int code, const char *error_msg, ...);
/**
* Send openmetrics-formatted strings using HTTP
* @param str string to send
*/
void rspamd_controller_send_string(struct rspamd_http_connection_entry *entry,
- const gchar *str);
+ const char *str);
/**
* Send UCL using HTTP and JSON serialization
* @param timeout
* @return
*/
-gdouble rspamd_worker_check_and_adjust_timeout(struct rspamd_config *cfg,
- gdouble timeout);
+double rspamd_worker_check_and_adjust_timeout(struct rspamd_config *cfg,
+ double timeout);
/**
* Returns TRUE if a specific worker is a primary controller
* @param pref
* @param ptr
*/
-void rspamd_worker_session_cache_add(void *cache, const gchar *tag,
- guint *pref, void *ptr);
+void rspamd_worker_session_cache_add(void *cache, const char *tag,
+ unsigned int *pref, void *ptr);
/**
* Removes session from cache
* Fork new worker with the specified configuration
*/
struct rspamd_worker *rspamd_fork_worker(struct rspamd_main *,
- struct rspamd_worker_conf *, guint idx,
+ struct rspamd_worker_conf *, unsigned int idx,
struct ev_loop *ev_base,
rspamd_worker_term_cb term_handler,
GHashTable *listen_sockets);
* @param sock
* @param data struct rspamd_worker_accept_event * list
*/
-void rspamd_worker_throttle_accept_events(gint sock, void *data);
+void rspamd_worker_throttle_accept_events(int sock, void *data);
/**
* Checks (and logs) the worker's termination status. Returns TRUE if a worker
struct rspamd_control_command;
gboolean rspamd_worker_hyperscan_ready(struct rspamd_main *rspamd_main,
- struct rspamd_worker *worker, gint fd,
- gint attached_fd,
+ struct rspamd_worker *worker, int fd,
+ int attached_fd,
struct rspamd_control_command *cmd,
gpointer ud);
gpointer (*runtime)(struct rspamd_task *task,
struct rspamd_statfile_config *stcf,
gboolean learn, gpointer ctx,
- gint id);
+ int id);
gboolean (*process_tokens)(struct rspamd_task *task, GPtrArray *tokens,
- gint id,
+ int id,
gpointer ctx);
gboolean (*finalize_process)(struct rspamd_task *task,
gpointer runtime, gpointer ctx);
gboolean (*learn_tokens)(struct rspamd_task *task, GPtrArray *tokens,
- gint id,
+ int id,
gpointer ctx);
gulong (*total_learns)(struct rspamd_task *task,
struct rspamd_config *cfg, struct rspamd_statfile *st); \
gpointer rspamd_##name##_runtime(struct rspamd_task *task, \
struct rspamd_statfile_config *stcf, \
- gboolean learn, gpointer ctx, gint id); \
+ gboolean learn, gpointer ctx, int id); \
gboolean rspamd_##name##_process_tokens(struct rspamd_task *task, \
- GPtrArray *tokens, gint id, \
+ GPtrArray *tokens, int id, \
gpointer runtime); \
gboolean rspamd_##name##_finalize_process(struct rspamd_task *task, \
gpointer runtime, \
gpointer ctx); \
gboolean rspamd_##name##_learn_tokens(struct rspamd_task *task, \
- GPtrArray *tokens, gint id, \
+ GPtrArray *tokens, int id, \
gpointer runtime); \
gboolean rspamd_##name##_finalize_learn(struct rspamd_task *task, \
gpointer runtime, \
struct rspamd_statfile_config *stcf,
gboolean learn,
gpointer ctx,
- gint _id)
+ int _id)
{
/* In CDB we don't have any dynamic stuff */
return ctx;
gboolean
rspamd_cdb_process_tokens(struct rspamd_task *task,
GPtrArray *tokens,
- gint id,
+ int id,
gpointer runtime)
{
auto *cdbp = CDB_FROM_RAW(runtime);
gboolean
rspamd_cdb_learn_tokens(struct rspamd_task *task,
GPtrArray *tokens,
- gint id,
+ int id,
gpointer ctx)
{
return false;
auto process_tokens(struct rspamd_task *task,
GPtrArray *tokens,
- gint id,
+ int id,
bool learn) -> bool;
private:
return new (allocated_runtime) http_backend_runtime{task, is_learn};
}
-auto http_backend_runtime::process_tokens(struct rspamd_task *task, GPtrArray *tokens, gint id, bool learn) -> bool
+auto http_backend_runtime::process_tokens(struct rspamd_task *task, GPtrArray *tokens, int id, bool learn) -> bool
{
if (!learn) {
if (id == seen_statfiles.size() - 1) {
struct rspamd_statfile_config *stcf,
gboolean learn,
gpointer ctx,
- gint id)
+ int id)
{
auto maybe_existing = rspamd_mempool_get_variable(task->task_pool, RSPAMD_MEMPOOL_HTTP_STAT_BACKEND_RUNTIME);
gboolean
rspamd_http_process_tokens(struct rspamd_task *task,
GPtrArray *tokens,
- gint id,
+ int id,
gpointer runtime)
{
auto real_runtime = (rspamd::stat::http::http_backend_runtime *) runtime;
gboolean
rspamd_http_learn_tokens(struct rspamd_task *task,
GPtrArray *tokens,
- gint id,
+ int id,
gpointer runtime)
{
auto real_runtime = (rspamd::stat::http::http_backend_runtime *) runtime;
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
*/
typedef struct {
#ifdef HAVE_PATH_MAX
- gchar filename[PATH_MAX]; /**< name of file */
+ char filename[PATH_MAX]; /**< name of file */
#else
- gchar filename[MAXPATHLEN]; /**< name of file */
+ char filename[MAXPATHLEN]; /**< name of file */
#endif
rspamd_mempool_t *pool;
- gint fd; /**< descriptor */
+ int fd; /**< descriptor */
void *map; /**< mmaped area */
off_t seek_pos; /**< current seek position */
struct stat_file_section cur_section; /**< current section */
uint32_t h1, uint32_t h2, double value);
rspamd_mmaped_file_t *rspamd_mmaped_file_open(rspamd_mempool_t *pool,
- const gchar *filename, size_t size,
+ const char *filename, size_t size,
struct rspamd_statfile_config *stcf);
-gint rspamd_mmaped_file_create(const gchar *filename, size_t size,
- struct rspamd_statfile_config *stcf,
- rspamd_mempool_t *pool);
-gint rspamd_mmaped_file_close_file(rspamd_mempool_t *pool,
- rspamd_mmaped_file_t *file);
+int rspamd_mmaped_file_create(const char *filename, size_t size,
+ struct rspamd_statfile_config *stcf,
+ rspamd_mempool_t *pool);
+int rspamd_mmaped_file_close_file(rspamd_mempool_t *pool,
+ rspamd_mmaped_file_t *file);
double
rspamd_mmaped_file_get_block(rspamd_mmaped_file_t *file,
uint32_t h2)
{
struct stat_file_block *block;
- guint i, blocknum;
+ unsigned int i, blocknum;
u_char *c;
if (!file->map) {
{
struct stat_file_block *block, *to_expire = NULL;
struct stat_file_header *header;
- guint i, blocknum;
+ unsigned int i, blocknum;
u_char *c;
double min = G_MAXDOUBLE;
}
/* Check whether specified file is statistic file and calculate its len in blocks */
-static gint
+static int
rspamd_mmaped_file_check(rspamd_mempool_t *pool, rspamd_mmaped_file_t *file)
{
struct stat_file *f;
- gchar *c;
- static gchar valid_version[] = RSPAMD_STATFILE_VERSION;
+ char *c;
+ static char valid_version[] = RSPAMD_STATFILE_VERSION;
if (!file || !file->map) {
static rspamd_mmaped_file_t *
rspamd_mmaped_file_reindex(rspamd_mempool_t *pool,
- const gchar *filename,
+ const char *filename,
size_t old_size,
size_t size,
struct rspamd_statfile_config *stcf)
{
- gchar *backup, *lock;
- gint fd, lock_fd;
+ char *backup, *lock;
+ int fd, lock_fd;
rspamd_mmaped_file_t *new, *old = NULL;
u_char *map, *pos;
struct stat_file_block *block;
static void
rspamd_mmaped_file_preload(rspamd_mmaped_file_t *file)
{
- guint8 *pos, *end;
- volatile guint8 t;
+ uint8_t *pos, *end;
+ volatile uint8_t t;
gsize size;
- pos = (guint8 *) file->map;
- end = (guint8 *) file->map + file->len;
+ pos = (uint8_t *) file->map;
+ end = (uint8_t *) file->map + file->len;
if (madvise(pos, end - pos, MADV_SEQUENTIAL) == -1) {
msg_info("madvise failed: %s", strerror(errno));
rspamd_mmaped_file_t *
rspamd_mmaped_file_open(rspamd_mempool_t *pool,
- const gchar *filename, size_t size,
+ const char *filename, size_t size,
struct rspamd_statfile_config *stcf)
{
struct stat st;
rspamd_mmaped_file_t *new_file;
- gchar *lock;
- gint lock_fd;
+ char *lock;
+ int lock_fd;
lock = g_strconcat(filename, ".lock", NULL);
lock_fd = open(lock, O_WRONLY | O_CREAT | O_EXCL, 00600);
return new_file;
}
-gint rspamd_mmaped_file_close_file(rspamd_mempool_t *pool,
- rspamd_mmaped_file_t *file)
+int rspamd_mmaped_file_close_file(rspamd_mempool_t *pool,
+ rspamd_mmaped_file_t *file)
{
if (file->map) {
msg_info_pool("syncing statfile %s", file->filename);
return 0;
}
-gint rspamd_mmaped_file_create(const gchar *filename,
- size_t size,
- struct rspamd_statfile_config *stcf,
- rspamd_mempool_t *pool)
+int rspamd_mmaped_file_create(const char *filename,
+ size_t size,
+ struct rspamd_statfile_config *stcf,
+ rspamd_mempool_t *pool)
{
struct stat_file_header header = {
.magic = {'r', 's', 'd'},
};
struct stat_file_block block = {0, 0, 0};
struct rspamd_stat_tokenizer *tokenizer;
- gint fd, lock_fd;
- guint buflen = 0, nblocks;
- gchar *buf = NULL, *lock;
+ int fd, lock_fd;
+ unsigned int buflen = 0, nblocks;
+ char *buf = NULL, *lock;
struct stat sb;
gpointer tok_conf;
gsize tok_conf_len;
struct rspamd_statfile_config *stf = st->stcf;
rspamd_mmaped_file_t *mf;
const ucl_object_t *filenameo, *sizeo;
- const gchar *filename;
+ const char *filename;
gsize size;
filenameo = ucl_object_lookup(stf->opts, "filename");
struct rspamd_statfile_config *stcf,
gboolean learn,
gpointer p,
- gint _id)
+ int _id)
{
rspamd_mmaped_file_t *mf = p;
gboolean
rspamd_mmaped_file_process_tokens(struct rspamd_task *task, GPtrArray *tokens,
- gint id,
+ int id,
gpointer p)
{
rspamd_mmaped_file_t *mf = p;
uint32_t h1, h2;
rspamd_token_t *tok;
- guint i;
+ unsigned int i;
g_assert(tokens != NULL);
g_assert(p != NULL);
for (i = 0; i < tokens->len; i++) {
tok = g_ptr_array_index(tokens, i);
- memcpy(&h1, (guchar *) &tok->data, sizeof(h1));
- memcpy(&h2, ((guchar *) &tok->data) + sizeof(h1), sizeof(h2));
+ memcpy(&h1, (unsigned char *) &tok->data, sizeof(h1));
+ memcpy(&h2, ((unsigned char *) &tok->data) + sizeof(h1), sizeof(h2));
tok->values[id] = rspamd_mmaped_file_get_block(mf, h1, h2);
}
gboolean
rspamd_mmaped_file_learn_tokens(struct rspamd_task *task, GPtrArray *tokens,
- gint id,
+ int id,
gpointer p)
{
rspamd_mmaped_file_t *mf = p;
uint32_t h1, h2;
rspamd_token_t *tok;
- guint i;
+ unsigned int i;
g_assert(tokens != NULL);
g_assert(p != NULL);
for (i = 0; i < tokens->len; i++) {
tok = g_ptr_array_index(tokens, i);
- memcpy(&h1, (guchar *) &tok->data, sizeof(h1));
- memcpy(&h2, ((guchar *) &tok->data) + sizeof(h1), sizeof(h2));
+ memcpy(&h1, (unsigned char *) &tok->data, sizeof(h1));
+ memcpy(&h2, ((unsigned char *) &tok->data) + sizeof(h1), sizeof(h2));
rspamd_mmaped_file_set_block(task->task_pool, mf, h1, h2,
tok->values[id]);
}
#define GET_TASK_ELT(task, elt) (task == nullptr ? nullptr : (task)->elt)
-static const gchar *M = "redis statistics";
+static const char *M = "redis statistics";
static GQuark
rspamd_redis_stat_quark(void)
/*
* Non-static for lua unit testing
*/
-gsize rspamd_redis_expand_object(const gchar *pattern,
+gsize rspamd_redis_expand_object(const char *pattern,
struct redis_stat_ctx *ctx,
struct rspamd_task *task,
- gchar **target)
+ char **target)
{
gsize tlen = 0;
- const gchar *p = pattern, *elt;
- gchar *d, *end;
+ const char *p = pattern, *elt;
+ char *d, *end;
enum {
just_char,
percent_char,
struct rspamd_statfile_config *stcf;
lua_State *L = nullptr;
struct rspamd_task **ptask;
- const gchar *rcpt = nullptr;
- gint err_idx;
+ const char *rcpt = nullptr;
+ int err_idx;
g_assert(ctx != nullptr);
g_assert(task != nullptr);
return -1;
}
- *target = (gchar *) rspamd_mempool_alloc(task->task_pool, tlen + 1);
+ *target = (char *) rspamd_mempool_alloc(task->task_pool, tlen + 1);
d = *target;
end = d + tlen + 1;
d[tlen] = '\0';
const ucl_object_t *classifier_obj,
struct rspamd_config *cfg)
{
- const gchar *lua_script;
+ const char *lua_script;
const ucl_object_t *elt, *users_enabled;
auto *L = RSPAMD_LUA_CFG_STATE(cfg);
gpointer
rspamd_redis_runtime(struct rspamd_task *task,
struct rspamd_statfile_config *stcf,
- gboolean learn, gpointer c, gint _id)
+ gboolean learn, gpointer c, int _id)
{
struct redis_stat_ctx *ctx = REDIS_CTX(c);
char *object_expanded = nullptr;
* Serialise stat tokens to message pack
*/
static char *
-rspamd_redis_serialize_tokens(struct rspamd_task *task, const gchar *prefix, GPtrArray *tokens, gsize *ser_len)
+rspamd_redis_serialize_tokens(struct rspamd_task *task, const char *prefix, GPtrArray *tokens, gsize *ser_len)
{
/* Each token is int64_t that requires 10 bytes (2 int32_t) + 4 bytes array len + 1 byte array magic */
char max_int64_str[] = "18446744073709551615";
/* Calculate required length */
req_len += tokens->len * (msgpack_str_len(sizeof(max_int64_str) + prefix_len) + 1);
- auto *buf = (gchar *) rspamd_mempool_alloc(task->task_pool, req_len);
+ auto *buf = (char *) rspamd_mempool_alloc(task->task_pool, req_len);
auto *p = buf;
/* Array */
- *p++ = (gchar) 0xdd;
+ *p++ = (char) 0xdd;
/* Length in big-endian (4 bytes) */
- *p++ = (gchar) ((tokens->len >> 24) & 0xff);
- *p++ = (gchar) ((tokens->len >> 16) & 0xff);
- *p++ = (gchar) ((tokens->len >> 8) & 0xff);
- *p++ = (gchar) (tokens->len & 0xff);
+ *p++ = (char) ((tokens->len >> 24) & 0xff);
+ *p++ = (char) ((tokens->len >> 16) & 0xff);
+ *p++ = (char) ((tokens->len >> 8) & 0xff);
+ *p++ = (char) (tokens->len & 0xff);
int i;
}
}
- auto *buf = (gchar *) rspamd_mempool_alloc(task->task_pool, req_len);
+ auto *buf = (char *) rspamd_mempool_alloc(task->task_pool, req_len);
auto *p = buf;
/* Array */
std::uint32_t nlen = tokens->len * 2;
nlen = GUINT32_TO_BE(nlen);
- *p++ = (gchar) 0xdd;
+ *p++ = (char) 0xdd;
/* Length in big-endian (4 bytes) */
memcpy(p, &nlen, sizeof(nlen));
p += sizeof(nlen);
return buf;
}
-static gint
+static int
rspamd_redis_classified(lua_State *L)
{
const auto *cookie = lua_tostring(L, lua_upvalueindex(1));
gboolean
rspamd_redis_process_tokens(struct rspamd_task *task,
GPtrArray *tokens,
- gint id, gpointer p)
+ int id, gpointer p)
{
auto *rt = REDIS_RUNTIME(p);
auto *L = rt->ctx->L;
}
gsize tokens_len;
- gchar *tokens_buf = rspamd_redis_serialize_tokens(task, rt->redis_object_expanded, tokens, &tokens_len);
+ char *tokens_buf = rspamd_redis_serialize_tokens(task, rt->redis_object_expanded, tokens, &tokens_len);
rt->id = id;
lua_pushcfunction(L, &rspamd_lua_traceback);
- gint err_idx = lua_gettop(L);
+ int err_idx = lua_gettop(L);
/* Function arguments */
lua_rawgeti(L, LUA_REGISTRYINDEX, rt->ctx->cbref_classify);
}
-static gint
+static int
rspamd_redis_learned(lua_State *L)
{
const auto *cookie = lua_tostring(L, lua_upvalueindex(1));
gboolean
rspamd_redis_learn_tokens(struct rspamd_task *task,
GPtrArray *tokens,
- gint id, gpointer p)
+ int id, gpointer p)
{
auto *rt = REDIS_RUNTIME(p);
auto *L = rt->ctx->L;
}
gsize tokens_len;
- gchar *tokens_buf = rspamd_redis_serialize_tokens(task, rt->redis_object_expanded, tokens, &tokens_len);
+ char *tokens_buf = rspamd_redis_serialize_tokens(task, rt->redis_object_expanded, tokens, &tokens_len);
rt->id = id;
gsize text_tokens_len = 0;
- gchar *text_tokens_buf = nullptr;
+ char *text_tokens_buf = nullptr;
if (rt->ctx->store_tokens) {
text_tokens_buf = rspamd_redis_serialize_text_tokens(task, tokens, &text_tokens_len);
}
lua_pushcfunction(L, &rspamd_lua_traceback);
- gint err_idx = lua_gettop(L);
+ int err_idx = lua_gettop(L);
auto nargs = 8;
/* Function arguments */
struct rspamd_stat_sqlite3_db {
sqlite3 *sqlite;
- gchar *fname;
+ char *fname;
GArray *prstmt;
lua_State *L;
rspamd_mempool_t *pool;
gboolean in_transaction;
gboolean enable_users;
gboolean enable_languages;
- gint cbref_user;
- gint cbref_language;
+ int cbref_user;
+ int cbref_language;
};
struct rspamd_stat_sqlite3_rt {
struct rspamd_task *task, gboolean learn)
{
int64_t id = 0; /* Default user is 0 */
- gint rc, err_idx;
- const gchar *user = NULL;
+ int rc, err_idx;
+ const char *user = NULL;
struct rspamd_task **ptask;
lua_State *L = db->L;
struct rspamd_task *task, gboolean learn)
{
int64_t id = 0; /* Default language is 0 */
- gint rc, err_idx;
- guint i;
- const gchar *language = NULL;
+ int rc, err_idx;
+ unsigned int i;
+ const char *language = NULL;
struct rspamd_mime_text_part *tp;
struct rspamd_task **ptask;
lua_State *L = db->L;
static struct rspamd_stat_sqlite3_db *
rspamd_sqlite3_opendb(rspamd_mempool_t *pool,
struct rspamd_statfile_config *stcf,
- const gchar *path, const ucl_object_t *opts,
+ const char *path, const ucl_object_t *opts,
gboolean create, GError **err)
{
struct rspamd_stat_sqlite3_db *bk;
gpointer tk_conf;
gsize sz = 0;
int64_t sz64 = 0;
- gchar *tok_conf_encoded;
- gint ret, ntries = 0;
- const gint max_tries = 100;
+ char *tok_conf_encoded;
+ int ret, ntries = 0;
+ const int max_tries = 100;
struct timespec sleep_ts = {
.tv_sec = 0,
.tv_nsec = 1000000};
struct rspamd_classifier_config *clf = st->classifier->cfg;
struct rspamd_statfile_config *stf = st->stcf;
const ucl_object_t *filenameo, *lang_enabled, *users_enabled;
- const gchar *filename, *lua_script;
+ const char *filename, *lua_script;
struct rspamd_stat_sqlite3_db *bk;
GError *err = NULL;
gpointer
rspamd_sqlite3_runtime(struct rspamd_task *task,
- struct rspamd_statfile_config *stcf, gboolean learn, gpointer p, gint _id)
+ struct rspamd_statfile_config *stcf, gboolean learn, gpointer p, int _id)
{
struct rspamd_stat_sqlite3_rt *rt = NULL;
struct rspamd_stat_sqlite3_db *bk = p;
gboolean
rspamd_sqlite3_process_tokens(struct rspamd_task *task,
GPtrArray *tokens,
- gint id, gpointer p)
+ int id, gpointer p)
{
struct rspamd_stat_sqlite3_db *bk;
struct rspamd_stat_sqlite3_rt *rt = p;
int64_t iv = 0;
- guint i;
+ unsigned int i;
rspamd_token_t *tok;
g_assert(p != NULL);
gboolean
rspamd_sqlite3_learn_tokens(struct rspamd_task *task, GPtrArray *tokens,
- gint id, gpointer p)
+ int id, gpointer p)
{
struct rspamd_stat_sqlite3_db *bk;
struct rspamd_stat_sqlite3_rt *rt = p;
int64_t iv = 0;
- guint i;
+ unsigned int i;
rspamd_token_t *tok;
g_assert(tokens != NULL);
{
struct rspamd_stat_sqlite3_rt *rt = runtime;
struct rspamd_stat_sqlite3_db *bk;
- gint wal_frames, wal_checkpointed, mode;
+ int wal_frames, wal_checkpointed, mode;
g_assert(rt != NULL);
bk = rt->db;
* @param freedom_deg number of degrees of freedom
* @return
*/
-static gdouble
-inv_chi_square(struct rspamd_task *task, gdouble value, gint freedom_deg)
+static double
+inv_chi_square(struct rspamd_task *task, double value, int freedom_deg)
{
double prob, sum, m;
- gint i;
+ int i;
errno = 0;
m = -value;
* from 1.0 (no confidence) to 0.0 (full confidence)
*/
for (i = 1; i < freedom_deg; i++) {
- prob *= m / (gdouble) i;
+ prob *= m / (double) i;
sum += prob;
msg_debug_bayes("i=%d, probability: %g, sum: %g", i, prob, sum);
}
struct bayes_task_closure {
double ham_prob;
double spam_prob;
- gdouble meta_skip_prob;
+ double meta_skip_prob;
uint64_t processed_tokens;
uint64_t total_hits;
uint64_t text_tokens;
bayes_classify_token(struct rspamd_classifier *ctx,
rspamd_token_t *tok, struct bayes_task_closure *cl)
{
- guint i;
- gint id;
- guint spam_count = 0, ham_count = 0, total_count = 0;
+ unsigned int i;
+ int id;
+ unsigned int spam_count = 0, ham_count = 0, total_count = 0;
struct rspamd_statfile *st;
struct rspamd_task *task;
- const gchar *token_type = "txt";
+ const char *token_type = "txt";
double spam_prob, spam_freq, ham_freq, bayes_spam_prob, bayes_ham_prob,
ham_prob, fw, w, val;
}
for (i = 0; i < ctx->statfiles_ids->len; i++) {
- id = g_array_index(ctx->statfiles_ids, gint, i);
+ id = g_array_index(ctx->statfiles_ids, int, i);
st = g_ptr_array_index(ctx->ctx->statfiles, id);
g_assert(st != NULL);
val = tok->values[id];
struct rspamd_task *task)
{
double final_prob, h, s, *pprob;
- gchar sumbuf[32];
+ char sumbuf[32];
struct rspamd_statfile *st = NULL;
struct bayes_task_closure cl;
rspamd_token_t *tok;
- guint i, text_tokens = 0;
- gint id;
+ unsigned int i, text_tokens = 0;
+ int id;
g_assert(ctx != NULL);
g_assert(tokens != NULL);
}
if (ctx->cfg->min_tokens > 0 &&
- cl.text_tokens < (gint) (ctx->cfg->min_tokens * 0.1)) {
+ cl.text_tokens < (int) (ctx->cfg->min_tokens * 0.1)) {
msg_info_bayes("ignore bayes probability since we have "
"found too few text tokens: %uL (of %ud checked), "
"at least %d required",
cl.text_tokens,
text_tokens,
- (gint) (ctx->cfg->min_tokens * 0.1));
+ (int) (ctx->cfg->min_tokens * 0.1));
return TRUE;
}
if (cl.processed_tokens > 0 && fabs(final_prob - 0.5) > 0.05) {
/* Now we can have exactly one HAM and exactly one SPAM statfiles per classifier */
for (i = 0; i < ctx->statfiles_ids->len; i++) {
- id = g_array_index(ctx->statfiles_ids, gint, i);
+ id = g_array_index(ctx->statfiles_ids, int, i);
st = g_ptr_array_index(ctx->ctx->statfiles, id);
if (final_prob > 0.5 && st->stcf->is_spam) {
gboolean unlearn,
GError **err)
{
- guint i, j, total_cnt, spam_cnt, ham_cnt;
- gint id;
+ unsigned int i, j, total_cnt, spam_cnt, ham_cnt;
+ int id;
struct rspamd_statfile *st;
rspamd_token_t *tok;
gboolean incrementing;
tok = g_ptr_array_index(tokens, i);
for (j = 0; j < ctx->statfiles_ids->len; j++) {
- id = g_array_index(ctx->statfiles_ids, gint, j);
+ id = g_array_index(ctx->statfiles_ids, int, j);
st = g_ptr_array_index(ctx->ctx->statfiles, id);
g_assert(st != NULL);
gboolean unlearn,
GError **err);
-extern gint rspamd_bayes_log_id;
+extern int rspamd_bayes_log_id;
#define msg_debug_bayes(...) rspamd_conditional_debug_fast(NULL, task->from_addr, \
rspamd_bayes_log_id, "bayes", task->task_pool->tag.uid, \
G_STRFUNC, \
#include "lua/lua_common.h"
struct rspamd_lua_classifier_ctx {
- gchar *name;
- gint classify_ref;
- gint learn_ref;
+ char *name;
+ int classify_ref;
+ int learn_ref;
};
static GHashTable *lua_classifiers = NULL;
{
struct rspamd_lua_classifier_ctx *ctx;
lua_State *L = cl->ctx->cfg->lua_state;
- gint cb_classify = -1, cb_learn = -1;
+ int cb_classify = -1, cb_learn = -1;
if (lua_classifiers == NULL) {
lua_classifiers = g_hash_table_new_full(rspamd_strcase_hash,
struct rspamd_classifier_config **pcfg;
lua_State *L;
rspamd_token_t *tok;
- guint i;
+ unsigned int i;
uint64_t v;
ctx = g_hash_table_lookup(lua_classifiers, cl->subrs->name);
struct rspamd_classifier_config **pcfg;
lua_State *L;
rspamd_token_t *tok;
- guint i;
+ unsigned int i;
uint64_t v;
ctx = g_hash_table_lookup(lua_classifiers, cl->subrs->name);
gpointer (*runtime)(struct rspamd_task *task,
gpointer ctx, gboolean learn);
- gint (*check)(struct rspamd_task *task,
- gboolean is_spam,
- gpointer runtime);
+ int (*check)(struct rspamd_task *task,
+ gboolean is_spam,
+ gpointer runtime);
- gint (*learn)(struct rspamd_task *task,
- gboolean is_spam,
- gpointer runtime);
+ int (*learn)(struct rspamd_task *task,
+ gboolean is_spam,
+ gpointer runtime);
void (*close)(gpointer ctx);
const ucl_object_t *cf); \
gpointer rspamd_stat_cache_##name##_runtime(struct rspamd_task *task, \
gpointer ctx, gboolean learn); \
- gint rspamd_stat_cache_##name##_check(struct rspamd_task *task, \
- gboolean is_spam, \
- gpointer runtime); \
- gint rspamd_stat_cache_##name##_learn(struct rspamd_task *task, \
- gboolean is_spam, \
- gpointer runtime); \
+ int rspamd_stat_cache_##name##_check(struct rspamd_task *task, \
+ gboolean is_spam, \
+ gpointer runtime); \
+ int rspamd_stat_cache_##name##_learn(struct rspamd_task *task, \
+ gboolean is_spam, \
+ gpointer runtime); \
void rspamd_stat_cache_##name##_close(gpointer ctx)
RSPAMD_STAT_CACHE_DEF(sqlite3);
sizeof(tok->data));
}
- guchar out[rspamd_cryptobox_HASHBYTES];
+ unsigned char out[rspamd_cryptobox_HASHBYTES];
rspamd_cryptobox_hash_final(&st, out);
auto *b32out = rspamd_mempool_alloc_array_type(task->task_pool,
return (void *) ctx;
}
-static gint
+static int
rspamd_stat_cache_checked(lua_State *L)
{
auto *task = lua_check_task(L, 1);
return 0;
}
-gint rspamd_stat_cache_redis_check(struct rspamd_task *task,
- gboolean is_spam,
- gpointer runtime)
+int rspamd_stat_cache_redis_check(struct rspamd_task *task,
+ gboolean is_spam,
+ gpointer runtime)
{
auto *ctx = (struct rspamd_redis_cache_ctx *) runtime;
auto *h = (char *) rspamd_mempool_get_variable(task->task_pool, "words_hash");
auto *L = ctx->L;
lua_pushcfunction(L, &rspamd_lua_traceback);
- gint err_idx = lua_gettop(L);
+ int err_idx = lua_gettop(L);
/* Function arguments */
lua_rawgeti(L, LUA_REGISTRYINDEX, ctx->check_ref);
return RSPAMD_LEARN_OK;
}
-gint rspamd_stat_cache_redis_learn(struct rspamd_task *task,
- gboolean is_spam,
- gpointer runtime)
+int rspamd_stat_cache_redis_learn(struct rspamd_task *task,
+ gboolean is_spam,
+ gpointer runtime)
{
auto *ctx = (struct rspamd_redis_cache_ctx *) runtime;
auto *L = ctx->L;
lua_pushcfunction(L, &rspamd_lua_traceback);
- gint err_idx = lua_gettop(L);
+ int err_idx = lua_gettop(L);
/* Function arguments */
lua_rawgeti(L, LUA_REGISTRYINDEX, ctx->learn_ref);
{
struct rspamd_stat_sqlite3_ctx *new = NULL;
const ucl_object_t *elt;
- gchar dbpath[PATH_MAX];
- const gchar *path = SQLITE_CACHE_PATH;
+ char dbpath[PATH_MAX];
+ const char *path = SQLITE_CACHE_PATH;
sqlite3 *sqlite;
GError *err = NULL;
return ctx;
}
-gint rspamd_stat_cache_sqlite3_check(struct rspamd_task *task,
- gboolean is_spam,
- gpointer runtime)
+int rspamd_stat_cache_sqlite3_check(struct rspamd_task *task,
+ gboolean is_spam,
+ gpointer runtime)
{
struct rspamd_stat_sqlite3_ctx *ctx = runtime;
rspamd_cryptobox_hash_state_t st;
rspamd_token_t *tok;
- guchar *out;
- gchar *user = NULL;
- guint i;
- gint rc;
+ unsigned char *out;
+ char *user = NULL;
+ unsigned int i;
+ int rc;
int64_t flag;
if (task->tokens == NULL || task->tokens->len == 0) {
for (i = 0; i < task->tokens->len; i++) {
tok = g_ptr_array_index(task->tokens, i);
- rspamd_cryptobox_hash_update(&st, (guchar *) &tok->data,
+ rspamd_cryptobox_hash_update(&st, (unsigned char *) &tok->data,
sizeof(tok->data));
}
return RSPAMD_LEARN_OK;
}
-gint rspamd_stat_cache_sqlite3_learn(struct rspamd_task *task,
- gboolean is_spam,
- gpointer runtime)
+int rspamd_stat_cache_sqlite3_learn(struct rspamd_task *task,
+ gboolean is_spam,
+ gpointer runtime)
{
struct rspamd_stat_sqlite3_ctx *ctx = runtime;
gboolean unlearn = !!(task->flags & RSPAMD_TASK_FLAG_UNLEARN);
- guchar *h;
+ unsigned char *h;
int64_t flag;
h = rspamd_mempool_get_variable(task->task_pool, "words_hash");
rspamd_ftok_unicode_t unicode; /* array of unicode characters, normalized, lowercased */
rspamd_ftok_t normalized; /* normalized and lowercased utf8 */
rspamd_ftok_t stemmed; /* stemmed utf8 */
- guint flags;
+ unsigned int flags;
} rspamd_stat_token_t;
#define RSPAMD_TOKEN_VALUE_TYPE float
typedef struct token_node_s {
uint64_t data;
- guint window_idx;
- guint flags;
+ unsigned int window_idx;
+ unsigned int flags;
rspamd_stat_token_t *t1;
rspamd_stat_token_t *t2;
RSPAMD_TOKEN_VALUE_TYPE values[0];
* @return TRUE if task has been classified
*/
rspamd_stat_result_t rspamd_stat_classify(struct rspamd_task *task,
- lua_State *L, guint stage, GError **err);
+ lua_State *L, unsigned int stage, GError **err);
/**
* @return TRUE if task has been learned
*/
rspamd_stat_result_t rspamd_stat_learn(struct rspamd_task *task,
- gboolean spam, lua_State *L, const gchar *classifier,
- guint stage,
+ gboolean spam, lua_State *L, const char *classifier,
+ unsigned int stage,
GError **err);
/**
struct rspamd_statfile *st;
struct rspamd_classifier *cl;
const ucl_object_t *cache_obj = NULL, *cache_name_obj;
- const gchar *cache_name = NULL;
+ const char *cache_name = NULL;
lua_State *L = cfg->lua_state;
- guint lua_classifiers_cnt = 0, i;
+ unsigned int lua_classifiers_cnt = 0, i;
gboolean skip_cache = FALSE;
if (stat_ctx == NULL) {
}
else {
/* Call this function to obtain closure */
- gint err_idx, ret;
+ int err_idx, ret;
struct rspamd_config **pcfg;
lua_pushcfunction(L, &rspamd_lua_traceback);
cl = g_malloc0(sizeof(*cl));
cl->cfg = clf;
cl->ctx = stat_ctx;
- cl->statfiles_ids = g_array_new(FALSE, FALSE, sizeof(gint));
+ cl->statfiles_ids = g_array_new(FALSE, FALSE, sizeof(int));
cl->subrs = rspamd_stat_get_classifier(clf->classifier);
if (cl->subrs == NULL) {
struct rspamd_stat_ctx *st_ctx;
struct rspamd_stat_async_elt *aelt;
GList *cur;
- guint i, j;
- gint id;
+ unsigned int i, j;
+ int id;
st_ctx = rspamd_stat_get_ctx();
g_assert(st_ctx != NULL);
cl = g_ptr_array_index(st_ctx->classifiers, i);
for (j = 0; j < cl->statfiles_ids->len; j++) {
- id = g_array_index(cl->statfiles_ids, gint, j);
+ id = g_array_index(cl->statfiles_ids, int, j);
st = g_ptr_array_index(st_ctx->statfiles, id);
if (!(st->classifier->cfg->flags & RSPAMD_FLAG_CLASSIFIER_NO_BACKEND)) {
st->backend->close(st->bkcf);
}
struct rspamd_stat_classifier *
-rspamd_stat_get_classifier(const gchar *name)
+rspamd_stat_get_classifier(const char *name)
{
- guint i;
+ unsigned int i;
if (name == NULL || name[0] == '\0') {
name = RSPAMD_DEFAULT_CLASSIFIER;
}
struct rspamd_stat_backend *
-rspamd_stat_get_backend(const gchar *name)
+rspamd_stat_get_backend(const char *name)
{
- guint i;
+ unsigned int i;
if (name == NULL || name[0] == '\0') {
name = RSPAMD_DEFAULT_BACKEND;
}
struct rspamd_stat_tokenizer *
-rspamd_stat_get_tokenizer(const gchar *name)
+rspamd_stat_get_tokenizer(const char *name)
{
- guint i;
+ unsigned int i;
if (name == NULL || name[0] == '\0') {
name = RSPAMD_DEFAULT_TOKENIZER;
}
struct rspamd_stat_cache *
-rspamd_stat_get_cache(const gchar *name)
+rspamd_stat_get_cache(const char *name)
{
- guint i;
+ unsigned int i;
if (name == NULL || name[0] == '\0') {
name = RSPAMD_DEFAULT_CACHE;
rspamd_async_elt_on_timer(EV_P_ ev_timer *w, int revents)
{
struct rspamd_stat_async_elt *elt = (struct rspamd_stat_async_elt *) w->data;
- gdouble jittered_time;
+ double jittered_time;
if (elt->enabled) {
rspamd_stat_ctx_register_async(rspamd_stat_async_handler handler,
rspamd_stat_async_cleanup cleanup,
gpointer d,
- gdouble timeout)
+ double timeout)
{
struct rspamd_stat_async_elt *elt;
struct rspamd_stat_ctx *st_ctx;
gpointer cachecf;
gulong spam_learns;
gulong ham_learns;
- gint autolearn_cbref;
+ int autolearn_cbref;
struct rspamd_classifier_config *cfg;
struct rspamd_stat_classifier *subrs;
gpointer specific;
};
struct rspamd_statfile {
- gint id;
+ int id;
struct rspamd_statfile_config *stcf;
struct rspamd_classifier *classifier;
struct rspamd_stat_backend *backend;
rspamd_stat_async_cleanup cleanup;
struct ev_loop *event_loop;
ev_timer timer_ev;
- gdouble timeout;
+ double timeout;
gboolean enabled;
gpointer ud;
ref_entry_t ref;
struct rspamd_stat_ctx {
/* Subroutines for all objects */
struct rspamd_stat_classifier *classifiers_subrs;
- guint classifiers_count;
+ unsigned int classifiers_count;
struct rspamd_stat_tokenizer *tokenizers_subrs;
- guint tokenizers_count;
+ unsigned int tokenizers_count;
struct rspamd_stat_backend *backends_subrs;
- guint backends_count;
+ unsigned int backends_count;
struct rspamd_stat_cache *caches_subrs;
- guint caches_count;
+ unsigned int caches_count;
/* Runtime configuration */
GPtrArray *statfiles; /* struct rspamd_statfile */
GQueue *async_elts; /* struct rspamd_stat_async_elt */
struct rspamd_config *cfg;
- gint lua_stat_tokens_ref;
+ int lua_stat_tokens_ref;
/* Global tokenizer */
struct rspamd_stat_tokenizer *tokenizer;
struct rspamd_stat_ctx *rspamd_stat_get_ctx(void);
-struct rspamd_stat_classifier *rspamd_stat_get_classifier(const gchar *name);
+struct rspamd_stat_classifier *rspamd_stat_get_classifier(const char *name);
-struct rspamd_stat_backend *rspamd_stat_get_backend(const gchar *name);
+struct rspamd_stat_backend *rspamd_stat_get_backend(const char *name);
-struct rspamd_stat_tokenizer *rspamd_stat_get_tokenizer(const gchar *name);
+struct rspamd_stat_tokenizer *rspamd_stat_get_tokenizer(const char *name);
-struct rspamd_stat_cache *rspamd_stat_get_cache(const gchar *name);
+struct rspamd_stat_cache *rspamd_stat_get_cache(const char *name);
struct rspamd_stat_async_elt *rspamd_stat_ctx_register_async(
rspamd_stat_async_handler handler, rspamd_stat_async_cleanup cleanup,
- gpointer d, gdouble timeout);
+ gpointer d, double timeout);
static GQuark rspamd_stat_quark(void)
{
#define RSPAMD_LEARN_OP 1
#define RSPAMD_UNLEARN_OP 2
-static const gdouble similarity_threshold = 80.0;
+static const double similarity_threshold = 80.0;
static void
rspamd_stat_tokenize_parts_metadata(struct rspamd_stat_ctx *st_ctx,
{
GArray *ar;
rspamd_stat_token_t elt;
- guint i;
+ unsigned int i;
lua_State *L = task->cfg->lua_state;
ar = g_array_sized_new(FALSE, FALSE, sizeof(elt), 16);
elt.flags = RSPAMD_STAT_TOKEN_FLAG_META;
if (st_ctx->lua_stat_tokens_ref != -1) {
- gint err_idx, ret;
+ int err_idx, ret;
struct rspamd_task **ptask;
lua_pushcfunction(L, &rspamd_lua_traceback);
lua_typename(L, lua_type(L, -1)));
}
else {
- guint vlen;
+ unsigned int vlen;
rspamd_ftok_t tok;
vlen = rspamd_lua_table_size(L, -1);
struct rspamd_mime_text_part *part;
rspamd_cryptobox_hash_state_t hst;
rspamd_token_t *st_tok;
- guint i, reserved_len = 0;
- gdouble *pdiff;
- guchar hout[rspamd_cryptobox_HASHBYTES];
- gchar *b32_hout;
+ unsigned int i, reserved_len = 0;
+ double *pdiff;
+ unsigned char hout[rspamd_cryptobox_HASHBYTES];
+ char *b32_hout;
if (st_ctx == NULL) {
st_ctx = rspamd_stat_get_ctx();
PTR_ARRAY_FOREACH(task->tokens, i, st_tok)
{
- rspamd_cryptobox_hash_update(&hst, (guchar *) &st_tok->data,
+ rspamd_cryptobox_hash_update(&hst, (unsigned char *) &st_tok->data,
sizeof(st_tok->data));
}
gboolean ret = FALSE;
while (cur) {
- gint cb_ref = GPOINTER_TO_INT(cur->data);
- gint old_top = lua_gettop(L);
- gint nargs;
+ int cb_ref = GPOINTER_TO_INT(cur->data);
+ int old_top = lua_gettop(L);
+ int nargs;
lua_rawgeti(L, LUA_REGISTRYINDEX, cb_ref);
/* Push task and two booleans: is_spam and is_unlearn */
rspamd_stat_preprocess(struct rspamd_stat_ctx *st_ctx,
struct rspamd_task *task, gboolean is_learn, gboolean is_spam)
{
- guint i;
+ unsigned int i;
struct rspamd_statfile *st;
gpointer bk_run;
if (skip_classifier) {
/* Set NULL for all statfiles indexed by id */
for (int j = 0; j < cl->statfiles_ids->len; j++) {
- int id = g_array_index(cl->statfiles_ids, gint, j);
+ int id = g_array_index(cl->statfiles_ids, int, j);
g_ptr_array_index(task->stat_runtimes, id) = NULL;
}
}
rspamd_stat_backends_process(struct rspamd_stat_ctx *st_ctx,
struct rspamd_task *task)
{
- guint i;
+ unsigned int i;
struct rspamd_statfile *st;
gpointer bk_run;
rspamd_stat_classifiers_process(struct rspamd_stat_ctx *st_ctx,
struct rspamd_task *task)
{
- guint i, j, id;
+ unsigned int i, j, id;
struct rspamd_classifier *cl;
struct rspamd_statfile *st;
gpointer bk_run;
/* Do not process classifiers on backend failures */
for (j = 0; j < cl->statfiles_ids->len; j++) {
- id = g_array_index(cl->statfiles_ids, gint, j);
+ id = g_array_index(cl->statfiles_ids, int, j);
bk_run = g_ptr_array_index(task->stat_runtimes, id);
st = g_ptr_array_index(st_ctx->statfiles, id);
/* Ensure that all symbols enabled */
if (!skip && !(cl->cfg->flags & RSPAMD_FLAG_CLASSIFIER_NO_BACKEND)) {
for (j = 0; j < cl->statfiles_ids->len; j++) {
- id = g_array_index(cl->statfiles_ids, gint, j);
+ id = g_array_index(cl->statfiles_ids, int, j);
bk_run = g_ptr_array_index(task->stat_runtimes, id);
st = g_ptr_array_index(st_ctx->statfiles, id);
}
rspamd_stat_result_t
-rspamd_stat_classify(struct rspamd_task *task, lua_State *L, guint stage,
+rspamd_stat_classify(struct rspamd_task *task, lua_State *L, unsigned int stage,
GError **err)
{
struct rspamd_stat_ctx *st_ctx;
static gboolean
rspamd_stat_cache_check(struct rspamd_stat_ctx *st_ctx,
struct rspamd_task *task,
- const gchar *classifier,
+ const char *classifier,
gboolean spam,
GError **err)
{
rspamd_learn_t learn_res = RSPAMD_LEARN_OK;
struct rspamd_classifier *cl, *sel = NULL;
gpointer rt;
- guint i;
+ unsigned int i;
/* Check whether we have learned that file */
for (i = 0; i < st_ctx->classifiers->len; i++) {
static gboolean
rspamd_stat_classifiers_learn(struct rspamd_stat_ctx *st_ctx,
struct rspamd_task *task,
- const gchar *classifier,
+ const char *classifier,
gboolean spam,
GError **err)
{
struct rspamd_classifier *cl, *sel = NULL;
- guint i;
+ unsigned int i;
gboolean learned = FALSE, too_small = FALSE, too_large = FALSE;
if ((task->flags & RSPAMD_TASK_FLAG_ALREADY_LEARNED) && err != NULL &&
static gboolean
rspamd_stat_backends_learn(struct rspamd_stat_ctx *st_ctx,
struct rspamd_task *task,
- const gchar *classifier,
+ const char *classifier,
gboolean spam,
GError **err)
{
struct rspamd_classifier *cl, *sel = NULL;
struct rspamd_statfile *st;
gpointer bk_run;
- guint i, j;
- gint id;
+ unsigned int i, j;
+ int id;
gboolean res = FALSE, backend_found = FALSE;
for (i = 0; i < st_ctx->classifiers->len; i++) {
sel = cl;
for (j = 0; j < cl->statfiles_ids->len; j++) {
- id = g_array_index(cl->statfiles_ids, gint, j);
+ id = g_array_index(cl->statfiles_ids, int, j);
st = g_ptr_array_index(st_ctx->statfiles, id);
bk_run = g_ptr_array_index(task->stat_runtimes, id);
static gboolean
rspamd_stat_backends_post_learn(struct rspamd_stat_ctx *st_ctx,
struct rspamd_task *task,
- const gchar *classifier,
+ const char *classifier,
gboolean spam,
GError **err)
{
struct rspamd_classifier *cl;
struct rspamd_statfile *st;
gpointer bk_run, cache_run;
- guint i, j;
- gint id;
+ unsigned int i, j;
+ int id;
gboolean res = TRUE;
for (i = 0; i < st_ctx->classifiers->len; i++) {
}
for (j = 0; j < cl->statfiles_ids->len; j++) {
- id = g_array_index(cl->statfiles_ids, gint, j);
+ id = g_array_index(cl->statfiles_ids, int, j);
st = g_ptr_array_index(st_ctx->statfiles, id);
bk_run = g_ptr_array_index(task->stat_runtimes, id);
rspamd_stat_result_t
rspamd_stat_learn(struct rspamd_task *task,
- gboolean spam, lua_State *L, const gchar *classifier, guint stage,
+ gboolean spam, lua_State *L, const char *classifier, unsigned int stage,
GError **err)
{
struct rspamd_stat_ctx *st_ctx;
struct rspamd_scan_result *mres,
struct rspamd_classifier *cl)
{
- guint i;
- gint id;
+ unsigned int i;
+ int id;
struct rspamd_statfile *st;
struct rspamd_stat_ctx *st_ctx;
gboolean is_spam;
is_spam = !!(task->flags & RSPAMD_TASK_FLAG_LEARN_SPAM);
for (i = 0; i < cl->statfiles_ids->len; i++) {
- id = g_array_index(cl->statfiles_ids, gint, i);
+ id = g_array_index(cl->statfiles_ids, int, i);
st = g_ptr_array_index(st_ctx->statfiles, id);
if (rspamd_task_find_symbol_result(task, st->stcf->symbol, NULL)) {
struct rspamd_scan_result *mres = NULL;
struct rspamd_task **ptask;
lua_State *L;
- guint i;
- gint err_idx;
+ unsigned int i;
+ int err_idx;
gboolean ret = FALSE;
- gdouble ham_score, spam_score;
- const gchar *lua_script, *lua_ret;
+ double ham_score, spam_score;
+ const char *lua_script, *lua_ret;
g_assert(RSPAMD_TASK_IS_CLASSIFIED(task));
st_ctx = rspamd_stat_get_ctx();
spam_score = ucl_object_todouble(elt2);
if (ham_score > spam_score) {
- gdouble t;
+ double t;
t = ham_score;
ham_score = spam_score;
gpointer backend_runtime;
ucl_object_t *res = NULL, *elt;
uint64_t learns = 0;
- guint i, j;
- gint id;
+ unsigned int i, j;
+ int id;
st_ctx = rspamd_stat_get_ctx();
g_assert(st_ctx != NULL);
}
for (j = 0; j < cl->statfiles_ids->len; j++) {
- id = g_array_index(cl->statfiles_ids, gint, j);
+ id = g_array_index(cl->statfiles_ids, int, j);
st = g_ptr_array_index(st_ctx->statfiles, id);
backend_runtime = st->backend->runtime(task, st->stcf, FALSE,
st->bkcf, id);
3277,
};
-static const guchar osb_tokenizer_magic[] = {'o', 's', 'b', 't', 'o', 'k', 'v', '2'};
+static const unsigned char osb_tokenizer_magic[] = {'o', 's', 'b', 't', 'o', 'k', 'v', '2'};
enum rspamd_osb_hash_type {
RSPAMD_OSB_HASH_COMPAT = 0,
};
struct rspamd_osb_tokenizer_config {
- guchar magic[8];
+ unsigned char magic[8];
gshort version;
gshort window_size;
enum rspamd_osb_hash_type ht;
{
const ucl_object_t *elt;
struct rspamd_osb_tokenizer_config *cf, *def;
- guchar *key = NULL;
+ unsigned char *key = NULL;
gsize keylen;
rspamd_stat_token_t *t;
};
-gint rspamd_tokenizer_osb(struct rspamd_stat_ctx *ctx,
- struct rspamd_task *task,
- GArray *words,
- gboolean is_utf,
- const gchar *prefix,
- GPtrArray *result)
+int rspamd_tokenizer_osb(struct rspamd_stat_ctx *ctx,
+ struct rspamd_task *task,
+ GArray *words,
+ gboolean is_utf,
+ const char *prefix,
+ GPtrArray *result)
{
rspamd_token_t *new_tok = NULL;
rspamd_stat_token_t *token;
struct token_pipe_entry *hashpipe;
uint32_t h1, h2;
gsize token_size;
- guint processed = 0, i, w, window_size, token_flags = 0;
+ unsigned int processed = 0, i, w, window_size, token_flags = 0;
if (words == NULL) {
return FALSE;
for (w = 0; w < words->len; w++) {
token = &g_array_index(words, rspamd_stat_token_t, w);
token_flags = token->flags;
- const gchar *begin;
+ const char *begin;
gsize len;
if (token->flags &
begin, len, osb_cf->seed);
}
else {
- rspamd_cryptobox_siphash((guchar *) &cur, begin,
+ rspamd_cryptobox_siphash((unsigned char *) &cur, begin,
len, osb_cf->sk);
if (prefix) {
((uint32_t) hashpipe[i].h) * primes[i << 1]; \
h2 = ((uint32_t) hashpipe[0].h) * primes[1] + \
((uint32_t) hashpipe[i].h) * primes[(i << 1) - 1]; \
- memcpy((guchar *) &new_tok->data, &h1, sizeof(h1)); \
- memcpy(((guchar *) &new_tok->data) + sizeof(h1), &h2, sizeof(h2)); \
+ memcpy((unsigned char *) &new_tok->data, &h1, sizeof(h1)); \
+ memcpy(((unsigned char *) &new_tok->data) + sizeof(h1), &h2, sizeof(h2)); \
} \
else { \
new_tok->data = hashpipe[0].h * primes[0] + hashpipe[i].h * primes[i << 1]; \
#include <math.h>
-typedef gboolean (*token_get_function)(rspamd_stat_token_t *buf, gchar const **pos,
+typedef gboolean (*token_get_function)(rspamd_stat_token_t *buf, char const **pos,
rspamd_stat_token_t *token,
GList **exceptions, gsize *rl, gboolean check_signature);
-const gchar t_delimiters[256] = {
+const char t_delimiters[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* Get next word from specified f_str_t buf */
static gboolean
rspamd_tokenizer_get_word_raw(rspamd_stat_token_t *buf,
- gchar const **cur, rspamd_stat_token_t *token,
+ char const **cur, rspamd_stat_token_t *token,
GList **exceptions, gsize *rl, gboolean unused)
{
gsize remain, pos;
- const gchar *p;
+ const char *p;
struct rspamd_process_exception *ex = NULL;
if (buf == NULL) {
pos++;
p++;
remain--;
- } while (remain > 0 && t_delimiters[(guchar) *p]);
+ } while (remain > 0 && t_delimiters[(unsigned char) *p]);
token->original.begin = p;
- while (remain > 0 && !t_delimiters[(guchar) *p]) {
+ while (remain > 0 && !t_delimiters[(unsigned char) *p]) {
if (ex != NULL && ex->pos == pos) {
*exceptions = g_list_next(*exceptions);
*cur = p + ex->len;
static inline gboolean
rspamd_tokenize_check_limit(gboolean decay,
- guint word_decay,
- guint nwords,
+ unsigned int word_decay,
+ unsigned int nwords,
uint64_t *hv,
uint64_t *prob,
const rspamd_stat_token_t *token,
gssize remain,
gssize total)
{
- static const gdouble avg_word_len = 6.0;
+ static const double avg_word_len = 6.0;
if (!decay) {
if (token->original.len >= sizeof(uint64_t)) {
/* Check for decay */
if (word_decay > 0 && nwords > word_decay && remain < (gssize) total) {
/* Start decay */
- gdouble decay_prob;
+ double decay_prob;
*hv = mum_hash_finish(*hv);
/* We assume that word is 6 symbols length in average */
- decay_prob = (gdouble) word_decay / ((total - (remain)) / avg_word_len) * 10;
+ decay_prob = (double) word_decay / ((total - (remain)) / avg_word_len) * 10;
decay_prob = floor(decay_prob) / 10.0;
if (decay_prob >= 1.0) {
}
static inline gboolean
-rspamd_utf_word_valid(const guchar *text, const guchar *end,
+rspamd_utf_word_valid(const unsigned char *text, const unsigned char *end,
int32_t start, int32_t finish)
{
- const guchar *st = text + start, *fin = text + finish;
+ const unsigned char *st = text + start, *fin = text + finish;
UChar32 c;
if (st >= end || fin > end || st >= fin) {
GArray *
-rspamd_tokenize_text(const gchar *text, gsize len,
+rspamd_tokenize_text(const char *text, gsize len,
const UText *utxt,
enum rspamd_tokenize_type how,
struct rspamd_config *cfg,
rspamd_mempool_t *pool)
{
rspamd_stat_token_t token, buf;
- const gchar *pos = NULL;
+ const char *pos = NULL;
gsize l = 0;
GArray *res;
GList *cur = exceptions;
- guint min_len = 0, max_len = 0, word_decay = 0, initial_size = 128;
+ unsigned int min_len = 0, max_len = 0, word_decay = 0, initial_size = 128;
uint64_t hv = 0;
gboolean decay = FALSE, long_text_mode = FALSE;
uint64_t prob = 0;
msg_warn_pool_check(
"tokenization reversed back on position %d,"
"%d new position (%d backward), likely libicu bug!",
- (gint) (p), (gint) (old_p), old_p - p);
+ (int) (p), (int) (old_p), old_p - p);
goto end;
}
msg_warn_pool_check(
"tokenization reversed back on position %d,"
"%d new position (%d backward), likely libicu bug!",
- (gint) (p), (gint) (old_p), old_p - p);
+ (int) (p), (int) (old_p), old_p - p);
goto end;
}
if (p != UBRK_DONE && p <= last) {
msg_warn_pool_check("tokenization reversed back on position %d,"
"%d new position (%d backward), likely libicu bug!",
- (gint) (p), (gint) (last), last - p);
+ (int) (p), (int) (last), last - p);
goto end;
}
#undef SHIFT_EX
static void
-rspamd_add_metawords_from_str(const gchar *beg, gsize len,
+rspamd_add_metawords_from_str(const char *beg, gsize len,
struct rspamd_task *task)
{
UText utxt = UTEXT_INITIALIZER;
UErrorCode uc_err = U_ZERO_ERROR;
- guint i = 0;
+ unsigned int i = 0;
UChar32 uc;
gboolean valid_utf = TRUE;
void rspamd_tokenize_meta_words(struct rspamd_task *task)
{
- guint i = 0;
+ unsigned int i = 0;
rspamd_stat_token_t *tok;
if (MESSAGE_FIELD(task, subject)) {
}
if (task->meta_words != NULL) {
- const gchar *language = NULL;
+ const char *language = NULL;
if (MESSAGE_FIELD(task, text_parts) &&
MESSAGE_FIELD(task, text_parts)->len > 0) {
rspamd_ucs32_to_normalised(rspamd_stat_token_t *tok,
rspamd_mempool_t *pool)
{
- guint i, doff = 0;
+ unsigned int i, doff = 0;
gsize utflen = 0;
- gchar *dest;
+ char *dest;
UChar32 t;
for (i = 0; i < tok->unicode.len; i++) {
if (!U_SUCCESS(uc_err)) {
if (uc_err != U_BUFFER_OVERFLOW_ERROR) {
msg_warn_pool_check("cannot normalise text '%*s': %s",
- (gint) tok->original.len, tok->original.begin,
+ (int) tok->original.len, tok->original.begin,
u_errorName(uc_err));
rspamd_uchars_to_ucs32(tmpbuf, ulen, tok, pool);
rspamd_ucs32_to_normalised(tok, pool);
else {
if (tok->flags & RSPAMD_STAT_TOKEN_FLAG_TEXT) {
/* Simple lowercase */
- gchar *dest;
+ char *dest;
dest = rspamd_mempool_alloc(pool, tok->original.len + 1);
rspamd_strlcpy(dest, tok->original.begin, tok->original.len + 1);
void rspamd_normalize_words(GArray *words, rspamd_mempool_t *pool)
{
rspamd_stat_token_t *tok;
- guint i;
+ unsigned int i;
for (i = 0; i < words->len; i++) {
tok = &g_array_index(words, rspamd_stat_token_t, i);
}
void rspamd_stem_words(GArray *words, rspamd_mempool_t *pool,
- const gchar *language,
+ const char *language,
struct rspamd_lang_detector *lang_detector)
{
static GHashTable *stemmers = NULL;
struct sb_stemmer *stem = NULL;
- guint i;
+ unsigned int i;
rspamd_stat_token_t *tok;
- gchar *dest;
+ char *dest;
gsize dlen;
if (!stemmers) {
if (tok->flags & RSPAMD_STAT_TOKEN_FLAG_UTF) {
if (stem) {
- const gchar *stemmed = NULL;
+ const char *stemmed = NULL;
stemmed = sb_stemmer_stem(stem,
tok->normalized.begin, tok->normalized.len);
/* Common tokenizer structure */
struct rspamd_stat_tokenizer {
- gchar *name;
+ char *name;
gpointer (*get_config)(rspamd_mempool_t *pool,
struct rspamd_tokenizer_config *cf, gsize *len);
- gint (*tokenize_func)(struct rspamd_stat_ctx *ctx,
- struct rspamd_task *task,
- GArray *words,
- gboolean is_utf,
- const gchar *prefix,
- GPtrArray *result);
+ int (*tokenize_func)(struct rspamd_stat_ctx *ctx,
+ struct rspamd_task *task,
+ GArray *words,
+ gboolean is_utf,
+ const char *prefix,
+ GPtrArray *result);
};
enum rspamd_tokenize_type {
};
/* Compare two token nodes */
-gint token_node_compare_func(gconstpointer a, gconstpointer b);
+int token_node_compare_func(gconstpointer a, gconstpointer b);
/* Tokenize text into array of words (rspamd_stat_token_t type) */
-GArray *rspamd_tokenize_text(const gchar *text, gsize len,
+GArray *rspamd_tokenize_text(const char *text, gsize len,
const UText *utxt,
enum rspamd_tokenize_type how,
struct rspamd_config *cfg,
rspamd_mempool_t *pool);
/* OSB tokenize function */
-gint rspamd_tokenizer_osb(struct rspamd_stat_ctx *ctx,
- struct rspamd_task *task,
- GArray *words,
- gboolean is_utf,
- const gchar *prefix,
- GPtrArray *result);
+int rspamd_tokenizer_osb(struct rspamd_stat_ctx *ctx,
+ struct rspamd_task *task,
+ GArray *words,
+ gboolean is_utf,
+ const char *prefix,
+ GPtrArray *result);
gpointer rspamd_tokenizer_osb_get_config(rspamd_mempool_t *pool,
struct rspamd_tokenizer_config *cf,
void rspamd_normalize_words(GArray *words, rspamd_mempool_t *pool);
void rspamd_stem_words(GArray *words, rspamd_mempool_t *pool,
- const gchar *language,
+ const char *language,
struct rspamd_lang_detector *lang_detector);
void rspamd_tokenize_meta_words(struct rspamd_task *task);
struct rspamd_addr_unix {
struct sockaddr_un addr;
- gint mode;
+ int mode;
uid_t owner;
gid_t group;
};
struct rspamd_addr_inet in;
struct rspamd_addr_unix *un;
} u;
- gint af;
+ int af;
socklen_t slen;
};
(pool != NULL) ? rspamd_mempool_alloc0((pool), (sz)) : g_malloc0(sz)
static rspamd_inet_addr_t *
-rspamd_inet_addr_create(gint af, rspamd_mempool_t *pool)
+rspamd_inet_addr_create(int af, rspamd_mempool_t *pool)
{
rspamd_inet_addr_t *addr;
rspamd_ip_check_ipv6(void)
{
if (ipv6_status == RSPAMD_IPV6_UNDEFINED) {
- gint s;
+ int s;
s = socket(AF_INET6, SOCK_STREAM, 0);
return ret;
}
-gint rspamd_accept_from_socket(gint sock, rspamd_inet_addr_t **target,
- rspamd_accept_throttling_handler hdl,
- void *hdl_data)
+int rspamd_accept_from_socket(int sock, rspamd_inet_addr_t **target,
+ rspamd_accept_throttling_handler hdl,
+ void *hdl_data)
{
- gint nfd, serrno;
+ int nfd, serrno;
union sa_union su;
socklen_t len = sizeof(su);
rspamd_inet_addr_t *addr = NULL;
if (su.sa.sa_family == AF_INET6) {
/* Deal with bloody v4 mapped to v6 addresses */
- static const guint8 mask[] = {
+ static const uint8_t mask[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- const guint8 *p;
+ const uint8_t *p;
- if (memcmp((const guint8 *) &su.s6.sin6_addr, mask, sizeof(mask)) == 0) {
- p = (const guint8 *) &su.s6.sin6_addr;
+ if (memcmp((const uint8_t *) &su.s6.sin6_addr, mask, sizeof(mask)) == 0) {
+ p = (const uint8_t *) &su.s6.sin6_addr;
if ((p[10] == 0xff && p[11] == 0xff)) {
addr = rspamd_inet_addr_create(AF_INET, NULL);
rspamd_mempool_t *pool,
enum rspamd_inet_address_parse_flags how)
{
- gchar **tokens, **cur_tok, *p, *pwbuf;
+ char **tokens, **cur_tok, *p, *pwbuf;
glong pwlen;
struct passwd pw, *ppw;
struct group gr, *pgr;
}
gboolean
-rspamd_parse_inet_address_ip4(const guchar *text, gsize len, gpointer target)
+rspamd_parse_inet_address_ip4(const unsigned char *text, gsize len, gpointer target)
{
- const guchar *p;
- guchar c;
+ const unsigned char *p;
+ unsigned char c;
uint32_t addr = 0, *addrptr = target;
- guint octet = 0, n = 0;
+ unsigned int octet = 0, n = 0;
g_assert(text != NULL);
g_assert(target != NULL);
}
gboolean
-rspamd_parse_inet_address_ip6(const guchar *text, gsize len, gpointer target)
+rspamd_parse_inet_address_ip6(const unsigned char *text, gsize len, gpointer target)
{
- guchar t, *zero = NULL, *s, *d, *addr = target;
- const guchar *p, *digit = NULL, *percent;
+ unsigned char t, *zero = NULL, *s, *d, *addr = target;
+ const unsigned char *p, *digit = NULL, *percent;
gsize len4 = 0;
- guint n = 8, nibbles = 0, word = 0;
+ unsigned int n = 8, nibbles = 0, word = 0;
g_assert(text != NULL);
g_assert(target != NULL);
}
word = ntohl(word);
- *addr++ = (guchar) ((word >> 24) & 0xff);
- *addr++ = (guchar) ((word >> 16) & 0xff);
+ *addr++ = (unsigned char) ((word >> 24) & 0xff);
+ *addr++ = (unsigned char) ((word >> 16) & 0xff);
n--;
break;
}
return FALSE;
}
- *addr++ = (guchar) (word >> 8);
- *addr++ = (guchar) (word & 0xff);
+ *addr++ = (unsigned char) (word >> 8);
+ *addr++ = (unsigned char) (word & 0xff);
if (--n) {
if (zero) {
{
rspamd_inet_addr_t *addr = NULL;
/* 10 zero bytes or 80 bits */
- static const guint8 mask[] = {
+ static const uint8_t mask[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- const guint8 *p;
+ const uint8_t *p;
- if (memcmp((const guint8 *) &sin6->sin6_addr, mask, sizeof(mask)) == 0) {
- p = (const guint8 *) &sin6->sin6_addr;
+ if (memcmp((const uint8_t *) &sin6->sin6_addr, mask, sizeof(mask)) == 0) {
+ p = (const uint8_t *) &sin6->sin6_addr;
if ((p[10] == 0xff && p[11] == 0xff)) {
addr = rspamd_inet_addr_create(AF_INET, pool);
rspamd_inet_addr_t *addr)
{
/* 10 zero bytes or 80 bits */
- static const guint8 mask[] = {
+ static const uint8_t mask[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- const guint8 *p;
+ const uint8_t *p;
- if (memcmp((const guint8 *) &sin6->sin6_addr, mask, sizeof(mask)) == 0) {
- p = (const guint8 *) &sin6->sin6_addr;
+ if (memcmp((const uint8_t *) &sin6->sin6_addr, mask, sizeof(mask)) == 0) {
+ p = (const uint8_t *) &sin6->sin6_addr;
if ((p[10] == 0xff && p[11] == 0xff)) {
memcpy(&addr->u.in.addr.s4.sin_addr, &p[12],
union sa_inet su;
const char *end = NULL;
char ipbuf[INET6_ADDRSTRLEN + 1];
- guint iplen;
+ unsigned int iplen;
gulong portnum;
if (srclen == 0) {
}
if (src[0] == '[') {
- const gchar *ip_start;
+ const char *ip_start;
/* Ipv6 address in format [::1]:port or just [::1] */
end = memchr(src + 1, ']', srclen - 1);
{
const char *end;
char ipbuf[INET6_ADDRSTRLEN + 1];
- guint iplen;
+ unsigned int iplen;
gulong portnum;
gboolean ret = FALSE;
union sa_inet su;
rspamd_inet_address_to_string(const rspamd_inet_addr_t *addr)
{
static char addr_str[NADDR_BUFS][INET6_ADDRSTRLEN + 1];
- static guint cur_addr = 0;
+ static unsigned int cur_addr = 0;
char *addr_buf;
if (addr == NULL) {
rspamd_inet_address_to_string_pretty(const rspamd_inet_addr_t *addr)
{
static char addr_str[NADDR_BUFS][PRETTY_IP_BUFSIZE];
- static guint cur_addr = 0;
+ static unsigned int cur_addr = 0;
char *addr_buf;
if (addr == NULL) {
}
}
-int rspamd_inet_address_connect(const rspamd_inet_addr_t *addr, gint type,
+int rspamd_inet_address_connect(const rspamd_inet_addr_t *addr, int type,
gboolean async)
{
int fd, r;
return fd;
}
-int rspamd_inet_address_listen(const rspamd_inet_addr_t *addr, gint type,
+int rspamd_inet_address_listen(const rspamd_inet_addr_t *addr, int type,
enum rspamd_inet_address_listen_opts opts,
- gint listen_queue)
+ int listen_queue)
{
- gint fd, r;
- gint on = 1, serrno;
+ int fd, r;
+ int on = 1, serrno;
const struct sockaddr *sa;
const char *path;
}
#if defined(SO_REUSEADDR)
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *) &on, sizeof(gint)) == -1) {
+ if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *) &on, sizeof(int)) == -1) {
msg_err("cannot set SO_REUSEADDR on %s (fd=%d): %s",
rspamd_inet_address_to_string_pretty(addr),
fd, strerror(errno));
if (opts & RSPAMD_INET_ADDRESS_LISTEN_REUSEPORT) {
on = 1;
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (const void *) &on, sizeof(gint)) == -1) {
+ if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (const void *) &on, sizeof(int)) == -1) {
msg_err("cannot set SO_REUSEPORT on %s (fd=%d): %s",
rspamd_inet_address_to_string_pretty(addr),
fd, strerror(errno));
/* We need to set this flag to avoid errors */
on = 1;
#ifdef SOL_IPV6
- (void) setsockopt(fd, SOL_IPV6, IPV6_V6ONLY, (const void *) &on, sizeof(gint));
+ (void) setsockopt(fd, SOL_IPV6, IPV6_V6ONLY, (const void *) &on, sizeof(int));
#elif defined(IPPROTO_IPV6)
- (void) setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (const void *) &on, sizeof(gint));
+ (void) setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (const void *) &on, sizeof(int));
#endif
}
#endif
}
gssize
-rspamd_inet_address_recvfrom(gint fd, void *buf, gsize len, gint fl,
+rspamd_inet_address_recvfrom(int fd, void *buf, gsize len, int fl,
rspamd_inet_addr_t **target)
{
gssize ret;
}
gssize
-rspamd_inet_address_sendto(gint fd, const void *buf, gsize len, gint fl,
+rspamd_inet_address_sendto(int fd, const void *buf, gsize len, int fl,
const rspamd_inet_addr_t *addr)
{
gssize r;
}
static gboolean
-rspamd_check_port_priority(const char *line, guint default_port,
- guint *priority, gchar *out,
+rspamd_check_port_priority(const char *line, unsigned int default_port,
+ unsigned int *priority, char *out,
gsize outlen, rspamd_mempool_t *pool)
{
- guint real_port = default_port, real_priority = 0;
- gchar *err_str, *err_str_prio;
+ unsigned int real_port = default_port, real_priority = 0;
+ char *err_str, *err_str_prio;
if (line && line[0] == ':') {
errno = 0;
static enum rspamd_parse_host_port_result
rspamd_resolve_addrs(const char *begin, size_t len, GPtrArray **addrs,
- const gchar *portbuf, gint flags,
+ const char *portbuf, int flags,
rspamd_mempool_t *pool)
{
struct addrinfo hints, *res, *cur;
rspamd_inet_addr_t *cur_addr = NULL;
- gint r, addr_cnt;
- gchar *addr_cpy = NULL;
+ int r, addr_cnt;
+ char *addr_cpy = NULL;
enum rspamd_parse_host_port_result ret = RSPAMD_PARSE_ADDR_FAIL;
rspamd_ip_check_ipv6();
}
enum rspamd_parse_host_port_result
-rspamd_parse_host_port_priority(const gchar *str,
+rspamd_parse_host_port_priority(const char *str,
GPtrArray **addrs,
- guint *priority,
- gchar **name_ptr,
- guint default_port,
+ unsigned int *priority,
+ char **name_ptr,
+ unsigned int default_port,
gboolean allow_listen,
rspamd_mempool_t *pool)
{
- gchar portbuf[8];
- const gchar *p, *name = NULL;
+ char portbuf[8];
+ const char *p, *name = NULL;
gsize namelen;
rspamd_inet_addr_t *cur_addr = NULL;
enum rspamd_parse_host_port_result ret = RSPAMD_PARSE_ADDR_FAIL;
portbuf, 0, pool);
}
else {
- const gchar *second_semicolon = strchr(p + 1, ':');
+ const char *second_semicolon = strchr(p + 1, ':');
name = str;
return ret;
}
-guchar *
-rspamd_inet_address_get_hash_key(const rspamd_inet_addr_t *addr, guint *klen)
+unsigned char *
+rspamd_inet_address_get_hash_key(const rspamd_inet_addr_t *addr, unsigned int *klen)
{
- guchar *res = NULL;
+ unsigned char *res = NULL;
static struct in_addr local = {INADDR_LOOPBACK};
g_assert(addr != NULL);
if (addr->af == AF_INET) {
*klen = sizeof(struct in_addr);
- res = (guchar *) &addr->u.in.addr.s4.sin_addr;
+ res = (unsigned char *) &addr->u.in.addr.s4.sin_addr;
}
else if (addr->af == AF_INET6) {
*klen = sizeof(struct in6_addr);
- res = (guchar *) &addr->u.in.addr.s6.sin6_addr;
+ res = (unsigned char *) &addr->u.in.addr.s6.sin6_addr;
}
else if (addr->af == AF_UNIX) {
*klen = sizeof(struct in_addr);
- res = (guchar *) &local;
+ res = (unsigned char *) &local;
}
else {
*klen = 0;
return addr;
}
-void rspamd_inet_address_apply_mask(rspamd_inet_addr_t *addr, guint mask)
+void rspamd_inet_address_apply_mask(rspamd_inet_addr_t *addr, unsigned int mask)
{
uint32_t umsk, *p;
}
}
-static gint
+static int
rspamd_inet_address_af_order(const rspamd_inet_addr_t *addr)
{
int ret;
return ret;
}
-gint rspamd_inet_address_compare(const rspamd_inet_addr_t *a1,
- const rspamd_inet_addr_t *a2, gboolean compare_ports)
+int rspamd_inet_address_compare(const rspamd_inet_addr_t *a1,
+ const rspamd_inet_addr_t *a2, gboolean compare_ports)
{
g_assert(a1 != NULL);
g_assert(a2 != NULL);
return 0;
}
-gint rspamd_inet_address_compare_ptr(gconstpointer a1,
- gconstpointer a2)
+int rspamd_inet_address_compare_ptr(gconstpointer a1,
+ gconstpointer a2)
{
const rspamd_inet_addr_t **i1 = (const rspamd_inet_addr_t **) a1,
**i2 = (const rspamd_inet_addr_t **) a2;
return n;
}
-gint rspamd_inet_address_get_af(const rspamd_inet_addr_t *addr)
+int rspamd_inet_address_get_af(const rspamd_inet_addr_t *addr)
{
g_assert(addr != NULL);
}
-guint rspamd_inet_address_hash(gconstpointer a)
+unsigned int rspamd_inet_address_hash(gconstpointer a)
{
const rspamd_inet_addr_t *addr = a;
struct {
- gchar buf[sizeof(struct in6_addr)]; /* 16 bytes */
+ char buf[sizeof(struct in6_addr)]; /* 16 bytes */
int af;
} layout;
return k;
}
-guint rspamd_inet_address_port_hash(gconstpointer a)
+unsigned int rspamd_inet_address_port_hash(gconstpointer a)
{
const rspamd_inet_addr_t *addr = a;
struct {
- gchar buf[sizeof(struct in6_addr)]; /* 16 bytes */
+ char buf[sizeof(struct in6_addr)]; /* 16 bytes */
int port;
int af;
} layout;
* @param target target structure
* @return TRUE if the address has been parsed, otherwise `target` content is undefined
*/
-gboolean rspamd_parse_inet_address_ip6(const guchar *text, gsize len,
+gboolean rspamd_parse_inet_address_ip6(const unsigned char *text, gsize len,
gpointer target);
enum rspamd_inet_address_parse_flags {
* @param target target structure
* @return TRUE if the address has been parsed, otherwise `target` content is undefined
*/
-gboolean rspamd_parse_inet_address_ip4(const guchar *text, gsize len,
+gboolean rspamd_parse_inet_address_ip4(const unsigned char *text, gsize len,
gpointer target);
/**
* @param addr
* @return
*/
-gint rspamd_inet_address_get_af(const rspamd_inet_addr_t *addr);
+int rspamd_inet_address_get_af(const rspamd_inet_addr_t *addr);
/**
* Returns sockaddr and size for this address
* @param klen
* @return
*/
-guchar *rspamd_inet_address_get_hash_key(const rspamd_inet_addr_t *addr, guint *klen);
+unsigned char *rspamd_inet_address_get_hash_key(const rspamd_inet_addr_t *addr, unsigned int *klen);
/**
* Receive data from an unconnected socket and fill the inet_addr structure if needed
* @param target
* @return same as recvfrom(2)
*/
-gssize rspamd_inet_address_recvfrom(gint fd, void *buf, gsize len, gint fl,
+gssize rspamd_inet_address_recvfrom(int fd, void *buf, gsize len, int fl,
rspamd_inet_addr_t **target);
/**
* @param target
* @return
*/
-gssize rspamd_inet_address_sendto(gint fd, const void *buf, gsize len, gint fl,
+gssize rspamd_inet_address_sendto(int fd, const void *buf, gsize len, int fl,
const rspamd_inet_addr_t *addr);
/**
* @param async perform operations asynchronously
* @return newly created and connected socket
*/
-int rspamd_inet_address_connect(const rspamd_inet_addr_t *addr, gint type,
+int rspamd_inet_address_connect(const rspamd_inet_addr_t *addr, int type,
gboolean async);
enum rspamd_inet_address_listen_opts {
* @param opts
* @return
*/
-int rspamd_inet_address_listen(const rspamd_inet_addr_t *addr, gint type,
+int rspamd_inet_address_listen(const rspamd_inet_addr_t *addr, int type,
enum rspamd_inet_address_listen_opts opts,
- gint listen_queue);
+ int listen_queue);
/**
* Check whether specified ip is valid (not INADDR_ANY or INADDR_NONE) for ipv4 or ipv6
*/
gboolean rspamd_ip_is_valid(const rspamd_inet_addr_t *addr);
-typedef void (*rspamd_accept_throttling_handler)(gint, void *);
+typedef void (*rspamd_accept_throttling_handler)(int, void *);
/**
* Accept from listening socket filling addr structure
* @param target allocated inet addr structure
* @return
*/
-gint rspamd_accept_from_socket(gint sock,
- rspamd_inet_addr_t **target,
- rspamd_accept_throttling_handler hdl,
- void *hdl_data);
+int rspamd_accept_from_socket(int sock,
+ rspamd_inet_addr_t **target,
+ rspamd_accept_throttling_handler hdl,
+ void *hdl_data);
enum rspamd_parse_host_port_result {
RSPAMD_PARSE_ADDR_FAIL = 0,
* @return RSPAMD_PARSE_ADDR_FAIL in case of error, RSPAMD_PARSE_ADDR_NUMERIC in case of pure ip/unix socket
*/
enum rspamd_parse_host_port_result
-rspamd_parse_host_port_priority(const gchar *str,
+rspamd_parse_host_port_priority(const char *str,
GPtrArray **addrs,
- guint *priority, gchar **name,
- guint default_port,
+ unsigned int *priority, char **name,
+ unsigned int default_port,
gboolean allow_listen,
rspamd_mempool_t *pool);
* @param addr
* @param mask
*/
-void rspamd_inet_address_apply_mask(rspamd_inet_addr_t *addr, guint mask);
+void rspamd_inet_address_apply_mask(rspamd_inet_addr_t *addr, unsigned int mask);
/**
* Compare a1 and a2 and return value >0, ==0 and <0 if a1 is more, equal or less than a2 correspondingly
* @param a2
* @return
*/
-gint rspamd_inet_address_compare(const rspamd_inet_addr_t *a1,
- const rspamd_inet_addr_t *a2, gboolean compare_ports);
+int rspamd_inet_address_compare(const rspamd_inet_addr_t *a1,
+ const rspamd_inet_addr_t *a2, gboolean compare_ports);
/**
* Utility function to compare addresses by in g_ptr_array
* @param a2
* @return
*/
-gint rspamd_inet_address_compare_ptr(gconstpointer a1,
- gconstpointer a2);
+int rspamd_inet_address_compare_ptr(gconstpointer a1,
+ gconstpointer a2);
/**
* Performs deep copy of rspamd inet addr
/**
* Returns hash for inet address (ignoring port)
*/
-guint rspamd_inet_address_hash(gconstpointer a);
+unsigned int rspamd_inet_address_hash(gconstpointer a);
-guint rspamd_inet_address_port_hash(gconstpointer a);
+unsigned int rspamd_inet_address_port_hash(gconstpointer a);
/**
* Returns true if two address are equal
return static_cast<enum rspamd_utf8_normalise_result>(ret);
}
-gchar *
-rspamd_utf8_transliterate(const gchar *start, gsize len, gsize *target_len)
+char *
+rspamd_utf8_transliterate(const char *start, gsize len, gsize *target_len)
{
UErrorCode uc_err = U_ZERO_ERROR;
// We assume that all characters are now ascii
auto dest_len = uc_string.length();
- gchar *dest = (gchar *) g_malloc(dest_len + 1);
+ char *dest = (char *) g_malloc(dest_len + 1);
auto sink = icu::CheckedArrayByteSink(dest, dest_len);
uc_string.toUTF8(sink);
* @param len
* @return TRUE if a string has been normalised
*/
-enum rspamd_utf8_normalise_result rspamd_normalise_unicode_inplace(gchar *start, gsize *len);
+enum rspamd_utf8_normalise_result rspamd_normalise_unicode_inplace(char *start, gsize *len);
/**
* Transliterate a string to ASCII
* @param target_len
* @return a new string that should be freed with g_free
*/
-gchar *rspamd_utf8_transliterate(const gchar *start, gsize len, gsize *target_len);
+char *rspamd_utf8_transliterate(const char *start, gsize len, gsize *target_len);
/**
* Compare two strings using libicu collator
struct rspamd_expression_operation {
enum rspamd_expression_op op;
- guint logical_priority;
- guint op_flags;
+ unsigned int logical_priority;
+ unsigned int op_flags;
};
struct rspamd_expression_elt {
union {
rspamd_expression_atom_t *atom;
struct rspamd_expression_operation op;
- gdouble lim;
+ double lim;
} p;
- gint flags;
- gint priority;
- gdouble value;
+ int flags;
+ int priority;
+ double value;
};
struct rspamd_expression {
GArray *expressions;
GPtrArray *expression_stack;
GNode *ast;
- gchar *log_id;
- guint next_resort;
- guint evals;
+ char *log_id;
+ unsigned int next_resort;
+ unsigned int evals;
};
struct rspamd_expr_process_data {
gpointer *ud;
- gint flags;
+ int flags;
/* != NULL if trace is collected */
GPtrArray *trace;
rspamd_expression_process_cb process_closure;
return g_quark_from_static_string("rspamd-expression");
}
-static const gchar *RSPAMD_CONST_FUNCTION
+static const char *RSPAMD_CONST_FUNCTION
rspamd_expr_op_to_str(enum rspamd_expression_op op);
-static const gchar *
+static const char *
rspamd_expr_op_to_str(enum rspamd_expression_op op)
{
- const gchar *op_str = NULL;
+ const char *op_str = NULL;
switch (op) {
case OP_AND:
rspamd_expr_stack_elt_pop(GPtrArray *stack)
{
gpointer e;
- gint idx;
+ int idx;
if (stack->len == 0) {
return NULL;
rspamd_expr_stack_peek(struct rspamd_expression *expr)
{
gpointer e;
- gint idx;
+ int idx;
GPtrArray *stack = expr->expression_stack;
if (stack->len == 0) {
/*
* Return operation priority
*/
-static gint RSPAMD_CONST_FUNCTION
+static int RSPAMD_CONST_FUNCTION
rspamd_expr_logic_priority(enum rspamd_expression_op op);
-static gint
+static int
rspamd_expr_logic_priority(enum rspamd_expression_op op)
{
- gint ret = 0;
+ int ret = 0;
switch (op) {
case OP_NOT:
return ret;
}
-static guint RSPAMD_CONST_FUNCTION
+static unsigned int RSPAMD_CONST_FUNCTION
rspamd_expr_op_flags(enum rspamd_expression_op op);
-static guint
+static unsigned int
rspamd_expr_op_flags(enum rspamd_expression_op op)
{
- guint ret = 0;
+ unsigned int ret = 0;
switch (op) {
case OP_NOT:
* Return TRUE if symbol is operation symbol
*/
static gboolean RSPAMD_CONST_FUNCTION
-rspamd_expr_is_operation_symbol(gchar a);
+rspamd_expr_is_operation_symbol(char a);
static gboolean
-rspamd_expr_is_operation_symbol(gchar a)
+rspamd_expr_is_operation_symbol(char a)
{
switch (a) {
case '!':
static gboolean
rspamd_expr_is_operation(struct rspamd_expression *e,
- const gchar *p, const gchar *end, rspamd_regexp_t *num_re)
+ const char *p, const char *end, rspamd_regexp_t *num_re)
{
if (rspamd_expr_is_operation_symbol(*p)) {
if (p + 1 < end) {
- gchar t = *(p + 1);
+ char t = *(p + 1);
if (t == ':') {
/* Special case, treat it as an atom */
}
else if (*p == '/') {
/* Lookahead for division operation to distinguish from regexp */
- const gchar *track = p + 1;
+ const char *track = p + 1;
/* Skip spaces */
while (track < end && g_ascii_isspace(*track)) {
/* Return character representation of operation */
static enum rspamd_expression_op
-rspamd_expr_str_to_op(const gchar *a, const gchar *end, const gchar **next)
+rspamd_expr_str_to_op(const char *a, const char *end, const char **next)
{
enum rspamd_expression_op op = OP_INVALID;
static void
rspamd_expression_destroy(struct rspamd_expression *expr)
{
- guint i;
+ unsigned int i;
struct rspamd_expression_elt *elt;
if (expr != NULL) {
{
struct rspamd_expression_elt *elt = node->data, *cur_elt;
struct rspamd_expression *expr = d;
- gint cnt = 0;
+ int cnt = 0;
GNode *cur;
if (node->children) {
#define ATOM_PRIORITY(a) ((a)->p.atom->hits / ((a)->p.atom->exec_time.mean > 0 ? (a)->p.atom->exec_time.mean * 10000000 : 1.0))
-static gint
+static int
rspamd_ast_priority_cmp(GNode *a, GNode *b)
{
struct rspamd_expression_elt *ea = a->data, *eb = b->data;
- gdouble w1, w2;
+ double w1, w2;
if (ea->type == ELT_LIMIT) {
return 1;
}
gboolean
-rspamd_parse_expression(const gchar *line, gsize len,
+rspamd_parse_expression(const char *line, gsize len,
const struct rspamd_atom_subr *subr, gpointer subr_data,
rspamd_mempool_t *pool, GError **err,
struct rspamd_expression **target)
rspamd_expression_atom_t *atom;
rspamd_regexp_t *num_re;
enum rspamd_expression_op op, op_stack;
- const gchar *p, *c, *end;
+ const char *p, *c, *end;
GPtrArray *operand_stack;
GNode *tmp;
goto error_label;
}
- guint op_priority = rspamd_expr_logic_priority(op);
+ unsigned int op_priority = rspamd_expr_logic_priority(op);
msg_debug_expression("found op: %s; priority = %d",
rspamd_expr_op_to_str(op), op_priority);
}
/* We ignore associativity for now */
- guint op_priority = rspamd_expr_logic_priority(op),
- stack_op_priority = rspamd_expr_logic_priority(op_stack);
+ unsigned int op_priority = rspamd_expr_logic_priority(op),
+ stack_op_priority = rspamd_expr_logic_priority(op_stack);
msg_debug_expression("operators stack %d; operands stack: %d; "
"process operation '%s'(%d); pop operation '%s'(%d)",
* Node optimizer function: skip nodes that are not relevant
*/
static gboolean
-rspamd_ast_node_done(struct rspamd_expression_elt *elt, gdouble acc)
+rspamd_ast_node_done(struct rspamd_expression_elt *elt, double acc)
{
gboolean ret = FALSE;
}
-static gdouble
-rspamd_ast_do_unary_op(struct rspamd_expression_elt *elt, gdouble operand)
+static double
+rspamd_ast_do_unary_op(struct rspamd_expression_elt *elt, double operand)
{
- gdouble ret;
+ double ret;
g_assert(elt->type == ELT_OP);
switch (elt->p.op.op) {
return ret;
}
-static gdouble
-rspamd_ast_do_binary_op(struct rspamd_expression_elt *elt, gdouble op1, gdouble op2)
+static double
+rspamd_ast_do_binary_op(struct rspamd_expression_elt *elt, double op1, double op2)
{
- gdouble ret;
+ double ret;
g_assert(elt->type == ELT_OP);
return ret;
}
-static gdouble
-rspamd_ast_do_nary_op(struct rspamd_expression_elt *elt, gdouble val, gdouble acc)
+static double
+rspamd_ast_do_nary_op(struct rspamd_expression_elt *elt, double val, double acc)
{
- gdouble ret;
+ double ret;
g_assert(elt->type == ELT_OP);
return ret;
}
-static gdouble
+static double
rspamd_ast_process_node(struct rspamd_expression *e, GNode *node,
struct rspamd_expr_process_data *process_data)
{
struct rspamd_expression_elt *elt;
GNode *cld;
- gdouble acc = NAN;
+ double acc = NAN;
float t1, t2;
- gdouble val;
+ double val;
gboolean calc_ticks = FALSE;
- __attribute__((unused)) const gchar *op_name = NULL;
+ __attribute__((unused)) const char *op_name = NULL;
elt = node->data;
c2 = c1->next;
g_assert(c2->next == NULL);
- gdouble val1, val2;
+ double val1, val2;
msg_debug_expression_verbose("proceed binary operation %s",
op_name);
return FALSE;
}
-gdouble
+double
rspamd_process_expression_closure(struct rspamd_expression *expr,
rspamd_expression_process_cb cb,
- gint flags,
+ int flags,
gpointer runtime_ud,
GPtrArray **track)
{
struct rspamd_expr_process_data pd;
- gdouble ret = 0;
+ double ret = 0;
g_assert(expr != NULL);
/* Ensure that stack is empty at this point */
return ret;
}
-gdouble
+double
rspamd_process_expression_track(struct rspamd_expression *expr,
- gint flags,
+ int flags,
gpointer runtime_ud,
GPtrArray **track)
{
expr->subr->process, flags, runtime_ud, track);
}
-gdouble
+double
rspamd_process_expression(struct rspamd_expression *expr,
- gint flags,
+ int flags,
gpointer runtime_ud)
{
return rspamd_process_expression_closure(expr,
rspamd_ast_string_traverse(GNode *n, gpointer d)
{
GString *res = d;
- gint cnt;
+ int cnt;
GNode *cur;
struct rspamd_expression_elt *elt = n->data;
const char *op_str = NULL;
/* Opaque userdata */
gpointer data;
/* String representation of atom */
- const gchar *str;
+ const char *str;
/* Length of the string representation of atom */
- guint len;
+ unsigned int len;
/* Relative priority */
- gint priority;
- guint hits;
+ int priority;
+ unsigned int hits;
struct rspamd_counter_data exec_time;
} rspamd_expression_atom_t;
-typedef gdouble (*rspamd_expression_process_cb)(gpointer runtime_data,
- rspamd_expression_atom_t *atom);
+typedef double (*rspamd_expression_process_cb)(gpointer runtime_data,
+ rspamd_expression_atom_t *atom);
struct rspamd_atom_subr {
/* Parses atom from string and returns atom structure */
- rspamd_expression_atom_t *(*parse)(const gchar *line, gsize len,
+ rspamd_expression_atom_t *(*parse)(const char *line, gsize len,
rspamd_mempool_t *pool, gpointer ud, GError **err);
/* Process atom via the opaque pointer (e.g. struct rspamd_task *) */
rspamd_expression_process_cb process;
/* Calculates the relative priority of the expression */
- gint (*priority)(rspamd_expression_atom_t *atom);
+ int (*priority)(rspamd_expression_atom_t *atom);
void (*destroy)(rspamd_expression_atom_t *atom);
};
* @param target the target expression
* @return TRUE if an expression have been parsed
*/
-gboolean rspamd_parse_expression(const gchar *line, gsize len,
+gboolean rspamd_parse_expression(const char *line, gsize len,
const struct rspamd_atom_subr *subr, gpointer subr_data,
rspamd_mempool_t *pool, GError **err,
struct rspamd_expression **target);
* @param data opaque data pointer for all the atoms
* @return the value of expression
*/
-gdouble rspamd_process_expression(struct rspamd_expression *expr,
- gint flags,
- gpointer runtime_ud);
+double rspamd_process_expression(struct rspamd_expression *expr,
+ int flags,
+ gpointer runtime_ud);
/**
* Process the expression and return its value using atom 'process' functions with the specified data pointer.
* @param track pointer array to atoms tracking
* @return the value of expression
*/
-gdouble rspamd_process_expression_track(struct rspamd_expression *expr,
- gint flags,
- gpointer runtime_ud,
- GPtrArray **track);
+double rspamd_process_expression_track(struct rspamd_expression *expr,
+ int flags,
+ gpointer runtime_ud,
+ GPtrArray **track);
/**
* Process the expression with the custom processor
* @param process_data
* @return
*/
-gdouble rspamd_process_expression_closure(struct rspamd_expression *expr,
- rspamd_expression_process_cb cb,
- gint flags,
- gpointer runtime_ud,
- GPtrArray **track);
+double rspamd_process_expression_closure(struct rspamd_expression *expr,
+ rspamd_expression_process_cb cb,
+ int flags,
+ gpointer runtime_ud,
+ GPtrArray **track);
/**
* Shows string representation of an expression
}
rspamd_fstring_t *
-rspamd_fstring_new_init(const gchar *init, gsize len)
+rspamd_fstring_new_init(const char *init, gsize len)
{
rspamd_fstring_t *s;
gsize real_size = MAX(default_initial_size, len);
}
rspamd_fstring_t *
-rspamd_fstring_assign(rspamd_fstring_t *str, const gchar *init, gsize len)
+rspamd_fstring_assign(rspamd_fstring_t *str, const char *init, gsize len)
{
gsize avail;
{
gsize i;
uint64_t hval;
- const gchar *p, *end = NULL;
+ const char *p, *end = NULL;
gunichar uc;
if (str == NULL) {
return FALSE;
}
-gint rspamd_fstring_casecmp(const rspamd_fstring_t *s1,
- const rspamd_fstring_t *s2)
+int rspamd_fstring_casecmp(const rspamd_fstring_t *s1,
+ const rspamd_fstring_t *s2)
{
- gint ret = 0;
+ int ret = 0;
g_assert(s1 != NULL && s2 != NULL);
return ret;
}
-gint rspamd_fstring_cmp(const rspamd_fstring_t *s1,
- const rspamd_fstring_t *s2)
+int rspamd_fstring_cmp(const rspamd_fstring_t *s1,
+ const rspamd_fstring_t *s2)
{
g_assert(s1 != NULL && s2 != NULL);
return s1->len - s2->len;
}
-gint rspamd_ftok_casecmp(const rspamd_ftok_t *s1,
- const rspamd_ftok_t *s2)
+int rspamd_ftok_casecmp(const rspamd_ftok_t *s1,
+ const rspamd_ftok_t *s2)
{
- gint ret = 0;
+ int ret = 0;
g_assert(s1 != NULL && s2 != NULL);
return ret;
}
-gint rspamd_ftok_cmp(const rspamd_ftok_t *s1,
- const rspamd_ftok_t *s2)
+int rspamd_ftok_cmp(const rspamd_ftok_t *s1,
+ const rspamd_ftok_t *s2)
{
g_assert(s1 != NULL && s2 != NULL);
}
gboolean
-rspamd_ftok_cstr_equal(const rspamd_ftok_t *s, const gchar *pat,
+rspamd_ftok_cstr_equal(const rspamd_ftok_t *s, const char *pat,
gboolean icase)
{
gsize slen;
return (rspamd_ftok_cmp(s, &srch) == 0);
}
-gchar *
+char *
rspamd_ftokdup(const rspamd_ftok_t *src)
{
- gchar *newstr;
+ char *newstr;
if (src == NULL) {
return NULL;
return newstr;
}
-gchar *
+char *
rspamd_fstringdup(const rspamd_fstring_t *src)
{
- gchar *newstr;
+ char *newstr;
if (src == NULL) {
return NULL;
typedef struct f_str_s {
gsize len;
gsize allocated;
- gchar str[];
+ char str[];
} rspamd_fstring_t;
#define RSPAMD_FSTRING_DATA(s) ((s)->str)
typedef struct f_str_tok {
gsize len;
- const gchar *begin;
+ const char *begin;
} rspamd_ftok_t;
typedef struct f_str_unicode_tok {
/**
* Create new fixed length string and initialize it with the initial data
*/
-rspamd_fstring_t *rspamd_fstring_new_init(const gchar *init, gsize len)
+rspamd_fstring_t *rspamd_fstring_new_init(const char *init, gsize len)
G_GNUC_WARN_UNUSED_RESULT;
/**
* Assign new value to fixed string
*/
rspamd_fstring_t *rspamd_fstring_assign(rspamd_fstring_t *str,
- const gchar *init, gsize len) G_GNUC_WARN_UNUSED_RESULT;
+ const char *init, gsize len) G_GNUC_WARN_UNUSED_RESULT;
/**
* Free fixed length string
/**
* Compare two fixed strings ignoring case
*/
-gint rspamd_fstring_casecmp(const rspamd_fstring_t *s1,
- const rspamd_fstring_t *s2);
+int rspamd_fstring_casecmp(const rspamd_fstring_t *s1,
+ const rspamd_fstring_t *s2);
/**
* Compare two fixed strings
*/
-gint rspamd_fstring_cmp(const rspamd_fstring_t *s1,
- const rspamd_fstring_t *s2);
+int rspamd_fstring_cmp(const rspamd_fstring_t *s1,
+ const rspamd_fstring_t *s2);
/**
* Compare two fixed tokens ignoring case
*/
-gint rspamd_ftok_casecmp(const rspamd_ftok_t *s1,
- const rspamd_ftok_t *s2);
+int rspamd_ftok_casecmp(const rspamd_ftok_t *s1,
+ const rspamd_ftok_t *s2);
/**
* Compare two fixed tokens
*/
-gint rspamd_ftok_cmp(const rspamd_ftok_t *s1,
- const rspamd_ftok_t *s2);
+int rspamd_ftok_cmp(const rspamd_ftok_t *s1,
+ const rspamd_ftok_t *s2);
/**
* Returns true if `s1` starts with `s2`
* Return TRUE if ftok is equal to specified C string
*/
gboolean rspamd_ftok_cstr_equal(const rspamd_ftok_t *s,
- const gchar *pat, gboolean icase);
+ const char *pat, gboolean icase);
/**
* Free fstring_t that is mapped to ftok_t
* @param src
* @return
*/
-gchar *rspamd_ftokdup(const rspamd_ftok_t *src) G_GNUC_WARN_UNUSED_RESULT;
+char *rspamd_ftokdup(const rspamd_ftok_t *src) G_GNUC_WARN_UNUSED_RESULT;
/**
* Copies fstring to zero terminated string (must be freed using g_free)
* @param src
* @return
*/
-gchar *rspamd_fstringdup(const rspamd_fstring_t *src) G_GNUC_WARN_UNUSED_RESULT;
+char *rspamd_fstringdup(const rspamd_fstring_t *src) G_GNUC_WARN_UNUSED_RESULT;
#define RSPAMD_FTOK_ASSIGN(t, lit) \
do { \
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* LRU hashing
*/
-static const guint log_base = 10;
-static const guint eviction_candidates = 16;
-static const gdouble lfu_base_value = 5.0;
+static const unsigned int log_base = 10;
+static const unsigned int eviction_candidates = 16;
+static const double lfu_base_value = 5.0;
struct rspamd_lru_volatile_element_s;
struct rspamd_lru_hash_s {
- guint maxsize;
- guint eviction_min_prio;
- guint eviction_used;
+ unsigned int maxsize;
+ unsigned int eviction_min_prio;
+ unsigned int eviction_used;
struct rspamd_lru_element_s **eviction_pool;
GDestroyNotify value_destroy;
};
struct rspamd_lru_element_s {
- guint16 last;
- guint8 lg_usages;
- guint8 eviction_pos;
- guint8 flags;
+ uint16_t last;
+ uint8_t lg_usages;
+ uint8_t eviction_pos;
+ uint8_t flags;
gpointer data;
};
};
typedef struct rspamd_lru_volatile_element_s rspamd_lru_vol_element_t;
-#define TIME_TO_TS(t) ((guint16) (((t) / 60) & 0xFFFFU))
+#define TIME_TO_TS(t) ((uint16_t) (((t) / 60) & 0xFFFFU))
static rspamd_lru_vol_element_t *
rspamd_lru_hash_get(const rspamd_lru_hash_t *h, gconstpointer key)
khint_t new_mask;
new_mask = new_n_buckets - 1;
val = h->vals[j];
- val.e.eviction_pos = (guint8) -1;
+ val.e.eviction_pos = (uint8_t) -1;
__ac_set_isdel_true(h->flags, j);
while (1) { /* kick-out process; sort of like in Cuckoo hashing */
rspamd_lru_vol_element_t tmp = h->vals[i];
h->vals[i] = val;
val = tmp;
- val.e.eviction_pos = (guint8) -1;
+ val.e.eviction_pos = (uint8_t) -1;
}
__ac_set_isdel_true(h->flags, i);
/* mark it as deleted in the old hash table */
rspamd_lru_hash_remove_evicted(rspamd_lru_hash_t *hash,
rspamd_lru_element_t *elt)
{
- guint i;
+ unsigned int i;
rspamd_lru_element_t *cur;
g_assert(hash->eviction_used > 0);
static void
rspamd_lru_hash_update_counter(rspamd_lru_element_t *elt)
{
- guint8 counter = elt->lg_usages;
+ uint8_t counter = elt->lg_usages;
if (counter != 255) {
double r, baseval, p;
rspamd_lru_hash_maybe_evict(rspamd_lru_hash_t *hash,
rspamd_lru_element_t *elt)
{
- guint i;
+ unsigned int i;
rspamd_lru_element_t *cur;
- if (elt->eviction_pos == (guint8) -1) {
+ if (elt->eviction_pos == (uint8_t) -1) {
if (hash->eviction_used < eviction_candidates) {
/* There are free places in eviction pool */
hash->eviction_pool[hash->eviction_used] = elt;
static void
rspamd_lru_hash_remove_node(rspamd_lru_hash_t *hash, rspamd_lru_element_t *elt)
{
- if (elt->eviction_pos != (guint8) -1) {
+ if (elt->eviction_pos != (uint8_t) -1) {
rspamd_lru_hash_remove_evicted(hash, elt);
}
rspamd_lru_hash_evict(rspamd_lru_hash_t *hash, time_t now)
{
double r;
- guint i;
+ unsigned int i;
rspamd_lru_element_t *elt = NULL;
- guint nexpired = 0;
+ unsigned int nexpired = 0;
/*
* We either evict one node from the eviction list
}
rspamd_lru_hash_t *
-rspamd_lru_hash_new_full(gint maxsize,
+rspamd_lru_hash_new_full(int maxsize,
GDestroyNotify key_destroy,
GDestroyNotify value_destroy,
GHashFunc hf,
}
rspamd_lru_hash_t *
-rspamd_lru_hash_new(gint maxsize,
+rspamd_lru_hash_new(int maxsize,
GDestroyNotify key_destroy,
GDestroyNotify value_destroy)
{
gpointer key,
gpointer value,
time_t now,
- guint ttl)
+ unsigned int ttl)
{
rspamd_lru_element_t *node;
rspamd_lru_vol_element_t *vnode;
- gint ret;
+ int ret;
vnode = rspamd_lru_hash_put(hash, key, &ret);
node = &vnode->e;
}
node->data = value;
- node->lg_usages = (guint8) lfu_base_value;
+ node->lg_usages = (uint8_t) lfu_base_value;
node->last = TIME_TO_TS(now);
- node->eviction_pos = (guint8) -1;
+ node->eviction_pos = (uint8_t) -1;
if (ret != 0) {
/* Also need to check maxsize */
int rspamd_lru_hash_foreach(rspamd_lru_hash_t *h, int it, gpointer *k,
gpointer *v)
{
- gint i;
+ int i;
g_assert(it >= 0);
for (i = it; i != kh_end(h); ++i) {
}
-guint rspamd_lru_hash_size(rspamd_lru_hash_t *hash)
+unsigned int rspamd_lru_hash_size(rspamd_lru_hash_t *hash)
{
return kh_size(hash);
}
* Returns hash capacity
* @param hash hash object
*/
-guint rspamd_lru_hash_capacity(rspamd_lru_hash_t *hash)
+unsigned int rspamd_lru_hash_capacity(rspamd_lru_hash_t *hash)
{
return hash->maxsize;
}
\ No newline at end of file
* @param key_equal_func pointer to function for comparing keys
* @return new rspamd_hash object
*/
-rspamd_lru_hash_t *rspamd_lru_hash_new(gint maxsize,
+rspamd_lru_hash_t *rspamd_lru_hash_new(int maxsize,
GDestroyNotify key_destroy,
GDestroyNotify value_destroy);
* @param key_equal_func pointer to function for comparing keys
* @return new rspamd_hash object
*/
-rspamd_lru_hash_t *rspamd_lru_hash_new_full(gint maxsize,
+rspamd_lru_hash_t *rspamd_lru_hash_new_full(int maxsize,
GDestroyNotify key_destroy,
GDestroyNotify value_destroy,
GHashFunc hfunc,
gpointer key,
gpointer value,
time_t now,
- guint ttl);
+ unsigned int ttl);
/**
* Remove lru hash
* Returns number of elements in a hash
* @param hash hash object
*/
-guint rspamd_lru_hash_size(rspamd_lru_hash_t *hash);
+unsigned int rspamd_lru_hash_size(rspamd_lru_hash_t *hash);
/**
* Returns hash capacity
* @param hash hash object
*/
-guint rspamd_lru_hash_capacity(rspamd_lru_hash_t *hash);
+unsigned int rspamd_lru_hash_capacity(rspamd_lru_hash_t *hash);
#ifdef __cplusplus
}
}
void rspamd_min_heap_update_elt(struct rspamd_min_heap *heap,
- struct rspamd_min_heap_elt *elt, guint npri)
+ struct rspamd_min_heap_elt *elt, unsigned int npri)
{
- guint oldpri;
+ unsigned int oldpri;
g_assert(heap != NULL);
g_assert(elt->idx > 0 && elt->idx <= heap->ar->len);
}
struct rspamd_min_heap_elt *
-rspamd_min_heap_index(struct rspamd_min_heap *heap, guint idx)
+rspamd_min_heap_index(struct rspamd_min_heap *heap, unsigned int idx)
{
g_assert(heap != NULL);
g_assert(idx < heap->ar->len);
struct rspamd_min_heap_elt {
gpointer data;
- guint pri;
- guint idx;
+ unsigned int pri;
+ unsigned int idx;
};
struct rspamd_min_heap;
* @param npri new priority
*/
void rspamd_min_heap_update_elt(struct rspamd_min_heap *heap,
- struct rspamd_min_heap_elt *elt, guint npri);
+ struct rspamd_min_heap_elt *elt, unsigned int npri);
/**
* @return
*/
struct rspamd_min_heap_elt *rspamd_min_heap_index(struct rspamd_min_heap *heap,
- guint idx);
+ unsigned int idx);
#ifdef __cplusplus
}
static inline uint32_t
rspamd_entry_hash(const char *str)
{
- return (guint) rspamd_cryptobox_fast_hash(str, strlen(str), rspamd_hash_seed());
+ return (unsigned int) rspamd_cryptobox_fast_hash(str, strlen(str), rspamd_hash_seed());
}
static inline int
}
-KHASH_INIT(mempool_entry, const gchar *, struct rspamd_mempool_entry_point *,
+KHASH_INIT(mempool_entry, const char *, struct rspamd_mempool_entry_point *,
1, rspamd_entry_hash, rspamd_entry_equal)
static khash_t(mempool_entry) *mempool_entries = NULL;
#define FIXED_POOL_SIZE 4096
static inline struct rspamd_mempool_entry_point *
-rspamd_mempool_entry_new(const gchar *loc)
+rspamd_mempool_entry_new(const char *loc)
{
struct rspamd_mempool_entry_point **pentry, *entry;
- gint r;
+ int r;
khiter_t k;
k = kh_put(mempool_entry, mempool_entries, loc, &r);
}
static inline struct rspamd_mempool_entry_point *
-rspamd_mempool_get_entry(const gchar *loc)
+rspamd_mempool_get_entry(const char *loc)
{
khiter_t k;
struct rspamd_mempool_entry_point *elt;
abort();
}
chain = map;
- chain->begin = ((guint8 *) chain) + sizeof(struct _pool_chain);
+ chain->begin = ((uint8_t *) chain) + sizeof(struct _pool_chain);
#elif defined(HAVE_MMAP_ZERO)
- gint fd;
+ int fd;
fd = open("/dev/zero", O_RDWR);
if (fd == -1) {
abort();
}
chain = map;
- chain->begin = ((guint8 *) chain) + sizeof(struct _pool_chain);
+ chain->begin = ((uint8_t *) chain) + sizeof(struct _pool_chain);
#else
#error No mmap methods are defined
#endif
optimal_size = sys_alloc_size(total_size);
#endif
total_size = MAX(total_size, optimal_size);
- gint ret = posix_memalign(&map, alignment, total_size);
+ int ret = posix_memalign(&map, alignment, total_size);
if (ret != 0 || map == NULL) {
g_error("%s: failed to allocate %" G_GSIZE_FORMAT " bytes: %d - %s",
}
chain = map;
- chain->begin = ((guint8 *) chain) + sizeof(struct _pool_chain);
+ chain->begin = ((uint8_t *) chain) + sizeof(struct _pool_chain);
g_atomic_int_add(&mem_pool_stat->bytes_allocated, total_size);
g_atomic_int_inc(&mem_pool_stat->chunks_allocated);
}
* @return new memory pool object
*/
rspamd_mempool_t *
-rspamd_mempool_new_(gsize size, const gchar *tag, gint flags, const gchar *loc)
+rspamd_mempool_new_(gsize size, const char *tag, int flags, const char *loc)
{
rspamd_mempool_t *new_pool;
gpointer map;
}
mem_pool_stat = (rspamd_mempool_stat_t *) map;
#elif defined(HAVE_MMAP_ZERO)
- gint fd;
+ int fd;
fd = open("/dev/zero", O_RDWR);
g_assert(fd != -1);
* alignment (if needed)
* memory chunk
*/
- guchar *mem_chunk;
- gint ret = posix_memalign((void **) &mem_chunk, MIN_MEM_ALIGNMENT,
- total_size);
+ unsigned char *mem_chunk;
+ int ret = posix_memalign((void **) &mem_chunk, MIN_MEM_ALIGNMENT,
+ total_size);
gsize priv_offset;
if (ret != 0 || mem_chunk == NULL) {
priv_offset +
sizeof(struct rspamd_mempool_specific));
- guchar *unaligned = mem_chunk +
- priv_offset +
- sizeof(struct rspamd_mempool_specific) +
- sizeof(struct _pool_chain);
+ unsigned char *unaligned = mem_chunk +
+ priv_offset +
+ sizeof(struct rspamd_mempool_specific) +
+ sizeof(struct _pool_chain);
nchain->slice_size = size;
nchain->begin = unaligned;
/* Adjust stats */
g_atomic_int_add(&mem_pool_stat->bytes_allocated,
- (gint) size);
+ (int) size);
g_atomic_int_add(&mem_pool_stat->chunks_allocated, 1);
return new_pool;
static void *
memory_pool_alloc_common(rspamd_mempool_t *pool, gsize size, gsize alignment,
enum rspamd_mempool_chain_type pool_type,
- const gchar *loc)
+ const char *loc)
RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL;
-void rspamd_mempool_notify_alloc_(rspamd_mempool_t *pool, gsize size, const gchar *loc)
+void rspamd_mempool_notify_alloc_(rspamd_mempool_t *pool, gsize size, const char *loc)
{
if (pool && G_UNLIKELY(pool->priv->flags & RSPAMD_MEMPOOL_DEBUG)) {
- GHashTable *debug_tbl = *(GHashTable **) (((guchar *) pool + sizeof(*pool)));
+ GHashTable *debug_tbl = *(GHashTable **) (((unsigned char *) pool + sizeof(*pool)));
gpointer ptr;
ptr = g_hash_table_lookup(debug_tbl, loc);
static void *
memory_pool_alloc_common(rspamd_mempool_t *pool, gsize size, gsize alignment,
- enum rspamd_mempool_chain_type pool_type, const gchar *loc)
+ enum rspamd_mempool_chain_type pool_type, const char *loc)
{
- guint8 *tmp;
+ uint8_t *tmp;
struct _pool_chain *new, *cur;
gsize free = 0;
void *
-rspamd_mempool_alloc_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc)
+rspamd_mempool_alloc_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc)
{
return memory_pool_alloc_common(pool, size, alignment, RSPAMD_MEMPOOL_NORMAL, loc);
}
#define MUL_NO_OVERFLOW (1UL << (sizeof(gsize) * 4))
void *
-rspamd_mempool_alloc_array_(rspamd_mempool_t *pool, gsize nmemb, gsize size, gsize alignment, const gchar *loc)
+rspamd_mempool_alloc_array_(rspamd_mempool_t *pool, gsize nmemb, gsize size, gsize alignment, const char *loc)
{
if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
nmemb > 0 && G_MAXSIZE / nmemb < size) {
}
void *
-rspamd_mempool_alloc0_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc)
+rspamd_mempool_alloc0_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc)
{
void *pointer = rspamd_mempool_alloc_(pool, size, alignment, loc);
memset(pointer, 0, size);
return pointer;
}
void *
-rspamd_mempool_alloc0_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc)
+rspamd_mempool_alloc0_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc)
{
void *pointer = rspamd_mempool_alloc_shared_(pool, size, alignment, loc);
}
void *
-rspamd_mempool_alloc_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc)
+rspamd_mempool_alloc_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc)
{
return memory_pool_alloc_common(pool, size, alignment, RSPAMD_MEMPOOL_SHARED, loc);
}
-gchar *
-rspamd_mempool_strdup_(rspamd_mempool_t *pool, const gchar *src, const gchar *loc)
+char *
+rspamd_mempool_strdup_(rspamd_mempool_t *pool, const char *src, const char *loc)
{
if (src == NULL) {
return NULL;
return rspamd_mempool_strdup_len_(pool, src, strlen(src), loc);
}
-gchar *
-rspamd_mempool_strdup_len_(rspamd_mempool_t *pool, const gchar *src, gsize len, const gchar *loc)
+char *
+rspamd_mempool_strdup_len_(rspamd_mempool_t *pool, const char *src, gsize len, const char *loc)
{
- gchar *newstr;
+ char *newstr;
if (src == NULL) {
return NULL;
return newstr;
}
-gchar *
+char *
rspamd_mempool_ftokdup_(rspamd_mempool_t *pool, const rspamd_ftok_t *src,
- const gchar *loc)
+ const char *loc)
{
- gchar *newstr;
+ char *newstr;
if (src == NULL) {
return NULL;
void rspamd_mempool_add_destructor_full(rspamd_mempool_t *pool,
rspamd_mempool_destruct_t func,
void *data,
- const gchar *function,
- const gchar *line)
+ const char *function,
+ const char *line)
{
struct _pool_destructors *cur;
}
}
-static gint
+static int
cmp_int(gconstpointer a, gconstpointer b)
{
- gint i1 = *(const gint *) a, i2 = *(const gint *) b;
+ int i1 = *(const int *) a, i2 = *(const int *) b;
return i1 - i2;
}
static void
rspamd_mempool_adjust_entry(struct rspamd_mempool_entry_point *e)
{
- gint sz[G_N_ELEMENTS(e->elts)], sel_pos, sel_neg;
- guint i, jitter;
+ int sz[G_N_ELEMENTS(e->elts)], sel_pos, sel_neg;
+ unsigned int i, jitter;
for (i = 0; i < G_N_ELEMENTS(sz); i++) {
- sz[i] = e->elts[i].fragmentation - (gint) e->elts[i].leftover;
+ sz[i] = e->elts[i].fragmentation - (int) e->elts[i].leftover;
}
- qsort(sz, G_N_ELEMENTS(sz), sizeof(gint), cmp_int);
+ qsort(sz, G_N_ELEMENTS(sz), sizeof(int), cmp_int);
jitter = rspamd_random_uint64_fast() % 10;
/*
* Take stochastic quantiles
* previous count
* 3) Our variables count is less than some hard limit
*/
- static const guint max_preallocated_vars = 512;
+ static const unsigned int max_preallocated_vars = 512;
- guint cur_size = kh_size(pool->priv->variables);
- guint old_guess = pool->priv->entry->cur_vars;
- guint new_guess;
+ unsigned int cur_size = kh_size(pool->priv->variables);
+ unsigned int old_guess = pool->priv->entry->cur_vars;
+ unsigned int new_guess;
if (old_guess == 0) {
new_guess = MIN(cur_size, max_preallocated_vars);
struct mempool_debug_elt {
gsize sz;
- const gchar *loc;
+ const char *loc;
};
-static gint
+static int
rspamd_mempool_debug_elt_cmp(const void *a, const void *b)
{
const struct mempool_debug_elt *e1 = a, *e2 = b;
/* Inverse order */
- return (gint) ((gssize) e2->sz) - ((gssize) e1->sz);
+ return (int) ((gssize) e2->sz) - ((gssize) e1->sz);
}
void rspamd_mempool_delete(rspamd_mempool_t *pool)
struct _pool_chain *cur, *tmp;
struct _pool_destructors *destructor;
gpointer ptr;
- guint i;
+ unsigned int i;
gsize len;
POOL_MTX_LOCK();
cur = pool->priv->pools[RSPAMD_MEMPOOL_NORMAL];
if (G_UNLIKELY(pool->priv->flags & RSPAMD_MEMPOOL_DEBUG)) {
- GHashTable *debug_tbl = *(GHashTable **) (((guchar *) pool) + sizeof(*pool));
+ GHashTable *debug_tbl = *(GHashTable **) (((unsigned char *) pool) + sizeof(*pool));
/* Show debug info */
gsize ndtor = 0;
LL_COUNT(pool->priv->dtors_head, destructor, ndtor);
while (g_hash_table_iter_next(&it, &k, &v)) {
struct mempool_debug_elt e;
- e.loc = (const gchar *) k;
+ e.loc = (const char *) k;
e.sz = GPOINTER_TO_SIZE(v);
g_array_append_val(sorted_debug_size, e);
}
g_array_sort(sorted_debug_size, rspamd_mempool_debug_elt_cmp);
- for (guint _i = 0; _i < sorted_debug_size->len; _i++) {
+ for (unsigned int _i = 0; _i < sorted_debug_size->len; _i++) {
struct mempool_debug_elt *e;
e = &g_array_index(sorted_debug_size, struct mempool_debug_elt, _i);
LL_FOREACH_SAFE(pool->priv->pools[i], cur, tmp)
{
g_atomic_int_add(&mem_pool_stat->bytes_allocated,
- -((gint) cur->slice_size));
+ -((int) cur->slice_size));
g_atomic_int_add(&mem_pool_stat->chunks_allocated, -1);
len = cur->slice_size + sizeof(struct _pool_chain);
/*
* Own emulation
*/
-static inline gint
+static inline int
__mutex_spin(rspamd_mempool_mutex_t *mutex)
{
/* check spin count */
#define RSPAMD_MEMPOOL_VARS_HASH_SEED 0xb32ad7c55eb2e647ULL
void rspamd_mempool_set_variable(rspamd_mempool_t *pool,
- const gchar *name,
+ const char *name,
gpointer value,
rspamd_mempool_destruct_t destructor)
{
}
}
- gint hv = rspamd_cryptobox_fast_hash(name, strlen(name),
- RSPAMD_MEMPOOL_VARS_HASH_SEED);
+ int hv = rspamd_cryptobox_fast_hash(name, strlen(name),
+ RSPAMD_MEMPOOL_VARS_HASH_SEED);
khiter_t it;
- gint r;
+ int r;
it = kh_put(rspamd_mempool_vars_hash, pool->priv->variables, hv, &r);
}
gpointer
-rspamd_mempool_get_variable(rspamd_mempool_t *pool, const gchar *name)
+rspamd_mempool_get_variable(rspamd_mempool_t *pool, const char *name)
{
if (pool->priv->variables == NULL) {
return NULL;
}
khiter_t it;
- gint hv = rspamd_cryptobox_fast_hash(name, strlen(name),
- RSPAMD_MEMPOOL_VARS_HASH_SEED);
+ int hv = rspamd_cryptobox_fast_hash(name, strlen(name),
+ RSPAMD_MEMPOOL_VARS_HASH_SEED);
it = kh_get(rspamd_mempool_vars_hash, pool->priv->variables, hv);
}
gpointer
-rspamd_mempool_steal_variable(rspamd_mempool_t *pool, const gchar *name)
+rspamd_mempool_steal_variable(rspamd_mempool_t *pool, const char *name)
{
if (pool->priv->variables == NULL) {
return NULL;
}
khiter_t it;
- gint hv = rspamd_cryptobox_fast_hash(name, strlen(name),
- RSPAMD_MEMPOOL_VARS_HASH_SEED);
+ int hv = rspamd_cryptobox_fast_hash(name, strlen(name),
+ RSPAMD_MEMPOOL_VARS_HASH_SEED);
it = kh_get(rspamd_mempool_vars_hash, pool->priv->variables, hv);
return NULL;
}
-void rspamd_mempool_remove_variable(rspamd_mempool_t *pool, const gchar *name)
+void rspamd_mempool_remove_variable(rspamd_mempool_t *pool, const char *name)
{
if (pool->priv->variables != NULL) {
khiter_t it;
- gint hv = rspamd_cryptobox_fast_hash(name, strlen(name),
- RSPAMD_MEMPOOL_VARS_HASH_SEED);
+ int hv = rspamd_cryptobox_fast_hash(name, strlen(name),
+ RSPAMD_MEMPOOL_VARS_HASH_SEED);
it = kh_get(rspamd_mempool_vars_hash, pool->priv->variables, hv);
*/
#if !defined(HAVE_PTHREAD_PROCESS_SHARED) || defined(DISABLE_PTHREAD_MUTEX)
typedef struct memory_pool_mutex_s {
- gint lock;
+ int lock;
pid_t owner;
- guint spin;
+ unsigned int spin;
} rspamd_mempool_mutex_t;
/**
* Rwlock for locking shared memory regions
* Tag to use for logging purposes
*/
struct rspamd_mempool_tag {
- gchar tagname[MEMPOOL_TAG_LEN]; /**< readable name */
- gchar uid[MEMPOOL_UID_LEN]; /**< unique id */
+ char tagname[MEMPOOL_TAG_LEN]; /**< readable name */
+ char uid[MEMPOOL_UID_LEN]; /**< unique id */
};
enum rspamd_mempool_flags {
* Statistics structure
*/
typedef struct memory_pool_stat_s {
- guint pools_allocated; /**< total number of allocated pools */
- guint pools_freed; /**< number of freed pools */
- guint bytes_allocated; /**< bytes that are allocated with pool allocator */
- guint chunks_allocated; /**< number of chunks that are allocated */
- guint shared_chunks_allocated; /**< shared chunks allocated */
- guint chunks_freed; /**< chunks freed */
- guint oversized_chunks; /**< oversized chunks */
- guint fragmented_size; /**< fragmentation size */
+ unsigned int pools_allocated; /**< total number of allocated pools */
+ unsigned int pools_freed; /**< number of freed pools */
+ unsigned int bytes_allocated; /**< bytes that are allocated with pool allocator */
+ unsigned int chunks_allocated; /**< number of chunks that are allocated */
+ unsigned int shared_chunks_allocated; /**< shared chunks allocated */
+ unsigned int chunks_freed; /**< chunks freed */
+ unsigned int oversized_chunks; /**< oversized chunks */
+ unsigned int fragmented_size; /**< fragmentation size */
} rspamd_mempool_stat_t;
* @param size size of pool's page
* @return new memory pool object
*/
-rspamd_mempool_t *rspamd_mempool_new_(gsize size, const gchar *tag, gint flags,
- const gchar *loc);
+rspamd_mempool_t *rspamd_mempool_new_(gsize size, const char *tag, int flags,
+ const char *loc);
#define rspamd_mempool_new(size, tag, flags) \
rspamd_mempool_new_((size), (tag), (flags), G_STRLOC)
* @param size bytes to allocate
* @return pointer to allocated object
*/
-void *rspamd_mempool_alloc_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc)
+void *rspamd_mempool_alloc_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc)
RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL;
/**
* Allocates array handling potential integer overflow
* @param loc
* @return
*/
-void *rspamd_mempool_alloc_array_(rspamd_mempool_t *pool, gsize nmemb, gsize size, gsize alignment, const gchar *loc)
+void *rspamd_mempool_alloc_array_(rspamd_mempool_t *pool, gsize nmemb, gsize size, gsize alignment, const char *loc)
RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL;
#define rspamd_mempool_alloc(pool, size) \
rspamd_mempool_alloc_((pool), (size), MIN_MEM_ALIGNMENT, (G_STRLOC))
* @param size
* @param loc
*/
-void rspamd_mempool_notify_alloc_(rspamd_mempool_t *pool, gsize size, const gchar *loc);
+void rspamd_mempool_notify_alloc_(rspamd_mempool_t *pool, gsize size, const char *loc);
#define rspamd_mempool_notify_alloc(pool, size) \
rspamd_mempool_notify_alloc_((pool), (size), (G_STRLOC))
* @param size bytes to allocate
* @return pointer to allocated object
*/
-void *rspamd_mempool_alloc0_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc)
+void *rspamd_mempool_alloc0_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc)
RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL;
#define rspamd_mempool_alloc0(pool, size) \
rspamd_mempool_alloc0_((pool), (size), MIN_MEM_ALIGNMENT, (G_STRLOC))
* @param src source string
* @return pointer to newly created string that is copy of src
*/
-gchar *rspamd_mempool_strdup_(rspamd_mempool_t *pool, const gchar *src, const gchar *loc)
+char *rspamd_mempool_strdup_(rspamd_mempool_t *pool, const char *src, const char *loc)
RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT);
#define rspamd_mempool_strdup(pool, src) \
rspamd_mempool_strdup_((pool), (src), (G_STRLOC))
-gchar *rspamd_mempool_strdup_len_(rspamd_mempool_t *pool, const gchar *src, gsize len, const gchar *loc)
+char *rspamd_mempool_strdup_len_(rspamd_mempool_t *pool, const char *src, gsize len, const char *loc)
RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT);
#define rspamd_mempool_strdup_len(pool, src, len) \
rspamd_mempool_strdup_len_((pool), (src), (len), (G_STRLOC))
* @param src source string
* @return pointer to newly created string that is copy of src
*/
-gchar *rspamd_mempool_ftokdup_(rspamd_mempool_t *pool,
- const struct f_str_tok *src,
- const gchar *loc)
+char *rspamd_mempool_ftokdup_(rspamd_mempool_t *pool,
+ const struct f_str_tok *src,
+ const char *loc)
RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT);
#define rspamd_mempool_ftokdup(pool, src) \
rspamd_mempool_ftokdup_((pool), (src), (G_STRLOC))
* @param pool memory pool object
* @param size bytes to allocate
*/
-void *rspamd_mempool_alloc_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc)
+void *rspamd_mempool_alloc_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc)
RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL;
#define rspamd_mempool_alloc_shared(pool, size) \
rspamd_mempool_alloc_shared_((pool), (size), MIN_MEM_ALIGNMENT, (G_STRLOC))
(type *) (rspamd_mempool_alloc_shared_((pool), sizeof(type), \
MAX(MIN_MEM_ALIGNMENT, RSPAMD_ALIGNOF(type)), (G_STRLOC)))
-void *rspamd_mempool_alloc0_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const gchar *loc)
+void *rspamd_mempool_alloc0_shared_(rspamd_mempool_t *pool, gsize size, gsize alignment, const char *loc)
RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL;
#define rspamd_mempool_alloc0_shared(pool, size) \
rspamd_mempool_alloc0_shared_((pool), (size), MIN_MEM_ALIGNMENT, (G_STRLOC))
void rspamd_mempool_add_destructor_full(rspamd_mempool_t *pool,
rspamd_mempool_destruct_t func,
void *data,
- const gchar *function,
- const gchar *line);
+ const char *function,
+ const char *line);
/* Macros for common usage */
#define rspamd_mempool_add_destructor(pool, func, data) \
* @param destructor pointer to function-destructor
*/
void rspamd_mempool_set_variable(rspamd_mempool_t *pool,
- const gchar *name,
+ const char *name,
gpointer value,
rspamd_mempool_destruct_t destructor);
* @return NULL or pointer to variable data
*/
gpointer rspamd_mempool_get_variable(rspamd_mempool_t *pool,
- const gchar *name);
+ const char *name);
/**
* Steal memory pool variable
* @param pool
* @return
*/
gpointer rspamd_mempool_steal_variable(rspamd_mempool_t *pool,
- const gchar *name);
+ const char *name);
/**
* Removes variable from memory pool
* @param name name of variable
*/
void rspamd_mempool_remove_variable(rspamd_mempool_t *pool,
- const gchar *name);
+ const char *name);
/**
* Prepend element to a list creating it in the memory pool
-/*-
- * Copyright 2019 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
*/
#define align_ptr(p, a) \
- ((guint8 *) ((uintptr_t) (p) + ((-(intptr_t) (p)) & ((a) -1))))
+ ((uint8_t *) ((uintptr_t) (p) + ((-(intptr_t) (p)) & ((a) -1))))
enum rspamd_mempool_chain_type {
RSPAMD_MEMPOOL_NORMAL = 0,
};
struct rspamd_mempool_entry_point {
- gchar src[ENTRY_LEN];
+ char src[ENTRY_LEN];
uint32_t cur_suggestion;
uint32_t cur_elts;
uint32_t cur_vars;
struct _pool_destructors {
rspamd_mempool_destruct_t func; /**< pointer to destructor */
void *data; /**< data to free */
- const gchar *function; /**< function from which this destructor was added */
- const gchar *loc; /**< line number */
+ const char *function; /**< function from which this destructor was added */
+ const char *loc; /**< line number */
struct _pool_destructors *next;
};
struct rspamd_mempool_entry_point *entry;
gsize elt_len; /**< size of an element */
gsize used_memory;
- guint wasted_memory;
- gint flags;
+ unsigned int wasted_memory;
+ int flags;
};
/**
* Pool page structure
*/
struct _pool_chain {
- guint8 *begin; /**< begin of pool chain block */
- guint8 *pos; /**< current start of free space in block */
+ uint8_t *begin; /**< begin of pool chain block */
+ uint8_t *pos; /**< current start of free space in block */
gsize slice_size; /**< length of block */
struct _pool_chain *next;
};
GArray *hs_pats;
GArray *hs_ids;
GArray *hs_flags;
- guint scratch_used;
+ unsigned int scratch_used;
#endif
ac_trie_t *t;
GArray *pats;
GArray *res;
gboolean compiled;
- guint cnt;
+ unsigned int cnt;
enum rspamd_multipattern_flags flags;
};
return hs_suitable_cpu == RSPAMD_HS_SUPPORTED;
}
-void rspamd_multipattern_library_init(const gchar *cache_dir)
+void rspamd_multipattern_library_init(const char *cache_dir)
{
hs_cache_dir = cache_dir;
#ifdef WITH_HYPERSCAN
}
#ifdef WITH_HYPERSCAN
-static gchar *
-rspamd_multipattern_escape_tld_hyperscan(const gchar *pattern, gsize slen,
+static char *
+rspamd_multipattern_escape_tld_hyperscan(const char *pattern, gsize slen,
gsize *dst_len)
{
gsize len;
- const gchar *p, *prefix, *suffix;
- gchar *res;
+ const char *p, *prefix, *suffix;
+ char *res;
/*
* We understand the following cases
}
#endif
-static gchar *
-rspamd_multipattern_escape_tld_acism(const gchar *pattern, gsize len,
+static char *
+rspamd_multipattern_escape_tld_acism(const char *pattern, gsize len,
gsize *dst_len)
{
gsize dlen, slen;
- const gchar *p, *prefix;
- gchar *res;
+ const char *p, *prefix;
+ char *res;
/*
* We understand the following cases
/*
* Escapes special characters from specific pattern
*/
-static gchar *
-rspamd_multipattern_pattern_filter(const gchar *pattern, gsize len,
+static char *
+rspamd_multipattern_pattern_filter(const char *pattern, gsize len,
enum rspamd_multipattern_flags flags,
gsize *dst_len)
{
- gchar *ret = NULL;
- gint gl_flags = RSPAMD_REGEXP_ESCAPE_ASCII;
+ char *ret = NULL;
+ int gl_flags = RSPAMD_REGEXP_ESCAPE_ASCII;
if (flags & RSPAMD_MULTIPATTERN_UTF8) {
gl_flags |= RSPAMD_REGEXP_ESCAPE_UTF;
#ifdef WITH_HYPERSCAN
if (rspamd_hs_check()) {
if (flags & RSPAMD_MULTIPATTERN_TLD) {
- gchar *tmp;
+ char *tmp;
gsize tlen;
tmp = rspamd_multipattern_escape_tld_hyperscan(pattern, len, &tlen);
#ifdef WITH_HYPERSCAN
if (rspamd_hs_check()) {
- mp->hs_pats = g_array_new(FALSE, TRUE, sizeof(gchar *));
- mp->hs_flags = g_array_new(FALSE, TRUE, sizeof(gint));
- mp->hs_ids = g_array_new(FALSE, TRUE, sizeof(gint));
+ mp->hs_pats = g_array_new(FALSE, TRUE, sizeof(char *));
+ mp->hs_flags = g_array_new(FALSE, TRUE, sizeof(int));
+ mp->hs_ids = g_array_new(FALSE, TRUE, sizeof(int));
rspamd_cryptobox_hash_init(&mp->hash_state, NULL, 0);
return mp;
}
struct rspamd_multipattern *
-rspamd_multipattern_create_sized(guint npatterns,
+rspamd_multipattern_create_sized(unsigned int npatterns,
enum rspamd_multipattern_flags flags)
{
struct rspamd_multipattern *mp;
#ifdef WITH_HYPERSCAN
if (rspamd_hs_check()) {
- mp->hs_pats = g_array_sized_new(FALSE, TRUE, sizeof(gchar *), npatterns);
- mp->hs_flags = g_array_sized_new(FALSE, TRUE, sizeof(gint), npatterns);
- mp->hs_ids = g_array_sized_new(FALSE, TRUE, sizeof(gint), npatterns);
+ mp->hs_pats = g_array_sized_new(FALSE, TRUE, sizeof(char *), npatterns);
+ mp->hs_flags = g_array_sized_new(FALSE, TRUE, sizeof(int), npatterns);
+ mp->hs_ids = g_array_sized_new(FALSE, TRUE, sizeof(int), npatterns);
rspamd_cryptobox_hash_init(&mp->hash_state, NULL, 0);
return mp;
}
void rspamd_multipattern_add_pattern(struct rspamd_multipattern *mp,
- const gchar *pattern, gint flags)
+ const char *pattern, int flags)
{
g_assert(pattern != NULL);
}
void rspamd_multipattern_add_pattern_len(struct rspamd_multipattern *mp,
- const gchar *pattern, gsize patlen, gint flags)
+ const char *pattern, gsize patlen, int flags)
{
gsize dlen;
#ifdef WITH_HYPERSCAN
if (rspamd_hs_check()) {
- gchar *np;
- gint fl = HS_FLAG_SOM_LEFTMOST;
- gint adjusted_flags = mp->flags | flags;
+ char *np;
+ int fl = HS_FLAG_SOM_LEFTMOST;
+ int adjusted_flags = mp->flags | flags;
if (adjusted_flags & RSPAMD_MULTIPATTERN_ICASE) {
fl |= HS_FLAG_CASELESS;
}
struct rspamd_multipattern *
-rspamd_multipattern_create_full(const gchar **patterns,
- guint npatterns, enum rspamd_multipattern_flags flags)
+rspamd_multipattern_create_full(const char **patterns,
+ unsigned int npatterns, enum rspamd_multipattern_flags flags)
{
struct rspamd_multipattern *mp;
- guint i;
+ unsigned int i;
g_assert(npatterns > 0);
g_assert(patterns != NULL);
#ifdef WITH_HYPERSCAN
static gboolean
rspamd_multipattern_try_load_hs(struct rspamd_multipattern *mp,
- const guchar *hash)
+ const unsigned char *hash)
{
- gchar fp[PATH_MAX];
+ char fp[PATH_MAX];
if (hs_cache_dir == NULL) {
return FALSE;
}
rspamd_snprintf(fp, sizeof(fp), "%s/%*xs.hsmp", hs_cache_dir,
- (gint) rspamd_cryptobox_HASHBYTES / 2, hash);
+ (int) rspamd_cryptobox_HASHBYTES / 2, hash);
mp->hs_db = rspamd_hyperscan_maybe_load(fp, 0);
return mp->hs_db != NULL;
static void
rspamd_multipattern_try_save_hs(struct rspamd_multipattern *mp,
- const guchar *hash)
+ const unsigned char *hash)
{
- gchar fp[PATH_MAX], np[PATH_MAX];
+ char fp[PATH_MAX], np[PATH_MAX];
char *bytes = NULL;
gsize len;
- gint fd;
+ int fd;
if (hs_cache_dir == NULL) {
return;
fsync(fd);
rspamd_snprintf(np, sizeof(np), "%s/%*xs.hsmp", hs_cache_dir,
- (gint) rspamd_cryptobox_HASHBYTES / 2, hash);
+ (int) rspamd_cryptobox_HASHBYTES / 2, hash);
if (rename(fp, np) == -1) {
msg_warn("cannot rename hyperscan cache from %s to %s: %s",
#ifdef WITH_HYPERSCAN
if (rspamd_hs_check()) {
- guint i;
+ unsigned int i;
hs_platform_info_t plt;
hs_compile_error_t *hs_errors;
- guchar hash[rspamd_cryptobox_HASHBYTES];
+ unsigned char hash[rspamd_cryptobox_HASHBYTES];
if (mp->cnt > 0) {
g_assert(hs_populate_platform(&plt) == HS_SUCCESS);
if (hs_cache_dir != NULL) {
char fpath[PATH_MAX];
rspamd_snprintf(fpath, sizeof(fpath), "%s/%*xs.hsmp", hs_cache_dir,
- (gint) rspamd_cryptobox_HASHBYTES / 2, hash);
+ (int) rspamd_cryptobox_HASHBYTES / 2, hash);
mp->hs_db = rspamd_hyperscan_from_raw_db(db, fpath);
}
else {
mp->res = g_array_sized_new(FALSE, TRUE,
sizeof(rspamd_regexp_t *), mp->cnt);
- for (guint i = 0; i < mp->cnt; i++) {
+ for (unsigned int i = 0; i < mp->cnt; i++) {
const ac_trie_pat_t *pat;
- const gchar *pat_flags = NULL;
+ const char *pat_flags = NULL;
if (mp->flags & RSPAMD_MULTIPATTERN_UTF8) {
pat_flags = "u";
struct rspamd_multipattern_cbdata {
struct rspamd_multipattern *mp;
- const gchar *in;
+ const char *in;
gsize len;
rspamd_multipattern_cb_t cb;
gpointer ud;
- guint nfound;
- gint ret;
+ unsigned int nfound;
+ int ret;
};
#ifdef WITH_HYPERSCAN
-static gint
+static int
rspamd_multipattern_hs_cb(unsigned int id,
unsigned long long from,
unsigned long long to,
void *ud)
{
struct rspamd_multipattern_cbdata *cbd = ud;
- gint ret = 0;
+ int ret = 0;
if (to > 0) {
}
#endif
-static gint
+static int
rspamd_multipattern_acism_cb(int strnum, int textpos, void *context)
{
struct rspamd_multipattern_cbdata *cbd = context;
- gint ret;
+ int ret;
ac_trie_pat_t pat;
pat = g_array_index(cbd->mp->pats, ac_trie_pat_t, strnum);
return ret;
}
-gint rspamd_multipattern_lookup(struct rspamd_multipattern *mp,
- const gchar *in, gsize len, rspamd_multipattern_cb_t cb,
- gpointer ud, guint *pnfound)
+int rspamd_multipattern_lookup(struct rspamd_multipattern *mp,
+ const char *in, gsize len, rspamd_multipattern_cb_t cb,
+ gpointer ud, unsigned int *pnfound)
{
struct rspamd_multipattern_cbdata cbd;
- gint ret = 0;
+ int ret = 0;
g_assert(mp != NULL);
#ifdef WITH_HYPERSCAN
if (rspamd_hs_check()) {
hs_scratch_t *scr = NULL;
- guint i;
+ unsigned int i;
for (i = 0; i < MAX_SCRATCH; i++) {
if (!(mp->scratch_used & (1 << i))) {
}
#endif
- gint state = 0;
+ int state = 0;
if (mp->flags & (RSPAMD_MULTIPATTERN_GLOB | RSPAMD_MULTIPATTERN_RE)) {
/* Terribly inefficient, but who cares - just use hyperscan */
- for (guint i = 0; i < mp->cnt; i++) {
+ for (unsigned int i = 0; i < mp->cnt; i++) {
rspamd_regexp_t *re = g_array_index(mp->res, rspamd_regexp_t *, i);
- const gchar *start = NULL, *end = NULL;
+ const char *start = NULL, *end = NULL;
while (rspamd_regexp_search(re,
in,
void rspamd_multipattern_destroy(struct rspamd_multipattern *mp)
{
- guint i;
+ unsigned int i;
if (mp) {
#ifdef WITH_HYPERSCAN
if (rspamd_hs_check()) {
- gchar *p;
+ char *p;
if (mp->compiled && mp->cnt > 0) {
for (i = 0; i < MAX_SCRATCH; i++) {
}
for (i = 0; i < mp->cnt; i++) {
- p = g_array_index(mp->hs_pats, gchar *, i);
+ p = g_array_index(mp->hs_pats, char *, i);
g_free(p);
}
for (i = 0; i < mp->cnt; i++) {
pat = g_array_index(mp->pats, ac_trie_pat_t, i);
- g_free((gchar *) pat.ptr);
+ g_free((char *) pat.ptr);
}
g_array_free(mp->pats, TRUE);
}
}
-const gchar *
+const char *
rspamd_multipattern_get_pattern(struct rspamd_multipattern *mp,
- guint index)
+ unsigned int index)
{
g_assert(mp != NULL);
g_assert(index < mp->cnt);
#ifdef WITH_HYPERSCAN
if (rspamd_hs_check()) {
- return g_array_index(mp->hs_pats, gchar *, index);
+ return g_array_index(mp->hs_pats, char *, index);
}
#endif
return pat.ptr;
}
-guint rspamd_multipattern_get_npatterns(struct rspamd_multipattern *mp)
+unsigned int rspamd_multipattern_get_npatterns(struct rspamd_multipattern *mp)
{
g_assert(mp != NULL);
* @param context userdata
* @return if 0 then search for another pattern, otherwise return this value to caller
*/
-typedef gint (*rspamd_multipattern_cb_t)(struct rspamd_multipattern *mp,
- guint strnum,
- gint match_start,
- gint match_pos,
- const gchar *text,
- gsize len,
- void *context);
+typedef int (*rspamd_multipattern_cb_t)(struct rspamd_multipattern *mp,
+ unsigned int strnum,
+ int match_start,
+ int match_pos,
+ const char *text,
+ gsize len,
+ void *context);
/**
* Init multipart library and set the appropriate cache dir
* @param cache_dir
*/
-void rspamd_multipattern_library_init(const gchar *cache_dir);
+void rspamd_multipattern_library_init(const char *cache_dir);
/**
* Creates empty multipattern structure
* @param reserved
* @return
*/
-struct rspamd_multipattern *rspamd_multipattern_create_sized(guint reserved,
+struct rspamd_multipattern *rspamd_multipattern_create_sized(unsigned int reserved,
enum rspamd_multipattern_flags flags);
/**
* @return new multipattern structure
*/
struct rspamd_multipattern *rspamd_multipattern_create_full(
- const gchar **patterns,
- guint npatterns,
+ const char **patterns,
+ unsigned int npatterns,
enum rspamd_multipattern_flags flags);
/**
* @param pattern
*/
void rspamd_multipattern_add_pattern(struct rspamd_multipattern *mp,
- const gchar *pattern, gint flags);
+ const char *pattern, int flags);
/**
* Adds new pattern from arbitrary string
* @param flags
*/
void rspamd_multipattern_add_pattern_len(struct rspamd_multipattern *mp,
- const gchar *pattern, gsize patlen, gint flags);
+ const char *pattern, gsize patlen, int flags);
#define RSPAMD_MULTIPATTERN_COMPILE_NO_FS (0x1u << 0u)
* @param ud callback data
* @return
*/
-gint rspamd_multipattern_lookup(struct rspamd_multipattern *mp,
- const gchar *in, gsize len, rspamd_multipattern_cb_t cb,
- gpointer ud, guint *pnfound);
+int rspamd_multipattern_lookup(struct rspamd_multipattern *mp,
+ const char *in, gsize len, rspamd_multipattern_cb_t cb,
+ gpointer ud, unsigned int *pnfound);
/**
* Get pattern string from multipattern identified by index
* @param index
* @return
*/
-const gchar *rspamd_multipattern_get_pattern(struct rspamd_multipattern *mp,
- guint index);
+const char *rspamd_multipattern_get_pattern(struct rspamd_multipattern *mp,
+ unsigned int index);
/**
* Returns number of patterns in a multipattern matcher
* @param mp
* @return
*/
-guint rspamd_multipattern_get_npatterns(struct rspamd_multipattern *mp);
+unsigned int rspamd_multipattern_get_npatterns(struct rspamd_multipattern *mp);
/**
* Destroys multipattern structure
* From FreeBSD libutil code
*/
static const int maxscale = 6;
-static const gchar _hex[] = "0123456789abcdef";
-static const gchar _HEX[] = "0123456789ABCDEF";
+static const char _hex[] = "0123456789abcdef";
+static const char _HEX[] = "0123456789ABCDEF";
-static gchar *
-rspamd_humanize_number(gchar *buf, gchar *last, int64_t num, gboolean bytes)
+static char *
+rspamd_humanize_number(char *buf, char *last, int64_t num, gboolean bytes)
{
- const gchar *prefixes;
+ const char *prefixes;
int i, r, remainder, sign;
int64_t divisor;
gsize len = last - buf;
else {
/* Floating point version */
r = rspamd_snprintf(buf, len, "%.2f%s",
- sign * (num + remainder / (gdouble) divisor),
+ sign * (num + remainder / (double) divisor),
SCALE2PREFIX(i));
}
'9', '0', '9', '1', '9', '2', '9', '3', '9', '4',
'9', '5', '9', '6', '9', '7', '9', '8', '9', '9'};
-static inline guint
-rspamd_uint32_print(uint32_t in, gchar *out)
+static inline unsigned int
+rspamd_uint32_print(uint32_t in, char *out)
{
- guint ndigits = rspamd_decimal_digits32(in);
- gchar *p;
+ unsigned int ndigits = rspamd_decimal_digits32(in);
+ char *p;
p = out + ndigits - 1;
return ndigits;
}
-static inline guint
-rspamd_uint64_print(uint64_t in, gchar *out)
+static inline unsigned int
+rspamd_uint64_print(uint64_t in, char *out)
{
- guint ndigits = rspamd_decimal_digits64(in);
+ unsigned int ndigits = rspamd_decimal_digits64(in);
uint32_t v32;
- gchar *p;
+ char *p;
p = out + ndigits - 1;
#endif
}
-static gchar *
-rspamd_sprintf_num(gchar *buf, gchar *last, uint64_t ui64, gchar zero,
- guint hexadecimal, guint binary, guint width)
+static char *
+rspamd_sprintf_num(char *buf, char *last, uint64_t ui64, char zero,
+ unsigned int hexadecimal, unsigned int binary, unsigned int width)
{
- gchar *p, temp[64];
+ char *p, temp[64];
size_t len = 0;
if (G_LIKELY(hexadecimal == 0 && binary == 0)) {
len = last - buf;
}
- return ((gchar *) memcpy(buf, p, len)) + len;
+ return ((char *) memcpy(buf, p, len)) + len;
}
struct rspamd_printf_char_buf {
};
static glong
-rspamd_printf_append_char(const gchar *buf, glong buflen, gpointer ud)
+rspamd_printf_append_char(const char *buf, glong buflen, gpointer ud)
{
struct rspamd_printf_char_buf *dst = (struct rspamd_printf_char_buf *) ud;
glong wr;
}
static glong
-rspamd_printf_append_file(const gchar *buf, glong buflen, gpointer ud)
+rspamd_printf_append_file(const char *buf, glong buflen, gpointer ud)
{
FILE *dst = (FILE *) ud;
if (buflen > 0) {
}
static glong
-rspamd_printf_append_gstring(const gchar *buf, glong buflen, gpointer ud)
+rspamd_printf_append_gstring(const char *buf, glong buflen, gpointer ud)
{
GString *dst = (GString *) ud;
}
static glong
-rspamd_printf_append_fstring(const gchar *buf, glong buflen, gpointer ud)
+rspamd_printf_append_fstring(const char *buf, glong buflen, gpointer ud)
{
rspamd_fstring_t **dst = ud;
return buflen;
}
-glong rspamd_fprintf(FILE *f, const gchar *fmt, ...)
+glong rspamd_fprintf(FILE *f, const char *fmt, ...)
{
va_list args;
glong r;
return r;
}
-glong rspamd_printf(const gchar *fmt, ...)
+glong rspamd_printf(const char *fmt, ...)
{
va_list args;
glong r;
return r;
}
-glong rspamd_log_fprintf(FILE *f, const gchar *fmt, ...)
+glong rspamd_log_fprintf(FILE *f, const char *fmt, ...)
{
va_list args;
glong r;
}
-glong rspamd_snprintf(gchar *buf, glong max, const gchar *fmt, ...)
+glong rspamd_snprintf(char *buf, glong max, const char *fmt, ...)
{
- gchar *r;
+ char *r;
va_list args;
va_start(args, fmt);
return (r - buf);
}
-gchar *
-rspamd_vsnprintf(gchar *buf, glong max, const gchar *fmt, va_list args)
+char *
+rspamd_vsnprintf(char *buf, glong max, const char *fmt, va_list args)
{
struct rspamd_printf_char_buf dst;
return dst.pos;
}
-glong rspamd_printf_gstring(GString *s, const gchar *fmt, ...)
+glong rspamd_printf_gstring(GString *s, const char *fmt, ...)
{
va_list args;
glong r;
return r;
}
-glong rspamd_vprintf_gstring(GString *s, const gchar *fmt, va_list args)
+glong rspamd_vprintf_gstring(GString *s, const char *fmt, va_list args)
{
return rspamd_vprintf_common(rspamd_printf_append_gstring, s, fmt, args);
}
-glong rspamd_printf_fstring(rspamd_fstring_t **s, const gchar *fmt, ...)
+glong rspamd_printf_fstring(rspamd_fstring_t **s, const char *fmt, ...)
{
va_list args;
glong r;
return r;
}
-glong rspamd_vprintf_fstring(rspamd_fstring_t **s, const gchar *fmt, va_list args)
+glong rspamd_vprintf_fstring(rspamd_fstring_t **s, const char *fmt, va_list args)
{
return rspamd_vprintf_common(rspamd_printf_append_fstring, s, fmt, args);
}
glong rspamd_vprintf_common(rspamd_printf_append_func func,
gpointer apd,
- const gchar *fmt,
+ const char *fmt,
va_list args)
{
- gchar zero, numbuf[G_ASCII_DTOSTR_BUF_SIZE], dtoabuf[32], *p, *last;
- guchar c;
- const gchar *buf_start = fmt;
- gint d;
- gdouble f;
+ char zero, numbuf[G_ASCII_DTOSTR_BUF_SIZE], dtoabuf[32], *p, *last;
+ unsigned char c;
+ const char *buf_start = fmt;
+ int d;
+ double f;
glong written = 0, wr, slen;
int64_t i64;
uint64_t ui64;
- guint width, sign, hex, humanize, bytes, frac_width, b32, b64;
+ unsigned int width, sign, hex, humanize, bytes, frac_width, b32, b64;
rspamd_fstring_t *v;
rspamd_ftok_t *tok;
GString *gs;
i64 = 0;
ui64 = 0;
- zero = (gchar) ((*++fmt == '0') ? '0' : ' ');
+ zero = (char) ((*++fmt == '0') ? '0' : ' ');
width = 0;
sign = 1;
hex = 0;
fmt++;
if (*fmt == '*') {
- d = (gint) va_arg(args, gint);
+ d = (int) va_arg(args, int);
if (G_UNLIKELY(d < 0)) {
return 0;
}
- frac_width = (guint) d;
+ frac_width = (unsigned int) d;
fmt++;
}
else {
break;
case '*':
- d = (gint) va_arg(args, gint);
+ d = (int) va_arg(args, int);
if (G_UNLIKELY(d < 0)) {
return 0;
}
continue;
case 's':
- p = va_arg(args, gchar *);
+ p = va_arg(args, char *);
if (p == NULL) {
p = "(NULL)";
slen = sizeof("(NULL)") - 1;
}
if (G_UNLIKELY(b32)) {
- gchar *b32buf;
+ char *b32buf;
if (G_UNLIKELY(slen == -1)) {
if (G_LIKELY(width != 0)) {
}
}
else if (G_UNLIKELY(hex)) {
- gchar hexbuf[2];
+ char hexbuf[2];
if (G_UNLIKELY(slen == -1)) {
if (G_LIKELY(width != 0)) {
buf_start = fmt;
}
else if (G_UNLIKELY(b64)) {
- gchar *b64buf;
+ char *b64buf;
gsize olen = 0;
if (G_UNLIKELY(slen == -1)) {
case 'd':
if (sign) {
- i64 = (int64_t) va_arg(args, gint);
+ i64 = (int64_t) va_arg(args, int);
}
else {
- ui64 = (uint64_t) va_arg(args, guint);
+ ui64 = (uint64_t) va_arg(args, unsigned int);
}
break;
case 'f':
- f = (gdouble) va_arg(args, double);
+ f = (double) va_arg(args, double);
slen = fpconv_dtoa(f, dtoabuf, frac_width, false);
RSPAMD_PRINTF_APPEND(dtoabuf, slen);
continue;
case 'g':
- f = (gdouble) va_arg(args, double);
+ f = (double) va_arg(args, double);
slen = fpconv_dtoa(f, dtoabuf, 0, true);
RSPAMD_PRINTF_APPEND(dtoabuf, slen);
continue;
case 'F':
- f = (gdouble) va_arg(args, long double);
+ f = (double) va_arg(args, long double);
slen = fpconv_dtoa(f, dtoabuf, frac_width, false);
RSPAMD_PRINTF_APPEND(dtoabuf, slen);
continue;
case 'G':
- f = (gdouble) va_arg(args, long double);
+ f = (double) va_arg(args, long double);
slen = fpconv_dtoa(f, dtoabuf, 0, true);
RSPAMD_PRINTF_APPEND(dtoabuf, slen);
break;
case 'c':
- c = va_arg(args, gint);
+ c = va_arg(args, int);
c &= 0xffu;
if (G_UNLIKELY(hex)) {
- gchar hexbuf[2];
+ char hexbuf[2];
hexbuf[0] = hex == 2 ? _HEX[(c >> 4u) & 0xfu] : _hex[(c >> 4u) & 0xfu];
hexbuf[1] = hex == 2 ? _HEX[c & 0xfu] : _hex[c & 0xfu];
* %[0][width][x][X]O off_t
* %[0][width]T time_t
* %[0][width][u][x|X|h|H|b|B]z ssize_t/size_t
- * %[0][width][u][x|X|h|H|b|B]d gint/guint
+ * %[0][width][u][x|X|h|H|b|B]d int/unsigned int
* %[0][width][u][x|X|h|H|b|B]l long
* %[0][width][u][x|X|h|H|b|B]D int32_t/uint32_t
* %[0][width][u][x|X|h|H|b|B]L int64_t/uint64_t
* %*s length and string
* %Z '\0'
* %N '\n'
- * %c gchar
+ * %c char
* %t time_t
* %e GError *
* %% %
* @param ud opaque pointer
* @return number of characters written
*/
-typedef glong (*rspamd_printf_append_func)(const gchar *buf, glong buflen,
+typedef glong (*rspamd_printf_append_func)(const char *buf, glong buflen,
gpointer ud);
-glong rspamd_fprintf(FILE *f, const gchar *fmt, ...);
+glong rspamd_fprintf(FILE *f, const char *fmt, ...);
-glong rspamd_printf(const gchar *fmt, ...);
+glong rspamd_printf(const char *fmt, ...);
-glong rspamd_log_fprintf(FILE *f, const gchar *fmt, ...);
+glong rspamd_log_fprintf(FILE *f, const char *fmt, ...);
-glong rspamd_snprintf(gchar *buf, glong max, const gchar *fmt, ...);
+glong rspamd_snprintf(char *buf, glong max, const char *fmt, ...);
-gchar *rspamd_vsnprintf(gchar *buf, glong max, const gchar *fmt,
- va_list args);
+char *rspamd_vsnprintf(char *buf, glong max, const char *fmt,
+ va_list args);
-glong rspamd_printf_gstring(GString *s, const gchar *fmt, ...);
+glong rspamd_printf_gstring(GString *s, const char *fmt, ...);
-glong rspamd_vprintf_gstring(GString *s, const gchar *fmt, va_list args);
+glong rspamd_vprintf_gstring(GString *s, const char *fmt, va_list args);
-glong rspamd_printf_fstring(rspamd_fstring_t **s, const gchar *fmt, ...);
+glong rspamd_printf_fstring(rspamd_fstring_t **s, const char *fmt, ...);
-glong rspamd_vprintf_fstring(rspamd_fstring_t **s, const gchar *fmt, va_list args);
+glong rspamd_vprintf_fstring(rspamd_fstring_t **s, const char *fmt, va_list args);
glong rspamd_vprintf_common(rspamd_printf_append_func func,
gpointer apd,
- const gchar *fmt,
+ const char *fmt,
va_list args);
#ifdef __cplusplus
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
struct radix_tree_compressed {
rspamd_mempool_t *pool;
struct btrie *tree;
- const gchar *name;
+ const char *name;
size_t size;
- guint duplicates;
+ unsigned int duplicates;
gboolean own_pool;
};
uintptr_t
-radix_find_compressed(radix_compressed_t *tree, const guint8 *key, gsize keylen)
+radix_find_compressed(radix_compressed_t *tree, const uint8_t *key, gsize keylen)
{
gconstpointer ret;
uintptr_t
radix_insert_compressed(radix_compressed_t *tree,
- guint8 *key, gsize keylen,
+ uint8_t *key, gsize keylen,
gsize masklen,
uintptr_t value)
{
- static const guint max_duplicates = 32;
- guint keybits = keylen * NBBY;
+ static const unsigned int max_duplicates = 32;
+ unsigned int keybits = keylen * NBBY;
uintptr_t old;
- gchar ip_str[INET6_ADDRSTRLEN + 1];
+ char ip_str[INET6_ADDRSTRLEN + 1];
int ret;
g_assert(tree != NULL);
tree->name,
(gpointer) value,
inet_ntop(AF_INET, key, ip_str, sizeof(ip_str) - 1),
- (gint) (keybits - masklen));
+ (int) (keybits - masklen));
}
else if (keybits == 128) {
msg_err_radix("%s: cannot insert %p, key: [%s]/%d, duplicate value",
tree->name,
(gpointer) value,
inet_ntop(AF_INET6, key, ip_str, sizeof(ip_str) - 1),
- (gint) (keybits - masklen));
+ (int) (keybits - masklen));
}
else {
msg_err_radix("%s: cannot insert %p with mask %z, key: %*xs, duplicate value",
radix_compressed_t *
-radix_create_compressed(const gchar *tree_name)
+radix_create_compressed(const char *tree_name)
{
radix_compressed_t *tree;
}
radix_compressed_t *
-radix_create_compressed_with_pool(rspamd_mempool_t *pool, const gchar *tree_name)
+radix_create_compressed_with_pool(rspamd_mempool_t *pool, const char *tree_name)
{
radix_compressed_t *tree;
radix_find_compressed_addr(radix_compressed_t *tree,
const rspamd_inet_addr_t *addr)
{
- const guchar *key;
- guint klen = 0;
- guchar buf[16];
+ const unsigned char *key;
+ unsigned int klen = 0;
+ unsigned char buf[16];
if (addr == NULL) {
return RADIX_NO_VALUE;
return RADIX_NO_VALUE;
}
-gint rspamd_radix_add_iplist(const gchar *list, const gchar *separators,
- radix_compressed_t *tree, gconstpointer value,
- gboolean resolve, const gchar *tree_name)
+int rspamd_radix_add_iplist(const char *list, const char *separators,
+ radix_compressed_t *tree, gconstpointer value,
+ gboolean resolve, const char *tree_name)
{
- gchar *token, *ipnet, *err_str, **strv, **cur, *brace;
+ char *token, *ipnet, *err_str, **strv, **cur, *brace;
union {
struct in_addr ina;
struct in6_addr ina6;
- guchar buf[16];
+ unsigned char buf[16];
} addr_buf;
- guint k = G_MAXINT;
- gint af;
- gint res = 0, r;
+ unsigned int k = G_MAXINT;
+ int af;
+ int res = 0, r;
struct addrinfo hints, *ai_res, *cur_ai;
/* Split string if there are multiple items inside a single string */
}
gboolean
-radix_add_generic_iplist(const gchar *ip_list, radix_compressed_t **tree,
- gboolean resolve, const gchar *tree_name)
+radix_add_generic_iplist(const char *ip_list, radix_compressed_t **tree,
+ gboolean resolve, const char *tree_name)
{
static const char fill_ptr[] = "1";
return NULL;
}
-const gchar *
+const char *
radix_get_info(radix_compressed_t *tree)
{
if (tree == NULL) {
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
*/
uintptr_t
radix_insert_compressed(radix_compressed_t *tree,
- guint8 *key, gsize keylen,
+ uint8_t *key, gsize keylen,
gsize masklen,
uintptr_t value);
* @param keylen length of a key
* @return opaque pointer or `RADIX_NO_VALUE` if no value has been found
*/
-uintptr_t radix_find_compressed(radix_compressed_t *tree, const guint8 *key,
+uintptr_t radix_find_compressed(radix_compressed_t *tree, const uint8_t *key,
gsize keylen);
/**
* Create new radix trie
* @return
*/
-radix_compressed_t *radix_create_compressed(const gchar *tree_name);
+radix_compressed_t *radix_create_compressed(const char *tree_name);
-radix_compressed_t *radix_create_compressed_with_pool(rspamd_mempool_t *pool, const gchar *tree_name);
+radix_compressed_t *radix_create_compressed_with_pool(rspamd_mempool_t *pool, const char *tree_name);
/**
* Insert list of ip addresses and masks to the radix tree
* @param tree target tree
* @return number of elements inserted
*/
-gint rspamd_radix_add_iplist(const gchar *list, const gchar *separators,
- radix_compressed_t *tree, gconstpointer value,
- gboolean resolve, const gchar *tree_name);
+int rspamd_radix_add_iplist(const char *list, const char *separators,
+ radix_compressed_t *tree, gconstpointer value,
+ gboolean resolve, const char *tree_name);
/**
* Generic version of @see rspamd_radix_add_iplist. This function creates tree
* if `tree` is NULL.
*/
gboolean
-radix_add_generic_iplist(const gchar *ip_list,
+radix_add_generic_iplist(const char *ip_list,
radix_compressed_t **tree,
gboolean resolve,
- const gchar *tree_name);
+ const char *tree_name);
/**
* Returns number of elements in the tree
* @param tree
* @return constant string
*/
-const gchar *radix_get_info(radix_compressed_t *tree);
+const char *radix_get_info(radix_compressed_t *tree);
/**
* Returns memory pool associated with the radix tree
#define PCRE_FLAG(x) G_PASTE(PCRE2_, x)
#endif
-typedef guchar regexp_id_t[rspamd_cryptobox_HASHBYTES];
+typedef unsigned char regexp_id_t[rspamd_cryptobox_HASHBYTES];
#undef DISABLE_JIT_FAST
struct rspamd_regexp_s {
- gdouble exec_time;
- gchar *pattern;
+ double exec_time;
+ char *pattern;
PCRE_T *re;
PCRE_T *raw_re;
#ifndef WITH_PCRE2
gpointer re_class;
uint64_t cache_id;
gsize match_limit;
- guint max_hits;
- gint flags;
- gint pcre_flags;
- gint ncaptures;
+ unsigned int max_hits;
+ int flags;
+ int pcre_flags;
+ int ncaptures;
};
struct rspamd_regexp_cache {
}
static void
-rspamd_regexp_generate_id(const gchar *pattern, const gchar *flags,
+rspamd_regexp_generate_id(const char *pattern, const char *flags,
regexp_id_t out)
{
rspamd_cryptobox_hash_state_t st;
rspamd_regexp_library_init(NULL);
}
#if defined(WITH_PCRE2)
- static const guint max_recursion_depth = 100000, max_backtrack = 1000000;
+ static const unsigned int max_recursion_depth = 100000, max_backtrack = 1000000;
/* Create match context */
r->mcontext = pcre2_match_context_create(NULL);
}
#ifdef HAVE_PCRE_JIT
- guint jit_flags = can_jit ? PCRE2_JIT_COMPLETE : 0;
+ unsigned int jit_flags = can_jit ? PCRE2_JIT_COMPLETE : 0;
gsize jsz;
PCRE2_UCHAR errstr[128];
int errcode;
#endif
#else
- const gchar *err_str = "unknown";
+ const char *err_str = "unknown";
gboolean try_jit = TRUE, try_raw_jit = TRUE;
- gint study_flags = 0;
+ int study_flags = 0;
#if defined(HAVE_PCRE_JIT)
study_flags |= PCRE_STUDY_JIT_COMPILE;
/* JIT path */
if (try_jit) {
#ifdef HAVE_PCRE_JIT
- gint jit, n;
+ int jit, n;
if (can_jit) {
jit = 0;
if (try_raw_jit) {
#ifdef HAVE_PCRE_JIT
- gint jit, n;
+ int jit, n;
if (can_jit) {
}
rspamd_regexp_t *
-rspamd_regexp_new_len(const gchar *pattern, gsize len, const gchar *flags,
+rspamd_regexp_new_len(const char *pattern, gsize len, const char *flags,
GError **err)
{
- const gchar *start = pattern, *end = start + len, *flags_str = NULL, *flags_end = NULL;
- gchar *err_str;
+ const char *start = pattern, *end = start + len, *flags_str = NULL, *flags_end = NULL;
+ char *err_str;
rspamd_regexp_t *res;
gboolean explicit_utf = FALSE;
PCRE_T *r;
- gchar sep = 0, *real_pattern;
+ char sep = 0, *real_pattern;
#ifndef WITH_PCRE2
- gint err_off;
+ int err_off;
#else
gsize err_off;
#endif
- gint regexp_flags = 0, rspamd_flags = 0, err_code, ncaptures;
+ int regexp_flags = 0, rspamd_flags = 0, err_code, ncaptures;
gboolean strict_flags = FALSE;
rspamd_regexp_library_init(NULL);
rspamd_flags &= ~RSPAMD_REGEXP_FLAG_FULL_MATCH;
}
else {
- gchar *last_sep = rspamd_memrchr(pattern, sep, len);
+ char *last_sep = rspamd_memrchr(pattern, sep, len);
if (last_sep == NULL || last_sep <= start) {
g_set_error(err, rspamd_regexp_quark(), EINVAL,
if (r == NULL) {
g_set_error(err, rspamd_regexp_quark(), EINVAL,
"regexp parsing error: '%s' at position %d; pattern: %s",
- err_str, (gint) err_off, real_pattern);
+ err_str, (int) err_off, real_pattern);
g_free(real_pattern);
return NULL;
#endif
if (res->raw_re == NULL) {
msg_warn("raw regexp parsing error: '%s': '%s' at position %d",
- err_str, real_pattern, (gint) err_off);
+ err_str, real_pattern, (int) err_off);
}
}
}
rspamd_regexp_t *
-rspamd_regexp_new(const gchar *pattern, const gchar *flags,
+rspamd_regexp_new(const char *pattern, const char *flags,
GError **err)
{
return rspamd_regexp_new_len(pattern, strlen(pattern), flags, err);
#ifndef WITH_PCRE2
gboolean
-rspamd_regexp_search(const rspamd_regexp_t *re, const gchar *text, gsize len,
- const gchar **start, const gchar **end, gboolean raw,
+rspamd_regexp_search(const rspamd_regexp_t *re, const char *text, gsize len,
+ const char **start, const char **end, gboolean raw,
GArray *captures)
{
pcre *r;
#if defined(HAVE_PCRE_JIT) && defined(HAVE_PCRE_JIT_FAST) && !defined(DISABLE_JIT_FAST)
pcre_jit_stack *st = NULL;
#endif
- const gchar *mt;
+ const char *mt;
gsize remain = 0;
- gint rc, match_flags = 0, *ovec, ncaptures, i;
+ int rc, match_flags = 0, *ovec, ncaptures, i;
const int junk = 0xdeadbabe;
g_assert(re != NULL);
/* Incremental search */
mt = (*end);
- if ((gint) len > (mt - text)) {
+ if ((int) len > (mt - text)) {
remain = len - (mt - text);
}
}
}
ncaptures = (re->ncaptures + 1) * 3;
- ovec = g_alloca(sizeof(gint) * ncaptures);
+ ovec = g_alloca(sizeof(int) * ncaptures);
for (i = 0; i < ncaptures; i++) {
if (re->flags & RSPAMD_REGEXP_FLAG_FULL_MATCH) {
/* We also ensure that the match is full */
- if (ovec[0] != 0 || (guint) ovec[1] < len) {
+ if (ovec[0] != 0 || (unsigned int) ovec[1] < len) {
return FALSE;
}
}
#else
/* PCRE 2 version */
gboolean
-rspamd_regexp_search(const rspamd_regexp_t *re, const gchar *text, gsize len,
- const gchar **start, const gchar **end, gboolean raw,
+rspamd_regexp_search(const rspamd_regexp_t *re, const char *text, gsize len,
+ const char **start, const char **end, gboolean raw,
GArray *captures)
{
pcre2_match_data *match_data;
pcre2_match_context *mcontext;
PCRE_T *r;
- const gchar *mt;
+ const char *mt;
PCRE2_SIZE remain = 0, *ovec;
const PCRE2_SIZE junk = 0xdeadbabeeeeeeeeULL;
- gint rc, match_flags, novec, i;
+ int rc, match_flags, novec, i;
gboolean ret = FALSE;
g_assert(re != NULL);
/* Incremental search */
mt = (*end);
- if ((gint) len > (mt - text)) {
+ if ((int) len > (mt - text)) {
remain = len - (mt - text);
}
}
if (re->flags & RSPAMD_REGEXP_FLAG_FULL_MATCH) {
/* We also ensure that the match is full */
- if (ovec[0] != 0 || (guint) ovec[1] < len) {
+ if (ovec[0] != 0 || (unsigned int) ovec[1] < len) {
ret = FALSE;
}
}
return re->pattern;
}
-guint rspamd_regexp_set_flags(rspamd_regexp_t *re, guint new_flags)
+unsigned int rspamd_regexp_set_flags(rspamd_regexp_t *re, unsigned int new_flags)
{
- guint old_flags;
+ unsigned int old_flags;
g_assert(re != NULL);
old_flags = re->flags;
return old_flags;
}
-guint rspamd_regexp_get_flags(const rspamd_regexp_t *re)
+unsigned int rspamd_regexp_get_flags(const rspamd_regexp_t *re)
{
g_assert(re != NULL);
return re->flags;
}
-guint rspamd_regexp_get_pcre_flags(const rspamd_regexp_t *re)
+unsigned int rspamd_regexp_get_pcre_flags(const rspamd_regexp_t *re)
{
g_assert(re != NULL);
return re->pcre_flags;
}
-guint rspamd_regexp_get_maxhits(const rspamd_regexp_t *re)
+unsigned int rspamd_regexp_get_maxhits(const rspamd_regexp_t *re)
{
g_assert(re != NULL);
return re->max_hits;
}
-guint rspamd_regexp_set_maxhits(rspamd_regexp_t *re, guint new_maxhits)
+unsigned int rspamd_regexp_set_maxhits(rspamd_regexp_t *re, unsigned int new_maxhits)
{
- guint old_hits;
+ unsigned int old_hits;
g_assert(re != NULL);
old_hits = re->max_hits;
}
gboolean
-rspamd_regexp_match(const rspamd_regexp_t *re, const gchar *text, gsize len,
+rspamd_regexp_match(const rspamd_regexp_t *re, const char *text, gsize len,
gboolean raw)
{
- const gchar *start = NULL, *end = NULL;
+ const char *start = NULL, *end = NULL;
g_assert(re != NULL);
g_assert(text != NULL);
gboolean
rspamd_regexp_equal(gconstpointer a, gconstpointer b)
{
- const guchar *ia = a, *ib = b;
+ const unsigned char *ia = a, *ib = b;
return (memcmp(ia, ib, sizeof(regexp_id_t)) == 0);
}
uint32_t
rspamd_regexp_hash(gconstpointer a)
{
- const guchar *ia = a;
+ const unsigned char *ia = a;
uint32_t res;
memcpy(&res, ia, sizeof(res));
gboolean
rspamd_regexp_cmp(gconstpointer a, gconstpointer b)
{
- const guchar *ia = a, *ib = b;
+ const unsigned char *ia = a, *ib = b;
return memcmp(ia, ib, sizeof(regexp_id_t));
}
rspamd_regexp_t *
rspamd_regexp_cache_query(struct rspamd_regexp_cache *cache,
- const gchar *pattern,
- const gchar *flags)
+ const char *pattern,
+ const char *flags)
{
rspamd_regexp_t *res = NULL;
regexp_id_t id;
rspamd_regexp_t *
rspamd_regexp_cache_create(struct rspamd_regexp_cache *cache,
- const gchar *pattern,
- const gchar *flags, GError **err)
+ const char *pattern,
+ const char *flags, GError **err)
{
rspamd_regexp_t *res;
if (check_jit) {
#ifdef HAVE_PCRE_JIT
- gint jit, rc;
- gchar *str;
+ int jit, rc;
+ char *str;
#ifndef WITH_PCRE2
rc = pcre_config(PCRE_CONFIG_JIT, &jit);
}
rspamd_regexp_t *
-rspamd_regexp_from_glob(const gchar *gl, gsize sz, GError **err)
+rspamd_regexp_from_glob(const char *gl, gsize sz, GError **err)
{
GString *out;
rspamd_regexp_t *re;
- const gchar *end;
+ const char *end;
gboolean escaping = FALSE;
- gint nbraces = 0;
+ int nbraces = 0;
g_assert(gl != NULL);
* @param err error pointer set if compilation failed
* @return new regexp object
*/
-rspamd_regexp_t *rspamd_regexp_new(const gchar *pattern, const gchar *flags,
+rspamd_regexp_t *rspamd_regexp_new(const char *pattern, const char *flags,
GError **err);
/**
* @param err error pointer set if compilation failed
* @return new regexp object
*/
-rspamd_regexp_t *rspamd_regexp_new_len(const gchar *pattern, gsize len, const gchar *flags,
+rspamd_regexp_t *rspamd_regexp_new_len(const char *pattern, gsize len, const char *flags,
GError **err);
/**
* @return
*/
gboolean rspamd_regexp_search(const rspamd_regexp_t *re,
- const gchar *text, gsize len,
- const gchar **start, const gchar **end, gboolean raw,
+ const char *text, gsize len,
+ const char **start, const char **end, gboolean raw,
GArray *captures);
* @return
*/
gboolean rspamd_regexp_match(const rspamd_regexp_t *re,
- const gchar *text, gsize len, gboolean raw);
+ const char *text, gsize len, gboolean raw);
/**
* Increase refcount for a regexp object
/**
* Get PCRE flags for the regexp
*/
-guint rspamd_regexp_get_pcre_flags(const rspamd_regexp_t *re);
+unsigned int rspamd_regexp_get_pcre_flags(const rspamd_regexp_t *re);
/**
* Get rspamd flags for the regexp
*/
-guint rspamd_regexp_get_flags(const rspamd_regexp_t *re);
+unsigned int rspamd_regexp_get_flags(const rspamd_regexp_t *re);
/**
* Set rspamd flags for the regexp
*/
-guint rspamd_regexp_set_flags(rspamd_regexp_t *re, guint new_flags);
+unsigned int rspamd_regexp_set_flags(rspamd_regexp_t *re, unsigned int new_flags);
/**
* Set regexp maximum hits
*/
-guint rspamd_regexp_get_maxhits(const rspamd_regexp_t *re);
+unsigned int rspamd_regexp_get_maxhits(const rspamd_regexp_t *re);
/**
* Get regexp maximum hits
*/
-guint rspamd_regexp_set_maxhits(rspamd_regexp_t *re, guint new_maxhits);
+unsigned int rspamd_regexp_set_maxhits(rspamd_regexp_t *re, unsigned int new_maxhits);
/**
* Returns cache id for a regexp
* @return
*/
rspamd_regexp_t *rspamd_regexp_cache_query(struct rspamd_regexp_cache *cache,
- const gchar *pattern,
- const gchar *flags);
+ const char *pattern,
+ const char *flags);
/**
* Create or get cached regexp from the specified cache
* @return new regexp object
*/
rspamd_regexp_t *rspamd_regexp_cache_create(struct rspamd_regexp_cache *cache,
- const gchar *pattern,
- const gchar *flags, GError **err);
+ const char *pattern,
+ const char *flags, GError **err);
/**
* Remove regexp from the cache
/**
* Acts like memcmp but for regexp
*/
-gint rspamd_regexp_cmp(gconstpointer a, gconstpointer b);
+int rspamd_regexp_cmp(gconstpointer a, gconstpointer b);
/**
* Initialize superglobal regexp cache and library
* @param err
* @return
*/
-rspamd_regexp_t *rspamd_regexp_from_glob(const gchar *gl, gsize sz, GError **err);
+rspamd_regexp_t *rspamd_regexp_from_glob(const char *gl, gsize sz, GError **err);
#ifdef __cplusplus
}
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* Convert rrd dst type from string to numeric value
*/
enum rrd_dst_type
-rrd_dst_from_string(const gchar *str)
+rrd_dst_from_string(const char *str)
{
if (g_ascii_strcasecmp(str, "counter") == 0) {
return RRD_DST_COUNTER;
/**
* Convert numeric presentation of dst to string
*/
-const gchar *
+const char *
rrd_dst_to_string(enum rrd_dst_type type)
{
switch (type) {
* Convert rrd consolidation function type from string to numeric value
*/
enum rrd_cf_type
-rrd_cf_from_string(const gchar *str)
+rrd_cf_from_string(const char *str)
{
if (g_ascii_strcasecmp(str, "average") == 0) {
return RRD_CF_AVERAGE;
/**
* Convert numeric presentation of cf to string
*/
-const gchar *
+const char *
rrd_cf_to_string(enum rrd_cf_type type)
{
switch (type) {
return "U";
}
-void rrd_make_default_rra(const gchar *cf_name,
+void rrd_make_default_rra(const char *cf_name,
gulong pdp_cnt,
gulong rows,
struct rrd_rra_def *rra)
rra->par[RRA_cdp_xff_val].dv = 0.5;
}
-void rrd_make_default_ds(const gchar *name,
- const gchar *type,
+void rrd_make_default_ds(const char *name,
+ const char *type,
gulong pdp_step,
struct rrd_ds_def *ds)
{
* Check rrd file for correctness (size, cookies, etc)
*/
static gboolean
-rspamd_rrd_check_file(const gchar *filename, gboolean need_data, GError **err)
+rspamd_rrd_check_file(const char *filename, gboolean need_data, GError **err)
{
- gint fd, i;
+ int fd, i;
struct stat st;
struct rrd_file_head head;
struct rrd_rra_def rra;
- gint head_size;
+ int head_size;
fd = open(filename, O_RDWR);
if (fd == -1) {
if (st.st_size < (goffset) sizeof(struct rrd_file_head)) {
/* We have trimmed file */
g_set_error(err, rrd_error_quark(), EINVAL, "rrd size is bad: %ud",
- (guint) st.st_size);
+ (unsigned int) st.st_size);
close(fd);
return FALSE;
}
close(fd);
return FALSE;
}
- for (i = 0; i < (gint) head.rra_cnt; i++) {
+ for (i = 0; i < (int) head.rra_cnt; i++) {
if (read(fd, &rra, sizeof(rra)) != sizeof(rra)) {
g_set_error(err,
rrd_error_quark(), errno, "rrd read rra error: %s",
close(fd);
return FALSE;
}
- head_size += rra.row_cnt * head.ds_cnt * sizeof(gdouble);
+ head_size += rra.row_cnt * head.ds_cnt * sizeof(double);
}
if (st.st_size != head_size) {
g_set_error(err,
rrd_error_quark(), EINVAL, "rrd file seems to have incorrect size: %d, must be %d",
- (gint) st.st_size, head_size);
+ (int) st.st_size, head_size);
close(fd);
return FALSE;
}
static void
rspamd_rrd_adjust_pointers(struct rspamd_rrd_file *file, gboolean completed)
{
- guint8 *ptr;
+ uint8_t *ptr;
ptr = file->map;
file->stat_head = (struct rrd_file_head *) ptr;
file->rra_ptr = (struct rrd_rra_ptr *) ptr;
if (completed) {
ptr += sizeof(struct rrd_rra_ptr) * file->stat_head->rra_cnt;
- file->rrd_value = (gdouble *) ptr;
+ file->rrd_value = (double *) ptr;
}
else {
file->rrd_value = NULL;
static void
rspamd_rrd_calculate_checksum(struct rspamd_rrd_file *file)
{
- guchar sigbuf[rspamd_cryptobox_HASHBYTES];
+ unsigned char sigbuf[rspamd_cryptobox_HASHBYTES];
struct rrd_ds_def *ds;
- guint i;
+ unsigned int i;
rspamd_cryptobox_hash_state_t st;
if (file->finalized) {
}
static int
-rspamd_rrd_open_exclusive(const gchar *filename)
+rspamd_rrd_open_exclusive(const char *filename)
{
struct timespec sleep_ts = {
.tv_sec = 0,
.tv_nsec = 1000000};
- gint fd;
+ int fd;
fd = open(filename, O_RDWR);
* @return
*/
static struct rspamd_rrd_file *
-rspamd_rrd_open_common(const gchar *filename, gboolean completed, GError **err)
+rspamd_rrd_open_common(const char *filename, gboolean completed, GError **err)
{
struct rspamd_rrd_file *file;
- gint fd;
+ int fd;
struct stat st;
if (!rspamd_rrd_check_file(filename, completed, err)) {
* @return rrd file structure
*/
struct rspamd_rrd_file *
-rspamd_rrd_open(const gchar *filename, GError **err)
+rspamd_rrd_open(const char *filename, GError **err)
{
struct rspamd_rrd_file *file;
* @return TRUE if file has been created
*/
struct rspamd_rrd_file *
-rspamd_rrd_create(const gchar *filename,
+rspamd_rrd_create(const char *filename,
gulong ds_count,
gulong rra_count,
gulong pdp_step,
- gdouble initial_ticks,
+ double initial_ticks,
GError **err)
{
struct rspamd_rrd_file *new;
struct rrd_pdp_prep pdp;
struct rrd_cdp_prep cdp;
struct rrd_rra_ptr rra_ptr;
- gint fd;
- guint i, j;
+ int fd;
+ unsigned int i, j;
/* Open file */
fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0644);
gboolean
rspamd_rrd_finalize(struct rspamd_rrd_file *file, GError **err)
{
- gint fd;
- guint i;
- gint count = 0;
- gdouble vbuf[1024];
+ int fd;
+ unsigned int i;
+ int count = 0;
+ double vbuf[1024];
struct stat st;
if (file == NULL || file->filename == NULL || file->fd == -1) {
while (count > 0) {
/* Write values in buffered matter */
if (write(fd, vbuf,
- MIN((gint) G_N_ELEMENTS(vbuf), count) * sizeof(gdouble)) == -1) {
+ MIN((int) G_N_ELEMENTS(vbuf), count) * sizeof(double)) == -1) {
g_set_error(err,
rrd_error_quark(), errno, "rrd write error: %s",
strerror(errno));
*/
static gboolean
rspamd_rrd_update_pdp_prep(struct rspamd_rrd_file *file,
- gdouble *vals,
- gdouble *pdp_new,
- gdouble interval)
+ double *vals,
+ double *pdp_new,
+ double interval)
{
- guint i;
+ unsigned int i;
enum rrd_dst_type type;
for (i = 0; i < file->stat_head->ds_cnt; i++) {
*/
static void
rspamd_rrd_update_pdp_step(struct rspamd_rrd_file *file,
- gdouble *pdp_new,
- gdouble *pdp_temp,
- gdouble interval,
+ double *pdp_new,
+ double *pdp_temp,
+ double interval,
gulong pdp_diff)
{
- guint i;
+ unsigned int i;
rrd_value_t *scratch;
gulong heartbeat;
*/
static void
rspamd_rrd_update_cdp(struct rspamd_rrd_file *file,
- gdouble pdp_steps,
- gdouble pdp_offset,
+ double pdp_steps,
+ double pdp_offset,
gulong *rra_steps,
gulong rra_index,
- gdouble *pdp_temp)
+ double *pdp_temp)
{
- guint i;
+ unsigned int i;
struct rrd_rra_def *rra;
rrd_value_t *scratch;
enum rrd_cf_type cf;
- gdouble last_cdp = INFINITY, cur_cdp = INFINITY;
+ double last_cdp = INFINITY, cur_cdp = INFINITY;
gulong pdp_in_cdp;
rra = &file->rra_def[rra_index];
*/
void rspamd_rrd_write_rra(struct rspamd_rrd_file *file, gulong *rra_steps)
{
- guint i, j, ds_cnt;
+ unsigned int i, j, ds_cnt;
struct rrd_rra_def *rra;
struct rrd_cdp_prep *cdp;
- gdouble *rra_row = file->rrd_value, *cur_row;
+ double *rra_row = file->rrd_value, *cur_row;
ds_cnt = file->stat_head->ds_cnt;
gboolean
rspamd_rrd_add_record(struct rspamd_rrd_file *file,
GArray *points,
- gdouble ticks,
+ double ticks,
GError **err)
{
- gdouble interval, *pdp_new, *pdp_temp;
- guint i;
+ double interval, *pdp_new, *pdp_temp;
+ unsigned int i;
glong seconds, microseconds;
gulong pdp_steps, cur_pdp_count, prev_pdp_step, cur_pdp_step,
prev_pdp_age, cur_pdp_age, *rra_steps, pdp_offset;
- if (file == NULL || file->stat_head->ds_cnt * sizeof(gdouble) !=
+ if (file == NULL || file->stat_head->ds_cnt * sizeof(double) !=
points->len) {
g_set_error(err,
rrd_error_quark(), EINVAL,
/* Get interval */
seconds = (glong) ticks;
microseconds = (glong) ((ticks - seconds) * 1000000.);
- interval = ticks - ((gdouble) file->live_head->last_up +
+ interval = ticks - ((double) file->live_head->last_up +
file->live_head->last_up_usec / 1000000.);
msg_debug_rrd("update rrd record after %.3f seconds", interval);
/* Update PDP preparation values */
- pdp_new = g_malloc0(sizeof(gdouble) * file->stat_head->ds_cnt);
- pdp_temp = g_malloc0(sizeof(gdouble) * file->stat_head->ds_cnt);
+ pdp_new = g_malloc0(sizeof(double) * file->stat_head->ds_cnt);
+ pdp_temp = g_malloc0(sizeof(double) * file->stat_head->ds_cnt);
/* How much steps need to be updated in each RRA */
rra_steps = g_malloc0(sizeof(gulong) * file->stat_head->rra_cnt);
- if (!rspamd_rrd_update_pdp_prep(file, (gdouble *) points->data, pdp_new,
+ if (!rspamd_rrd_update_pdp_prep(file, (double *) points->data, pdp_new,
interval)) {
g_set_error(err,
rrd_error_quark(), EINVAL,
* @param file
* @return
*/
-gint rspamd_rrd_close(struct rspamd_rrd_file *file)
+int rspamd_rrd_close(struct rspamd_rrd_file *file)
{
if (file == NULL) {
errno = EINVAL;
}
static struct rspamd_rrd_file *
-rspamd_rrd_create_file(const gchar *path, gboolean finalize, GError **err)
+rspamd_rrd_create_file(const char *path, gboolean finalize, GError **err)
{
struct rspamd_rrd_file *file;
struct rrd_ds_def ds[RSPAMD_RRD_DS_COUNT];
struct rrd_rra_def rra[RSPAMD_RRD_RRA_COUNT];
- gint i;
+ int i;
GArray ar;
/* Try to create new rrd file */
rrd_dst_to_string(RRD_DST_COUNTER), 1, &ds[i]);
}
- ar.data = (gchar *) ds;
+ ar.data = (char *) ds;
ar.len = sizeof(ds);
if (!rspamd_rrd_add_ds(file, &ar, err)) {
/* Once per hour for 1 year */
rrd_make_default_rra(rrd_cf_to_string(RRD_CF_AVERAGE),
60 * 60, 365 * 24, &rra[3]);
- ar.data = (gchar *) rra;
+ ar.data = (char *) rra;
ar.len = sizeof(rra);
if (!rspamd_rrd_add_rra(file, &ar, err)) {
static void
rspamd_rrd_convert_ds(struct rspamd_rrd_file *old,
- struct rspamd_rrd_file *cur, gint idx_old, gint idx_new)
+ struct rspamd_rrd_file *cur, int idx_old, int idx_new)
{
struct rrd_pdp_prep *pdp_prep_old, *pdp_prep_new;
struct rrd_cdp_prep *cdp_prep_old, *cdp_prep_new;
- gdouble *val_old, *val_new;
+ double *val_old, *val_new;
gulong rra_cnt, i, j, points_cnt, old_ds, new_ds;
rra_cnt = old->stat_head->rra_cnt;
}
static struct rspamd_rrd_file *
-rspamd_rrd_convert(const gchar *path, struct rspamd_rrd_file *old,
+rspamd_rrd_convert(const char *path, struct rspamd_rrd_file *old,
GError **err)
{
struct rspamd_rrd_file *rrd;
- gchar tpath[PATH_MAX];
+ char tpath[PATH_MAX];
g_assert(old != NULL);
}
struct rspamd_rrd_file *
-rspamd_rrd_file_default(const gchar *path,
+rspamd_rrd_file_default(const char *path,
GError **err)
{
struct rspamd_rrd_file *file, *nf;
{
struct rspamd_rrd_query_result *res;
struct rrd_rra_def *rra;
- const gdouble *rra_offset = NULL;
- guint i;
+ const double *rra_offset = NULL;
+ unsigned int i;
g_assert(file != NULL);
res = g_malloc0(sizeof(*res));
res->ds_count = file->stat_head->ds_cnt;
- res->last_update = (gdouble) file->live_head->last_up +
- ((gdouble) file->live_head->last_up_usec / 1e6f);
+ res->last_update = (double) file->live_head->last_up +
+ ((double) file->live_head->last_up_usec / 1e6f);
res->pdp_per_cdp = file->rra_def[rra_num].pdp_cnt;
res->rra_rows = file->rra_def[rra_num].row_cnt;
rra_offset = file->rrd_value;
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
struct rrd_file_head {
/* Data Base Identification Section ** */
- gchar cookie[4]; /* RRD */
- gchar version[5]; /* version of the format */
- gdouble float_cookie; /* is it the correct double representation ? */
+ char cookie[4]; /* RRD */
+ char version[5]; /* version of the format */
+ double float_cookie; /* is it the correct double representation ? */
/* Data Base Structure Definition **** */
gulong ds_cnt; /* how many different ds provide input to the rrd */
#define RRD_DST_SIZE 20
struct rrd_ds_def {
- gchar ds_nam[RRD_DS_NAM_SIZE]; /* Name of the data source (null terminated) */
- gchar dst[RRD_DST_SIZE]; /* Type of data source (null terminated) */
- rrd_value_t par[10]; /* index of this array see ds_param_en */
+ char ds_nam[RRD_DS_NAM_SIZE]; /* Name of the data source (null terminated) */
+ char dst[RRD_DST_SIZE]; /* Type of data source (null terminated) */
+ rrd_value_t par[10]; /* index of this array see ds_param_en */
};
/* RRA definition */
#define RRD_CF_NAM_SIZE 20
struct rrd_rra_def {
- gchar cf_nam[RRD_CF_NAM_SIZE]; /* consolidation function (null term) */
+ char cf_nam[RRD_CF_NAM_SIZE]; /* consolidation function (null term) */
gulong row_cnt; /* number of entries in the store */
gulong pdp_cnt; /* how many primary data points are
* required for a consolidated data point?*/
this depends on dst */
struct rrd_pdp_prep {
- gchar last_ds[RRD_LAST_DS_LEN]; /* the last reading from the data
+ char last_ds[RRD_LAST_DS_LEN]; /* the last reading from the data
* source. this is stored in ASCII
* to cater for very large counters
* we might encounter in connection
* with SNMP. */
- rrd_value_t scratch[10]; /* contents according to pdp_par_en */
+ rrd_value_t scratch[10]; /* contents according to pdp_par_en */
};
#define RRD_MAX_CDP_PAR_EN 10
struct rrd_pdp_prep *pdp_prep; /* pdp data prep area */
struct rrd_cdp_prep *cdp_prep; /* cdp prep area */
struct rrd_rra_ptr *rra_ptr; /* list of rra pointers */
- gdouble *rrd_value; /* list of rrd values */
+ double *rrd_value; /* list of rrd values */
- gchar *filename;
- guint8 *map; /* mmapped area */
- gsize size; /* its size */
+ char *filename;
+ uint8_t *map; /* mmapped area */
+ gsize size; /* its size */
gboolean finalized;
- gchar *id;
- gint fd;
+ char *id;
+ int fd;
};
* @param err error pointer
* @return rrd file structure
*/
-struct rspamd_rrd_file *rspamd_rrd_open(const gchar *filename, GError **err);
+struct rspamd_rrd_file *rspamd_rrd_open(const char *filename, GError **err);
/**
* Create basic header for rrd file
* @param err error pointer
* @return TRUE if file has been created
*/
-struct rspamd_rrd_file *rspamd_rrd_create(const gchar *filename,
+struct rspamd_rrd_file *rspamd_rrd_create(const char *filename,
gulong ds_count,
gulong rra_count,
gulong pdp_step,
- gdouble initial_ticks,
+ double initial_ticks,
GError **err);
/**
*/
gboolean rspamd_rrd_add_record(struct rspamd_rrd_file *file,
GArray *points,
- gdouble ticks,
+ double ticks,
GError **err);
/**
* @param file
* @return
*/
-gint rspamd_rrd_close(struct rspamd_rrd_file *file);
+int rspamd_rrd_close(struct rspamd_rrd_file *file);
/*
* Conversion functions
/**
* Convert rrd dst type from string to numeric value
*/
-enum rrd_dst_type rrd_dst_from_string(const gchar *str);
+enum rrd_dst_type rrd_dst_from_string(const char *str);
/**
* Convert numeric presentation of dst to string
*/
-const gchar *rrd_dst_to_string(enum rrd_dst_type type);
+const char *rrd_dst_to_string(enum rrd_dst_type type);
/**
* Convert rrd consolidation function type from string to numeric value
*/
-enum rrd_cf_type rrd_cf_from_string(const gchar *str);
+enum rrd_cf_type rrd_cf_from_string(const char *str);
/**
* Convert numeric presentation of cf to string
*/
-const gchar *rrd_cf_to_string(enum rrd_cf_type type);
+const char *rrd_cf_to_string(enum rrd_cf_type type);
/* Default RRA and DS */
/**
* Create default RRA
*/
-void rrd_make_default_rra(const gchar *cf_name,
+void rrd_make_default_rra(const char *cf_name,
gulong pdp_cnt,
gulong rows,
struct rrd_rra_def *rra);
/**
* Create default DS
*/
-void rrd_make_default_ds(const gchar *name,
- const gchar *type,
+void rrd_make_default_ds(const char *name,
+ const char *type,
gulong pdp_step,
struct rrd_ds_def *ds);
/**
* Open or create the default rspamd rrd file
*/
-struct rspamd_rrd_file *rspamd_rrd_file_default(const gchar *path,
+struct rspamd_rrd_file *rspamd_rrd_file_default(const char *path,
GError **err);
/**
gulong rra_rows;
gulong pdp_per_cdp;
gulong ds_count;
- gdouble last_update;
+ double last_update;
gulong cur_row;
- const gdouble *data;
+ const double *data;
};
/**
#define SHINGLES_WINDOW 3
#define SHINGLES_KEY_SIZE rspamd_cryptobox_SIPKEYBYTES
-static guint
+static unsigned int
rspamd_shingles_keys_hash(gconstpointer k)
{
return rspamd_cryptobox_fast_hash(k, SHINGLES_KEY_SIZE,
static void
rspamd_shingles_keys_free(gpointer p)
{
- guchar **k = p;
- guint i;
+ unsigned char **k = p;
+ unsigned int i;
for (i = 0; i < RSPAMD_SHINGLE_SIZE; i++) {
g_free(k[i]);
g_free(k);
}
-static guchar **
+static unsigned char **
rspamd_shingles_keys_new(void)
{
- guchar **k;
- guint i;
+ unsigned char **k;
+ unsigned int i;
- k = g_malloc0(sizeof(guchar *) * RSPAMD_SHINGLE_SIZE);
+ k = g_malloc0(sizeof(unsigned char *) * RSPAMD_SHINGLE_SIZE);
for (i = 0; i < RSPAMD_SHINGLE_SIZE; i++) {
- k[i] = g_malloc0(sizeof(guchar) * SHINGLES_KEY_SIZE);
+ k[i] = g_malloc0(sizeof(unsigned char) * SHINGLES_KEY_SIZE);
}
return k;
}
-static guchar **
-rspamd_shingles_get_keys_cached(const guchar key[SHINGLES_KEY_SIZE])
+static unsigned char **
+rspamd_shingles_get_keys_cached(const unsigned char key[SHINGLES_KEY_SIZE])
{
static GHashTable *ht = NULL;
- guchar **keys = NULL, *key_cpy;
+ unsigned char **keys = NULL, *key_cpy;
rspamd_cryptobox_hash_state_t bs;
- const guchar *cur_key;
- guchar shabuf[rspamd_cryptobox_HASHBYTES], *out_key;
- guint i;
+ const unsigned char *cur_key;
+ unsigned char shabuf[rspamd_cryptobox_HASHBYTES], *out_key;
+ unsigned int i;
if (ht == NULL) {
ht = g_hash_table_new_full(rspamd_shingles_keys_hash,
struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops")
rspamd_shingles_from_text(GArray *input,
- const guchar key[16],
+ const unsigned char key[16],
rspamd_mempool_t *pool,
rspamd_shingles_filter filter,
gpointer filterd,
{
struct rspamd_shingle *res;
uint64_t **hashes;
- guchar **keys;
+ unsigned char **keys;
rspamd_fstring_t *row;
rspamd_stat_token_t *word;
uint64_t val;
- gint i, j, k;
+ int i, j, k;
gsize hlen, ilen = 0, beg = 0, widx = 0;
enum rspamd_cryptobox_fast_hash_type ht;
/* Now parse input words into a vector of hashes using rolling window */
if (alg == RSPAMD_SHINGLES_OLD) {
- for (i = 0; i <= (gint) ilen; i++) {
- if (i - beg >= SHINGLES_WINDOW || i == (gint) ilen) {
+ for (i = 0; i <= (int) ilen; i++) {
+ if (i - beg >= SHINGLES_WINDOW || i == (int) ilen) {
for (j = beg; j < i; j++) {
word = NULL;
/* Now we need to create a new row here */
for (j = 0; j < RSPAMD_SHINGLE_SIZE; j++) {
- rspamd_cryptobox_siphash((guchar *) &val, row->str, row->len,
+ rspamd_cryptobox_siphash((unsigned char *) &val, row->str, row->len,
keys[j]);
g_assert(hlen > beg);
hashes[j][beg] = val;
}
struct rspamd_shingle *RSPAMD_OPTIMIZE("unroll-loops")
- rspamd_shingles_from_image(guchar *dct,
- const guchar key[16],
+ rspamd_shingles_from_image(unsigned char *dct,
+ const unsigned char key[16],
rspamd_mempool_t *pool,
rspamd_shingles_filter filter,
gpointer filterd,
{
struct rspamd_shingle *shingle;
uint64_t **hashes;
- guchar **keys;
+ unsigned char **keys;
uint64_t d;
uint64_t val;
- gint i, j;
+ int i, j;
gsize hlen, beg = 0;
enum rspamd_cryptobox_fast_hash_type ht;
uint64_t res[SHINGLES_WINDOW * RSPAMD_SHINGLE_SIZE], seed;
uint64_t
rspamd_shingles_default_filter(uint64_t *input, gsize count,
- gint shno, const guchar *key, gpointer ud)
+ int shno, const unsigned char *key, gpointer ud)
{
uint64_t minimal = G_MAXUINT64;
gsize i;
}
-gdouble rspamd_shingles_compare(const struct rspamd_shingle *a,
- const struct rspamd_shingle *b)
+double rspamd_shingles_compare(const struct rspamd_shingle *a,
+ const struct rspamd_shingle *b)
{
- gint i, common = 0;
+ int i, common = 0;
for (i = 0; i < RSPAMD_SHINGLE_SIZE; i++) {
if (a->hashes[i] == b->hashes[i]) {
}
}
- return (gdouble) common / (gdouble) RSPAMD_SHINGLE_SIZE;
+ return (double) common / (double) RSPAMD_SHINGLE_SIZE;
}
* @return shingle value
*/
typedef uint64_t (*rspamd_shingles_filter)(uint64_t *input, gsize count,
- gint shno, const guchar *key, gpointer ud);
+ int shno, const unsigned char *key, gpointer ud);
/**
* Generate shingles from the input of fixed size strings using lemmatizer
* @return shingles array
*/
struct rspamd_shingle *rspamd_shingles_from_text(GArray *input,
- const guchar key[16],
+ const unsigned char key[16],
rspamd_mempool_t *pool,
rspamd_shingles_filter filter,
gpointer filterd,
* @param filterd opaque data for filtering function
* @return shingles array
*/
-struct rspamd_shingle *rspamd_shingles_from_image(guchar *dct,
- const guchar key[16],
+struct rspamd_shingle *rspamd_shingles_from_image(unsigned char *dct,
+ const unsigned char key[16],
rspamd_mempool_t *pool,
rspamd_shingles_filter filter,
gpointer filterd,
* @param b
* @return
*/
-gdouble rspamd_shingles_compare(const struct rspamd_shingle *a,
- const struct rspamd_shingle *b);
+double rspamd_shingles_compare(const struct rspamd_shingle *a,
+ const struct rspamd_shingle *b);
/**
* Default filtering function
*/
uint64_t rspamd_shingles_default_filter(uint64_t *input, gsize count,
- gint shno, const guchar *key, gpointer ud);
+ int shno, const unsigned char *key, gpointer ud);
#ifdef __cplusplus
}
GArray *
rspamd_sqlite3_init_prstmt(sqlite3 *db,
struct rspamd_sqlite3_prstmt *init_stmt,
- gint max_idx,
+ int max_idx,
GError **err)
{
- gint i;
+ int i;
GArray *res;
struct rspamd_sqlite3_prstmt *nst;
}
int rspamd_sqlite3_run_prstmt(rspamd_mempool_t *pool, sqlite3 *db, GArray *stmts,
- gint idx, ...)
+ int idx, ...)
{
- gint retcode;
+ int retcode;
va_list ap;
sqlite3_stmt *stmt;
- gint i, rowid, nargs, j;
+ int i, rowid, nargs, j;
int64_t len;
gpointer p;
struct rspamd_sqlite3_prstmt *nst;
const char *argtypes;
- if (idx < 0 || idx >= (gint) stmts->len) {
+ if (idx < 0 || idx >= (int) stmts->len) {
return -1;
}
case 'S':
for (j = 0; j < nargs; j++, rowid++) {
- sqlite3_bind_int(stmt, rowid, va_arg(ap, gint));
+ sqlite3_bind_int(stmt, rowid, va_arg(ap, int));
}
nargs = 1;
break;
case '*':
- nargs = va_arg(ap, gint);
+ nargs = va_arg(ap, int);
break;
}
}
void rspamd_sqlite3_close_prstmt(sqlite3 *db, GArray *stmts)
{
- guint i;
+ unsigned int i;
struct rspamd_sqlite3_prstmt *nst;
for (i = 0; i < stmts->len; i++) {
}
static gboolean
-rspamd_sqlite3_wait(rspamd_mempool_t *pool, const gchar *lock)
+rspamd_sqlite3_wait(rspamd_mempool_t *pool, const char *lock)
{
- gint fd;
+ int fd;
pid_t pid;
gssize r;
struct timespec sleep_ts = {
#define RSPAMD_SQLITE_CACHE_SIZE 262144
sqlite3 *
-rspamd_sqlite3_open_or_create(rspamd_mempool_t *pool, const gchar *path, const gchar *create_sql, guint version, GError **err)
+rspamd_sqlite3_open_or_create(rspamd_mempool_t *pool, const char *path, const char *create_sql, unsigned int version, GError **err)
{
sqlite3 *sqlite;
- gint rc, flags, lock_fd;
- gchar lock_path[PATH_MAX], dbdir[PATH_MAX], *pdir;
+ int rc, flags, lock_fd;
+ char lock_path[PATH_MAX], dbdir[PATH_MAX], *pdir;
static const char sqlite_wal[] =
"PRAGMA journal_mode=\"wal\";"
"PRAGMA wal_autocheckpoint = 16;"
}
gboolean
-rspamd_sqlite3_sync(sqlite3 *db, gint *wal_frames, gint *wal_checkpoints)
+rspamd_sqlite3_sync(sqlite3 *db, int *wal_frames, int *wal_checkpoints)
{
- gint wf = 0, wc = 0, mode;
+ int wf = 0, wc = 0, mode;
#ifdef SQLITE_OPEN_WAL
#ifdef SQLITE_CHECKPOINT_TRUNCATE
#endif
struct rspamd_sqlite3_prstmt {
- gint idx;
- const gchar *sql;
- const gchar *args;
+ int idx;
+ const char *sql;
+ const char *args;
sqlite3_stmt *stmt;
- gint result;
- const gchar *ret;
- gint flags;
+ int result;
+ const char *ret;
+ int flags;
};
/**
*/
GArray *rspamd_sqlite3_init_prstmt(sqlite3 *db,
struct rspamd_sqlite3_prstmt *init_stmt,
- gint max_idx,
+ int max_idx,
GError **err);
/**
* @param idx
* @return
*/
-gint rspamd_sqlite3_run_prstmt(rspamd_mempool_t *pool, sqlite3 *db, GArray *stmts,
- gint idx, ...);
+int rspamd_sqlite3_run_prstmt(rspamd_mempool_t *pool, sqlite3 *db, GArray *stmts,
+ int idx, ...);
/**
* Close and free prepared statements
* @return
*/
sqlite3 *rspamd_sqlite3_open_or_create(rspamd_mempool_t *pool,
- const gchar *path, const gchar *create_sql,
+ const char *path, const char *create_sql,
uint32_t version, GError **err);
* Sync sqlite3 db ensuring that all wal things are done
* @param db
*/
-gboolean rspamd_sqlite3_sync(sqlite3 *db, gint *wal_frames, gint *wal_checkpoints);
+gboolean rspamd_sqlite3_sync(sqlite3 *db, int *wal_frames, int *wal_checkpoints);
#ifdef __cplusplus
}
#include "contrib/fastutf8/fastutf8.h"
-const guchar lc_map[256] = {
+const unsigned char lc_map[256] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff};
-guint rspamd_str_lc(gchar *str, guint size)
+unsigned int rspamd_str_lc(char *str, unsigned int size)
{
- guint leftover = size % 4;
- guint fp, i;
+ unsigned int leftover = size % 4;
+ unsigned int fp, i;
const uint8_t *s = (const uint8_t *) str;
- gchar *dest = str;
- guchar c1, c2, c3, c4;
+ char *dest = str;
+ unsigned char c1, c2, c3, c4;
fp = size - leftover;
switch (leftover) {
case 3:
- *dest++ = lc_map[(guchar) str[i++]];
+ *dest++ = lc_map[(unsigned char) str[i++]];
/* FALLTHRU */
case 2:
- *dest++ = lc_map[(guchar) str[i++]];
+ *dest++ = lc_map[(unsigned char) str[i++]];
/* FALLTHRU */
case 1:
- *dest = lc_map[(guchar) str[i]];
+ *dest = lc_map[(unsigned char) str[i]];
}
return size;
}
-gsize rspamd_str_copy_lc(const gchar *src, gchar *dst, gsize size)
+gsize rspamd_str_copy_lc(const char *src, char *dst, gsize size)
{
- gchar *d = dst;
+ char *d = dst;
/* Find aligned start */
while ((0xf & (uintptr_t) src) && size > 0) {
- *d++ = lc_map[(guchar) *src++];
+ *d++ = lc_map[(unsigned char) *src++];
size--;
}
/* Leftover */
while (size > 0) {
- *d++ = lc_map[(guchar) *src++];
+ *d++ = lc_map[(unsigned char) *src++];
size--;
}
return (d - dst);
}
-gint rspamd_lc_cmp(const gchar *s, const gchar *d, gsize l)
+int rspamd_lc_cmp(const char *s, const char *d, gsize l)
{
gsize fp, i;
- guchar c1, c2, c3, c4;
+ unsigned char c1, c2, c3, c4;
union {
- guchar c[4];
+ unsigned char c[4];
uint32_t n;
} cmp1, cmp2;
gsize leftover = l % 4;
- gint ret = 0;
+ int ret = 0;
fp = l - leftover;
* string to lower case, so some locale peculiarities are simply ignored
* If the target string is longer than initial one, then we just trim it
*/
-guint rspamd_str_lc_utf8(gchar *str, guint size)
+unsigned int rspamd_str_lc_utf8(char *str, unsigned int size)
{
- guchar *d = (guchar *) str, tst[6];
+ unsigned char *d = (unsigned char *) str, tst[6];
int32_t i = 0, prev = 0;
UChar32 uc;
while (i < size) {
prev = i;
- U8_NEXT((guint8 *) str, i, size, uc);
+ U8_NEXT((uint8_t *) str, i, size, uc);
uc = u_tolower(uc);
int32_t olen = 0;
}
}
- return d - (guchar *) str;
+ return d - (unsigned char *) str;
}
gboolean
rspamd_strcase_equal(gconstpointer v, gconstpointer v2)
{
- if (g_ascii_strcasecmp((const gchar *) v, (const gchar *) v2) == 0) {
+ if (g_ascii_strcasecmp((const char *) v, (const char *) v2) == 0) {
return TRUE;
}
}
uint64_t
-rspamd_icase_hash(const gchar *in, gsize len, uint64_t seed)
+rspamd_icase_hash(const char *in, gsize len, uint64_t seed)
{
- guint leftover = len % sizeof(uint64_t);
- guint fp, i;
+ unsigned int leftover = len % sizeof(uint64_t);
+ unsigned int fp, i;
const uint8_t *s = (const uint8_t *) in;
union {
struct {
- guchar c1, c2, c3, c4, c5, c6, c7, c8;
+ unsigned char c1, c2, c3, c4, c5, c6, c7, c8;
} c;
uint64_t pp;
} u;
switch (leftover) {
case 7:
- u.c.c7 = lc_map[(guchar) s[i++]]; /* FALLTHRU */
+ u.c.c7 = lc_map[(unsigned char) s[i++]]; /* FALLTHRU */
case 6:
- u.c.c6 = lc_map[(guchar) s[i++]]; /* FALLTHRU */
+ u.c.c6 = lc_map[(unsigned char) s[i++]]; /* FALLTHRU */
case 5:
- u.c.c5 = lc_map[(guchar) s[i++]]; /* FALLTHRU */
+ u.c.c5 = lc_map[(unsigned char) s[i++]]; /* FALLTHRU */
case 4:
- u.c.c4 = lc_map[(guchar) s[i++]]; /* FALLTHRU */
+ u.c.c4 = lc_map[(unsigned char) s[i++]]; /* FALLTHRU */
case 3:
- u.c.c3 = lc_map[(guchar) s[i++]]; /* FALLTHRU */
+ u.c.c3 = lc_map[(unsigned char) s[i++]]; /* FALLTHRU */
case 2:
- u.c.c2 = lc_map[(guchar) s[i++]]; /* FALLTHRU */
+ u.c.c2 = lc_map[(unsigned char) s[i++]]; /* FALLTHRU */
case 1:
- u.c.c1 = lc_map[(guchar) s[i]];
+ u.c.c1 = lc_map[(unsigned char) s[i]];
break;
}
return h;
}
-guint rspamd_strcase_hash(gconstpointer key)
+unsigned int rspamd_strcase_hash(gconstpointer key)
{
- const gchar *p = key;
+ const char *p = key;
gsize len;
len = strlen(p);
- return (guint) rspamd_icase_hash(p, len, rspamd_hash_seed());
+ return (unsigned int) rspamd_icase_hash(p, len, rspamd_hash_seed());
}
-guint rspamd_str_hash(gconstpointer key)
+unsigned int rspamd_str_hash(gconstpointer key)
{
gsize len;
- len = strlen((const gchar *) key);
+ len = strlen((const char *) key);
- return (guint) rspamd_cryptobox_fast_hash(key, len, rspamd_hash_seed());
+ return (unsigned int) rspamd_cryptobox_fast_hash(key, len, rspamd_hash_seed());
}
gboolean
rspamd_str_equal(gconstpointer v, gconstpointer v2)
{
- return strcmp((const gchar *) v, (const gchar *) v2) == 0;
+ return strcmp((const char *) v, (const char *) v2) == 0;
}
gboolean
}
-guint rspamd_ftok_icase_hash(gconstpointer key)
+unsigned int rspamd_ftok_icase_hash(gconstpointer key)
{
const rspamd_ftok_t *f = key;
- return (guint) rspamd_icase_hash(f->begin, f->len, rspamd_hash_seed());
+ return (unsigned int) rspamd_icase_hash(f->begin, f->len, rspamd_hash_seed());
}
gboolean
return FALSE;
}
-guint rspamd_gstring_icase_hash(gconstpointer key)
+unsigned int rspamd_gstring_icase_hash(gconstpointer key)
{
const GString *f = key;
- return (guint) rspamd_icase_hash(f->str, f->len, rspamd_hash_seed());
+ return (unsigned int) rspamd_icase_hash(f->str, f->len, rspamd_hash_seed());
}
/* https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord */
#define HASZERO(x) ~(((((x) &ZEROMASK) + ZEROMASK) | (x)) | ZEROMASK)
-gsize rspamd_strlcpy_fast(gchar *dst, const gchar *src, gsize siz)
+gsize rspamd_strlcpy_fast(char *dst, const char *src, gsize siz)
{
- gchar *d = dst;
- const gchar *s = src;
+ char *d = dst;
+ const char *s = src;
gsize n = siz;
WORD_TYPE *wd;
const WORD_TYPE *ws;
return (d - dst);
}
-gsize rspamd_null_safe_copy(const gchar *src, gsize srclen,
- gchar *dest, gsize destlen)
+gsize rspamd_null_safe_copy(const char *src, gsize srclen,
+ char *dest, gsize destlen)
{
gsize copied = 0, si = 0, di = 0;
size_t
-rspamd_strlcpy_safe(gchar *dst, const gchar *src, gsize siz)
+rspamd_strlcpy_safe(char *dst, const char *src, gsize siz)
{
- gchar *d = dst;
+ char *d = dst;
gsize nleft = siz;
if (nleft != 0) {
* Try to convert string of length to long
*/
gboolean
-rspamd_strtol(const gchar *s, gsize len, glong *value)
+rspamd_strtol(const char *s, gsize len, glong *value)
{
- const gchar *p = s, *end = s + len;
- gchar c;
+ const char *p = s, *end = s + len;
+ char c;
glong v = 0;
const glong cutoff = G_MAXLONG / 10, cutlim = G_MAXLONG % 10;
gboolean neg;
/*
* Try to convert string of length to long
*/
-#define CONV_STR_LIM_DECIMAL(max_num) \
- do { \
- while (p < end) { \
- c = *p; \
- if (c >= '0' && c <= '9') { \
- c -= '0'; \
- if (v > cutoff || (v == cutoff && (guint8) c > cutlim)) { \
- *value = (max_num); \
- return FALSE; \
- } \
- else { \
- v *= 10; \
- v += c; \
- } \
- } \
- else { \
- *value = v; \
- return FALSE; \
- } \
- p++; \
- } \
+#define CONV_STR_LIM_DECIMAL(max_num) \
+ do { \
+ while (p < end) { \
+ c = *p; \
+ if (c >= '0' && c <= '9') { \
+ c -= '0'; \
+ if (v > cutoff || (v == cutoff && (uint8_t) c > cutlim)) { \
+ *value = (max_num); \
+ return FALSE; \
+ } \
+ else { \
+ v *= 10; \
+ v += c; \
+ } \
+ } \
+ else { \
+ *value = v; \
+ return FALSE; \
+ } \
+ p++; \
+ } \
} while (0)
gboolean
-rspamd_strtoul(const gchar *s, gsize len, gulong *value)
+rspamd_strtoul(const char *s, gsize len, gulong *value)
{
- const gchar *p = s, *end = s + len;
- gchar c;
+ const char *p = s, *end = s + len;
+ char c;
gulong v = 0;
const gulong cutoff = G_MAXULONG / 10, cutlim = G_MAXULONG % 10;
}
gboolean
-rspamd_strtou64(const gchar *s, gsize len, uint64_t *value)
+rspamd_strtou64(const char *s, gsize len, uint64_t *value)
{
- const gchar *p = s, *end = s + len;
- gchar c;
+ const char *p = s, *end = s + len;
+ char c;
uint64_t v = 0;
const uint64_t cutoff = G_MAXUINT64 / 10, cutlim = G_MAXUINT64 % 10;
}
gboolean
-rspamd_xstrtoul(const gchar *s, gsize len, gulong *value)
+rspamd_xstrtoul(const char *s, gsize len, gulong *value)
{
- const gchar *p = s, *end = s + len;
- gchar c;
+ const char *p = s, *end = s + len;
+ char c;
gulong v = 0;
const gulong cutoff = G_MAXULONG / 10, cutlim = G_MAXULONG % 10;
c = g_ascii_tolower(*p);
if (c >= '0' && c <= '9') {
c -= '0';
- if (v > cutoff || (v == cutoff && (guint8) c > cutlim)) {
+ if (v > cutoff || (v == cutoff && (uint8_t) c > cutlim)) {
/* Range error */
*value = G_MAXULONG;
return FALSE;
}
else if (c >= 'a' || c <= 'f') {
c = c - 'a' + 10;
- if (v > cutoff || (v == cutoff && (guint8) c > cutlim)) {
+ if (v > cutoff || (v == cutoff && (uint8_t) c > cutlim)) {
/* Range error */
*value = G_MAXULONG;
return FALSE;
* http://philzimmermann.com/docs/human-oriented-base-32-encoding.txt
*/
-gint rspamd_encode_base32_buf(const guchar *in, gsize inlen, gchar *out, gsize outlen,
- enum rspamd_base32_type type)
+int rspamd_encode_base32_buf(const unsigned char *in, gsize inlen, char *out, gsize outlen,
+ enum rspamd_base32_type type)
{
static const char b32_default[] = "ybndrfg8ejkmcpqxot1uwisza345h769",
b32_bleach[] = "qpzry9x8gf2tvdw0s3jn54khce6mua7l",
b32_rfc[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
*b32;
- gchar *o, *end;
+ char *o, *end;
gsize i;
- gint remain = -1, x;
+ int remain = -1, x;
bool inverse_order = true;
end = out + outlen;
return -1;
}
-gchar *
-rspamd_encode_base32(const guchar *in, gsize inlen, enum rspamd_base32_type type)
+char *
+rspamd_encode_base32(const unsigned char *in, gsize inlen, enum rspamd_base32_type type)
{
gsize allocated_len = inlen * 8 / 5 + 2;
- gchar *out;
- gint outlen;
+ char *out;
+ int outlen;
out = g_malloc(allocated_len);
outlen = rspamd_encode_base32_buf(in, inlen, out,
}
enum rspamd_base32_type
-rspamd_base32_decode_type_from_str(const gchar *str)
+rspamd_base32_decode_type_from_str(const char *str)
{
enum rspamd_base32_type ret = RSPAMD_BASE32_INVALID;
return ret;
}
-static const guchar b32_dec_zbase[] = {
+static const unsigned char b32_dec_zbase[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
-static const guchar b32_dec_bleach[] = {
+static const unsigned char b32_dec_bleach[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
-static const guchar b32_dec_rfc[] = {
+static const unsigned char b32_dec_rfc[] = {
0xff,
0xff,
0xff,
};
-gint rspamd_decode_base32_buf(const gchar *in, gsize inlen, guchar *out, gsize outlen,
- enum rspamd_base32_type type)
+int rspamd_decode_base32_buf(const char *in, gsize inlen, unsigned char *out, gsize outlen,
+ enum rspamd_base32_type type)
{
- guchar *o, *end, decoded;
- guchar c;
- guint acc = 0U;
- guint processed_bits = 0;
+ unsigned char *o, *end, decoded;
+ unsigned char c;
+ unsigned int acc = 0U;
+ unsigned int processed_bits = 0;
gsize i;
- const guchar *b32_dec;
+ const unsigned char *b32_dec;
bool inverse_bits = true;
end = out + outlen;
if (inverse_bits) {
for (i = 0; i < inlen; i++) {
- c = (guchar) in[i];
+ c = (unsigned char) in[i];
if (processed_bits >= 8) {
/* Emit from left to right */
}
else {
for (i = 0; i < inlen; i++) {
- c = (guchar) in[i];
+ c = (unsigned char) in[i];
decoded = b32_dec[c];
if (decoded == 0xff) {
return (o - out);
}
-guchar *
-rspamd_decode_base32(const gchar *in, gsize inlen, gsize *outlen,
+unsigned char *
+rspamd_decode_base32(const char *in, gsize inlen, gsize *outlen,
enum rspamd_base32_type type)
{
- guchar *res;
+ unsigned char *res;
gsize allocated_len = inlen * 5 / 8 + 2;
gssize olen;
}
-gchar *
-rspamd_encode_base64_common(const guchar *in, gsize inlen, gint str_len,
+char *
+rspamd_encode_base64_common(const unsigned char *in, gsize inlen, int str_len,
gsize *outlen, gboolean fold, enum rspamd_newlines_type how)
{
#define ADD_SPLIT \
} while (0)
gsize allocated_len = (inlen / 3) * 4 + 5;
- gchar *out, *o;
+ char *out, *o;
uint64_t n;
uint32_t rem, t, carry;
- gint cols, shift;
+ int cols, shift;
static const char b64_enc[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
return out;
}
-gchar *
-rspamd_encode_base64(const guchar *in, gsize inlen, gint str_len,
+char *
+rspamd_encode_base64(const unsigned char *in, gsize inlen, int str_len,
gsize *outlen)
{
return rspamd_encode_base64_common(in, inlen, str_len, outlen, FALSE,
RSPAMD_TASK_NEWLINES_CRLF);
}
-gchar *
-rspamd_encode_base64_fold(const guchar *in, gsize inlen, gint str_len,
+char *
+rspamd_encode_base64_fold(const unsigned char *in, gsize inlen, int str_len,
gsize *outlen, enum rspamd_newlines_type how)
{
return rspamd_encode_base64_common(in, inlen, str_len, outlen, TRUE, how);
#define QP_SPAN_SPECIAL(span, str_len) ((str_len) > 0 && \
((span) + 4) >= (str_len))
-gchar *
-rspamd_encode_qp_fold(const guchar *in, gsize inlen, gint str_len,
+char *
+rspamd_encode_qp_fold(const unsigned char *in, gsize inlen, int str_len,
gsize *outlen, enum rspamd_newlines_type how)
{
gsize olen = 0, span = 0, i = 0, seen_spaces = 0;
- gchar *out;
- gint ch, last_sp;
- const guchar *end = in + inlen, *p = in;
- static const gchar hexdigests[16] = "0123456789ABCDEF";
+ char *out;
+ int ch, last_sp;
+ const unsigned char *end = in + inlen, *p = in;
+ static const char hexdigests[16] = "0123456789ABCDEF";
while (p < end) {
ch = *p;
#define MIN3(a, b, c) ((a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c)))
-gint rspamd_strings_levenshtein_distance(const gchar *s1, gsize s1len,
- const gchar *s2, gsize s2len,
- guint replace_cost)
+int rspamd_strings_levenshtein_distance(const char *s1, gsize s1len,
+ const char *s2, gsize s2len,
+ unsigned int replace_cost)
{
- gchar c1, c2, last_c2, last_c1;
+ char c1, c2, last_c2, last_c1;
static GArray *current_row = NULL, *prev_row = NULL, *transp_row = NULL;
- gint eq;
- static const guint max_cmp = 8192;
- gint ret;
+ int eq;
+ static const unsigned int max_cmp = 8192;
+ int ret;
g_assert(s1 != NULL);
g_assert(s2 != NULL);
if (s1len > s2len) {
/* Exchange s1 and s2 */
- const gchar *tmp;
+ const char *tmp;
gsize tmplen;
tmp = s2;
/* Adjust static space */
if (current_row == NULL) {
- current_row = g_array_sized_new(FALSE, FALSE, sizeof(gint), s1len + 1);
- prev_row = g_array_sized_new(FALSE, FALSE, sizeof(gint), s1len + 1);
- transp_row = g_array_sized_new(FALSE, FALSE, sizeof(gint), s1len + 1);
+ current_row = g_array_sized_new(FALSE, FALSE, sizeof(int), s1len + 1);
+ prev_row = g_array_sized_new(FALSE, FALSE, sizeof(int), s1len + 1);
+ transp_row = g_array_sized_new(FALSE, FALSE, sizeof(int), s1len + 1);
g_array_set_size(current_row, s1len + 1);
g_array_set_size(prev_row, s1len + 1);
g_array_set_size(transp_row, s1len + 1);
g_array_set_size(transp_row, s1len + 1);
}
- memset(current_row->data, 0, (s1len + 1) * sizeof(gint));
- memset(transp_row->data, 0, (s1len + 1) * sizeof(gint));
+ memset(current_row->data, 0, (s1len + 1) * sizeof(int));
+ memset(transp_row->data, 0, (s1len + 1) * sizeof(int));
- for (gint i = 0; i <= s1len; i++) {
- g_array_index(prev_row, gint, i) = i;
+ for (int i = 0; i <= s1len; i++) {
+ g_array_index(prev_row, int, i) = i;
}
last_c2 = '\0';
- for (gint i = 1; i <= s2len; i++) {
+ for (int i = 1; i <= s2len; i++) {
c2 = s2[i - 1];
- g_array_index(current_row, gint, 0) = i;
+ g_array_index(current_row, int, 0) = i;
last_c1 = '\0';
- for (gint j = 1; j <= s1len; j++) {
+ for (int j = 1; j <= s1len; j++) {
c1 = s1[j - 1];
eq = c1 == c2 ? 0 : replace_cost;
- ret = MIN3(g_array_index(current_row, gint, j - 1) + 1, /* Insert */
- g_array_index(prev_row, gint, j) + 1, /* Remove */
- g_array_index(prev_row, gint, j - 1) + eq /* Replace */);
+ ret = MIN3(g_array_index(current_row, int, j - 1) + 1, /* Insert */
+ g_array_index(prev_row, int, j) + 1, /* Remove */
+ g_array_index(prev_row, int, j - 1) + eq /* Replace */);
/* Take reordering into account */
if (c1 == last_c2 && c2 == last_c1 && j >= 2) {
- ret = MIN(ret, g_array_index(transp_row, gint, j - 2) + eq);
+ ret = MIN(ret, g_array_index(transp_row, int, j - 2) + eq);
}
- g_array_index(current_row, gint, j) = ret;
+ g_array_index(current_row, int, j) = ret;
last_c1 = c1;
}
current_row = tmp;
}
- ret = g_array_index(prev_row, gint, s1len);
+ ret = g_array_index(prev_row, int, s1len);
return ret;
}
GString *
-rspamd_header_value_fold(const gchar *name, gsize name_len,
- const gchar *value,
+rspamd_header_value_fold(const char *name, gsize name_len,
+ const char *value,
gsize value_len,
- guint fold_max,
+ unsigned int fold_max,
enum rspamd_newlines_type how,
- const gchar *fold_on_chars)
+ const char *fold_on_chars)
{
GString *res;
- const guint default_fold_max = 76;
- guint cur_len;
- const gchar *p, *c, *end, *fold_sequence;
- guint nspaces = 0;
+ const unsigned int default_fold_max = 76;
+ unsigned int cur_len;
+ const char *p, *c, *end, *fold_sequence;
+ unsigned int nspaces = 0;
gboolean first_token = TRUE;
enum {
fold_before = 0,
* Check any spaces that are appended to the result
* before folding
*/
- const gchar *last = &res->str[res->len - 1];
+ const char *last = &res->str[res->len - 1];
while (g_ascii_isspace(*last)) {
last--;
cur_len = 0;
}
else {
- const gchar *last;
+ const char *last;
/* Skip space if needed */
if (g_ascii_isspace(*c) && p > c) {
return res;
}
-static inline bool rspamd_substring_cmp_func(guchar a, guchar b)
+static inline bool rspamd_substring_cmp_func(unsigned char a, unsigned char b)
{
return a == b;
}
-static inline bool rspamd_substring_casecmp_func(guchar a, guchar b)
+static inline bool rspamd_substring_casecmp_func(unsigned char a, unsigned char b)
{
return lc_map[a] == lc_map[b];
}
-typedef bool (*rspamd_cmpchar_func_t)(guchar a, guchar b);
+typedef bool (*rspamd_cmpchar_func_t)(unsigned char a, unsigned char b);
static inline void
-rspamd_substring_preprocess_kmp(const gchar *pat, gsize len, goffset *fsm,
+rspamd_substring_preprocess_kmp(const char *pat, gsize len, goffset *fsm,
rspamd_cmpchar_func_t f)
{
goffset i, j;
}
static inline goffset
-rspamd_substring_search_preprocessed(const gchar *in, gsize inlen,
- const gchar *srch,
+rspamd_substring_search_preprocessed(const char *in, gsize inlen,
+ const char *srch,
gsize srchlen,
const goffset *fsm,
rspamd_cmpchar_func_t f)
}
static inline goffset
-rspamd_substring_search_common(const gchar *in, gsize inlen,
- const gchar *srch, gsize srchlen, rspamd_cmpchar_func_t f)
+rspamd_substring_search_common(const char *in, gsize inlen,
+ const char *srch, gsize srchlen, rspamd_cmpchar_func_t f)
{
static goffset st_fsm[128];
goffset *fsm, ret;
}
goffset
-rspamd_substring_search(const gchar *in, gsize inlen,
- const gchar *srch, gsize srchlen)
+rspamd_substring_search(const char *in, gsize inlen,
+ const char *srch, gsize srchlen)
{
if (inlen > srchlen) {
if (G_UNLIKELY(srchlen == 1)) {
- const gchar *p;
+ const char *p;
p = memchr(in, srch[0], inlen);
}
goffset
-rspamd_substring_search_caseless(const gchar *in, gsize inlen,
- const gchar *srch, gsize srchlen)
+rspamd_substring_search_caseless(const char *in, gsize inlen,
+ const char *srch, gsize srchlen)
{
if (inlen > srchlen) {
if (G_UNLIKELY(srchlen == 1)) {
goffset i;
- gchar s = lc_map[(guchar) srch[0]];
+ char s = lc_map[(unsigned char) srch[0]];
for (i = 0; i < inlen; i++) {
- if (lc_map[(guchar) in[i]] == s) {
+ if (lc_map[(unsigned char) in[i]] == s) {
return i;
}
}
goffset
rspamd_string_find_eoh(GString *input, goffset *body_start)
{
- const gchar *p, *c = NULL, *end;
+ const char *p, *c = NULL, *end;
enum {
skip_char = 0,
got_cr,
return -1;
}
-gint rspamd_encode_hex_buf(const guchar *in, gsize inlen, gchar *out,
- gsize outlen)
+int rspamd_encode_hex_buf(const unsigned char *in, gsize inlen, char *out,
+ gsize outlen)
{
- gchar *o, *end;
- const guchar *p;
- static const gchar hexdigests[16] = "0123456789abcdef";
+ char *o, *end;
+ const unsigned char *p;
+ static const char hexdigests[16] = "0123456789abcdef";
end = out + outlen;
o = out;
return -1;
}
-gchar *
-rspamd_encode_hex(const guchar *in, gsize inlen)
+char *
+rspamd_encode_hex(const unsigned char *in, gsize inlen)
{
- gchar *out;
+ char *out;
gsize outlen = inlen * 2 + 1;
- gint olen;
+ int olen;
if (in == NULL) {
return NULL;
}
gssize
-rspamd_decode_hex_buf(const gchar *in, gsize inlen,
- guchar *out, gsize outlen)
+rspamd_decode_hex_buf(const char *in, gsize inlen,
+ unsigned char *out, gsize outlen)
{
- guchar *o, *end, ret = 0;
- const gchar *p;
- gchar c;
+ unsigned char *o, *end, ret = 0;
+ const char *p;
+ char c;
end = out + outlen;
o = out;
return -1;
}
-guchar *
-rspamd_decode_hex(const gchar *in, gsize inlen)
+unsigned char *
+rspamd_decode_hex(const char *in, gsize inlen)
{
- guchar *out;
+ unsigned char *out;
gsize outlen = (inlen / 2 + inlen % 2) + 1;
- gint olen;
+ int olen;
if (in == NULL) {
return NULL;
}
gssize
-rspamd_decode_qp_buf(const gchar *in, gsize inlen,
- gchar *out, gsize outlen)
+rspamd_decode_qp_buf(const char *in, gsize inlen,
+ char *out, gsize outlen)
{
- gchar *o, *end, *pos, c;
- const gchar *p;
- guchar ret;
+ char *o, *end, *pos, c;
+ const char *p;
+ unsigned char ret;
gssize remain, processed;
p = in;
}
if (end - o > 0) {
- *o++ = (gchar) ret;
+ *o++ = (char) ret;
}
else {
return (-1);
}
gssize
-rspamd_decode_uue_buf(const gchar *in, gsize inlen,
- gchar *out, gsize outlen)
+rspamd_decode_uue_buf(const char *in, gsize inlen,
+ char *out, gsize outlen)
{
- gchar *o, *out_end;
- const gchar *p;
+ char *o, *out_end;
+ const char *p;
gssize remain;
gboolean base64 = FALSE;
goffset pos;
- const gchar *nline = "\r\n";
+ const char *nline = "\r\n";
p = in;
o = out;
while (remain > 0 && o < out_end) {
/* Main cycle */
- const gchar *eol;
- gint i, ch;
+ const char *eol;
+ int i, ch;
pos = rspamd_memcspn(p, nline, remain);
((a)[(gsize) (b) / (8 * sizeof *(a))] op(gsize) 1 << ((gsize) (b) % (8 * sizeof *(a))))
-gsize rspamd_memcspn(const gchar *s, const gchar *e, gsize len)
+gsize rspamd_memcspn(const char *s, const char *e, gsize len)
{
gsize byteset[32 / sizeof(gsize)];
- const gchar *p = s, *end = s + len;
+ const char *p = s, *end = s + len;
if (!e[1]) {
for (; p < end && *p != *e; p++)
memset(byteset, 0, sizeof byteset);
- for (; *e && BITOP(byteset, *(guchar *) e, |=); e++)
+ for (; *e && BITOP(byteset, *(unsigned char *) e, |=); e++)
;
- for (; p < end && !BITOP(byteset, *(guchar *) p, &); p++)
+ for (; p < end && !BITOP(byteset, *(unsigned char *) p, &); p++)
;
return p - s;
}
-gsize rspamd_memspn(const gchar *s, const gchar *e, gsize len)
+gsize rspamd_memspn(const char *s, const char *e, gsize len)
{
gsize byteset[32 / sizeof(gsize)];
- const gchar *p = s, *end = s + len;
+ const char *p = s, *end = s + len;
if (!e[1]) {
for (; p < end && *p == *e; p++)
memset(byteset, 0, sizeof byteset);
- for (; *e && BITOP(byteset, *(guchar *) e, |=); e++)
+ for (; *e && BITOP(byteset, *(unsigned char *) e, |=); e++)
;
- for (; p < end && BITOP(byteset, *(guchar *) p, &); p++)
+ for (; p < end && BITOP(byteset, *(unsigned char *) p, &); p++)
;
return p - s;
}
gssize
-rspamd_decode_qp2047_buf(const gchar *in, gsize inlen,
- gchar *out, gsize outlen)
+rspamd_decode_qp2047_buf(const char *in, gsize inlen,
+ char *out, gsize outlen)
{
- gchar *o, *end, c;
- const gchar *p;
- guchar ret;
+ char *o, *end, c;
+ const char *p;
+ unsigned char ret;
gsize remain, processed;
p = in;
}
if (end - o > 0) {
- *o++ = (gchar) ret;
+ *o++ = (char) ret;
}
else {
return (-1);
}
gssize
-rspamd_encode_qp2047_buf(const gchar *in, gsize inlen,
- gchar *out, gsize outlen)
+rspamd_encode_qp2047_buf(const char *in, gsize inlen,
+ char *out, gsize outlen)
{
- gchar *o = out, *end = out + outlen, c;
- static const gchar hexdigests[16] = "0123456789ABCDEF";
+ char *o = out, *end = out + outlen, c;
+ static const char hexdigests[16] = "0123456789ABCDEF";
while (inlen > 0 && o < end) {
c = *in;
#define MAX_PRECISION 6
if (isfinite(val)) {
- if (val == (double) ((gint) val)) {
+ if (val == (double) ((int) val)) {
rspamd_printf_fstring(buf, "%.1f", val);
}
else {
#ifndef HAVE_MEMRCHR
void *
-rspamd_memrchr(const void *m, gint c, gsize len)
+rspamd_memrchr(const void *m, int c, gsize len)
{
- const guint8 *p = m;
+ const uint8_t *p = m;
for (gsize i = len; i > 0; i--) {
if (p[i - 1] == c) {
#endif
}
-gchar *
-rspamd_str_regexp_escape(const gchar *pattern, gsize slen,
+char *
+rspamd_str_regexp_escape(const char *pattern, gsize slen,
gsize *dst_len, enum rspamd_regexp_escape_flags flags)
{
- const gchar *p, *end = pattern + slen;
- gchar *res, *d, t, *tmp_utf = NULL, *dend;
+ const char *p, *end = pattern + slen;
+ char *res, *d, t, *tmp_utf = NULL, *dend;
gsize len;
- static const gchar hexdigests[16] = "0123456789abcdef";
+ static const char hexdigests[16] = "0123456789abcdef";
len = 0;
p = pattern;
}
-gchar *
-rspamd_str_make_utf_valid(const guchar *src, gsize slen,
+char *
+rspamd_str_make_utf_valid(const unsigned char *src, gsize slen,
gsize *dstlen,
rspamd_mempool_t *pool)
{
UChar32 uc;
goffset err_offset;
- const guchar *p;
- gchar *dst, *d;
+ const unsigned char *p;
+ char *dst, *d;
gsize remain = slen, dlen = 0;
if (src == NULL) {
/* Check space required */
while (remain > 0 && (err_offset = rspamd_fast_utf8_validate(p, remain)) > 0) {
- gint i = 0;
+ int i = 0;
err_offset--; /* As it returns it 1 indexed */
p += err_offset;
d += err_offset;
/* Append 0xFFFD for each bad character */
- gint i = 0;
+ int i = 0;
p += err_offset;
remain -= err_offset;
while (i < remain) {
- gint old_i = i;
+ int old_i = i;
U8_NEXT(p, i, remain, uc);
if (uc < 0) {
return dst;
}
-gsize rspamd_gstring_strip(GString *s, const gchar *strip_chars)
+gsize rspamd_gstring_strip(GString *s, const char *strip_chars)
{
- const gchar *p, *sc;
+ const char *p, *sc;
gsize strip_len = 0, total = 0;
p = s->str + s->len - 1;
return total;
}
-const gchar *rspamd_string_len_strip(const gchar *in,
- gsize *len,
- const gchar *strip_chars)
+const char *rspamd_string_len_strip(const char *in,
+ gsize *len,
+ const char *strip_chars)
{
- const gchar *p, *sc;
+ const char *p, *sc;
gsize strip_len = 0, old_len = *len;
p = in + old_len - 1;
return in;
}
-gchar **
-rspamd_string_len_split(const gchar *in, gsize len, const gchar *spill,
- gint max_elts, rspamd_mempool_t *pool)
+char **
+rspamd_string_len_split(const char *in, gsize len, const char *spill,
+ int max_elts, rspamd_mempool_t *pool)
{
- const gchar *p = in, *end = in + len;
+ const char *p = in, *end = in + len;
gsize detected_elts = 0;
- gchar **res;
+ char **res;
/* Detect number of elements */
while (p < end) {
p += rspamd_memspn(p, spill, end - p);
}
- res = pool ? rspamd_mempool_alloc(pool, sizeof(gchar *) * (detected_elts + 1)) : g_malloc(sizeof(gchar *) * (detected_elts + 1));
+ res = pool ? rspamd_mempool_alloc(pool, sizeof(char *) * (detected_elts + 1)) : g_malloc(sizeof(char *) * (detected_elts + 1));
/* Last one */
res[detected_elts] = NULL;
detected_elts = 0;
gsize cur_fragment = rspamd_memcspn(p, spill, end - p);
if (cur_fragment > 0) {
- gchar *elt;
+ char *elt;
elt = pool ? rspamd_mempool_alloc(pool, cur_fragment + 1) : g_malloc(cur_fragment + 1);
#endif
static inline gboolean
-rspamd_str_has_8bit_u64(const guchar *beg, gsize len)
+rspamd_str_has_8bit_u64(const unsigned char *beg, gsize len)
{
- guint8 orb = 0;
+ uint8_t orb = 0;
if (len >= 16) {
- const guchar *nextd = beg + sizeof(uint64_t);
+ const unsigned char *nextd = beg + sizeof(uint64_t);
uint64_t n1 = 0, n2 = 0;
do {
}
gboolean
-rspamd_str_has_8bit(const guchar *beg, gsize len)
+rspamd_str_has_8bit(const unsigned char *beg, gsize len)
{
#if defined(__x86_64__)
if (len >= 32) {
/**
* Compare two memory regions of size `l` using case insensitive matching
*/
-gint rspamd_lc_cmp(const gchar *s, const gchar *d, gsize l);
+int rspamd_lc_cmp(const char *s, const char *d, gsize l);
/**
* Convert string to lowercase in-place using ASCII conversion
*/
-guint rspamd_str_lc(gchar *str, guint size);
+unsigned int rspamd_str_lc(char *str, unsigned int size);
/**
* Performs ascii copy & lowercase
* @param size
* @return
*/
-gsize rspamd_str_copy_lc(const gchar *src, gchar *dst, gsize size);
+gsize rspamd_str_copy_lc(const char *src, char *dst, gsize size);
/**
* Convert string to lowercase in-place using utf (limited) conversion
*/
-guint rspamd_str_lc_utf8(gchar *str, guint size);
+unsigned int rspamd_str_lc_utf8(char *str, unsigned int size);
/*
* Hash table utility functions for case insensitive hashing
*/
-uint64_t rspamd_icase_hash(const gchar *in, gsize len, uint64_t seed);
+uint64_t rspamd_icase_hash(const char *in, gsize len, uint64_t seed);
-guint rspamd_strcase_hash(gconstpointer key);
+unsigned int rspamd_strcase_hash(gconstpointer key);
gboolean rspamd_strcase_equal(gconstpointer v, gconstpointer v2);
/*
* Hash table utility functions for case sensitive hashing
*/
-guint rspamd_str_hash(gconstpointer key);
+unsigned int rspamd_str_hash(gconstpointer key);
gboolean rspamd_str_equal(gconstpointer v, gconstpointer v2);
/*
* Hash table utility functions for hashing fixed strings
*/
-guint rspamd_ftok_icase_hash(gconstpointer key);
+unsigned int rspamd_ftok_icase_hash(gconstpointer key);
gboolean rspamd_ftok_icase_equal(gconstpointer v, gconstpointer v2);
#define rspamd_ftok_hash(key) _wyhash32((key)->begin, (key)->len, 0)
#define rspamd_ftok_equal(v1, v2) ((v1)->len == (v2)->len && memcmp((v1)->begin, (v2)->begin, (v1)->len) == 0)
-guint rspamd_gstring_icase_hash(gconstpointer key);
+unsigned int rspamd_gstring_icase_hash(gconstpointer key);
gboolean rspamd_gstring_icase_equal(gconstpointer v, gconstpointer v2);
* @param siz length of destination buffer
* @return bytes copied
*/
-gsize rspamd_strlcpy_fast(gchar *dst, const gchar *src, gsize siz);
+gsize rspamd_strlcpy_fast(char *dst, const char *src, gsize siz);
-gsize rspamd_strlcpy_safe(gchar *dst, const gchar *src, gsize siz);
+gsize rspamd_strlcpy_safe(char *dst, const char *src, gsize siz);
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
* @param destlen
* @return number of bytes copied
*/
-gsize rspamd_null_safe_copy(const gchar *src, gsize srclen,
- gchar *dest, gsize destlen);
+gsize rspamd_null_safe_copy(const char *src, gsize srclen,
+ char *dest, gsize destlen);
/*
* Try to convert string of length to long
*/
-gboolean rspamd_strtol(const gchar *s, gsize len, glong *value);
+gboolean rspamd_strtol(const char *s, gsize len, glong *value);
/*
* Try to convert a string of length to unsigned long
*/
-gboolean rspamd_strtoul(const gchar *s, gsize len, gulong *value);
-gboolean rspamd_strtou64(const gchar *s, gsize len, uint64_t *value);
+gboolean rspamd_strtoul(const char *s, gsize len, gulong *value);
+gboolean rspamd_strtou64(const char *s, gsize len, uint64_t *value);
/*
* Try to convert a hex string of length to unsigned long
*/
-gboolean rspamd_xstrtoul(const gchar *s, gsize len, gulong *value);
+gboolean rspamd_xstrtoul(const char *s, gsize len, gulong *value);
/**
* Utility function to provide mem_pool copy for rspamd_hash_table_copy function
* @param inlen input length
* @return freshly allocated base32 encoding of a specified string
*/
-gchar *rspamd_encode_hex(const guchar *in, gsize inlen);
+char *rspamd_encode_hex(const unsigned char *in, gsize inlen);
/**
* Decode string using hex encoding
* @param inlen input length
* @return freshly allocated base32 decoded value or NULL if input is invalid
*/
-guchar *rspamd_decode_hex(const gchar *in, gsize inlen);
+unsigned char *rspamd_decode_hex(const char *in, gsize inlen);
enum rspamd_base32_type {
RSPAMD_BASE32_DEFAULT = 0,
* @param str
* @return
*/
-enum rspamd_base32_type rspamd_base32_decode_type_from_str(const gchar *str);
+enum rspamd_base32_type rspamd_base32_decode_type_from_str(const char *str);
/**
* Encode string using base32 encoding
* @param inlen input length
* @return freshly allocated base32 encoding of a specified string
*/
-gchar *rspamd_encode_base32(const guchar *in, gsize inlen,
- enum rspamd_base32_type type);
+char *rspamd_encode_base32(const unsigned char *in, gsize inlen,
+ enum rspamd_base32_type type);
/**
* Decode string using base32 encoding
* @param inlen input length
* @return freshly allocated base32 decoded value or NULL if input is invalid
*/
-guchar *rspamd_decode_base32(const gchar *in, gsize inlen, gsize *outlen, enum rspamd_base32_type type);
+unsigned char *rspamd_decode_base32(const char *in, gsize inlen, gsize *outlen, enum rspamd_base32_type type);
/**
* Encode string using base32 encoding
* @param outlen output buf len
* @return encoded len if `outlen` is enough to encode `inlen`
*/
-gint rspamd_encode_base32_buf(const guchar *in, gsize inlen, gchar *out,
- gsize outlen, enum rspamd_base32_type type);
+int rspamd_encode_base32_buf(const unsigned char *in, gsize inlen, char *out,
+ gsize outlen, enum rspamd_base32_type type);
/**
* Decode string using base32 encoding
* @param outlen output buf len
* @return decoded len if in is valid base32 and `outlen` is enough to encode `inlen`
*/
-gint rspamd_decode_base32_buf(const gchar *in, gsize inlen, guchar *out,
- gsize outlen, enum rspamd_base32_type type);
+int rspamd_decode_base32_buf(const char *in, gsize inlen, unsigned char *out,
+ gsize outlen, enum rspamd_base32_type type);
/**
* Encode string using hex encoding
* @param outlen output buf len
* @return encoded len if `outlen` is enough to encode `inlen`
*/
-gint rspamd_encode_hex_buf(const guchar *in, gsize inlen, gchar *out,
- gsize outlen);
+int rspamd_encode_hex_buf(const unsigned char *in, gsize inlen, char *out,
+ gsize outlen);
/**
* @param outlen output buf len
* @return decoded len if in is valid hex and `outlen` is enough to encode `inlen`
*/
-gssize rspamd_decode_hex_buf(const gchar *in, gsize inlen,
- guchar *out, gsize outlen);
+gssize rspamd_decode_hex_buf(const char *in, gsize inlen,
+ unsigned char *out, gsize outlen);
/**
* Common version of base64 encoder
* @param how
* @return
*/
-gchar *
-rspamd_encode_base64_common(const guchar *in,
+char *
+rspamd_encode_base64_common(const unsigned char *in,
gsize inlen,
- gint str_len,
+ int str_len,
gsize *outlen,
gboolean fold,
enum rspamd_newlines_type how);
* @param str_len maximum string length (if <= 0 then no lines are split)
* @return freshly allocated base64 encoded value or NULL if input is invalid
*/
-gchar *rspamd_encode_base64(const guchar *in, gsize inlen, gint str_len,
- gsize *outlen);
+char *rspamd_encode_base64(const unsigned char *in, gsize inlen, int str_len,
+ gsize *outlen);
/**
* Encode and fold string using base64 encoding
* @param str_len maximum string length (if <= 0 then no lines are split)
* @return freshly allocated base64 encoded value or NULL if input is invalid
*/
-gchar *rspamd_encode_base64_fold(const guchar *in, gsize inlen, gint str_len,
- gsize *outlen, enum rspamd_newlines_type how);
+char *rspamd_encode_base64_fold(const unsigned char *in, gsize inlen, int str_len,
+ gsize *outlen, enum rspamd_newlines_type how);
/**
* Encode and fold string using quoted printable encoding
* @param str_len maximum string length (if <= 0 then no lines are split)
* @return freshly allocated base64 encoded value or NULL if input is invalid
*/
-gchar *rspamd_encode_qp_fold(const guchar *in, gsize inlen, gint str_len,
- gsize *outlen, enum rspamd_newlines_type how);
+char *rspamd_encode_qp_fold(const unsigned char *in, gsize inlen, int str_len,
+ gsize *outlen, enum rspamd_newlines_type how);
/**
* Decode quoted-printable encoded buffer, input and output must not overlap
* @param outlen length of output
* @return real size of decoded output or (-1) if outlen is not enough
*/
-gssize rspamd_decode_qp_buf(const gchar *in, gsize inlen,
- gchar *out, gsize outlen);
+gssize rspamd_decode_qp_buf(const char *in, gsize inlen,
+ char *out, gsize outlen);
/**
* Decode uuencode encoded buffer, input and output must not overlap
* @param outlen length of output
* @return real size of decoded output or (-1) if outlen is not enough
*/
-gssize rspamd_decode_uue_buf(const gchar *in, gsize inlen,
- gchar *out, gsize outlen);
+gssize rspamd_decode_uue_buf(const char *in, gsize inlen,
+ char *out, gsize outlen);
/**
* Decode quoted-printable encoded buffer using rfc2047 format, input and output must not overlap
* @param outlen length of output
* @return real size of decoded output or (-1) if outlen is not enough
*/
-gssize rspamd_decode_qp2047_buf(const gchar *in, gsize inlen,
- gchar *out, gsize outlen);
+gssize rspamd_decode_qp2047_buf(const char *in, gsize inlen,
+ char *out, gsize outlen);
/**
* Encode quoted-printable buffer using rfc2047 format, input and output must not overlap
* @param outlen
* @return
*/
-gssize rspamd_encode_qp2047_buf(const gchar *in, gsize inlen,
- gchar *out, gsize outlen);
+gssize rspamd_encode_qp2047_buf(const char *in, gsize inlen,
+ char *out, gsize outlen);
#ifndef g_tolower
#define g_tolower(x) (((x) >= 'A' && (x) <= 'Z') ? (x) - 'A' + 'a' : (x))
* @param s2len
* @return
*/
-gint rspamd_strings_levenshtein_distance(const gchar *s1, gsize s1len,
- const gchar *s2, gsize s2len, guint replace_cost);
+int rspamd_strings_levenshtein_distance(const char *s1, gsize s1len,
+ const char *s2, gsize s2len, unsigned int replace_cost);
/**
* Fold header using rfc822 rules, return new GString from the previous one
* @param fold_on_chars
* @return new GString with the folded value
*/
-GString *rspamd_header_value_fold(const gchar *name,
+GString *rspamd_header_value_fold(const char *name,
gsize name_len,
- const gchar *value,
+ const char *value,
gsize value_len,
- guint fold_max,
+ unsigned int fold_max,
enum rspamd_newlines_type how,
- const gchar *fold_on_chars);
+ const char *fold_on_chars);
/**
* Search for a substring `srch` in the text `in` using Apostolico-Crochemore algorithm
* @param srchlen length of the search string
* @return position of the first substring match or (-1) if not found
*/
-goffset rspamd_substring_search(const gchar *in, gsize inlen,
- const gchar *srch, gsize srchlen);
+goffset rspamd_substring_search(const char *in, gsize inlen,
+ const char *srch, gsize srchlen);
/**
* Search for a substring `srch` in the text `in` using Apostolico-Crochemore algorithm in caseless matter (ASCII only)
* @param srchlen length of the search string
* @return position of the first substring match or (-1) if not found
*/
-goffset rspamd_substring_search_caseless(const gchar *in, gsize inlen,
- const gchar *srch, gsize srchlen);
+goffset rspamd_substring_search_caseless(const char *in, gsize inlen,
+ const char *srch, gsize srchlen);
/**
* Search for end-of-headers mark in the input string. Returns position just after
rspamd_fstring_t **target,
const ucl_object_t *comments);
-extern const guchar lc_map[256];
+extern const unsigned char lc_map[256];
/**
* Search for the last occurrence of character `c` in memory block of size `len`
#ifdef HAVE_MEMRCHR
#define rspamd_memrchr memrchr
#else
-void *rspamd_memrchr(const void *m, gint c, gsize len);
+void *rspamd_memrchr(const void *m, int c, gsize len);
#endif
/**
* @param len length of `s`
* @return segment size
*/
-gsize rspamd_memcspn(const gchar *s, const gchar *e, gsize len);
+gsize rspamd_memcspn(const char *s, const char *e, gsize len);
/**
* Return length of memory segment starting in `s` that contains only chars from `e`
* @param len length of `s`
* @return segment size
*/
-gsize rspamd_memspn(const gchar *s, const gchar *e, gsize len);
+gsize rspamd_memspn(const char *s, const char *e, gsize len);
/* https://graphics.stanford.edu/~seander/bithacks.html#HasMoreInWord */
#define rspamd_str_hasmore(x, n) ((((x) + ~0UL / 255 * (127 - (n))) | (x)) & ~0UL / 255 * 128)
*/
#define rspamd_is_aligned(p, n) (((uintptr_t) (p) & ((uintptr_t) (n) -1)) == 0)
#define rspamd_is_aligned_as(p, v) rspamd_is_aligned(p, RSPAMD_ALIGNOF(__typeof((v))))
-gboolean rspamd_str_has_8bit(const guchar *beg, gsize len);
+gboolean rspamd_str_has_8bit(const unsigned char *beg, gsize len);
struct UConverter;
* @param allow_glob allow glob expressions to be translated into pcre
* @return newly allocated zero terminated escaped pattern
*/
-gchar *
-rspamd_str_regexp_escape(const gchar *pattern, gsize slen,
+char *
+rspamd_str_regexp_escape(const char *pattern, gsize slen,
gsize *dst_len, enum rspamd_regexp_escape_flags flags) G_GNUC_WARN_UNUSED_RESULT;
/**
* @param dstelen
* @return
*/
-gchar *rspamd_str_make_utf_valid(const guchar *src, gsize slen, gsize *dstlen,
- rspamd_mempool_t *pool) G_GNUC_WARN_UNUSED_RESULT;
+char *rspamd_str_make_utf_valid(const unsigned char *src, gsize slen, gsize *dstlen,
+ rspamd_mempool_t *pool) G_GNUC_WARN_UNUSED_RESULT;
/**
* Strips characters in `strip_chars` from start and end of the GString
* @param s
* @param strip_chars
*/
-gsize rspamd_gstring_strip(GString *s, const gchar *strip_chars);
+gsize rspamd_gstring_strip(GString *s, const char *strip_chars);
/**
* Strips characters in `strip_chars` from start and end of the sized string
* @param s
* @param strip_chars
*/
-const gchar *rspamd_string_len_strip(const gchar *in,
- gsize *len, const gchar *strip_chars) G_GNUC_WARN_UNUSED_RESULT;
+const char *rspamd_string_len_strip(const char *in,
+ gsize *len, const char *strip_chars) G_GNUC_WARN_UNUSED_RESULT;
/**
* Returns a NULL terminated list of zero terminated strings based on splitting of
* @param max_elts
* @return
*/
-gchar **rspamd_string_len_split(const gchar *in, gsize len,
- const gchar *spill, gint max_elts, rspamd_mempool_t *pool);
+char **rspamd_string_len_split(const char *in, gsize len,
+ const char *spill, int max_elts, rspamd_mempool_t *pool);
#define IS_ZERO_WIDTH_SPACE(uc) ((uc) == 0x200B || \
(uc) == 0x200C || \
struct upstream_inet_addr_entry {
rspamd_inet_addr_t *addr;
- guint priority;
+ unsigned int priority;
struct upstream_inet_addr_entry *next;
};
struct upstream_addr_elt {
rspamd_inet_addr_t *addr;
- guint priority;
- guint errors;
+ unsigned int priority;
+ unsigned int errors;
};
struct upstream_list_watcher {
};
struct upstream {
- guint weight;
- guint cur_weight;
- guint errors;
- guint checked;
- guint dns_requests;
- gint active_idx;
- guint ttl;
- gchar *name;
+ unsigned int weight;
+ unsigned int cur_weight;
+ unsigned int errors;
+ unsigned int checked;
+ unsigned int dns_requests;
+ int active_idx;
+ unsigned int ttl;
+ char *name;
ev_timer ev;
- gdouble last_fail;
- gdouble last_resolve;
+ double last_fail;
+ double last_resolve;
gpointer ud;
enum rspamd_upstream_flag flags;
struct upstream_list *ls;
struct {
GPtrArray *addr; /* struct upstream_addr_elt */
- guint cur;
+ unsigned int cur;
} addrs;
struct upstream_inet_addr_entry *new_addrs;
gpointer data;
- gchar uid[8];
+ char uid[8];
ref_entry_t ref;
#ifdef UPSTREAMS_THREAD_SAFE
rspamd_mutex_t *lock;
};
struct upstream_limits {
- gdouble revive_time;
- gdouble revive_jitter;
- gdouble error_time;
- gdouble dns_timeout;
- gdouble lazy_resolve_time;
- guint max_errors;
- guint dns_retransmits;
+ double revive_time;
+ double revive_jitter;
+ double error_time;
+ double dns_timeout;
+ double lazy_resolve_time;
+ unsigned int max_errors;
+ unsigned int dns_retransmits;
};
struct upstream_list {
- gchar *ups_line;
+ char *ups_line;
struct upstream_ctx *ctx;
GPtrArray *ups;
GPtrArray *alive;
uint64_t hash_seed;
const struct upstream_limits *limits;
enum rspamd_upstream_flag flags;
- guint cur_elt;
+ unsigned int cur_elt;
enum rspamd_upstream_rotation rot_alg;
#ifdef UPSTREAMS_THREAD_SAFE
rspamd_mutex_t *lock;
/* 4 errors in 10 seconds */
#define DEFAULT_MAX_ERRORS 4
-static const guint default_max_errors = DEFAULT_MAX_ERRORS;
+static const unsigned int default_max_errors = DEFAULT_MAX_ERRORS;
#define DEFAULT_REVIVE_TIME 60
-static const gdouble default_revive_time = DEFAULT_REVIVE_TIME;
+static const double default_revive_time = DEFAULT_REVIVE_TIME;
#define DEFAULT_REVIVE_JITTER 0.4
-static const gdouble default_revive_jitter = DEFAULT_REVIVE_JITTER;
+static const double default_revive_jitter = DEFAULT_REVIVE_JITTER;
#define DEFAULT_ERROR_TIME 10
-static const gdouble default_error_time = DEFAULT_ERROR_TIME;
+static const double default_error_time = DEFAULT_ERROR_TIME;
#define DEFAULT_DNS_TIMEOUT 1.0
-static const gdouble default_dns_timeout = DEFAULT_DNS_TIMEOUT;
+static const double default_dns_timeout = DEFAULT_DNS_TIMEOUT;
#define DEFAULT_DNS_RETRANSMITS 2
-static const guint default_dns_retransmits = DEFAULT_DNS_RETRANSMITS;
+static const unsigned int default_dns_retransmits = DEFAULT_DNS_RETRANSMITS;
/* TODO: make it configurable */
#define DEFAULT_LAZY_RESOLVE_TIME 3600.0
-static const gdouble default_lazy_resolve_time = DEFAULT_LAZY_RESOLVE_TIME;
+static const double default_lazy_resolve_time = DEFAULT_LAZY_RESOLVE_TIME;
static const struct upstream_limits default_limits = {
.revive_time = DEFAULT_REVIVE_TIME,
upstream = cur->data;
if (!ev_can_stop(&upstream->ev) && upstream->ls &&
!(upstream->flags & RSPAMD_UPSTREAM_FLAG_NORESOLVE)) {
- gdouble when;
+ double when;
if (upstream->flags & RSPAMD_UPSTREAM_FLAG_SRV_RESOLVE) {
/* Resolve them immediately ! */
return ctx;
}
-static gint
+static int
rspamd_upstream_af_to_weight(const rspamd_inet_addr_t *addr)
{
int ret;
/*
* Select IPv4 addresses before IPv6
*/
-static gint
+static int
rspamd_upstream_addr_sort_func(gconstpointer a, gconstpointer b)
{
const struct upstream_addr_elt *ip1 = *(const struct upstream_addr_elt **) a,
*ip2 = *(const struct upstream_addr_elt **) b;
- gint w1, w2;
+ int w1, w2;
if (ip1->priority == 0 && ip2->priority == 0) {
w1 = rspamd_upstream_af_to_weight(ip1->addr);
}
/* Start lazy (or not so lazy) names resolution */
- gdouble when;
+ double when;
if (upstream->flags & RSPAMD_UPSTREAM_FLAG_SRV_RESOLVE) {
/* Resolve them immediately ! */
static void
rspamd_upstream_update_addrs(struct upstream *upstream)
{
- guint addr_cnt, i, port;
+ unsigned int addr_cnt, i, port;
gboolean seen_addr, reset_errors = FALSE;
struct upstream_inet_addr_entry *cur, *tmp;
GPtrArray *new_addrs;
struct rspamd_upstream_srv_dns_cb {
struct upstream *up;
- guint priority;
- guint port;
- guint requests_inflight;
+ unsigned int priority;
+ unsigned int port;
+ unsigned int requests_inflight;
};
/* Used when we have resolved SRV record and resolved addrs */
struct upstream *upstream)
{
/* XXX: maybe make it configurable */
- static const gdouble min_resolve_interval = 60.0;
+ static const double min_resolve_interval = 60.0;
if (upstream->ctx->res != NULL &&
upstream->ctx->configured &&
upstream->dns_requests == 0 &&
!(upstream->flags & RSPAMD_UPSTREAM_FLAG_NORESOLVE)) {
- gdouble now = ev_now(upstream->ctx->event_loop);
+ double now = ev_now(upstream->ctx->event_loop);
if (now - upstream->last_resolve < min_resolve_interval) {
msg_info_upstream("do not resolve upstream %s as it was checked %.0f "
static void
rspamd_upstream_set_inactive(struct upstream_list *ls, struct upstream *upstream)
{
- gdouble ntim;
- guint i;
+ double ntim;
+ unsigned int i;
struct upstream *cur;
struct upstream_list_watcher *w;
void rspamd_upstream_fail(struct upstream *upstream,
gboolean addr_failure,
- const gchar *reason)
+ const char *reason)
{
- gdouble error_rate = 0, max_error_rate = 0;
- gdouble sec_last, sec_cur;
+ double error_rate = 0, max_error_rate = 0;
+ double sec_last, sec_cur;
struct upstream_addr_elt *addr_elt;
struct upstream_list_watcher *w;
}
if (sec_cur - sec_last >= upstream->ls->limits->error_time) {
- error_rate = ((gdouble) upstream->errors) / (sec_cur - sec_last);
- max_error_rate = ((gdouble) upstream->ls->limits->max_errors) /
+ error_rate = ((double) upstream->errors) / (sec_cur - sec_last);
+ max_error_rate = ((double) upstream->ls->limits->max_errors) /
upstream->ls->limits->error_time;
}
RSPAMD_UPSTREAM_UNLOCK(upstream);
}
-void rspamd_upstream_set_weight(struct upstream *up, guint weight)
+void rspamd_upstream_set_weight(struct upstream *up, unsigned int weight)
{
RSPAMD_UPSTREAM_LOCK(up);
up->weight = weight;
rspamd_inet_addr_t *
rspamd_upstream_addr_next(struct upstream *up)
{
- guint idx, next_idx;
+ unsigned int idx, next_idx;
struct upstream_addr_elt *e1, *e2;
do {
return elt->addr;
}
-const gchar *
+const char *
rspamd_upstream_name(struct upstream *up)
{
return up->name;
}
-gint rspamd_upstream_port(struct upstream *up)
+int rspamd_upstream_port(struct upstream *up)
{
struct upstream_addr_elt *elt;
}
gboolean
-rspamd_upstreams_add_upstream(struct upstream_list *ups, const gchar *str,
- guint16 def_port, enum rspamd_upstream_parse_type parse_type,
+rspamd_upstreams_add_upstream(struct upstream_list *ups, const char *str,
+ uint16_t def_port, enum rspamd_upstream_parse_type parse_type,
void *data)
{
struct upstream *upstream;
GPtrArray *addrs = NULL;
- guint i, slen;
+ unsigned int i, slen;
rspamd_inet_addr_t *addr;
enum rspamd_parse_host_port_result ret = RSPAMD_PARSE_ADDR_FAIL;
case RSPAMD_UPSTREAM_PARSE_DEFAULT:
if (slen > sizeof("service=") &&
RSPAMD_LEN_CHECK_STARTS_WITH(str, slen, "service=")) {
- const gchar *plus_pos, *service_pos, *semicolon_pos;
+ const char *plus_pos, *service_pos, *semicolon_pos;
/* Accept service=srv_name+hostname[:priority] */
service_pos = str + sizeof("service=") - 1;
* where <domain> is string between semicolon_pos and plus_pos +1
* while service is a string between service_pos and plus_pos
*/
- guint namelen = (semicolon_pos - (plus_pos + 1)) +
- (plus_pos - service_pos) +
- (sizeof("tcp") - 1) +
- 4;
+ unsigned int namelen = (semicolon_pos - (plus_pos + 1)) +
+ (plus_pos - service_pos) +
+ (sizeof("tcp") - 1) +
+ 4;
addrs = g_ptr_array_sized_new(1);
upstream->name = ups->ctx ? rspamd_mempool_alloc(ups->ctx->pool, namelen + 1) : g_malloc(namelen + 1);
rspamd_snprintf(upstream->name, namelen + 1,
"_%*s._tcp.%*s",
- (gint) (plus_pos - service_pos), service_pos,
- (gint) (semicolon_pos - (plus_pos + 1)), plus_pos + 1);
+ (int) (plus_pos - service_pos), service_pos,
+ (int) (semicolon_pos - (plus_pos + 1)), plus_pos + 1);
upstream->flags |= RSPAMD_UPSTREAM_FLAG_SRV_RESOLVE;
ret = RSPAMD_PARSE_ADDR_RESOLVED;
}
upstream->ctx_pos = g_queue_peek_tail_link(ups->ctx->upstreams);
}
- guint h = rspamd_cryptobox_fast_hash(upstream->name,
- strlen(upstream->name), 0);
+ unsigned int h = rspamd_cryptobox_fast_hash(upstream->name,
+ strlen(upstream->name), 0);
memset(upstream->uid, 0, sizeof(upstream->uid));
- rspamd_encode_base32_buf((const guchar *) &h, sizeof(h),
+ rspamd_encode_base32_buf((const unsigned char *) &h, sizeof(h),
upstream->uid, sizeof(upstream->uid) - 1, RSPAMD_BASE32_DEFAULT);
msg_debug_upstream("added upstream %s (%s)", upstream->name,
gboolean
rspamd_upstreams_parse_line_len(struct upstream_list *ups,
- const gchar *str, gsize len, guint16 def_port, void *data)
+ const char *str, gsize len, uint16_t def_port, void *data)
{
- const gchar *end = str + len, *p = str;
- const gchar *separators = ";, \n\r\t";
- gchar *tmp;
- guint span_len;
+ const char *end = str + len, *p = str;
+ const char *separators = ";, \n\r\t";
+ char *tmp;
+ unsigned int span_len;
gboolean ret = FALSE;
if (RSPAMD_LEN_CHECK_STARTS_WITH(p, len, "random:")) {
gboolean
rspamd_upstreams_parse_line(struct upstream_list *ups,
- const gchar *str, guint16 def_port, void *data)
+ const char *str, uint16_t def_port, void *data)
{
return rspamd_upstreams_parse_line_len(ups, str, strlen(str),
def_port, data);
gboolean
rspamd_upstreams_from_ucl(struct upstream_list *ups,
- const ucl_object_t *in, guint16 def_port, void *data)
+ const ucl_object_t *in, uint16_t def_port, void *data)
{
gboolean ret = FALSE;
const ucl_object_t *cur;
void rspamd_upstreams_destroy(struct upstream_list *ups)
{
- guint i;
+ unsigned int i;
struct upstream *up;
struct upstream_list_watcher *w, *tmp;
struct upstream *except)
{
for (;;) {
- guint idx = ottery_rand_range(ups->alive->len - 1);
+ unsigned int idx = ottery_rand_range(ups->alive->len - 1);
struct upstream *up;
up = g_ptr_array_index(ups->alive, idx);
struct upstream *except,
gboolean use_cur)
{
- guint max_weight = 0, min_checked = G_MAXUINT;
+ unsigned int max_weight = 0, min_checked = G_MAXUINT;
struct upstream *up = NULL, *selected = NULL, *min_checked_sel = NULL;
- guint i;
+ unsigned int i;
/* Select upstream with the maximum cur_weight */
RSPAMD_UPSTREAM_LOCK(ups);
static struct upstream *
rspamd_upstream_get_hashed(struct upstream_list *ups,
struct upstream *except,
- const guint8 *key, guint keylen)
+ const uint8_t *key, unsigned int keylen)
{
uint64_t k;
uint32_t idx;
- static const guint max_tries = 20;
+ static const unsigned int max_tries = 20;
struct upstream *up = NULL;
/* Generate 64 bits input key */
/*
* Select new upstream from all upstreams
*/
- for (guint i = 0; i < max_tries; i++) {
+ for (unsigned int i = 0; i < max_tries; i++) {
idx = rspamd_consistent_hash(k, ups->ups->len);
up = g_ptr_array_index(ups->ups, idx);
rspamd_upstream_get_common(struct upstream_list *ups,
struct upstream *except,
enum rspamd_upstream_rotation default_type,
- const guchar *key, gsize keylen,
+ const unsigned char *key, gsize keylen,
gboolean forced)
{
enum rspamd_upstream_rotation type;
struct upstream *
rspamd_upstream_get(struct upstream_list *ups,
enum rspamd_upstream_rotation default_type,
- const guchar *key, gsize keylen)
+ const unsigned char *key, gsize keylen)
{
return rspamd_upstream_get_common(ups, NULL, default_type, key, keylen, FALSE);
}
struct upstream *
rspamd_upstream_get_forced(struct upstream_list *ups,
enum rspamd_upstream_rotation forced_type,
- const guchar *key, gsize keylen)
+ const unsigned char *key, gsize keylen)
{
return rspamd_upstream_get_common(ups, NULL, forced_type, key, keylen, TRUE);
}
struct upstream *rspamd_upstream_get_except(struct upstream_list *ups,
struct upstream *except,
enum rspamd_upstream_rotation default_type,
- const guchar *key, gsize keylen)
+ const unsigned char *key, gsize keylen)
{
return rspamd_upstream_get_common(ups, except, default_type, key, keylen, FALSE);
}
rspamd_upstream_traverse_func cb, void *ud)
{
struct upstream *up;
- guint i;
+ unsigned int i;
for (i = 0; i < ups->ups->len; i++) {
up = g_ptr_array_index(ups->ups, i);
}
void rspamd_upstreams_set_limits(struct upstream_list *ups,
- gdouble revive_time,
- gdouble revive_jitter,
- gdouble error_time,
- gdouble dns_timeout,
- guint max_errors,
- guint dns_retransmits)
+ double revive_time,
+ double revive_jitter,
+ double error_time,
+ double dns_timeout,
+ unsigned int max_errors,
+ unsigned int dns_retransmits)
{
struct upstream_limits *nlimits;
g_assert(ups != NULL);
/*
- * Copyright 2023 Vsevolod Stakhov
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
/**
* Add an error to an upstream
*/
-void rspamd_upstream_fail(struct upstream *upstream, gboolean addr_failure, const gchar *reason);
+void rspamd_upstream_fail(struct upstream *upstream, gboolean addr_failure, const char *reason);
/**
* Increase upstream successes count
* Set weight for an upstream
* @param up
*/
-void rspamd_upstream_set_weight(struct upstream *up, guint weight);
+void rspamd_upstream_set_weight(struct upstream *up, unsigned int weight);
/**
* Create new list of upstreams
* @param dns_retransmits
*/
void rspamd_upstreams_set_limits(struct upstream_list *ups,
- gdouble revive_time,
- gdouble revive_jitter,
- gdouble error_time,
- gdouble dns_timeout,
- guint max_errors,
- guint dns_retransmits);
+ double revive_time,
+ double revive_jitter,
+ double error_time,
+ double dns_timeout,
+ unsigned int max_errors,
+ unsigned int dns_retransmits);
/**
* Sets rotation policy for upstreams list
* @param data optional userdata
* @return TRUE if upstream has been added
*/
-gboolean rspamd_upstreams_add_upstream(struct upstream_list *ups, const gchar *str,
- guint16 def_port, enum rspamd_upstream_parse_type parse_type,
+gboolean rspamd_upstreams_add_upstream(struct upstream_list *ups, const char *str,
+ uint16_t def_port, enum rspamd_upstream_parse_type parse_type,
void *data);
/**
* @return TRUE if **any** of upstreams has been added
*/
gboolean rspamd_upstreams_parse_line(struct upstream_list *ups,
- const gchar *str, guint16 def_port, void *data);
+ const char *str, uint16_t def_port, void *data);
gboolean rspamd_upstreams_parse_line_len(struct upstream_list *ups,
- const gchar *str, gsize len,
- guint16 def_port,
+ const char *str, gsize len,
+ uint16_t def_port,
void *data);
/**
* @return
*/
gboolean rspamd_upstreams_from_ucl(struct upstream_list *ups,
- const ucl_object_t *in, guint16 def_port, void *data);
+ const ucl_object_t *in, uint16_t def_port, void *data);
-typedef void (*rspamd_upstream_traverse_func)(struct upstream *up, guint idx,
+typedef void (*rspamd_upstream_traverse_func)(struct upstream *up, unsigned int idx,
void *ud);
/**
typedef void (*rspamd_upstream_watch_func)(struct upstream *up,
enum rspamd_upstreams_watch_event event,
- guint cur_errors,
+ unsigned int cur_errors,
void *ud);
/**
* @param up
* @return
*/
-const gchar *rspamd_upstream_name(struct upstream *up);
+const char *rspamd_upstream_name(struct upstream *up);
/**
* Returns the port of the current address for the upstream
* @param up
* @return
*/
-gint rspamd_upstream_port(struct upstream *up);
+int rspamd_upstream_port(struct upstream *up);
/**
* Sets opaque user data associated with this upstream
*/
struct upstream *rspamd_upstream_get(struct upstream_list *ups,
enum rspamd_upstream_rotation default_type,
- const guchar *key, gsize keylen);
+ const unsigned char *key, gsize keylen);
/**
* Get new upstream from the list
*/
struct upstream *rspamd_upstream_get_forced(struct upstream_list *ups,
enum rspamd_upstream_rotation forced_type,
- const guchar *key, gsize keylen);
+ const unsigned char *key, gsize keylen);
/**
* Get new upstream from the list excepting the upstream specified
struct upstream *rspamd_upstream_get_except(struct upstream_list *ups,
struct upstream *except,
enum rspamd_upstream_rotation default_type,
- const guchar *key, gsize keylen);
+ const unsigned char *key, gsize keylen);
/**
* Re-resolve addresses for all upstreams registered
.salt_len = 20,
.key_len = rspamd_cryptobox_HASHBYTES / 2}};
-gint rspamd_socket_nonblocking(gint fd)
+int rspamd_socket_nonblocking(int fd)
{
- gint ofl;
+ int ofl;
ofl = fcntl(fd, F_GETFL, 0);
return 0;
}
-gint rspamd_socket_blocking(gint fd)
+int rspamd_socket_blocking(int fd)
{
- gint ofl;
+ int ofl;
ofl = fcntl(fd, F_GETFL, 0);
return 0;
}
-gint rspamd_socket_poll(gint fd, gint timeout, short events)
+int rspamd_socket_poll(int fd, int timeout, short events)
{
- gint r;
+ int r;
struct pollfd fds[1];
fds->fd = fd;
return r;
}
-gint rspamd_socket_create(gint af, gint type, gint protocol, gboolean async)
+int rspamd_socket_create(int af, int type, int protocol, gboolean async)
{
- gint fd;
+ int fd;
fd = socket(af, type, protocol);
if (fd == -1) {
return fd;
}
-static gint
-rspamd_inet_socket_create(gint type, struct addrinfo *addr, gboolean is_server,
+static int
+rspamd_inet_socket_create(int type, struct addrinfo *addr, gboolean is_server,
gboolean async, GList **list)
{
- gint fd = -1, r, on = 1, s_error;
+ int fd = -1, r, on = 1, s_error;
struct addrinfo *cur;
gpointer ptr;
socklen_t optlen;
if (is_server) {
(void) setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *) &on,
- sizeof(gint));
+ sizeof(int));
#ifdef HAVE_IPV6_V6ONLY
if (cur->ai_family == AF_INET6) {
setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (const void *) &on,
- sizeof(gint));
+ sizeof(int));
}
#endif
r = bind(fd, cur->ai_addr, cur->ai_addrlen);
return (fd);
}
-gint rspamd_socket_tcp(struct addrinfo *addr, gboolean is_server, gboolean async)
+int rspamd_socket_tcp(struct addrinfo *addr, gboolean is_server, gboolean async)
{
return rspamd_inet_socket_create(SOCK_STREAM, addr, is_server, async, NULL);
}
-gint rspamd_socket_udp(struct addrinfo *addr, gboolean is_server, gboolean async)
+int rspamd_socket_udp(struct addrinfo *addr, gboolean is_server, gboolean async)
{
return rspamd_inet_socket_create(SOCK_DGRAM, addr, is_server, async, NULL);
}
-gint rspamd_socket_unix(const gchar *path,
- struct sockaddr_un *addr,
- gint type,
- gboolean is_server,
- gboolean async)
+int rspamd_socket_unix(const char *path,
+ struct sockaddr_un *addr,
+ int type,
+ gboolean is_server,
+ gboolean async)
{
socklen_t optlen;
- gint fd = -1, s_error, r, serrno, on = 1;
+ int fd = -1, s_error, r, serrno, on = 1;
struct stat st;
if (path == NULL)
}
if (is_server) {
(void) setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *) &on,
- sizeof(gint));
+ sizeof(int));
r = bind(fd, (struct sockaddr *) addr, SUN_LEN(addr));
}
else {
* @param is_server make this socket as server socket
* @param try_resolve try name resolution for a socket (BLOCKING)
*/
-gint rspamd_socket(const gchar *credits, guint16 port,
- gint type, gboolean async, gboolean is_server, gboolean try_resolve)
+int rspamd_socket(const char *credits, uint16_t port,
+ int type, gboolean async, gboolean is_server, gboolean try_resolve)
{
struct sockaddr_un un;
struct stat st;
struct addrinfo hints, *res;
- gint r;
- gchar portbuf[8];
+ int r;
+ char portbuf[8];
if (*credits == '/') {
if (is_server) {
}
gboolean
-rspamd_socketpair(gint pair[2], gint af)
+rspamd_socketpair(int pair[2], int af)
{
- gint r = -1, serrno;
+ int r = -1, serrno;
#ifdef HAVE_SOCK_SEQPACKET
if (af == SOCK_SEQPACKET) {
}
#ifdef HAVE_SA_SIGINFO
-void rspamd_signals_init(struct sigaction *signals, void (*sig_handler)(gint,
+void rspamd_signals_init(struct sigaction *signals, void (*sig_handler)(int,
siginfo_t *,
void *))
#else
-void rspamd_signals_init(struct sigaction *signals, void (*sig_handler)(gint))
+void rspamd_signals_init(struct sigaction *signals, void (*sig_handler)(int))
#endif
{
struct sigaction sigpipe_act;
#ifndef HAVE_SETPROCTITLE
#ifdef LINUX
-static gchar *title_buffer = NULL;
+static char *title_buffer = NULL;
static size_t title_buffer_size = 0;
-static gchar *title_progname, *title_progname_full;
-gchar **old_environ = NULL;
+static char *title_progname, *title_progname_full;
+char **old_environ = NULL;
static void
rspamd_title_dtor(gpointer d)
environ = old_environ;
}
- gchar **env = (gchar **) d;
- guint i;
+ char **env = (char **) d;
+ unsigned int i;
for (i = 0; env[i] != NULL; i++) {
g_free(env[i]);
#endif /* ifndef HAVE_SETPROCTITLE */
-gint rspamd_init_title(rspamd_mempool_t *pool,
- gint argc, gchar *argv[], gchar *envp[])
+int rspamd_init_title(rspamd_mempool_t *pool,
+ int argc, char *argv[], char *envp[])
{
#if defined(LINUX) && !defined(HAVE_SETPROCTITLE)
- gchar *begin_of_buffer = 0, *end_of_buffer = 0;
- gint i;
+ char *begin_of_buffer = 0, *end_of_buffer = 0;
+ int i;
for (i = 0; i < argc; ++i) {
if (!begin_of_buffer) {
return 0;
}
- gchar **new_environ = g_malloc((i + 1) * sizeof(envp[0]));
+ char **new_environ = g_malloc((i + 1) * sizeof(envp[0]));
for (i = 0; envp[i]; ++i) {
new_environ[i] = g_strdup(envp[i]);
if (program_invocation_name) {
title_progname_full = g_strdup(program_invocation_name);
- gchar *p = strrchr(title_progname_full, '/');
+ char *p = strrchr(title_progname_full, '/');
if (p) {
title_progname = p + 1;
return 0;
}
-gint rspamd_setproctitle(const gchar *fmt, ...)
+int rspamd_setproctitle(const char *fmt, ...)
{
#ifdef HAVE_SETPROCTITLE
if (fmt) {
#ifndef HAVE_PIDFILE
-static gint _rspamd_pidfile_remove(rspamd_pidfh_t *pfh, gint freeit);
+static int _rspamd_pidfile_remove(rspamd_pidfh_t *pfh, int freeit);
-static gint
+static int
rspamd_pidfile_verify(rspamd_pidfh_t *pfh)
{
struct stat sb;
return 0;
}
-static gint
-rspamd_pidfile_read(const gchar *path, pid_t *pidptr)
+static int
+rspamd_pidfile_read(const char *path, pid_t *pidptr)
{
- gchar buf[16], *endptr;
- gint error, fd, i;
+ char buf[16], *endptr;
+ int error, fd, i;
fd = open(path, O_RDONLY);
if (fd == -1)
}
rspamd_pidfh_t *
-rspamd_pidfile_open(const gchar *path, mode_t mode, pid_t *pidptr)
+rspamd_pidfile_open(const char *path, mode_t mode, pid_t *pidptr)
{
rspamd_pidfh_t *pfh;
struct stat sb;
- gint error, fd, len, count;
+ int error, fd, len, count;
struct timespec rqtp;
pfh = g_malloc(sizeof(*pfh));
g_get_prgname());
else
len = snprintf(pfh->pf_path, sizeof(pfh->pf_path), "%s", path);
- if (len >= (gint) sizeof(pfh->pf_path)) {
+ if (len >= (int) sizeof(pfh->pf_path)) {
g_free(pfh);
errno = ENAMETOOLONG;
return NULL;
return pfh;
}
-gint rspamd_pidfile_write(rspamd_pidfh_t *pfh)
+int rspamd_pidfile_write(rspamd_pidfh_t *pfh)
{
- gchar pidstr[16];
- gint error, fd;
+ char pidstr[16];
+ int error, fd;
/*
* Check remembered descriptor, so we don't overwrite some other
return 0;
}
-gint rspamd_pidfile_close(rspamd_pidfh_t *pfh)
+int rspamd_pidfile_close(rspamd_pidfh_t *pfh)
{
- gint error;
+ int error;
error = rspamd_pidfile_verify(pfh);
if (error != 0) {
return 0;
}
-static gint
-_rspamd_pidfile_remove(rspamd_pidfh_t *pfh, gint freeit)
+static int
+_rspamd_pidfile_remove(rspamd_pidfh_t *pfh, int freeit)
{
- gint error;
+ int error;
error = rspamd_pidfile_verify(pfh);
if (error != 0) {
return 0;
}
-gint rspamd_pidfile_remove(rspamd_pidfh_t *pfh)
+int rspamd_pidfile_remove(rspamd_pidfh_t *pfh)
{
return (_rspamd_pidfile_remove(pfh, 1));
#endif
/* Replace %r with rcpt value and %f with from value, new string is allocated in pool */
-gchar *
+char *
resolve_stat_filename(rspamd_mempool_t *pool,
- gchar *pattern,
- gchar *rcpt,
- gchar *from)
+ char *pattern,
+ char *rcpt,
+ char *from)
{
- gint need_to_format = 0, len = 0;
- gint rcptlen, fromlen;
- gchar *c = pattern, *new, *s;
+ int need_to_format = 0, len = 0;
+ int rcptlen, fromlen;
+ char *c = pattern, *new, *s;
if (rcpt) {
rcptlen = strlen(rcpt);
return new;
}
-const gchar *
-rspamd_log_check_time(gdouble start, gdouble end, gint resolution)
+const char *
+rspamd_log_check_time(double start, double end, int resolution)
{
- gdouble diff;
- static gchar res[64];
- gchar fmt[32];
+ double diff;
+ static char res[64];
+ char fmt[32];
diff = (end - start) * 1000.0;
rspamd_snprintf(fmt, sizeof(fmt), "%%.%dfms", resolution);
rspamd_snprintf(res, sizeof(res), fmt, diff);
- return (const gchar *) res;
+ return (const char *) res;
}
#ifdef HAVE_FLOCK
/* Flock version */
gboolean
-rspamd_file_lock(gint fd, gboolean async)
+rspamd_file_lock(int fd, gboolean async)
{
- gint flags;
+ int flags;
if (async) {
flags = LOCK_EX | LOCK_NB;
}
gboolean
-rspamd_file_unlock(gint fd, gboolean async)
+rspamd_file_unlock(int fd, gboolean async)
{
- gint flags;
+ int flags;
if (async) {
flags = LOCK_UN | LOCK_NB;
#else /* HAVE_FLOCK */
/* Fctnl version */
gboolean
-rspamd_file_lock(gint fd, gboolean async)
+rspamd_file_lock(int fd, gboolean async)
{
struct flock fl = {
.l_type = F_WRLCK,
}
gboolean
-rspamd_file_unlock(gint fd, gboolean async)
+rspamd_file_unlock(int fd, gboolean async)
{
struct flock fl = {
.l_type = F_UNLCK,
{
return *((const int64_t *) v1) == *((const int64_t *) v2);
}
-guint g_int64_hash(gconstpointer v)
+unsigned int g_int64_hash(gconstpointer v)
{
uint64_t v64 = *(uint64_t *) v;
- return (guint) (v ^ (v >> 32));
+ return (unsigned int) (v ^ (v >> 32));
}
#endif
#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 14))
#endif
#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 30))
GPtrArray *
-g_ptr_array_new_full(guint reserved_size,
+g_ptr_array_new_full(unsigned int reserved_size,
GDestroyNotify element_free_func)
{
GPtrArray *array;
#endif
#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 40))
-void g_ptr_array_insert(GPtrArray *array, gint index_, gpointer data)
+void g_ptr_array_insert(GPtrArray *array, int index_, gpointer data)
{
g_return_if_fail(array);
g_return_if_fail(index_ >= -1);
- g_return_if_fail(index_ <= (gint) array->len);
+ g_return_if_fail(index_ <= (int) array->len);
g_ptr_array_set_size(array, array->len + 1);
#endif
#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 32))
-const gchar *
-g_environ_getenv(gchar **envp, const gchar *variable)
+const char *
+g_environ_getenv(char **envp, const char *variable)
{
gsize len;
- gint i;
+ int i;
if (envp == NULL) {
return NULL;
}
#endif
-gint rspamd_fallocate(gint fd, off_t offset, off_t len)
+int rspamd_fallocate(int fd, off_t offset, off_t len)
{
#if defined(HAVE_FALLOCATE)
return fallocate(fd, 0, offset, len);
}
struct rspamd_thread_data {
- gchar *name;
- gint id;
+ char *name;
+ int id;
GThreadFunc func;
gpointer data;
};
#define _PATH_TTY "/dev/tty"
#endif
-gint rspamd_read_passphrase_with_prompt(const gchar *prompt, gchar *buf, gint size, bool echo, gpointer key)
+int rspamd_read_passphrase_with_prompt(const char *prompt, char *buf, int size, bool echo, gpointer key)
{
#ifdef HAVE_READPASSPHRASE_H
int flags = echo ? RPP_ECHO_ON : RPP_ECHO_OFF;
struct sigaction sa, savealrm, saveint, savehup, savequit, saveterm;
struct sigaction savetstp, savettin, savettou, savepipe;
struct termios term, oterm;
- gint input, output, i;
- gchar *end, *p, ch;
+ int input, output, i;
+ char *end, *p, ch;
restart:
if ((input = output = open(_PATH_TTY, O_RDWR)) == -1) {
#endif
#endif
-gdouble
+double
rspamd_get_ticks(gboolean rdtsc_ok)
{
- gdouble res;
+ double res;
#ifdef HAVE_RDTSC
#ifdef __x86_64__
#endif
#ifdef HAVE_CLOCK_GETTIME
struct timespec ts;
- gint clk_id = RSPAMD_FAST_MONOTONIC_CLOCK;
+ int clk_id = RSPAMD_FAST_MONOTONIC_CLOCK;
clock_gettime(clk_id, &ts);
return res;
}
-gdouble
+double
rspamd_get_virtual_ticks(void)
{
- gdouble res;
+ double res;
#ifdef HAVE_CLOCK_GETTIME
struct timespec ts;
}
res = info.user_time.seconds + info.system_time.seconds;
- res += ((gdouble) (info.user_time.microseconds + info.system_time.microseconds)) / 1e6;
+ res += ((double) (info.user_time.microseconds + info.system_time.microseconds)) / 1e6;
mach_port_deallocate(mach_task_self(), thread);
#elif defined(HAVE_RUSAGE_SELF)
struct rusage rusage;
return res;
}
-gdouble
+double
rspamd_get_calendar_ticks(void)
{
- gdouble res;
+ double res;
#ifdef HAVE_CLOCK_GETTIME
struct timespec ts;
return res;
}
-void rspamd_random_hex(gchar *buf, uint64_t len)
+void rspamd_random_hex(char *buf, uint64_t len)
{
- static const gchar hexdigests[16] = "0123456789abcdef";
+ static const char hexdigests[16] = "0123456789abcdef";
int64_t i;
g_assert(len > 0);
}
}
-gint rspamd_shmem_mkstemp(gchar *pattern)
+int rspamd_shmem_mkstemp(char *pattern)
{
- gint fd = -1;
- gchar *nbuf, *xpos;
+ int fd = -1;
+ char *nbuf, *xpos;
gsize blen;
xpos = strchr(pattern, 'X');
return 0xabf9727ba290690bULL;
}
-static inline gdouble
+static inline double
rspamd_double_from_int64(uint64_t x)
{
const union {
return u.d - 1.0;
}
-gdouble
+double
rspamd_random_double(void)
{
uint64_t rnd_int;
#endif
}
-gdouble
+double
rspamd_random_double_fast(void)
{
return rspamd_random_double_fast_seed(rspamd_fast_random_seed());
}
/* xoshiro256+ */
-inline gdouble
+inline double
rspamd_random_double_fast_seed(uint64_t *seed)
{
return rspamd_double_from_int64(rspamd_random_uint64_fast_seed(seed));
(void) rspamd_fast_random_seed();
}
-gdouble
-rspamd_time_jitter(gdouble in, gdouble jitter)
+double
+rspamd_time_jitter(double in, double jitter)
{
if (jitter == 0) {
jitter = in;
rspamd_constant_memcmp(const void *a, const void *b, gsize len)
{
gsize lena, lenb, i;
- guint16 d, r = 0, m;
- guint16 v;
- const guint8 *aa = (const guint8 *) a,
- *bb = (const guint8 *) b;
+ uint16_t d, r = 0, m;
+ uint16_t v;
+ const uint8_t *aa = (const uint8_t *) a,
+ *bb = (const uint8_t *) b;
if (len == 0) {
lena = strlen((const char *) a);
}
for (i = 0; i < len; i++) {
- v = ((guint16) (guint8) r) + 255;
+ v = ((uint16_t) (uint8_t) r) + 255;
m = v / 256 - 1;
- d = (guint16) ((int) aa[i] - (int) bb[i]);
+ d = (uint16_t) ((int) aa[i] - (int) bb[i]);
r |= (d & m);
}
- return (((int32_t) (guint16) ((uint32_t) r + 0x8000) - 0x8000) == 0);
+ return (((int32_t) (uint16_t) ((uint32_t) r + 0x8000) - 0x8000) == 0);
}
-int rspamd_file_xopen(const char *fname, int oflags, guint mode,
+int rspamd_file_xopen(const char *fname, int oflags, unsigned int mode,
gboolean allow_symlink)
{
struct stat sb;
}
gpointer
-rspamd_file_xmap(const char *fname, guint mode, gsize *size,
+rspamd_file_xmap(const char *fname, unsigned int mode, gsize *size,
gboolean allow_symlink)
{
- gint fd;
+ int fd;
struct stat sb;
gpointer map;
gpointer
-rspamd_shmem_xmap(const char *fname, guint mode,
+rspamd_shmem_xmap(const char *fname, unsigned int mode,
gsize *size)
{
- gint fd;
+ int fd;
struct stat sb;
gpointer map;
* New approach:
* y = ((x - bias)*2)^8
*/
-gdouble
-rspamd_normalize_probability(gdouble x, gdouble bias)
+double
+rspamd_normalize_probability(double x, double bias)
{
- gdouble xx;
+ double xx;
xx = (x - bias) * 2.0;
{
uint64_t result;
gboolean is_leap = FALSE;
- gint leaps, y = tm->tm_year, cycles, rem, centuries;
+ int leaps, y = tm->tm_year, cycles, rem, centuries;
glong offset = (tz / 100) * 3600 + (tz % 100) * 60;
/* How many seconds in each month from the beginning of the year */
- static const gint secs_through_month[] = {
+ static const int secs_through_month[] = {
0, 31 * 86400, 59 * 86400, 90 * 86400,
120 * 86400, 151 * 86400, 181 * 86400, 212 * 86400,
243 * 86400, 273 * 86400, 304 * 86400, 334 * 86400};
}
}
- leaps += 97 * cycles + 24 * centuries - (gint) is_leap;
+ leaps += 97 * cycles + 24 * centuries - (int) is_leap;
result = (y - 100) * 31536000LL + leaps * 86400LL + 946684800 + 86400;
}
}
static gboolean
-rspamd_glob_dir(const gchar *full_path, const gchar *pattern,
- gboolean recursive, guint rec_len,
+rspamd_glob_dir(const char *full_path, const char *pattern,
+ gboolean recursive, unsigned int rec_len,
GPtrArray *res, GError **err)
{
glob_t globbuf;
- const gchar *path;
- static gchar pathbuf[PATH_MAX]; /* Static to help recursion */
- guint i;
- gint rc;
- static const guint rec_lim = 16;
+ const char *path;
+ static char pathbuf[PATH_MAX]; /* Static to help recursion */
+ unsigned int i;
+ int rc;
+ static const unsigned int rec_lim = 16;
struct stat st;
if (rec_len > rec_lim) {
}
GPtrArray *
-rspamd_glob_path(const gchar *dir,
- const gchar *pattern,
+rspamd_glob_path(const char *dir,
+ const char *pattern,
gboolean recursive,
GError **err)
{
- gchar path[PATH_MAX];
+ char path[PATH_MAX];
GPtrArray *res;
res = g_ptr_array_new_full(32, (GDestroyNotify) g_free);
}
double
-rspamd_set_counter(struct rspamd_counter_data *cd, gdouble value)
+rspamd_set_counter(struct rspamd_counter_data *cd, double value)
{
- gdouble cerr;
+ double cerr;
/* Cumulative moving average using per-process counter data */
if (cd->number == 0) {
cd->stddev = 0;
}
- cd->mean += (value - cd->mean) / (gdouble) (++cd->number);
+ cd->mean += (value - cd->mean) / (double) (++cd->number);
cerr = (value - cd->mean) * (value - cd->mean);
- cd->stddev += (cerr - cd->stddev) / (gdouble) (cd->number);
+ cd->stddev += (cerr - cd->stddev) / (double) (cd->number);
return cd->mean;
}
return;
}
- guint n = ar->len;
+ unsigned int n = ar->len;
- for (guint i = 0; i < n - 1; i++) {
- guint j = i + rspamd_random_uint64_fast() % (n - i);
+ for (unsigned int i = 0; i < n - 1; i++) {
+ unsigned int j = i + rspamd_random_uint64_fast() % (n - i);
gpointer t = g_ptr_array_index(ar, j);
g_ptr_array_index(ar, j) = g_ptr_array_index(ar, i);
g_ptr_array_index(ar, i) = t;
return sum;
}
-void rspamd_normalize_path_inplace(gchar *path, guint len, gsize *nlen)
+void rspamd_normalize_path_inplace(char *path, unsigned int len, gsize *nlen)
{
- const gchar *p, *end, *slash = NULL, *dot = NULL;
- gchar *o;
+ const char *p, *end, *slash = NULL, *dot = NULL;
+ char *o;
enum {
st_normal = 0,
st_got_dot,
}
if (slash) {
- o = (gchar *) slash;
+ o = (char *) slash;
}
/* Otherwise we keep these dots */
slash = p;
if (slash) {
/* Remove last / */
- o = (gchar *) slash;
+ o = (char *) slash;
}
}
else {
*/
struct rspamd_process_exception {
goffset pos;
- guint len;
+ unsigned int len;
gpointer ptr;
enum rspamd_exception_type type;
};
* @param async set non-blocking on a socket
* @return socket FD or -1 in case of error
*/
-gint rspamd_socket_create(gint af, gint type, gint protocol, gboolean async);
+int rspamd_socket_create(int af, int type, int protocol, gboolean async);
/*
* Create socket and bind or connect it to specified address and port
*/
-gint rspamd_socket_tcp(struct addrinfo *, gboolean is_server, gboolean async);
+int rspamd_socket_tcp(struct addrinfo *, gboolean is_server, gboolean async);
/*
* Create socket and bind or connect it to specified address and port
*/
-gint rspamd_socket_udp(struct addrinfo *, gboolean is_server, gboolean async);
+int rspamd_socket_udp(struct addrinfo *, gboolean is_server, gboolean async);
/*
* Create and bind or connect unix socket
*/
-gint rspamd_socket_unix(const gchar *,
- struct sockaddr_un *,
- gint type,
- gboolean is_server,
- gboolean async);
+int rspamd_socket_unix(const char *,
+ struct sockaddr_un *,
+ int type,
+ gboolean is_server,
+ gboolean async);
/**
* Make a universal socket
* @param is_server make this socket as server socket
* @param try_resolve try name resolution for a socket (BLOCKING)
*/
-gint rspamd_socket(const gchar *credits, guint16 port, gint type,
- gboolean async, gboolean is_server, gboolean try_resolve);
+int rspamd_socket(const char *credits, uint16_t port, int type,
+ gboolean async, gboolean is_server, gboolean try_resolve);
/*
* Create socketpair
*/
-gboolean rspamd_socketpair(gint pair[2], gint af);
+gboolean rspamd_socketpair(int pair[2], int af);
/*
* Make specified socket non-blocking
*/
-gint rspamd_socket_nonblocking(gint);
+int rspamd_socket_nonblocking(int);
/*
* Make specified socket blocking
*/
-gint rspamd_socket_blocking(gint);
+int rspamd_socket_blocking(int);
/*
* Poll a sync socket for specified events
*/
-gint rspamd_socket_poll(gint fd, gint timeout, short events);
+int rspamd_socket_poll(int fd, int timeout, short events);
/*
* Init signals
*/
#ifdef HAVE_SA_SIGINFO
-void rspamd_signals_init(struct sigaction *sa, void (*sig_handler)(gint,
+void rspamd_signals_init(struct sigaction *sa, void (*sig_handler)(int,
siginfo_t *,
void *));
#else
-void rspamd_signals_init(struct sigaction *sa, void (*sig_handler)(gint));
+void rspamd_signals_init(struct sigaction *sa, void (*sig_handler)(int));
#endif
/*
* Process title utility functions
*/
-gint rspamd_init_title(rspamd_mempool_t *pool, gint argc, gchar *argv[], gchar *envp[]);
-gint rspamd_setproctitle(const gchar *fmt, ...);
+int rspamd_init_title(rspamd_mempool_t *pool, int argc, char *argv[], char *envp[]);
+int rspamd_setproctitle(const char *fmt, ...);
#ifndef HAVE_PIDFILE
/*
* Pidfile functions from FreeBSD libutil code
*/
typedef struct rspamd_pidfh_s {
- gint pf_fd;
+ int pf_fd;
#ifdef HAVE_PATH_MAX
- gchar pf_path[PATH_MAX + 1];
+ char pf_path[PATH_MAX + 1];
#elif defined(HAVE_MAXPATHLEN)
- gchar pf_path[MAXPATHLEN + 1];
+ char pf_path[MAXPATHLEN + 1];
#else
- gchar pf_path[1024 + 1];
+ char pf_path[1024 + 1];
#endif
dev_t pf_dev;
ino_t pf_ino;
} rspamd_pidfh_t;
-rspamd_pidfh_t *rspamd_pidfile_open(const gchar *path,
+rspamd_pidfh_t *rspamd_pidfile_open(const char *path,
mode_t mode,
pid_t *pidptr);
-gint rspamd_pidfile_write(rspamd_pidfh_t *pfh);
+int rspamd_pidfile_write(rspamd_pidfh_t *pfh);
-gint rspamd_pidfile_close(rspamd_pidfh_t *pfh);
+int rspamd_pidfile_close(rspamd_pidfh_t *pfh);
-gint rspamd_pidfile_remove(rspamd_pidfh_t *pfh);
+int rspamd_pidfile_remove(rspamd_pidfh_t *pfh);
#else
typedef struct pidfh rspamd_pidfh_t;
/*
* Replace %r with rcpt value and %f with from value, new string is allocated in pool
*/
-gchar *resolve_stat_filename(rspamd_mempool_t *pool,
- gchar *pattern,
- gchar *rcpt,
- gchar *from);
+char *resolve_stat_filename(rspamd_mempool_t *pool,
+ char *pattern,
+ char *rcpt,
+ char *from);
-const gchar *
-rspamd_log_check_time(gdouble start, gdouble end, gint resolution);
+const char *
+rspamd_log_check_time(double start, double end, int resolution);
/*
* File locking functions
*/
-gboolean rspamd_file_lock(gint fd, gboolean async);
+gboolean rspamd_file_lock(int fd, gboolean async);
-gboolean rspamd_file_unlock(gint fd, gboolean async);
+gboolean rspamd_file_unlock(int fd, gboolean async);
/*
* Workarounds for older versions of glib
#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 22))
void g_ptr_array_unref(GPtrArray *array);
gboolean g_int64_equal(gconstpointer v1, gconstpointer v2);
-guint g_int64_hash(gconstpointer v);
+unsigned int g_int64_hash(gconstpointer v);
#endif
#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 14))
void g_queue_clear(GQueue *queue);
void g_queue_free_full(GQueue *queue, GDestroyNotify free_func);
#endif
#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 40))
-void g_ptr_array_insert(GPtrArray *array, gint index_, gpointer data);
+void g_ptr_array_insert(GPtrArray *array, int index_, gpointer data);
#endif
#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 30))
-GPtrArray *g_ptr_array_new_full(guint reserved_size,
+GPtrArray *g_ptr_array_new_full(unsigned int reserved_size,
GDestroyNotify element_free_func);
#endif
#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 32))
-const gchar *g_environ_getenv(gchar **envp, const gchar *variable);
+const char *g_environ_getenv(char **envp, const char *variable);
#endif
/*
* @param len length to allocate
* @return -1 in case of failure
*/
-gint rspamd_fallocate(gint fd, off_t offset, off_t len);
+int rspamd_fallocate(int fd, off_t offset, off_t len);
/**
* Utils for working with threads to be compatible with all glib versions
* @param key unused key
* @return
*/
-gint rspamd_read_passphrase_with_prompt(const gchar *prompt, gchar *buf, gint size, bool echo, gpointer key);
+int rspamd_read_passphrase_with_prompt(const char *prompt, char *buf, int size, bool echo, gpointer key);
/**
* Portably return the current clock ticks as seconds
* @return
*/
-gdouble rspamd_get_ticks(gboolean rdtsc_ok);
+double rspamd_get_ticks(gboolean rdtsc_ok);
/**
* Portably return the current virtual clock ticks as seconds
* @return
*/
-gdouble rspamd_get_virtual_ticks(void);
+double rspamd_get_virtual_ticks(void);
/**
* Return the real timestamp as unixtime
*/
-gdouble rspamd_get_calendar_ticks(void);
+double rspamd_get_calendar_ticks(void);
/**
* Special utility to help array freeing in rspamd_mempool
* @param buf
* @param len
*/
-void rspamd_random_hex(gchar *buf, uint64_t len);
+void rspamd_random_hex(char *buf, uint64_t len);
/**
* Returns
* @param pattern pattern to create (should end with some number of X symbols), modified by this function
* @return
*/
-gint rspamd_shmem_mkstemp(gchar *pattern);
+int rspamd_shmem_mkstemp(char *pattern);
/**
* Return jittered time value
*/
-gdouble rspamd_time_jitter(gdouble in, gdouble jitter);
+double rspamd_time_jitter(double in, double jitter);
/**
* Return random double in range [0..1)
* @return
*/
-gdouble rspamd_random_double(void);
+double rspamd_random_double(void);
/**
* Return random double in range [0..1) using xoroshiro128+ algorithm (not crypto secure)
* @return
*/
-gdouble rspamd_random_double_fast(void);
-gdouble rspamd_random_double_fast_seed(uint64_t *seed);
+double rspamd_random_double_fast(void);
+double rspamd_random_double_fast_seed(uint64_t *seed);
uint64_t rspamd_random_uint64_fast_seed(uint64_t *seed);
uint64_t rspamd_random_uint64_fast(void);
* @param mode mode to open
* @return fd or -1 in case of error
*/
-int rspamd_file_xopen(const char *fname, int oflags, guint mode,
+int rspamd_file_xopen(const char *fname, int oflags, unsigned int mode,
gboolean allow_symlink);
/**
* @param size target size (must NOT be NULL)
* @return pointer to memory (should be freed using munmap) or NULL in case of error
*/
-gpointer rspamd_file_xmap(const char *fname, guint mode, gsize *size,
+gpointer rspamd_file_xmap(const char *fname, unsigned int mode, gsize *size,
gboolean allow_symlink);
/**
* @param size target size (must NOT be NULL)
* @return pointer to memory (should be freed using munmap) or NULL in case of error
*/
-gpointer rspamd_shmem_xmap(const char *fname, guint mode,
+gpointer rspamd_shmem_xmap(const char *fname, unsigned int mode,
gsize *size);
/**
* @param x probability (bias .. 1)
* @return
*/
-gdouble rspamd_normalize_probability(gdouble x, gdouble bias);
+double rspamd_normalize_probability(double x, double bias);
/**
* Converts struct tm to time_t
* @param pattern
* @param recursive
* @param err
- * @return GPtrArray of gchar *, elements are freed when array is freed
+ * @return GPtrArray of char *, elements are freed when array is freed
*/
-GPtrArray *rspamd_glob_path(const gchar *dir,
- const gchar *pattern,
+GPtrArray *rspamd_glob_path(const char *dir,
+ const char *pattern,
gboolean recursive,
GError **err);
* @return new counter value
*/
double rspamd_set_counter(struct rspamd_counter_data *cd,
- gdouble value);
+ double value);
/**
* Shuffle elements in an array inplace
const char *alias;
const char *description;
int type; /* enum rspamd_cryptobox_pbkdf_type */
- gint id;
- guint complexity;
+ int id;
+ unsigned int complexity;
gsize salt_len;
gsize key_len;
};
* @param len
* @param nlen
*/
-void rspamd_normalize_path_inplace(gchar *path, guint len, gsize *nlen);
+void rspamd_normalize_path_inplace(char *path, unsigned int len, gsize *nlen);
#ifdef __cplusplus
}
return NULL;
}
-static gint
+static int
lua_cdb_create(lua_State *L)
{
struct cdb *cdb, **pcdb;
- const gchar *filename;
- gint fd;
+ const char *filename;
+ int fd;
struct ev_loop *ev_base = NULL;
return 1;
}
-static gint
+static int
lua_cdb_get_name(lua_State *L)
{
struct cdb *cdb = lua_check_cdb(L, 1);
return 1;
}
-static gint
+static int
lua_cdb_lookup(lua_State *L)
{
struct cdb *cdb = lua_check_cdb(L, 1);
gsize klen;
- const gchar *what = lua_cdb_get_input(L, 2, &klen);
+ const char *what = lua_cdb_get_input(L, 2, &klen);
if (!cdb || what == NULL) {
return lua_error(L);
return 1;
}
-static gint
+static int
lua_cdb_destroy(lua_State *L)
{
struct cdb *cdb = lua_check_cdb(L, 1);
return 0;
}
-static gint
+static int
lua_cdb_build(lua_State *L)
{
const char *filename = luaL_checkstring(L, 1);
return 1;
}
-static gint
+static int
lua_cdb_builder_add(lua_State *L)
{
struct cdb_make *cdbm = lua_check_cdb_builder(L, 1);
return 1;
}
-static gint
+static int
lua_cdb_builder_finalize(lua_State *L)
{
struct cdb_make *cdbm = lua_check_cdb_builder(L, 1);
return 1;
}
-static gint
+static int
lua_cdb_builder_dtor(lua_State *L)
{
struct cdb_make *cdbm = lua_check_cdb_builder(L, 1);
return 0;
}
-static gint
+static int
lua_load_cdb(lua_State *L)
{
lua_newtable(L);
/* Process a single item in 'metrics' table */
static void
-lua_process_metric(lua_State *L, const gchar *name, struct rspamd_config *cfg)
+lua_process_metric(lua_State *L, const char *name, struct rspamd_config *cfg)
{
- gchar *symbol;
- const gchar *desc = NULL;
- gdouble *score;
+ char *symbol;
+ const char *desc = NULL;
+ double *score;
struct rspamd_symbol *s;
/* Now iterate through module table */
void rspamd_lua_post_load_config(struct rspamd_config *cfg)
{
lua_State *L = cfg->lua_state;
- const gchar *name;
+ const char *name;
ucl_object_t *obj;
gsize keylen, i;
g_free);
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 2)) {
- gchar *tmp;
+ char *tmp;
lua_pushvalue(L, -2);
name = luaL_checklstring(L, -1, &keylen);
}
/* Return table of statfiles indexed by name */
-static gint
+static int
lua_classifier_get_statfiles(lua_State *L)
{
struct rspamd_classifier_config *ccf = lua_check_classifier(L);
GList *cur;
struct rspamd_statfile_config *st, **pst;
- gint i;
+ int i;
if (ccf) {
lua_newtable(L);
return 1;
}
-static gint
+static int
lua_classifier_get_param(lua_State *L)
{
struct rspamd_classifier_config *ccf = lua_check_classifier(L);
- const gchar *param;
+ const char *param;
const ucl_object_t *value;
param = luaL_checkstring(L, 2);
}
/* Get statfile with specified label */
-static gint
+static int
lua_classifier_get_statfile_by_label(lua_State *L)
{
struct rspamd_classifier_config *ccf = lua_check_classifier(L);
struct rspamd_statfile_config *st, **pst;
- const gchar *label;
+ const char *label;
GList *cur;
- gint i;
+ int i;
label = luaL_checkstring(L, 2);
if (ccf && label) {
}
/* Statfile functions */
-static gint
+static int
lua_statfile_get_symbol(lua_State *L)
{
struct rspamd_statfile_config *st = lua_check_statfile(L);
return 1;
}
-static gint
+static int
lua_statfile_get_label(lua_State *L)
{
struct rspamd_statfile_config *st = lua_check_statfile(L);
return 1;
}
-static gint
+static int
lua_statfile_is_spam(lua_State *L)
{
struct rspamd_statfile_config *st = lua_check_statfile(L);
return 1;
}
-static gint
+static int
lua_statfile_get_param(lua_State *L)
{
struct rspamd_statfile_config *st = lua_check_statfile(L);
- const gchar *param;
+ const char *param;
const ucl_object_t *value;
param = luaL_checkstring(L, 2);
}
const char *
-rspamd_lua_static_classname(const char *name, guint len)
+rspamd_lua_static_classname(const char *name, unsigned int len)
{
khiter_t k;
/*
* Return a static class name for a given name (only for known classes) or NULL
*/
-const char *rspamd_lua_static_classname(const char *name, guint len);
+const char *rspamd_lua_static_classname(const char *name, unsigned int len);
#endif//RSPAMD_LUA_CLASSNAMES_H
* @param func table of class methods
*/
void rspamd_lua_new_class(lua_State *L,
- const gchar *classname,
+ const char *classname,
const struct luaL_reg *methods)
{
khiter_t k;
- gint r, nmethods = 0;
+ int r, nmethods = 0;
gboolean seen_index = false;
struct rspamd_lua_context *ctx = rspamd_lua_ctx_by_state(L);
/* MT is left on stack ! */
}
-static const gchar *
-rspamd_lua_class_tostring_buf(lua_State *L, gboolean print_pointer, gint pos)
+static const char *
+rspamd_lua_class_tostring_buf(lua_State *L, gboolean print_pointer, int pos)
{
- static gchar buf[64];
- const gchar *ret = NULL;
- gint pop = 0;
+ static char buf[64];
+ const char *ret = NULL;
+ int pop = 0;
if (!lua_getmetatable(L, pos)) {
goto err;
return ret;
}
-gint rspamd_lua_class_tostring(lua_State *L)
+int rspamd_lua_class_tostring(lua_State *L)
{
- const gchar *p;
+ const char *p;
p = rspamd_lua_class_tostring_buf(L, TRUE, 1);
}
-void rspamd_lua_setclass(lua_State *L, const gchar *classname, gint objidx)
+void rspamd_lua_setclass(lua_State *L, const char *classname, int objidx)
{
khiter_t k;
struct rspamd_lua_context *ctx = rspamd_lua_ctx_by_state(L);
lua_setmetatable(L, objidx);
}
-void rspamd_lua_class_metatable(lua_State *L, const gchar *classname)
+void rspamd_lua_class_metatable(lua_State *L, const char *classname)
{
khiter_t k;
struct rspamd_lua_context *ctx = rspamd_lua_ctx_by_state(L);
lua_rawgeti(L, LUA_REGISTRYINDEX, kh_value(ctx->classes, k));
}
-void rspamd_lua_add_metamethod(lua_State *L, const gchar *classname,
+void rspamd_lua_add_metamethod(lua_State *L, const char *classname,
luaL_Reg *meth)
{
khiter_t k;
}
/* assume that table is at the top */
-void rspamd_lua_table_set(lua_State *L, const gchar *index, const gchar *value)
+void rspamd_lua_table_set(lua_State *L, const char *index, const char *value)
{
lua_pushstring(L, index);
if (value) {
lua_settable(L, -3);
}
-const gchar *
-rspamd_lua_table_get(lua_State *L, const gchar *index)
+const char *
+rspamd_lua_table_get(lua_State *L, const char *index)
{
- const gchar *result;
+ const char *result;
lua_pushstring(L, index);
lua_gettable(L, -2);
static void
lua_add_actions_global(lua_State *L)
{
- gint i;
+ int i;
lua_newtable(L);
void rspamd_lua_set_path(lua_State *L, const ucl_object_t *cfg_obj, GHashTable *vars)
{
- const gchar *old_path, *additional_path = NULL;
+ const char *old_path, *additional_path = NULL;
const ucl_object_t *opts = NULL;
- const gchar *rulesdir = RSPAMD_RULESDIR,
- *lualibdir = RSPAMD_LUALIBDIR,
- *libdir = RSPAMD_LIBDIR;
- const gchar *t;
+ const char *rulesdir = RSPAMD_RULESDIR,
+ *lualibdir = RSPAMD_LUALIBDIR,
+ *libdir = RSPAMD_LIBDIR;
+ const char *t;
- gchar path_buf[PATH_MAX];
+ char path_buf[PATH_MAX];
lua_getglobal(L, "package");
lua_getfield(L, -1, "path");
lua_pop(L, 1);
}
-static gint
-rspamd_lua_cmp_version_components(const gchar *comp1, const gchar *comp2)
+static int
+rspamd_lua_cmp_version_components(const char *comp1, const char *comp2)
{
- guint v1, v2;
+ unsigned int v1, v2;
v1 = strtoul(comp1, NULL, 10);
v2 = strtoul(comp2, NULL, 10);
static int
rspamd_lua_rspamd_version_cmp(lua_State *L)
{
- const gchar *ver;
- gchar **components;
- gint ret = 0;
+ const char *ver;
+ char **components;
+ int ret = 0;
if (lua_type(L, 2) == LUA_TSTRING) {
ver = lua_tostring(L, 2);
rspamd_lua_rspamd_version_numeric(lua_State *L)
{
static int64_t version_num = RSPAMD_VERSION_NUM;
- const gchar *type;
+ const char *type;
if (lua_gettop(L) >= 2 && lua_type(L, 1) == LUA_TSTRING) {
type = lua_tostring(L, 1);
static int
rspamd_lua_rspamd_version(lua_State *L)
{
- const gchar *result = NULL, *type;
+ const char *result = NULL, *type;
if (lua_gettop(L) == 0) {
result = RVERSION;
}
static gboolean
-rspamd_lua_load_env(lua_State *L, const char *fname, gint tbl_pos, GError **err)
+rspamd_lua_load_env(lua_State *L, const char *fname, int tbl_pos, GError **err)
{
- gint orig_top = lua_gettop(L), err_idx;
+ int orig_top = lua_gettop(L), err_idx;
gboolean ret = TRUE;
lua_pushcfunction(L, &rspamd_lua_traceback);
gboolean
rspamd_lua_set_env(lua_State *L, GHashTable *vars, char **lua_env, GError **err)
{
- gint orig_top = lua_gettop(L);
- gchar **env = g_get_environ();
+ int orig_top = lua_gettop(L);
+ char **env = g_get_environ();
/* Set known paths as rspamd_paths global */
lua_getglobal(L, "rspamd_paths");
if (lua_isnil(L, -1)) {
- const gchar *confdir = RSPAMD_CONFDIR,
- *local_confdir = RSPAMD_LOCAL_CONFDIR,
- *rundir = RSPAMD_RUNDIR,
- *dbdir = RSPAMD_DBDIR,
- *logdir = RSPAMD_LOGDIR,
- *wwwdir = RSPAMD_WWWDIR,
- *pluginsdir = RSPAMD_PLUGINSDIR,
- *rulesdir = RSPAMD_RULESDIR,
- *lualibdir = RSPAMD_LUALIBDIR,
- *prefix = RSPAMD_PREFIX,
- *sharedir = RSPAMD_SHAREDIR;
- const gchar *t;
+ const char *confdir = RSPAMD_CONFDIR,
+ *local_confdir = RSPAMD_LOCAL_CONFDIR,
+ *rundir = RSPAMD_RUNDIR,
+ *dbdir = RSPAMD_DBDIR,
+ *logdir = RSPAMD_LOGDIR,
+ *wwwdir = RSPAMD_WWWDIR,
+ *pluginsdir = RSPAMD_PLUGINSDIR,
+ *rulesdir = RSPAMD_RULESDIR,
+ *lualibdir = RSPAMD_LUALIBDIR,
+ *prefix = RSPAMD_PREFIX,
+ *sharedir = RSPAMD_SHAREDIR;
+ const char *t;
/* Try environment */
t = g_environ_getenv(env, "SHAREDIR");
}
}
- gint hostlen = sysconf(_SC_HOST_NAME_MAX);
+ int hostlen = sysconf(_SC_HOST_NAME_MAX);
if (hostlen <= 0) {
hostlen = 256;
hostlen++;
}
- gchar *hostbuf = g_alloca(hostlen);
+ char *hostbuf = g_alloca(hostlen);
memset(hostbuf, 0, hostlen);
gethostname(hostbuf, hostlen - 1);
lua_settable(L, -3);
if (env) {
- gint lim = g_strv_length(env);
+ int lim = g_strv_length(env);
- for (gint i = 0; i < lim; i++) {
+ for (int i = 0; i < lim; i++) {
if (RSPAMD_LEN_CHECK_STARTS_WITH(env[i], strlen(env[i]), "RSPAMD_")) {
const char *var = env[i] + sizeof("RSPAMD_") - 1, *value;
- gint varlen;
+ int varlen;
varlen = strcspn(var, "=");
value = var + varlen;
}
if (lua_env) {
- gint lim = g_strv_length(lua_env);
+ int lim = g_strv_length(lua_env);
- for (gint i = 0; i < lim; i++) {
+ for (int i = 0; i < lim; i++) {
if (!rspamd_lua_load_env(L, lua_env[i], lua_gettop(L), err)) {
return FALSE;
}
void rspamd_lua_set_globals(struct rspamd_config *cfg, lua_State *L)
{
struct rspamd_config **pcfg;
- gint orig_top = lua_gettop(L);
+ int orig_top = lua_gettop(L);
/* First check for global variable 'config' */
lua_getglobal(L, "config");
}
#ifdef WITH_LUA_TRACE
-static gint
+static int
lua_push_trace_data(lua_State *L)
{
if (lua_traces) {
}
-void rspamd_plugins_table_push_elt(lua_State *L, const gchar *field_name,
- const gchar *new_elt)
+void rspamd_plugins_table_push_elt(lua_State *L, const char *field_name,
+ const char *new_elt)
{
lua_getglobal(L, rspamd_modules_state_global);
struct rspamd_config **pcfg;
struct script_module *module;
lua_State *L = cfg->lua_state;
- gint err_idx, i;
+ int err_idx, i;
pcfg = lua_newuserdata(L, sizeof(struct rspamd_config *));
rspamd_lua_setclass(L, rspamd_config_classname, -1);
err_idx = lua_gettop(L);
gsize fsize;
- guint8 *data = rspamd_file_xmap(module->path,
- PROT_READ, &fsize, TRUE);
- guchar digest[rspamd_cryptobox_HASHBYTES];
- gchar *lua_fname;
+ uint8_t *data = rspamd_file_xmap(module->path,
+ PROT_READ, &fsize, TRUE);
+ unsigned char digest[rspamd_cryptobox_HASHBYTES];
+ char *lua_fname;
if (data == NULL) {
msg_err_config("cannot mmap %s failed: %s", module->path,
void rspamd_lua_dumpstack(lua_State *L)
{
- gint i, t, r = 0;
- gint top = lua_gettop(L);
- gchar buf[BUFSIZ];
+ int i, t, r = 0;
+ int top = lua_gettop(L);
+ char buf[BUFSIZ];
r += rspamd_snprintf(buf + r, sizeof(buf) - r, "lua stack: ");
for (i = 1; i <= top; i++) { /* repeat for each level */
}
gpointer
-rspamd_lua_check_class(lua_State *L, gint index, const gchar *name)
+rspamd_lua_check_class(lua_State *L, int index, const char *name)
{
gpointer p;
khiter_t k;
}
-void rspamd_lua_add_preload(lua_State *L, const gchar *name, lua_CFunction func)
+void rspamd_lua_add_preload(lua_State *L, const char *name, lua_CFunction func)
{
lua_getglobal(L, "package");
lua_pushstring(L, "preload");
gboolean
-rspamd_lua_parse_table_arguments(lua_State *L, gint pos,
+rspamd_lua_parse_table_arguments(lua_State *L, int pos,
GError **err,
enum rspamd_lua_parse_arguments_flags how,
- const gchar *extraction_pattern, ...)
+ const char *extraction_pattern, ...)
{
- const gchar *p, *key = NULL, *end, *cls;
+ const char *p, *key = NULL, *end, *cls;
va_list ap;
gboolean required = FALSE, failed = FALSE, is_table;
enum {
read_semicolon
} state = read_key;
gsize keylen = 0, *valuelen, clslen;
- gint idx = 0, t, direct_userdata = 0;
+ int idx = 0, t, direct_userdata = 0;
g_assert(extraction_pattern != NULL);
switch (*p) {
case 'S':
if (t == LUA_TSTRING) {
- *(va_arg(ap, const gchar **)) = lua_tostring(L, idx);
+ *(va_arg(ap, const char **)) = lua_tostring(L, idx);
}
else if (t == LUA_TNIL || t == LUA_TNONE) {
failed = TRUE;
if (how != RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING) {
- *(va_arg(ap, const gchar **)) = NULL;
+ *(va_arg(ap, const char **)) = NULL;
}
else {
- (void) va_arg(ap, gchar **);
+ (void) va_arg(ap, char **);
}
}
else {
1,
"bad type for key:"
" %.*s: '%s', '%s' is expected",
- (gint) keylen,
+ (int) keylen,
key,
lua_typename(L, lua_type(L, idx)), "string");
va_end(ap);
1,
"bad type for key:"
" %.*s: '%s', '%s' is expected",
- (gint) keylen,
+ (int) keylen,
key,
lua_typename(L, lua_type(L, idx)),
"int64");
1,
"bad type for key:"
" %.*s: '%s', '%s' is expected",
- (gint) keylen,
+ (int) keylen,
key,
lua_typename(L, lua_type(L, idx)),
"int64");
lua_pushvalue(L, idx);
}
- *(va_arg(ap, gint *)) = luaL_ref(L, LUA_REGISTRYINDEX);
+ *(va_arg(ap, int *)) = luaL_ref(L, LUA_REGISTRYINDEX);
}
else if (t == LUA_TNIL || t == LUA_TNONE) {
failed = TRUE;
if (how != RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING) {
- *(va_arg(ap, gint *)) = -1;
+ *(va_arg(ap, int *)) = -1;
}
else {
- (void) va_arg(ap, gint *);
+ (void) va_arg(ap, int *);
}
if (is_table) {
1,
"bad type for key:"
" %.*s: '%s', '%s' is expected",
- (gint) keylen,
+ (int) keylen,
key,
lua_typename(L, lua_type(L, idx)),
"function");
1,
"bad type for key:"
" %.*s: '%s', '%s' is expected",
- (gint) keylen,
+ (int) keylen,
key,
lua_typename(L, lua_type(L, idx)),
"bool");
case 'N':
if (t == LUA_TNUMBER) {
- *(va_arg(ap, gdouble *)) = lua_tonumber(L, idx);
+ *(va_arg(ap, double *)) = lua_tonumber(L, idx);
}
else if (t == LUA_TNIL || t == LUA_TNONE) {
failed = TRUE;
if (how != RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING) {
- *(va_arg(ap, gdouble *)) = 0;
+ *(va_arg(ap, double *)) = 0;
}
else {
- (void) va_arg(ap, gdouble *);
+ (void) va_arg(ap, double *);
}
}
else {
1,
"bad type for key:"
" %.*s: '%s', '%s' is expected",
- (gint) keylen,
+ (int) keylen,
key,
lua_typename(L, lua_type(L, idx)),
"double");
case 'D':
if (t == LUA_TNUMBER) {
- *(va_arg(ap, gdouble *)) = lua_tonumber(L, idx);
+ *(va_arg(ap, double *)) = lua_tonumber(L, idx);
}
else if (t == LUA_TNIL || t == LUA_TNONE) {
failed = TRUE;
if (how != RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING) {
- *(va_arg(ap, gdouble *)) = NAN;
+ *(va_arg(ap, double *)) = NAN;
}
else {
- (void) va_arg(ap, gdouble *);
+ (void) va_arg(ap, double *);
}
}
else {
1,
"bad type for key:"
" %.*s: '%s', '%s' is expected",
- (gint) keylen,
+ (int) keylen,
key,
lua_typename(L, lua_type(L, idx)),
"double");
valuelen = va_arg(ap, gsize *);
if (t == LUA_TSTRING) {
- *(va_arg(ap, const gchar **)) = lua_tolstring(L, idx,
- valuelen);
+ *(va_arg(ap, const char **)) = lua_tolstring(L, idx,
+ valuelen);
}
else if (t == LUA_TNIL || t == LUA_TNONE) {
failed = TRUE;
1,
"bad type for key:"
" %.*s: '%s', '%s' is expected",
- (gint) keylen,
+ (int) keylen,
key,
lua_typename(L, lua_type(L, idx)),
"string");
1,
"bad type for key:"
" %.*s: '%s', '%s' is expected",
- (gint) keylen,
+ (int) keylen,
key,
lua_typename(L, lua_type(L, idx)),
"int64");
1,
"bad type for key:"
" %.*s: '%s', '%s' is expected",
- (gint) keylen,
+ (int) keylen,
key,
lua_typename(L, lua_type(L, idx)),
"int64");
if (failed && required) {
g_set_error(err, lua_error_quark(), 2, "required parameter "
"%.*s is missing",
- (gint) keylen, key);
+ (int) keylen, key);
va_end(ap);
return FALSE;
g_set_error(err, lua_error_quark(), 2, "missing classname for "
"%.*s",
- (gint) keylen, key);
+ (int) keylen, key);
va_end(ap);
return FALSE;
2,
"empty classname for "
"%*.s",
- (gint) keylen,
+ (int) keylen,
key);
va_end(ap);
lua_error_quark(),
2,
"invalid class for key %.*s, expected %s, got %s",
- (gint) keylen,
+ (int) keylen,
key,
static_cls,
rspamd_lua_class_tostring_buf(L, FALSE, idx));
2,
"required parameter "
"%.*s is missing",
- (gint) keylen,
+ (int) keylen,
key);
va_end(ap);
static void
rspamd_lua_traceback_string(lua_State *L, luaL_Buffer *buf)
{
- gint i = 1, r;
+ int i = 1, r;
lua_Debug d;
- gchar tmp[256];
+ char tmp[256];
while (lua_getstack(L, i++, &d)) {
lua_getinfo(L, "nSl", &d);
}
}
-gint rspamd_lua_traceback(lua_State *L)
+int rspamd_lua_traceback(lua_State *L)
{
luaL_Buffer b;
void rspamd_lua_get_traceback_string(lua_State *L, luaL_Buffer *buf)
{
- const gchar *msg = lua_tostring(L, -1);
+ const char *msg = lua_tostring(L, -1);
if (msg) {
luaL_addstring(buf, msg);
rspamd_lua_traceback_string(L, buf);
}
-guint rspamd_lua_table_size(lua_State *L, gint tbl_pos)
+unsigned int rspamd_lua_table_size(lua_State *L, int tbl_pos)
{
- guint tbl_size = 0;
+ unsigned int tbl_size = 0;
if (!lua_istable(L, tbl_pos)) {
return 0;
}
static void *
-rspamd_lua_check_udata_common(lua_State *L, gint pos, const gchar *classname,
+rspamd_lua_check_udata_common(lua_State *L, int pos, const char *classname,
gboolean fatal)
{
void *p = lua_touserdata(L, pos);
- gint i, top = lua_gettop(L);
+ int i, top = lua_gettop(L);
if (p == NULL) {
goto err;
err:
if (fatal) {
- const gchar *actual_classname = NULL;
+ const char *actual_classname = NULL;
if (lua_type(L, pos) == LUA_TUSERDATA && lua_getmetatable(L, pos)) {
lua_pushstring(L, "__index");
}
luaL_Buffer buf;
- gchar tmp[512];
- gint r;
+ char tmp[512];
+ int r;
luaL_buffinit(L, &buf);
r = rspamd_snprintf(tmp, sizeof(tmp),
}
void *
-rspamd_lua_check_udata(lua_State *L, gint pos, const gchar *classname)
+rspamd_lua_check_udata(lua_State *L, int pos, const char *classname)
{
return rspamd_lua_check_udata_common(L, pos, classname, TRUE);
}
void *
-rspamd_lua_check_udata_maybe(lua_State *L, gint pos, const gchar *classname)
+rspamd_lua_check_udata_maybe(lua_State *L, int pos, const char *classname)
{
return rspamd_lua_check_udata_common(L, pos, classname, FALSE);
}
struct rspamd_async_session *
-lua_check_session(lua_State *L, gint pos)
+lua_check_session(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_session_classname);
luaL_argcheck(L, ud != NULL, pos, "'session' expected");
}
struct ev_loop *
-lua_check_ev_base(lua_State *L, gint pos)
+lua_check_ev_base(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_ev_base_classname);
luaL_argcheck(L, ud != NULL, pos, "'event_base' expected");
LL_FOREACH(cfg->post_init_scripts, sc)
{
lua_pushcfunction(L, &rspamd_lua_traceback);
- gint err_idx = lua_gettop(L);
+ int err_idx = lua_gettop(L);
lua_rawgeti(L, LUA_REGISTRYINDEX, sc->cbref);
pcfg = lua_newuserdata(L, sizeof(*pcfg));
LL_FOREACH(cfg->config_unload_scripts, sc)
{
lua_pushcfunction(L, &rspamd_lua_traceback);
- gint err_idx = lua_gettop(L);
+ int err_idx = lua_gettop(L);
lua_rawgeti(L, LUA_REGISTRYINDEX, sc->cbref);
pcfg = lua_newuserdata(L, sizeof(*pcfg));
struct rspamd_lua_ref_cbdata {
lua_State *L;
- gint cbref;
+ int cbref;
};
static void
}
void rspamd_lua_add_ref_dtor(lua_State *L, rspamd_mempool_t *pool,
- gint ref)
+ int ref)
{
struct rspamd_lua_ref_cbdata *cbdata;
}
gboolean
-rspamd_lua_require_function(lua_State *L, const gchar *modname,
- const gchar *funcname)
+rspamd_lua_require_function(lua_State *L, const char *modname,
+ const char *funcname)
{
- gint table_pos, err_pos;
+ int table_pos, err_pos;
lua_pushcfunction(L, &rspamd_lua_traceback);
err_pos = lua_gettop(L);
}
}
-gint rspamd_lua_function_ref_from_str(lua_State *L, const gchar *str, gsize slen,
- const gchar *modname, GError **err)
+int rspamd_lua_function_ref_from_str(lua_State *L, const char *str, gsize slen,
+ const char *modname, GError **err)
{
- gint err_idx, ref_idx;
+ int err_idx, ref_idx;
lua_pushcfunction(L, &rspamd_lua_traceback);
err_idx = lua_gettop(L);
gboolean
rspamd_lua_try_load_redis(lua_State *L, const ucl_object_t *obj,
- struct rspamd_config *cfg, gint *ref_id)
+ struct rspamd_config *cfg, int *ref_id)
{
- gint err_idx;
+ int err_idx;
struct rspamd_config **pcfg;
lua_pushcfunction(L, &rspamd_lua_traceback);
void rspamd_lua_push_full_word(lua_State *L, rspamd_stat_token_t *w)
{
- gint fl_cnt;
+ int fl_cnt;
lua_createtable(L, 4, 0);
lua_rawseti(L, -2, 4);
}
-gint rspamd_lua_push_words(lua_State *L, GArray *words,
- enum rspamd_lua_words_type how)
+int rspamd_lua_push_words(lua_State *L, GArray *words,
+ enum rspamd_lua_words_type how)
{
rspamd_stat_token_t *w;
- guint i, cnt;
+ unsigned int i, cnt;
lua_createtable(L, words->len, 0);
return 1;
}
-gchar *
+char *
rspamd_lua_get_module_name(lua_State *L)
{
lua_Debug d;
- gchar *p;
- gchar func_buf[128];
+ char *p;
+ char func_buf[128];
if (lua_getstack(L, 1, &d) == 1) {
(void) lua_getinfo(L, "Sl", &d);
return NULL;
}
-bool rspamd_lua_universal_pcall(lua_State *L, gint cbref, const gchar *strloc,
- gint nret, const gchar *args, GError **err, ...)
+bool rspamd_lua_universal_pcall(lua_State *L, int cbref, const char *strloc,
+ int nret, const char *args, GError **err, ...)
{
va_list ap;
- const gchar *argp = args, *classname;
- gint err_idx, nargs = 0;
+ const char *argp = args, *classname;
+ int err_idx, nargs = 0;
gpointer *cls_ptr;
gsize sz;
/*
* Possible arguments
* - i - lua_integer, argument - int64_t
- * - n - lua_number, argument - gdouble
- * - s - lua_string, argument - const gchar * (zero terminated)
- * - l - lua_lstring, argument - (size_t + const gchar *) pair
+ * - n - lua_number, argument - double
+ * - s - lua_string, argument - const char * (zero terminated)
+ * - l - lua_lstring, argument - (size_t + const char *) pair
* - u - lua_userdata, argument - (const char * + void *) - classname + pointer
* - b - lua_boolean, argument - gboolean (not bool due to varargs promotion)
* - f - lua_function, argument - int - position of the function on stack (not lua_registry)
nargs++;
break;
case 'n':
- lua_pushnumber(L, va_arg(ap, gdouble));
+ lua_pushnumber(L, va_arg(ap, double));
nargs++;
break;
case 's':
- lua_pushstring(L, va_arg(ap, const gchar *));
+ lua_pushstring(L, va_arg(ap, const char *));
nargs++;
break;
case 'l':
sz = va_arg(ap, gsize);
- lua_pushlstring(L, va_arg(ap, const gchar *), sz);
+ lua_pushlstring(L, va_arg(ap, const char *), sz);
nargs++;
break;
case 'b':
nargs++;
break;
case 'u':
- classname = va_arg(ap, const gchar *);
+ classname = va_arg(ap, const char *);
cls_ptr = (gpointer *) lua_newuserdata(L, sizeof(gpointer));
*cls_ptr = va_arg(ap, gpointer);
rspamd_lua_setclass(L, classname, -1);
break;
case 'f':
case 't':
- lua_pushvalue(L, va_arg(ap, gint));
+ lua_pushvalue(L, va_arg(ap, int));
nargs++;
break;
default:
}
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM <= 502
-gint rspamd_lua_geti(lua_State *L, int pos, int i)
+int rspamd_lua_geti(lua_State *L, int pos, int i)
{
pos = lua_absindex(L, pos);
lua_pushinteger(L, i);
#if LUA_VERSION_NUM > 501 && !defined LUA_COMPAT_MODULE
static inline void
-luaL_register(lua_State *L, const gchar *name, const struct luaL_reg *methods)
+luaL_register(lua_State *L, const char *name, const struct luaL_reg *methods)
{
if (name != NULL) {
lua_newtable(L);
#define RSPAMD_TEXT_FLAG_FAKE (1u << 4u)
#define RSPAMD_TEXT_FLAG_BINARY (1u << 5u)
struct rspamd_lua_text {
- const gchar *start;
- guint len;
- guint flags;
+ const char *start;
+ unsigned int len;
+ unsigned int flags;
};
struct rspamd_lua_url {
struct rspamd_lua_regexp {
rspamd_regexp_t *re;
- gchar *module;
- gchar *re_pattern;
- gint re_flags;
+ char *module;
+ char *re_pattern;
+ int re_flags;
};
struct rspamd_map;
struct rspamd_lua_map {
struct rspamd_map *map;
enum rspamd_lua_map_type type;
- guint flags;
+ unsigned int flags;
union {
struct rspamd_radix_map_helper *radix;
struct rspamd_lua_upstream {
struct upstream *up;
- gint upref;
+ int upref;
};
/* Common utility functions */
* Create and register new class
*/
void rspamd_lua_new_class(lua_State *L,
- const gchar *classname,
+ const char *classname,
const struct luaL_reg *methods);
/**
* @param L
* @param classname **MUST BE STATIC**, direct address is used for comparisons!
*/
-void rspamd_lua_setclass(lua_State *L, const gchar *classname, gint objidx);
+void rspamd_lua_setclass(lua_State *L, const char *classname, int objidx);
/**
* Pushes the metatable for specific class on top of the stack
* @param L
* @param classname
*/
-void rspamd_lua_class_metatable(lua_State *L, const gchar *classname);
+void rspamd_lua_class_metatable(lua_State *L, const char *classname);
/**
* Adds a new field to the class (metatable) identified by `classname`
* @param classname
* @param meth
*/
-void rspamd_lua_add_metamethod(lua_State *L, const gchar *classname,
+void rspamd_lua_add_metamethod(lua_State *L, const char *classname,
luaL_Reg *meth);
/**
* Set index of table to value (like t['index'] = value)
*/
-void rspamd_lua_table_set(lua_State *L, const gchar *index, const gchar *value);
+void rspamd_lua_table_set(lua_State *L, const char *index, const char *value);
/**
* Get string value of index in a table (return t['index'])
*/
-const gchar *rspamd_lua_table_get(lua_State *L, const gchar *index);
+const char *rspamd_lua_table_get(lua_State *L, const char *index);
/**
* Convert classname to string
*/
-gint rspamd_lua_class_tostring(lua_State *L);
+int rspamd_lua_class_tostring(lua_State *L);
/**
* Check whether the argument at specified index is of the specified class
*/
-gpointer rspamd_lua_check_class(lua_State *L, gint index, const gchar *name);
+gpointer rspamd_lua_check_class(lua_State *L, int index, const char *name);
/**
* Initialize lua and bindings
* @param field_name
* @param new_elt
*/
-void rspamd_plugins_table_push_elt(lua_State *L, const gchar *field_name,
- const gchar *new_elt);
+void rspamd_plugins_table_push_elt(lua_State *L, const char *field_name,
+ const char *new_elt);
/**
* Load and initialize lua plugins
/**
* Return lua ip structure at the specified address
*/
-struct rspamd_lua_ip *lua_check_ip(lua_State *L, gint pos);
+struct rspamd_lua_ip *lua_check_ip(lua_State *L, int pos);
-struct rspamd_lua_text *lua_check_text(lua_State *L, gint pos);
+struct rspamd_lua_text *lua_check_text(lua_State *L, int pos);
/**
* Checks for a text or a string. In case of string a pointer to static structure is returned.
* So it should not be reused or placed to Lua stack anyhow!
* @param pos
* @return
*/
-struct rspamd_lua_text *lua_check_text_or_string(lua_State *L, gint pos);
+struct rspamd_lua_text *lua_check_text_or_string(lua_State *L, int pos);
/**
* Create new text object
* @param L
* @param own
* @return
*/
-struct rspamd_lua_text *lua_new_text(lua_State *L, const gchar *start,
+struct rspamd_lua_text *lua_new_text(lua_State *L, const char *start,
gsize len, gboolean own);
/**
* Create new text object from task pool if allocation is needed
* @return
*/
struct rspamd_lua_text *lua_new_text_task(lua_State *L, struct rspamd_task *task,
- const gchar *start, gsize len, gboolean own);
+ const char *start, gsize len, gboolean own);
/**
* Checks if a text has binary characters (non ascii and non-utf8 characters)
* @param t
*/
bool lua_is_text_binary(struct rspamd_lua_text *t);
-struct rspamd_lua_regexp *lua_check_regexp(lua_State *L, gint pos);
+struct rspamd_lua_regexp *lua_check_regexp(lua_State *L, int pos);
struct rspamd_lua_upstream *lua_check_upstream(lua_State *L, int pos);
RSPAMD_TASK_HEADER_PUSH_HAS,
};
-gint rspamd_lua_push_header(lua_State *L,
- struct rspamd_mime_header *h,
- enum rspamd_lua_task_header_type how);
+int rspamd_lua_push_header(lua_State *L,
+ struct rspamd_mime_header *h,
+ enum rspamd_lua_task_header_type how);
/**
* Push specific header to lua
*/
-gint rspamd_lua_push_header_array(lua_State *L,
- const gchar *name,
- struct rspamd_mime_header *rh,
- enum rspamd_lua_task_header_type how,
- gboolean strong);
+int rspamd_lua_push_header_array(lua_State *L,
+ const char *name,
+ struct rspamd_mime_header *rh,
+ enum rspamd_lua_task_header_type how,
+ gboolean strong);
/**
* Check for task at the specified position
*/
-struct rspamd_task *lua_check_task(lua_State *L, gint pos);
+struct rspamd_task *lua_check_task(lua_State *L, int pos);
-struct rspamd_task *lua_check_task_maybe(lua_State *L, gint pos);
+struct rspamd_task *lua_check_task_maybe(lua_State *L, int pos);
-struct rspamd_lua_map *lua_check_map(lua_State *L, gint pos);
+struct rspamd_lua_map *lua_check_map(lua_State *L, int pos);
/**
* Push ip address from a string (nil is pushed if a string cannot be converted)
*/
-void rspamd_lua_ip_push_fromstring(lua_State *L, const gchar *ip_str);
+void rspamd_lua_ip_push_fromstring(lua_State *L, const char *ip_str);
/**
* Create type error
/**
* Add preload function
*/
-void rspamd_lua_add_preload(lua_State *L, const gchar *name, lua_CFunction func);
+void rspamd_lua_add_preload(lua_State *L, const char *name, lua_CFunction func);
void luaopen_task(lua_State *L);
void luaopen_parsers(lua_State *L);
-void rspamd_lua_dostring(const gchar *line);
+void rspamd_lua_dostring(const char *line);
double rspamd_lua_normalize(struct rspamd_config *cfg,
long double score,
void rspamd_lua_set_globals(struct rspamd_config *cfg, lua_State *L);
-struct memory_pool_s *rspamd_lua_check_mempool(lua_State *L, gint pos);
+struct memory_pool_s *rspamd_lua_check_mempool(lua_State *L, int pos);
-struct rspamd_config *lua_check_config(lua_State *L, gint pos);
+struct rspamd_config *lua_check_config(lua_State *L, int pos);
-struct rspamd_async_session *lua_check_session(lua_State *L, gint pos);
+struct rspamd_async_session *lua_check_session(lua_State *L, int pos);
-struct ev_loop *lua_check_ev_base(lua_State *L, gint pos);
+struct ev_loop *lua_check_ev_base(lua_State *L, int pos);
-struct rspamd_dns_resolver *lua_check_dns_resolver(lua_State *L, gint pos);
+struct rspamd_dns_resolver *lua_check_dns_resolver(lua_State *L, int pos);
-struct rspamd_lua_url *lua_check_url(lua_State *L, gint pos);
+struct rspamd_lua_url *lua_check_url(lua_State *L, int pos);
enum rspamd_lua_parse_arguments_flags {
RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT = 0,
* @param extraction_pattern static pattern
* @return TRUE if a table has been parsed
*/
-gboolean rspamd_lua_parse_table_arguments(lua_State *L, gint pos,
+gboolean rspamd_lua_parse_table_arguments(lua_State *L, int pos,
GError **err,
enum rspamd_lua_parse_arguments_flags how,
- const gchar *extraction_pattern, ...);
+ const char *extraction_pattern, ...);
-gint rspamd_lua_traceback(lua_State *L);
+int rspamd_lua_traceback(lua_State *L);
/**
* Returns stack trace as a string. Caller should clear memory.
/**
* Returns size of table at position `tbl_pos`
*/
-guint rspamd_lua_table_size(lua_State *L, gint tbl_pos);
+unsigned int rspamd_lua_table_size(lua_State *L, int tbl_pos);
void lua_push_emails_address_list(lua_State *L, GPtrArray *addrs, int flags);
#define TRACE_POINTS 6
struct lua_logger_trace {
- gint cur_level;
+ int cur_level;
gconstpointer traces[TRACE_POINTS];
};
* @param len
* @return
*/
-gsize lua_logger_out_type(lua_State *L, gint pos, gchar *outbuf,
+gsize lua_logger_out_type(lua_State *L, int pos, char *outbuf,
gsize len, struct lua_logger_trace *trace,
enum lua_logger_escape_type esc_type);
* @param pos
* @param classname **MUST BE STATIC**, direct address is used for comparisons!
*/
-void *rspamd_lua_check_udata(lua_State *L, gint pos, const gchar *classname);
+void *rspamd_lua_check_udata(lua_State *L, int pos, const char *classname);
#define RSPAMD_LUA_CHECK_UDATA_PTR_OR_RETURN(L, pos, classname, type, dest) \
do { \
* @param pos
* @param classname **MUST BE STATIC**, direct address is used for comparisons!
*/
-void *rspamd_lua_check_udata_maybe(lua_State *L, gint pos, const gchar *classname);
+void *rspamd_lua_check_udata_maybe(lua_State *L, int pos, const char *classname);
/**
* Call finishing script with the specified task
* @param ref
*/
void rspamd_lua_add_ref_dtor(lua_State *L, rspamd_mempool_t *pool,
- gint ref);
+ int ref);
/**
* Returns a lua reference from a function like string, e.g. `return function(...) end`
* @param str
* @return
*/
-gint rspamd_lua_function_ref_from_str(lua_State *L, const gchar *str, gsize slen,
- const gchar *modname, GError **err);
+int rspamd_lua_function_ref_from_str(lua_State *L, const char *str, gsize slen,
+ const char *modname, GError **err);
/**
* Tries to load some module using `require` and get some method from it
* @param funcname
* @return TRUE if function exists in that module, the function is pushed in stack, otherwise stack is unchanged and FALSE is returned
*/
-gboolean rspamd_lua_require_function(lua_State *L, const gchar *modname,
- const gchar *funcname);
+gboolean rspamd_lua_require_function(lua_State *L, const char *modname,
+ const char *funcname);
/**
* Tries to load redis server definition from ucl object specified
* @return
*/
gboolean rspamd_lua_try_load_redis(lua_State *L, const ucl_object_t *obj,
- struct rspamd_config *cfg, gint *ref_id);
+ struct rspamd_config *cfg, int *ref_id);
struct rspamd_stat_token_s;
* @param words
* @param how
*/
-gint rspamd_lua_push_words(lua_State *L, GArray *words,
- enum rspamd_lua_words_type how);
+int rspamd_lua_push_words(lua_State *L, GArray *words,
+ enum rspamd_lua_words_type how);
/**
* Returns newly allocated name for caller module name
* @param L
* @return
*/
-gchar *rspamd_lua_get_module_name(lua_State *L);
+char *rspamd_lua_get_module_name(lua_State *L);
/**
* Call Lua function in a universal way. Arguments string:
* - i - lua_integer, argument - int64_t
-* - n - lua_number, argument - gdouble
-* - s - lua_string, argument - const gchar * (zero terminated)
-* - l - lua_lstring, argument - (size_t + const gchar *) pair
+* - n - lua_number, argument - double
+* - s - lua_string, argument - const char * (zero terminated)
+* - l - lua_lstring, argument - (size_t + const char *) pair
* - u - lua_userdata, argument - (const char * + void *) - classname + pointer
* - b - lua_boolean, argument - gboolean (not bool due to varargs promotion)
* - f - lua_function, argument - int - position of the function on stack (not lua_registry)
* @param ... arguments
* @return true of pcall returned 0, false + err otherwise
*/
-bool rspamd_lua_universal_pcall(lua_State *L, gint cbref, const gchar *strloc,
- gint nret, const gchar *args, GError **err, ...);
+bool rspamd_lua_universal_pcall(lua_State *L, int cbref, const char *strloc,
+ int nret, const char *args, GError **err, ...);
/**
* Returns true if lua is initialised
* @return
*/
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM <= 502
-gint rspamd_lua_geti(lua_State *L, int index, int i);
+int rspamd_lua_geti(lua_State *L, int index, int i);
#else
#define rspamd_lua_geti lua_geti
#endif
{NULL, NULL}};
static ZSTD_CStream *
-lua_check_zstd_compress_ctx(lua_State *L, gint pos)
+lua_check_zstd_compress_ctx(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_zstd_compress_classname);
luaL_argcheck(L, ud != NULL, pos, "'zstd_compress' expected");
}
static ZSTD_DStream *
-lua_check_zstd_decompress_ctx(lua_State *L, gint pos)
+lua_check_zstd_decompress_ctx(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_zstd_decompress_classname);
luaL_argcheck(L, ud != NULL, pos, "'zstd_decompress' expected");
return 2;
}
-gint lua_compress_zstd_compress(lua_State *L)
+int lua_compress_zstd_compress(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_text *t = NULL, *res;
gsize sz, r;
- gint comp_level = 1;
+ int comp_level = 1;
t = lua_check_text_or_string(L, 1);
return 1;
}
-gint lua_compress_zstd_decompress(lua_State *L)
+int lua_compress_zstd_decompress(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_text *t = NULL, *res;
ZSTD_DStream *zstream;
ZSTD_inBuffer zin;
ZSTD_outBuffer zout;
- gchar *out;
+ char *out;
t = lua_check_text_or_string(L, 1);
return 2;
}
-gint lua_compress_zlib_decompress(lua_State *L, bool is_gzip)
+int lua_compress_zlib_decompress(lua_State *L, bool is_gzip)
{
LUA_TRACE_POINT;
struct rspamd_lua_text *t = NULL, *res;
gsize sz;
z_stream strm;
- gint rc;
- guchar *p;
+ int rc;
+ unsigned char *p;
gsize remain;
gssize size_limit = -1;
}
strm.avail_in = t->len;
- strm.next_in = (guchar *) t->start;
+ strm.next_in = (unsigned char *) t->start;
res = lua_newuserdata(L, sizeof(*res));
res->start = g_malloc(sz);
res->flags = RSPAMD_TEXT_FLAG_OWN;
rspamd_lua_setclass(L, rspamd_text_classname, -1);
- p = (guchar *) res->start;
+ p = (unsigned char *) res->start;
remain = sz;
while (strm.avail_in != 0) {
remain = res->len;
res->start = g_realloc((gpointer) res->start, res->len * 2);
sz = res->len * 2;
- p = (guchar *) res->start + remain;
+ p = (unsigned char *) res->start + remain;
remain = sz - remain;
}
}
return 1;
}
-gint lua_compress_zlib_compress(lua_State *L)
+int lua_compress_zlib_compress(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_text *t = NULL, *res;
gsize sz;
z_stream strm;
- gint rc, comp_level = Z_DEFAULT_COMPRESSION;
- guchar *p;
+ int rc, comp_level = Z_DEFAULT_COMPRESSION;
+ unsigned char *p;
gsize remain;
t = lua_check_text_or_string(L, 1);
sz = deflateBound(&strm, t->len);
strm.avail_in = t->len;
- strm.next_in = (guchar *) t->start;
+ strm.next_in = (unsigned char *) t->start;
res = lua_newuserdata(L, sizeof(*res));
res->start = g_malloc(sz);
res->flags = RSPAMD_TEXT_FLAG_OWN;
rspamd_lua_setclass(L, rspamd_text_classname, -1);
- p = (guchar *) res->start;
+ p = (unsigned char *) res->start;
remain = sz;
while (strm.avail_in != 0) {
remain = res->len;
res->start = g_realloc((gpointer) res->start, strm.avail_in + sz);
sz = strm.avail_in + sz;
- p = (guchar *) res->start + remain;
+ p = (unsigned char *) res->start + remain;
remain = sz - remain;
}
}
"end",
NULL};
-static gint
+static int
lua_zstd_compress_ctx(lua_State *L)
{
ZSTD_CCtx *ctx, **pctx;
return 1;
}
-static gint
+static int
lua_zstd_compress_dtor(lua_State *L)
{
ZSTD_CCtx *ctx = lua_check_zstd_compress_ctx(L, 1);
return 0;
}
-static gint
+static int
lua_zstd_compress_reset(lua_State *L)
{
ZSTD_CCtx *ctx = lua_check_zstd_compress_ctx(L, 1);
return 0;
}
-static gint
+static int
lua_zstd_compress_stream(lua_State *L)
{
ZSTD_CStream *ctx = lua_check_zstd_compress_ctx(L, 1);
return 1;
}
-static gint
+static int
lua_zstd_decompress_dtor(lua_State *L)
{
ZSTD_DStream *ctx = lua_check_zstd_decompress_ctx(L, 1);
}
-static gint
+static int
lua_zstd_decompress_ctx(lua_State *L)
{
ZSTD_DStream *ctx, **pctx;
return 1;
}
-static gint
+static int
lua_zstd_decompress_stream(lua_State *L)
{
ZSTD_DStream *ctx = lua_check_zstd_decompress_ctx(L, 1);
return 1;
}
-static gint
+static int
lua_load_zstd(lua_State *L)
{
lua_newtable(L);
extern "C" {
#endif
-gint lua_compress_zstd_compress(lua_State *L);
-gint lua_compress_zstd_decompress(lua_State *L);
-gint lua_compress_zlib_compress(lua_State *L);
-gint lua_compress_zlib_decompress(lua_State *L, bool is_gzip);
+int lua_compress_zstd_compress(lua_State *L);
+int lua_compress_zstd_decompress(lua_State *L);
+int lua_compress_zlib_compress(lua_State *L);
+int lua_compress_zlib_decompress(lua_State *L, bool is_gzip);
void luaopen_compress(lua_State *L);
static const uint64_t rspamd_lua_callback_magic = 0x32c118af1e3263c7ULL;
struct rspamd_config *
-lua_check_config(lua_State *L, gint pos)
+lua_check_config(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_config_classname);
luaL_argcheck(L, ud != NULL, pos, "'config' expected");
}
static struct rspamd_monitored *
-lua_check_monitored(lua_State *L, gint pos)
+lua_check_monitored(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_monitored_classname);
luaL_argcheck(L, ud != NULL, pos, "'monitored' expected");
}
/*** Config functions ***/
-static gint
+static int
lua_config_get_api_version(lua_State *L)
{
msg_warn("get_api_version is deprecated, do not use it");
return 1;
}
-static gint
+static int
lua_config_get_module_opt(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *mname, *optname;
+ const char *mname, *optname;
const ucl_object_t *obj;
if (cfg) {
return 1;
}
-static gint
+static int
lua_config_get_all_opt(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *mname;
+ const char *mname;
const ucl_object_t *obj, *cur, *cur_elt;
ucl_object_iter_t it = NULL;
- gint i;
+ int i;
if (cfg) {
mname = luaL_checkstring(L, 2);
struct rspamd_lua_cached_config {
lua_State *L;
- gint ref;
+ int ref;
};
static void
luaL_unref(cached->L, LUA_REGISTRYINDEX, cached->ref);
}
-static gint
+static int
lua_config_get_ucl(lua_State *L)
{
LUA_TRACE_POINT;
}
-static gint
+static int
lua_config_get_classifier(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
struct rspamd_classifier_config *clc = NULL, **pclc = NULL;
- const gchar *name;
+ const char *name;
GList *cur;
if (cfg) {
struct lua_callback_data {
uint64_t magic;
lua_State *L;
- gchar *symbol;
+ char *symbol;
union {
- gchar *name;
- gint ref;
+ char *name;
+ int ref;
} callback;
gboolean cb_is_ref;
/* Dynamic data */
- gint stack_level;
- gint order;
+ int stack_level;
+ int order;
struct rspamd_symcache_dynamic_item *item;
};
}
}
-static gint
+static int
lua_config_register_module_option(lua_State *L)
{
return 0;
}
-static gint
+static int
rspamd_compare_order_func(gconstpointer a, gconstpointer b)
{
const struct lua_callback_data *cb1 = a, *cb2 = b;
{
struct lua_callback_data *cd = ud;
struct rspamd_task **ptask;
- gint level = lua_gettop(cd->L), nresults, err_idx, ret;
+ int level = lua_gettop(cd->L), nresults, err_idx, ret;
lua_State *L = cd->L;
struct rspamd_symbol_result *s;
if (nresults >= 1) {
/* Function returned boolean, so maybe we need to insert result? */
- gint res = 0;
- gint i;
- gdouble flag = 1.0;
- gint type;
+ int res = 0;
+ int i;
+ double flag = 1.0;
+ int type;
type = lua_type(cd->L, level + 1);
}
if (res) {
- gint first_opt = 2;
+ int first_opt = 2;
if (lua_type(L, level + 2) == LUA_TNUMBER) {
flag = lua_tonumber(L, level + 2);
s = rspamd_task_insert_result(task, cd->symbol, flag, NULL);
if (s) {
- guint last_pos = lua_gettop(L);
+ unsigned int last_pos = lua_gettop(L);
for (i = level + first_opt; i <= last_pos; i++) {
if (lua_type(L, i) == LUA_TSTRING) {
else if (lua_type(L, i) == LUA_TTABLE) {
gsize objlen = rspamd_lua_table_size(L, i);
- for (guint j = 1; j <= objlen; j++) {
+ for (unsigned int j = 1; j <= objlen; j++) {
lua_rawgeti(L, i, j);
if (lua_type(L, -1) == LUA_TSTRING) {
if (nresults >= 1) {
/* Function returned boolean, so maybe we need to insert result? */
- gint res = 0;
- gint i;
- gdouble flag = 1.0;
- gint type;
+ int res = 0;
+ int i;
+ double flag = 1.0;
+ int type;
type = lua_type(L, cd->stack_level + 1);
}
if (res) {
- gint first_opt = 2;
+ int first_opt = 2;
if (lua_type(L, cd->stack_level + 2) == LUA_TNUMBER) {
flag = lua_tonumber(L, cd->stack_level + 2);
s = rspamd_task_insert_result(task, cd->symbol, flag, NULL);
if (s) {
- guint last_pos = lua_gettop(L);
+ unsigned int last_pos = lua_gettop(L);
for (i = cd->stack_level + first_opt; i <= last_pos; i++) {
if (lua_type(L, i) == LUA_TSTRING) {
else if (lua_type(L, i) == LUA_TTABLE) {
gsize objlen = rspamd_lua_table_size(L, i);
- for (guint j = 1; j <= objlen; j++) {
+ for (unsigned int j = 1; j <= objlen; j++) {
lua_rawgeti(L, i, j);
if (lua_type(L, -1) == LUA_TSTRING) {
}
static GArray *
-rspamd_process_id_list(const gchar *entries)
+rspamd_process_id_list(const char *entries)
{
- gchar **sym_elts;
+ char **sym_elts;
GArray *ret;
sym_elts = g_strsplit_set(entries, ",;", -1);
- guint nids = g_strv_length(sym_elts);
+ unsigned int nids = g_strv_length(sym_elts);
ret = g_array_sized_new(FALSE, FALSE, sizeof(uint32_t), nids);
- for (guint i = 0; i < nids; i++) {
+ for (unsigned int i = 0; i < nids; i++) {
uint32_t v = rspamd_config_name_to_id(sym_elts[i], strlen(sym_elts[i]));
g_array_append_val(ret, v);
}
return ret;
}
-static gint
+static int
rspamd_register_symbol_fromlua(lua_State *L,
struct rspamd_config *cfg,
- const gchar *name,
- gint ref,
- gdouble weight,
- gint priority,
+ const char *name,
+ int ref,
+ double weight,
+ int priority,
enum rspamd_symbol_type type,
- gint parent,
+ int parent,
GArray *allowed_ids,
GArray *forbidden_ids,
gboolean optional)
{
struct lua_callback_data *cd;
- gint ret = -1;
+ int ret = -1;
if (priority == 0 && weight < 0) {
priority = 1;
return ret;
}
-static gint
+static int
lua_config_register_post_filter(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- gint order = 0, cbref, ret;
+ int order = 0, cbref, ret;
if (cfg) {
if (lua_type(L, 3) == LUA_TNUMBER) {
return 1;
}
-static gint
+static int
lua_config_register_pre_filter(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- gint order = 0, cbref, ret;
+ int order = 0, cbref, ret;
if (cfg) {
if (lua_type(L, 3) == LUA_TNUMBER) {
return 1;
}
-static gint
+static int
lua_config_get_key(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *name;
+ const char *name;
size_t namelen;
const ucl_object_t *val;
return 1;
}
-static guint
-lua_parse_symbol_flags(const gchar *str)
+static unsigned int
+lua_parse_symbol_flags(const char *str)
{
- guint ret = 0;
+ unsigned int ret = 0;
if (str) {
if (strstr(str, "fine") != NULL) {
return ret;
}
-static guint
-lua_parse_symbol_type(const gchar *str)
+static unsigned int
+lua_parse_symbol_type(const char *str)
{
- guint ret = SYMBOL_TYPE_NORMAL;
- gchar **vec;
- guint i, l;
+ unsigned int ret = SYMBOL_TYPE_NORMAL;
+ char **vec;
+ unsigned int i, l;
if (str) {
vec = g_strsplit_set(str, ",;", -1);
SYMBOL_TYPE_IDEMPOTENT | SYMBOL_TYPE_CALLBACK;
}
else {
- gint fl = 0;
+ int fl = 0;
fl = lua_parse_symbol_flags(str);
} while (0)
static void
-lua_push_symbol_flags(lua_State *L, guint flags, enum lua_push_symbol_flags_opts fl)
+lua_push_symbol_flags(lua_State *L, unsigned int flags, enum lua_push_symbol_flags_opts fl)
{
- guint i = 1;
+ unsigned int i = 1;
if (LUA_SYMOPT_IS_CREATE(fl)) {
lua_newtable(L);
}
}
-static gint
+static int
lua_config_get_symbol_flags(lua_State *L)
{
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *name = luaL_checkstring(L, 2);
- guint flags;
+ const char *name = luaL_checkstring(L, 2);
+ unsigned int flags;
if (cfg && name) {
flags = rspamd_symcache_get_symbol_flags(cfg->cache,
return 1;
}
-static gint
+static int
lua_config_register_symbol(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *name = NULL, *type_str = NULL,
- *description = NULL, *group = NULL;
+ const char *name = NULL, *type_str = NULL,
+ *description = NULL, *group = NULL;
double weight = 0, score = NAN, parent_float = NAN;
gboolean one_shot = FALSE;
- gint ret = -1, cbref = -1;
- guint type = 0, flags = 0;
+ int ret = -1, cbref = -1;
+ unsigned int type = 0, flags = 0;
int64_t parent = 0, priority = 0, nshots = 0;
GArray *allowed_ids = NULL, *forbidden_ids = NULL;
GError *err = NULL;
return 1;
}
-static gint
+static int
lua_config_register_symbols(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- gint i, top, idx, ret = -1;
- const gchar *sym;
- gdouble weight = 1.0;
+ int i, top, idx, ret = -1;
+ const char *sym;
+ double weight = 1.0;
if (lua_gettop(L) < 3) {
if (cfg) {
return 1;
}
-static gint
+static int
lua_config_register_virtual_symbol(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *name;
+ const char *name;
double weight;
- gint ret = -1, parent = -1;
+ int ret = -1, parent = -1;
if (cfg) {
name = luaL_checkstring(L, 2);
return 1;
}
-static gint
+static int
lua_config_register_callback_symbol(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *name = NULL;
+ const char *name = NULL;
double weight;
- gint ret = -1, top = 2;
+ int ret = -1, top = 2;
if (cfg) {
if (lua_type(L, 2) == LUA_TSTRING) {
return 1;
}
-static gint
+static int
lua_config_register_callback_symbol_priority(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *name = NULL;
+ const char *name = NULL;
double weight;
- gint priority, ret = -1, top = 2;
+ int priority, ret = -1, top = 2;
if (cfg) {
if (lua_type(L, 2) == LUA_TSTRING) {
}
-static gint
+static int
lua_config_register_dependency(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *parent = NULL, *child = NULL;
- gint child_id;
+ const char *parent = NULL, *child = NULL;
+ int child_id;
if (cfg == NULL) {
lua_error(L);
return 0;
}
-static gint
+static int
lua_config_set_metric_symbol(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *description = NULL,
- *group = NULL, *name = NULL, *flags_str = NULL;
+ const char *description = NULL,
+ *group = NULL, *name = NULL, *flags_str = NULL;
double score;
gboolean one_shot = FALSE, one_param = FALSE;
GError *err = NULL;
- gdouble priority = 0.0;
- guint flags = 0;
+ double priority = 0.0;
+ unsigned int flags = 0;
int64_t nshots = 0;
if (cfg) {
}
rspamd_config_add_symbol(cfg, name,
- score, description, group, flags, (guint) priority, nshots);
+ score, description, group, flags, (unsigned int) priority, nshots);
if (lua_type(L, 2) == LUA_TTABLE) {
return 0;
}
-static gint
+static int
lua_config_set_metric_action(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *name = NULL;
+ const char *name = NULL;
double threshold = NAN;
GError *err = NULL;
- gdouble priority = 0.0;
+ double priority = 0.0;
ucl_object_t *obj_tbl = NULL;
if (cfg) {
return 0;
}
-static gint
+static int
lua_config_get_metric_action(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *act_name = luaL_checkstring(L, 2);
+ const char *act_name = luaL_checkstring(L, 2);
struct rspamd_action *act;
if (cfg && act_name) {
}
}
-static gint
+static int
lua_config_get_all_actions(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_config_add_composite(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- gchar *name;
- const gchar *expr_str;
+ char *name;
+ const char *expr_str;
struct rspamd_composite *composite;
gboolean ret = FALSE;
return 1;
}
-static gint
+static int
lua_config_newindex(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *name;
+ const char *name;
GArray *allowed_ids = NULL, *forbidden_ids = NULL;
- gint id, nshots;
- guint flags = 0;
+ int id, nshots;
+ unsigned int flags = 0;
gboolean optional = FALSE;
name = luaL_checkstring(L, 2);
FALSE);
}
else if (lua_type(L, 3) == LUA_TTABLE) {
- guint type = SYMBOL_TYPE_NORMAL, priority = 0;
- gint idx;
- gdouble weight = 1.0, score = NAN;
+ unsigned int type = SYMBOL_TYPE_NORMAL, priority = 0;
+ int idx;
+ double weight = 1.0, score = NAN;
const char *type_str, *group = NULL, *description = NULL;
/*
lua_gettable(L, -2);
if (lua_type(L, -1) == LUA_TFUNCTION) {
- gint condref;
+ int condref;
/* Here we pop function from the stack, so no lua_pop is required */
condref = luaL_ref(L, LUA_REGISTRYINDEX);
return 0;
}
-static gint
+static int
lua_config_add_condition(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *sym = luaL_checkstring(L, 2);
+ const char *sym = luaL_checkstring(L, 2);
gboolean ret = FALSE;
- gint condref;
+ int condref;
if (cfg && sym && lua_type(L, 3) == LUA_TFUNCTION) {
lua_pushvalue(L, 3);
return 1;
}
-static gint
+static int
lua_config_set_peak_cb(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- gint condref;
+ int condref;
if (cfg && lua_type(L, 2) == LUA_TFUNCTION) {
lua_pushvalue(L, 2);
return 0;
}
-static gint
+static int
lua_config_enable_symbol(lua_State *L)
{
struct rspamd_config *cfg = lua_check_config(L, 1);
return 0;
}
-static gint
+static int
lua_config_disable_symbol(lua_State *L)
{
struct rspamd_config *cfg = lua_check_config(L, 1);
return 0;
}
-static gint
+static int
lua_config_register_regexp(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
struct rspamd_lua_regexp *re = NULL;
rspamd_regexp_t *cache_re;
- const gchar *type_str = NULL, *header_str = NULL;
+ const char *type_str = NULL, *header_str = NULL;
gsize header_len = 0;
GError *err = NULL;
enum rspamd_re_type type = RSPAMD_RE_BODY;
return 0;
}
-static gint
+static int
lua_config_replace_regexp(lua_State *L)
{
LUA_TRACE_POINT;
RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT,
"*old_re=U{regexp};*new_re=U{regexp};pcre_only=B",
&old_re, &new_re, &pcre_only)) {
- gint ret = luaL_error(L, "cannot get parameters list: %s",
- err ? err->message : "invalid arguments");
+ int ret = luaL_error(L, "cannot get parameters list: %s",
+ err ? err->message : "invalid arguments");
if (err) {
g_error_free(err);
return 0;
}
-static gint
+static int
lua_config_register_worker_script(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *worker_type = luaL_checkstring(L, 2), *wtype;
+ const char *worker_type = luaL_checkstring(L, 2), *wtype;
struct rspamd_worker_conf *cf;
GList *cur;
struct rspamd_worker_lua_script *sc;
return 1;
}
-static gint
+static int
lua_config_add_on_load(lua_State *L)
{
LUA_TRACE_POINT;
return prb->priority - pra->priority;
}
-static gint
+static int
lua_config_add_post_init(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
struct rspamd_config_cfg_lua_script *sc;
- guint priority = 0;
+ unsigned int priority = 0;
lua_Debug d;
- gchar tmp[256], *p;
+ char tmp[256], *p;
if (cfg == NULL || lua_type(L, 2) != LUA_TFUNCTION) {
return luaL_error(L, "invalid arguments");
return 0;
}
-static gint
+static int
lua_config_add_config_unload(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
struct rspamd_config_cfg_lua_script *sc;
lua_Debug d;
- gchar tmp[256], *p;
+ char tmp[256], *p;
if (cfg == NULL || lua_type(L, 2) != LUA_TFUNCTION) {
return luaL_error(L, "invalid arguments");
struct rspamd_lua_periodic {
struct ev_loop *event_loop;
struct rspamd_config *cfg;
- gchar *lua_src_pos;
+ char *lua_src_pos;
lua_State *L;
- gdouble timeout;
+ double timeout;
ev_timer ev;
- gint cbref;
+ int cbref;
gboolean need_jitter;
ref_entry_t ref;
};
lua_State *L;
struct rspamd_lua_periodic *periodic = thread->cd;
gboolean plan_more = FALSE;
- gdouble timeout = 0.0;
+ double timeout = 0.0;
L = thread->lua_state;
}
-static gint
+static int
lua_config_add_periodic(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
struct ev_loop *ev_base = lua_check_ev_base(L, 2);
- gdouble timeout = lua_tonumber(L, 3);
+ double timeout = lua_tonumber(L, 3);
struct rspamd_lua_periodic *periodic;
gboolean need_jitter = FALSE;
lua_Debug d;
- gchar tmp[256], *p;
+ char tmp[256], *p;
if (cfg == NULL || timeout < 0 || lua_type(L, 4) != LUA_TFUNCTION) {
return luaL_error(L, "invalid arguments");
return 0;
}
-static gint
+static int
lua_config_get_symbols_count(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- guint res = 0;
+ unsigned int res = 0;
if (cfg != NULL) {
res = rspamd_symcache_stats_symbols_count(cfg->cache);
return 1;
}
-static gint
+static int
lua_config_get_symbols_cksum(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_config_get_symbols_counters(lua_State *L)
{
LUA_TRACE_POINT;
{
struct lua_metric_symbols_cbdata *cbd = (struct lua_metric_symbols_cbdata *) ud;
lua_State *L;
- const gchar *sym = k;
+ const char *sym = k;
struct rspamd_symbol *s = (struct rspamd_symbol *) v;
struct rspamd_symbols_group *gr;
- gint i;
+ int i;
L = cbd->L;
}
if (s->cache_item) {
- guint sflags = rspamd_symcache_get_symbol_flags(cbd->cfg->cache, sym);
+ unsigned int sflags = rspamd_symcache_get_symbol_flags(cbd->cfg->cache, sym);
lua_push_symbol_flags(L, sflags, LUA_SYMOPT_FLAG_USE_MAP);
- guint nids;
- const guint *allowed_ids = rspamd_symcache_get_allowed_settings_ids(cbd->cfg->cache,
- sym, &nids);
+ unsigned int nids;
+ const unsigned int *allowed_ids = rspamd_symcache_get_allowed_settings_ids(cbd->cfg->cache,
+ sym, &nids);
if (allowed_ids && nids > 0) {
lua_createtable(L, nids, 0);
lua_setfield(L, -2, "allowed_ids");
}
- const guint *forbidden_ids = rspamd_symcache_get_forbidden_settings_ids(
+ const unsigned int *forbidden_ids = rspamd_symcache_get_forbidden_settings_ids(
cbd->cfg->cache,
sym, &nids);
}
}
-static gint
+static int
lua_config_get_symbols(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_config_get_symbol(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *sym_name = luaL_checkstring(L, 2);
+ const char *sym_name = luaL_checkstring(L, 2);
if (cfg != NULL && sym_name != NULL) {
struct lua_metric_symbols_cbdata cbd;
return 1;
}
-static gint
+static int
lua_config_get_symbol_callback(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *sym = luaL_checkstring(L, 2);
+ const char *sym = luaL_checkstring(L, 2);
struct rspamd_abstract_callback_data *abs_cbdata;
struct lua_callback_data *cbd;
return 1;
}
-static gint
+static int
lua_config_set_symbol_callback(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *sym = luaL_checkstring(L, 2);
+ const char *sym = luaL_checkstring(L, 2);
struct rspamd_abstract_callback_data *abs_cbdata;
struct lua_callback_data *cbd;
return 1;
}
-static gint
+static int
lua_config_get_symbol_stat(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *sym = luaL_checkstring(L, 2);
- gdouble freq, stddev, tm;
- guint hits;
+ const char *sym = luaL_checkstring(L, 2);
+ double freq, stddev, tm;
+ unsigned int hits;
if (cfg != NULL && sym != NULL) {
if (!rspamd_symcache_stat_symbol(cfg->cache, sym, &freq,
return 1;
}
-static gint
+static int
lua_config_get_symbol_parent(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *sym = luaL_checkstring(L, 2), *parent;
+ const char *sym = luaL_checkstring(L, 2), *parent;
if (cfg != NULL && sym != NULL) {
parent = rspamd_symcache_get_parent(cfg->cache, sym);
return 1;
}
-static gint
+static int
lua_config_get_group_symbols(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *gr_name = luaL_checkstring(L, 2);
+ const char *gr_name = luaL_checkstring(L, 2);
if (cfg != NULL && gr_name != NULL) {
struct rspamd_symbols_group *group;
lua_pushnil(L);
}
else {
- guint i = 1;
+ unsigned int i = 1;
gpointer k, v;
GHashTableIter it;
return 1;
}
-static gint
+static int
lua_config_get_groups(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_config_register_finish_script(lua_State *L)
{
LUA_TRACE_POINT;
return false;
}
-static gint
+static int
lua_config_register_settings_id(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *settings_name = luaL_checkstring(L, 2);
+ const char *settings_name = luaL_checkstring(L, 2);
if (cfg != NULL && settings_name) {
ucl_object_t *sym_enabled, *sym_disabled;
/* Check policy */
if (lua_isstring(L, 5)) {
- const gchar *policy_str = lua_tostring(L, 5);
+ const char *policy_str = lua_tostring(L, 5);
if (strcmp(policy_str, "default") == 0) {
policy = RSPAMD_SETTINGS_POLICY_DEFAULT;
return 0;
}
-static gint
+static int
lua_config_register_monitored(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
struct rspamd_monitored *m, **pm;
- const gchar *url, *type;
+ const char *url, *type;
ucl_object_t *params = NULL;
url = lua_tostring(L, 2);
return 1;
}
-static gint
+static int
lua_config_add_doc(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg;
- const gchar *path = NULL, *option, *doc_string;
- const gchar *type_str = NULL, *default_value = NULL;
+ const char *path = NULL, *option, *doc_string;
+ const char *type_str = NULL, *default_value = NULL;
ucl_type_t type = UCL_NULL;
gboolean required = FALSE;
GError *err = NULL;
return 0;
}
-static gint
+static int
lua_config_add_example(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg;
- const gchar *path = NULL, *option, *doc_string, *example;
+ const char *path = NULL, *option, *doc_string, *example;
gsize example_len;
cfg = lua_check_config(L, 1);
return 0;
}
-static gint
+static int
lua_config_get_cpu_flags(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_config_has_torch(lua_State *L)
{
msg_warn("use of the obsoleted `has_torch` function");
return 1;
}
-static gint
+static int
lua_config_experimental_enabled(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_include_trace_cbdata {
lua_State *L;
- gint cbref;
+ int cbref;
};
static void
{
struct rspamd_lua_include_trace_cbdata *cbdata =
(struct rspamd_lua_include_trace_cbdata *) user_data;
- gint err_idx;
+ int err_idx;
lua_State *L;
L = cbdata->L;
lua_pop(L, 1); \
} while (0)
-static gint
+static int
lua_config_load_ucl(lua_State *L)
{
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *filename;
+ const char *filename;
GHashTable *paths = g_hash_table_new_full(rspamd_str_hash, rspamd_str_equal,
NULL, g_free);
GError *err = NULL;
#undef IDX_TO_HASH
-static gint
+static int
lua_config_parse_rcl(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_config_init_modules(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_config_init_subsystem(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *subsystem = luaL_checkstring(L, 2);
- gchar **parts;
- guint nparts, i;
+ const char *subsystem = luaL_checkstring(L, 2);
+ char **parts;
+ unsigned int nparts, i;
if (cfg != NULL && subsystem != NULL) {
parts = g_strsplit_set(subsystem, ";,", -1);
return 0;
}
-static gint
+static int
lua_config_register_re_selector(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *name = luaL_checkstring(L, 2);
- const gchar *selector_str = luaL_checkstring(L, 3);
- const gchar *delimiter = "";
+ const char *name = luaL_checkstring(L, 2);
+ const char *selector_str = luaL_checkstring(L, 3);
+ const char *delimiter = "";
bool flatten = false;
- gint top = lua_gettop(L);
+ int top = lua_gettop(L);
bool res = false;
if (cfg && name && selector_str) {
lua_typename(L, lua_type(L, -1)));
}
else {
- gint err_idx, ret;
+ int err_idx, ret;
struct rspamd_config **pcfg;
lua_pushcfunction(L, &rspamd_lua_traceback);
return 1;
}
-static gint
+static int
lua_config_get_tld_path(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_config_get_dns_max_requests(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_config_get_dns_timeout(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_monitored_alive(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_monitored_offline(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_monitored_total_offline(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_monitored_latency(lua_State *L)
{
LUA_TRACE_POINT;
};
struct rspamd_lua_cryptobox_secretbox {
- guchar sk[crypto_secretbox_KEYBYTES];
+ unsigned char sk[crypto_secretbox_KEYBYTES];
};
static struct rspamd_cryptobox_pubkey *
* @param {string} alg optional 'default' or 'nist' for curve25519/nistp256 keys
* @return {cryptobox_pubkey} new public key
*/
-static gint
+static int
lua_cryptobox_pubkey_load(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_cryptobox_pubkey *pkey = NULL, **ppkey;
- const gchar *filename, *arg;
- gint type = RSPAMD_KEYPAIR_SIGN;
- gint alg = RSPAMD_CRYPTOBOX_MODE_25519;
- guchar *map;
+ const char *filename, *arg;
+ int type = RSPAMD_KEYPAIR_SIGN;
+ int alg = RSPAMD_CRYPTOBOX_MODE_25519;
+ unsigned char *map;
gsize len;
filename = luaL_checkstring(L, 1);
* @param {string} alg optional 'default' or 'nist' for curve25519/nistp256 keys
* @return {cryptobox_pubkey} new public key
*/
-static gint
+static int
lua_cryptobox_pubkey_create(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_cryptobox_pubkey *pkey = NULL, **ppkey;
- const gchar *buf, *arg;
+ const char *buf, *arg;
gsize len;
- gint type = RSPAMD_KEYPAIR_SIGN;
- gint alg = RSPAMD_CRYPTOBOX_MODE_25519;
+ int type = RSPAMD_KEYPAIR_SIGN;
+ int alg = RSPAMD_CRYPTOBOX_MODE_25519;
buf = luaL_checklstring(L, 1, &len);
if (buf != NULL) {
return 1;
}
-static gint
+static int
lua_cryptobox_pubkey_gc(lua_State *L)
{
LUA_TRACE_POINT;
* @param {string} file filename to load
* @return {cryptobox_keypair} new keypair
*/
-static gint
+static int
lua_cryptobox_keypair_load(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_cryptobox_keypair *kp, **pkp;
- const gchar *buf;
+ const char *buf;
gsize len;
struct ucl_parser *parser;
ucl_object_t *obj;
* @param {string} alg algorithm of keypair: 'curve25519' (default) or 'nist'
* @return {cryptobox_keypair} new keypair
*/
-static gint
+static int
lua_cryptobox_keypair_create(lua_State *L)
{
LUA_TRACE_POINT;
enum rspamd_cryptobox_mode alg = RSPAMD_CRYPTOBOX_MODE_25519;
if (lua_isstring(L, 1)) {
- const gchar *str = lua_tostring(L, 1);
+ const char *str = lua_tostring(L, 1);
if (strcmp(str, "sign") == 0) {
type = RSPAMD_KEYPAIR_SIGN;
}
if (lua_isstring(L, 2)) {
- const gchar *str = lua_tostring(L, 2);
+ const char *str = lua_tostring(L, 2);
if (strcmp(str, "nist") == 0 || strcmp(str, "openssl") == 0) {
alg = RSPAMD_CRYPTOBOX_MODE_NIST;
return 1;
}
-static gint
+static int
lua_cryptobox_keypair_gc(lua_State *L)
{
LUA_TRACE_POINT;
* @method keypair:totable([hex=false]])
* Converts keypair to table (not very safe due to memory leftovers)
*/
-static gint
+static int
lua_cryptobox_keypair_totable(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_cryptobox_keypair *kp = lua_check_cryptobox_keypair(L, 1);
ucl_object_t *obj;
gboolean hex = FALSE;
- gint ret = 1;
+ int ret = 1;
if (kp != NULL) {
* Returns type of keypair as a string: 'encryption' or 'sign'
* @return {string} type of keypair as a string
*/
-static gint
+static int
lua_cryptobox_keypair_get_type(lua_State *L)
{
LUA_TRACE_POINT;
* Returns algorithm of keypair as a string: 'encryption' or 'sign'
* @return {string} type of keypair as a string
*/
-static gint
+static int
lua_cryptobox_keypair_get_alg(lua_State *L)
{
LUA_TRACE_POINT;
* Returns pubkey for a specific keypair
* @return {rspamd_pubkey} pubkey for a keypair
*/
-static gint
+static int
lua_cryptobox_keypair_get_pk(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_cryptobox_keypair *kp = lua_check_cryptobox_keypair(L, 1);
struct rspamd_cryptobox_pubkey *pk, **ppk;
- const guchar *data;
- guint dlen;
+ const unsigned char *data;
+ unsigned int dlen;
if (kp) {
data = rspamd_keypair_component(kp, RSPAMD_KEYPAIR_COMPONENT_PK, &dlen);
* @param {string} file filename to load
* @return {cryptobox_signature} new signature
*/
-static gint
+static int
lua_cryptobox_signature_load(lua_State *L)
{
LUA_TRACE_POINT;
rspamd_fstring_t *sig, **psig;
- const gchar *filename;
+ const char *filename;
gpointer data;
int fd;
struct stat st;
}
else {
if (lua_isstring(L, 2)) {
- const gchar *str = lua_tostring(L, 2);
+ const char *str = lua_tostring(L, 2);
if (strcmp(str, "nist") == 0 || strcmp(str, "openssl") == 0) {
alg = RSPAMD_CRYPTOBOX_MODE_NIST;
* @param {string} file filename to use
* @return {boolean} true if signature has been saved
*/
-static gint
+static int
lua_cryptobox_signature_save(lua_State *L)
{
LUA_TRACE_POINT;
rspamd_fstring_t *sig;
- gint fd, flags;
- const gchar *filename;
+ int fd, flags;
+ const char *filename;
gboolean forced = FALSE, res = TRUE;
sig = lua_check_cryptobox_sign(L, 1);
* @param {data} raw signature data
* @return {cryptobox_signature} signature object
*/
-static gint
+static int
lua_cryptobox_signature_create(lua_State *L)
{
LUA_TRACE_POINT;
rspamd_fstring_t *sig, **psig;
struct rspamd_lua_text *t;
- const gchar *data;
+ const char *data;
gsize dlen;
if (lua_isuserdata(L, 1)) {
* Return hex encoded signature string
* @return {string} raw value of signature
*/
-static gint
+static int
lua_cryptobox_signature_hex(lua_State *L)
{
LUA_TRACE_POINT;
rspamd_fstring_t *sig = lua_check_cryptobox_sign(L, 1);
- gchar *encoded;
+ char *encoded;
if (sig) {
encoded = rspamd_encode_hex(sig->str, sig->len);
* @param {string} b32type base32 type (default, bleach, rfc)
* @return {string} raw value of signature
*/
-static gint
+static int
lua_cryptobox_signature_base32(lua_State *L)
{
LUA_TRACE_POINT;
rspamd_fstring_t *sig = lua_check_cryptobox_sign(L, 1);
- gchar *encoded;
+ char *encoded;
enum rspamd_base32_type btype = RSPAMD_BASE32_DEFAULT;
if (lua_type(L, 2) == LUA_TSTRING) {
* Return base64 encoded signature string
* @return {string} raw value of signature
*/
-static gint
+static int
lua_cryptobox_signature_base64(lua_State *L)
{
LUA_TRACE_POINT;
rspamd_fstring_t *sig = lua_check_cryptobox_sign(L, 1);
gsize dlen;
- gchar *encoded;
+ char *encoded;
if (sig) {
encoded = rspamd_encode_base64(sig->str, sig->len, 0, &dlen);
* Return raw signature string
* @return {string} raw value of signature
*/
-static gint
+static int
lua_cryptobox_signature_bin(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_cryptobox_signature_gc(lua_State *L)
{
LUA_TRACE_POINT;
static inline void
rspamd_lua_hash_init_default(struct rspamd_lua_cryptobox_hash *h,
- const gchar *key, gsize keylen)
+ const char *key, gsize keylen)
{
h->type = LUA_CRYPTOBOX_HASH_BLAKE2;
if (posix_memalign((void **) &h->content.h,
static void
rspamd_lua_ssl_hmac_create(struct rspamd_lua_cryptobox_hash *h, const EVP_MD *htype,
- const gchar *key, gsize keylen,
+ const char *key, gsize keylen,
bool insecure)
{
h->type = LUA_CRYPTOBOX_HASH_HMAC;
}
static struct rspamd_lua_cryptobox_hash *
-rspamd_lua_hash_create(const gchar *type, const gchar *key, gsize keylen)
+rspamd_lua_hash_create(const char *type, const char *key, gsize keylen)
{
struct rspamd_lua_cryptobox_hash *h;
* @param {string} data optional string to hash
* @return {cryptobox_hash} hash object
*/
-static gint
+static int
lua_cryptobox_hash_create(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_cryptobox_hash *h, **ph;
- const gchar *s = NULL;
+ const char *s = NULL;
struct rspamd_lua_text *t;
gsize len = 0;
* @param {string} string initial data
* @return {cryptobox_hash} hash object
*/
-static gint
+static int
lua_cryptobox_hash_create_specific(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_cryptobox_hash *h, **ph;
- const gchar *s = NULL, *type = luaL_checkstring(L, 1);
+ const char *s = NULL, *type = luaL_checkstring(L, 1);
gsize len = 0;
struct rspamd_lua_text *t;
* @param {string} key key
* @return {cryptobox_hash} hash object
*/
-static gint
+static int
lua_cryptobox_hash_create_keyed(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_cryptobox_hash *h, **ph;
- const gchar *key, *s = NULL;
+ const char *key, *s = NULL;
struct rspamd_lua_text *t;
gsize len = 0;
gsize keylen;
* @param {string} key key
* @return {cryptobox_hash} hash object
*/
-static gint
+static int
lua_cryptobox_hash_create_specific_keyed(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_cryptobox_hash *h, **ph;
- const gchar *key, *s = NULL, *type = luaL_checkstring(L, 2);
+ const char *key, *s = NULL, *type = luaL_checkstring(L, 2);
struct rspamd_lua_text *t;
gsize len = 0;
gsize keylen;
* Updates hash with the specified data (hash should not be finalized using `hex` or `bin` methods)
* @param {string} data data to hash
*/
-static gint
+static int
lua_cryptobox_hash_update(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_cryptobox_hash *h = lua_check_cryptobox_hash(L, 1), **ph;
- const gchar *data;
+ const char *data;
struct rspamd_lua_text *t;
gsize len;
* @method cryptobox_hash:reset()
* Resets hash to the initial state
*/
-static gint
+static int
lua_cryptobox_hash_reset(lua_State *L)
{
LUA_TRACE_POINT;
lua_cryptobox_hash_finish(struct rspamd_lua_cryptobox_hash *h)
{
uint64_t ll;
- guchar out[rspamd_cryptobox_HASHBYTES];
- guint ssl_outlen = sizeof(out);
+ unsigned char out[rspamd_cryptobox_HASHBYTES];
+ unsigned int ssl_outlen = sizeof(out);
switch (h->type) {
case LUA_CRYPTOBOX_HASH_BLAKE2:
* Finalizes hash and return it as hex string
* @return {string} hex value of hash
*/
-static gint
+static int
lua_cryptobox_hash_hex(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_cryptobox_hash *h = lua_check_cryptobox_hash(L, 1);
- guchar out_hex[rspamd_cryptobox_HASHBYTES * 2 + 1], *r;
- guint dlen;
+ unsigned char out_hex[rspamd_cryptobox_HASHBYTES * 2 + 1], *r;
+ unsigned int dlen;
if (h) {
if (!h->is_finished) {
dlen = h->out_len;
if (lua_isnumber(L, 2)) {
- guint lim = lua_tonumber(L, 2);
+ unsigned int lim = lua_tonumber(L, 2);
if (lim < dlen) {
r += dlen - lim;
* @param {string} b32type base32 type (default, bleach, rfc)
* @return {string} base32 value of hash
*/
-static gint
+static int
lua_cryptobox_hash_base32(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_cryptobox_hash *h = lua_check_cryptobox_hash(L, 1);
- guchar out_b32[rspamd_cryptobox_HASHBYTES * 2], *r;
- guint dlen;
+ unsigned char out_b32[rspamd_cryptobox_HASHBYTES * 2], *r;
+ unsigned int dlen;
if (h) {
enum rspamd_base32_type btype = RSPAMD_BASE32_DEFAULT;
dlen = h->out_len;
if (lua_isnumber(L, 2)) {
- guint lim = lua_tonumber(L, 2);
+ unsigned int lim = lua_tonumber(L, 2);
if (lim < dlen) {
r += dlen - lim;
* Finalizes hash and return it as base64 string
* @return {string} base64 value of hash
*/
-static gint
+static int
lua_cryptobox_hash_base64(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_cryptobox_hash *h = lua_check_cryptobox_hash(L, 1);
- guchar *b64, *r;
+ unsigned char *b64, *r;
gsize len;
- guint dlen;
+ unsigned int dlen;
if (h) {
if (!h->is_finished) {
dlen = h->out_len;
if (lua_isnumber(L, 2)) {
- guint lim = lua_tonumber(L, 2);
+ unsigned int lim = lua_tonumber(L, 2);
if (lim < dlen) {
r += dlen - lim;
* Finalizes hash and return it as raw string
* @return {string} raw value of hash
*/
-static gint
+static int
lua_cryptobox_hash_bin(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_cryptobox_hash *h = lua_check_cryptobox_hash(L, 1);
- guchar *r;
- guint dlen;
+ unsigned char *r;
+ unsigned int dlen;
if (h) {
if (!h->is_finished) {
dlen = h->out_len;
if (lua_isnumber(L, 2)) {
- guint lim = lua_tonumber(L, 2);
+ unsigned int lim = lua_tonumber(L, 2);
if (lim < dlen) {
r += dlen - lim;
return 1;
}
-static gint
+static int
lua_cryptobox_hash_gc(lua_State *L)
{
LUA_TRACE_POINT;
* @param {string} data data to check signature against
* @return {boolean} `true` - if string matches cryptobox signature
*/
-static gint
+static int
lua_cryptobox_verify_memory(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_cryptobox_pubkey *pk;
rspamd_fstring_t *signature;
struct rspamd_lua_text *t;
- const gchar *data;
+ const char *data;
enum rspamd_cryptobox_mode alg = RSPAMD_CRYPTOBOX_MODE_25519;
gsize len;
- gint ret;
+ int ret;
pk = lua_check_cryptobox_pubkey(L, 1);
signature = lua_check_cryptobox_sign(L, 2);
}
if (lua_isstring(L, 4)) {
- const gchar *str = lua_tostring(L, 4);
+ const char *str = lua_tostring(L, 4);
if (strcmp(str, "nist") == 0 || strcmp(str, "openssl") == 0) {
alg = RSPAMD_CRYPTOBOX_MODE_NIST;
* @param {string} file to load data from
* @return {boolean} `true` - if string matches cryptobox signature
*/
-static gint
+static int
lua_cryptobox_verify_file(lua_State *L)
{
LUA_TRACE_POINT;
- const gchar *fname;
+ const char *fname;
struct rspamd_cryptobox_pubkey *pk;
rspamd_fstring_t *signature;
- guchar *map = NULL;
+ unsigned char *map = NULL;
enum rspamd_cryptobox_mode alg = RSPAMD_CRYPTOBOX_MODE_25519;
gsize len;
- gint ret;
+ int ret;
pk = lua_check_cryptobox_pubkey(L, 1);
signature = lua_check_cryptobox_sign(L, 2);
fname = luaL_checkstring(L, 3);
if (lua_isstring(L, 4)) {
- const gchar *str = lua_tostring(L, 4);
+ const char *str = lua_tostring(L, 4);
if (strcmp(str, "nist") == 0 || strcmp(str, "openssl") == 0) {
alg = RSPAMD_CRYPTOBOX_MODE_NIST;
* @param {string} data
* @return {cryptobox_signature} signature object
*/
-static gint
+static int
lua_cryptobox_sign_memory(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_cryptobox_keypair *kp;
- const gchar *data;
+ const char *data;
struct rspamd_lua_text *t;
gsize len = 0;
rspamd_fstring_t *sig, **psig;
* @param {string} filename
* @return {cryptobox_signature} signature object
*/
-static gint
+static int
lua_cryptobox_sign_file(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_cryptobox_keypair *kp;
- const gchar *filename;
- gchar *data;
+ const char *filename;
+ char *data;
gsize len = 0;
rspamd_fstring_t *sig, **psig;
* @param {string|text} data
* @return {rspamd_text} encrypted text
*/
-static gint
+static int
lua_cryptobox_encrypt_memory(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_cryptobox_keypair *kp = NULL;
struct rspamd_cryptobox_pubkey *pk = NULL;
- const gchar *data;
- guchar *out = NULL;
+ const char *data;
+ unsigned char *out = NULL;
struct rspamd_lua_text *t, *res;
gsize len = 0, outlen = 0;
GError *err = NULL;
}
}
else if (lua_type(L, 1) == LUA_TSTRING) {
- const gchar *b32;
+ const char *b32;
gsize blen;
b32 = lua_tolstring(L, 1, &blen);
if (kp) {
if (!rspamd_keypair_encrypt(kp, data, len, &out, &outlen, &err)) {
- gint ret = luaL_error(L, "cannot encrypt data: %s", err->message);
+ int ret = luaL_error(L, "cannot encrypt data: %s", err->message);
g_error_free(err);
if (owned_pk) {
}
else {
if (!rspamd_pubkey_encrypt(pk, data, len, &out, &outlen, &err)) {
- gint ret = luaL_error(L, "cannot encrypt data: %s", err->message);
+ int ret = luaL_error(L, "cannot encrypt data: %s", err->message);
g_error_free(err);
if (owned_pk) {
* @param {string} filename
* @return {rspamd_text} encrypted text
*/
-static gint
+static int
lua_cryptobox_encrypt_file(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_cryptobox_keypair *kp = NULL;
struct rspamd_cryptobox_pubkey *pk = NULL;
- const gchar *filename;
- gchar *data = NULL;
- guchar *out = NULL;
+ const char *filename;
+ char *data = NULL;
+ unsigned char *out = NULL;
struct rspamd_lua_text *res;
gsize len = 0, outlen = 0;
GError *err = NULL;
}
}
else if (lua_type(L, 1) == LUA_TSTRING) {
- const gchar *b32;
+ const char *b32;
gsize blen;
b32 = lua_tolstring(L, 1, &blen);
if (kp) {
if (!rspamd_keypair_encrypt(kp, data, len, &out, &outlen, &err)) {
- gint ret = luaL_error(L, "cannot encrypt file %s: %s", filename,
- err->message);
+ int ret = luaL_error(L, "cannot encrypt file %s: %s", filename,
+ err->message);
g_error_free(err);
munmap(data, len);
if (own_pk) {
}
else if (pk) {
if (!rspamd_pubkey_encrypt(pk, data, len, &out, &outlen, &err)) {
- gint ret = luaL_error(L, "cannot encrypt file %s: %s", filename,
- err->message);
+ int ret = luaL_error(L, "cannot encrypt file %s: %s", filename,
+ err->message);
g_error_free(err);
munmap(data, len);
* @param {string} data
* @return status,{rspamd_text}|error status is boolean variable followed by either unencrypted data or an error message
*/
-static gint
+static int
lua_cryptobox_decrypt_memory(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_cryptobox_keypair *kp;
- const gchar *data;
- guchar *out;
+ const char *data;
+ unsigned char *out;
struct rspamd_lua_text *t, *res;
gsize len = 0, outlen;
GError *err = NULL;
* @param {string} filename
* @return status,{rspamd_text}|error status is boolean variable followed by either unencrypted data or an error message
*/
-static gint
+static int
lua_cryptobox_decrypt_file(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_cryptobox_keypair *kp;
- const gchar *filename;
- gchar *data;
- guchar *out;
+ const char *filename;
+ char *data;
+ unsigned char *out;
struct rspamd_lua_text *res;
gsize len = 0, outlen;
GError *err = NULL;
* @param {string} secret_cookie secret cookie as a string for up to 31 character
* @return {string} e function value for this sk and cookie
*/
-static gint
+static int
lua_cryptobox_encrypt_cookie(lua_State *L)
{
- guchar aes_block[RSPAMD_CRYPTOBOX_AES_BLOCKSIZE], *blk;
- guchar padded_cookie[RSPAMD_CRYPTOBOX_AES_BLOCKSIZE];
- guchar nonce[RSPAMD_CRYPTOBOX_AES_BLOCKSIZE];
- guchar aes_key[RSPAMD_CRYPTOBOX_AES_KEYSIZE];
- guchar result[RSPAMD_CRYPTOBOX_AES_BLOCKSIZE * 2];
+ unsigned char aes_block[RSPAMD_CRYPTOBOX_AES_BLOCKSIZE], *blk;
+ unsigned char padded_cookie[RSPAMD_CRYPTOBOX_AES_BLOCKSIZE];
+ unsigned char nonce[RSPAMD_CRYPTOBOX_AES_BLOCKSIZE];
+ unsigned char aes_key[RSPAMD_CRYPTOBOX_AES_KEYSIZE];
+ unsigned char result[RSPAMD_CRYPTOBOX_AES_BLOCKSIZE * 2];
uint32_t ts;
- const gchar *sk, *cookie;
+ const char *sk, *cookie;
gsize sklen, cookie_len;
- gint bklen;
+ int bklen;
sk = lua_tolstring(L, 1, &sklen);
cookie = lua_tolstring(L, 2, &cookie_len);
memcpy(aes_key, sk, sizeof(aes_key));
}
else {
- return luaL_error(L, "invalid keysize %d", (gint) sklen);
+ return luaL_error(L, "invalid keysize %d", (int) sklen);
}
if (cookie_len > sizeof(padded_cookie) - 1) {
- return luaL_error(L, "cookie is too long %d", (gint) cookie_len);
+ return luaL_error(L, "cookie is too long %d", (int) cookie_len);
}
/* Fill nonce */
/* Encode result */
memcpy(result, nonce, sizeof(nonce));
- for (guint i = 0; i < sizeof(aes_block); i++) {
+ for (unsigned int i = 0; i < sizeof(aes_block); i++) {
result[i + sizeof(nonce)] = padded_cookie[i] ^ aes_block[i];
}
gsize rlen;
- gchar *res = rspamd_encode_base64(result, sizeof(result),
- 0, &rlen);
+ char *res = rspamd_encode_base64(result, sizeof(result),
+ 0, &rlen);
lua_pushlstring(L, res, rlen);
g_free(res);
* @param {string} encrypted_cookie encrypted cookie as a base64 encoded string
* @return {string+number} decrypted value of the cookie and the cookie timestamp
*/
-static gint
+static int
lua_cryptobox_decrypt_cookie(lua_State *L)
{
- guchar *blk;
- guchar nonce[RSPAMD_CRYPTOBOX_AES_BLOCKSIZE];
- guchar aes_key[RSPAMD_CRYPTOBOX_AES_KEYSIZE];
- guchar *src;
+ unsigned char *blk;
+ unsigned char nonce[RSPAMD_CRYPTOBOX_AES_BLOCKSIZE];
+ unsigned char aes_key[RSPAMD_CRYPTOBOX_AES_KEYSIZE];
+ unsigned char *src;
uint32_t ts;
- const gchar *sk, *cookie;
+ const char *sk, *cookie;
gsize sklen, cookie_len;
- gint bklen;
+ int bklen;
sk = lua_tolstring(L, 1, &sklen);
cookie = lua_tolstring(L, 2, &cookie_len);
memcpy(aes_key, sk, sizeof(aes_key));
}
else {
- return luaL_error(L, "invalid keysize %d", (gint) sklen);
+ return luaL_error(L, "invalid keysize %d", (int) sklen);
}
src = g_malloc(cookie_len);
EVP_CIPHER_CTX_free(ctx);
/* Decode result */
- for (guint i = 0; i < RSPAMD_CRYPTOBOX_AES_BLOCKSIZE; i++) {
+ for (unsigned int i = 0; i < RSPAMD_CRYPTOBOX_AES_BLOCKSIZE; i++) {
src[i + sizeof(nonce)] ^= nonce[i];
}
* @param {string} kdf_alg algorithm to use (catena or pbkdf2)
* @return {string} encrypted password or nil if error occurs
*/
-static gint
+static int
lua_cryptobox_pbkdf(lua_State *L)
{
const struct rspamd_controller_pbkdf *pbkdf = NULL;
- const gchar *pbkdf_str = "catena";
- gchar *password;
+ const char *pbkdf_str = "catena";
+ char *password;
gsize pwlen;
if (lua_type(L, 2) == LUA_TSTRING) {
pbkdf_str = lua_tostring(L, 2);
}
- for (guint i = 0; i < RSPAMD_PBKDF_ID_MAX - 1; i++) {
+ for (unsigned int i = 0; i < RSPAMD_PBKDF_ID_MAX - 1; i++) {
pbkdf = &pbkdf_list[i];
if (g_ascii_strcasecmp(pbkdf_str, pbkdf->alias) == 0) {
return 1;
}
- guchar *salt, *key;
- gchar *encoded_salt, *encoded_key;
+ unsigned char *salt, *key;
+ char *encoded_salt, *encoded_key;
GString *result;
salt = g_alloca(pbkdf->salt_len);
* @param {number} nbits optional number of bits for rsa (default 1024)
* @return {rspamd_text,rspamd_text} private key and public key as base64 encoded strings
*/
-static gint
+static int
lua_cryptobox_gen_dkim_keypair(lua_State *L)
{
- const gchar *alg_str = "rsa";
- guint nbits = 1024;
+ const char *alg_str = "rsa";
+ unsigned int nbits = 1024;
struct rspamd_lua_text *priv_out, *pub_out;
if (lua_type(L, 1) == LUA_TSTRING) {
}
BIO *mbio;
- gint rc, len;
- guchar *data;
- gchar *b64_data;
+ int rc, len;
+ unsigned char *data;
+ char *b64_data;
gsize b64_len;
mbio = BIO_new(BIO_s_mem());
else if (strcmp(alg_str, "ed25519") == 0) {
rspamd_sig_pk_t pk;
rspamd_sig_sk_t sk;
- gchar *b64_data;
+ char *b64_data;
gsize b64_len;
rspamd_cryptobox_keypair_sig(pk, sk, RSPAMD_CRYPTOBOX_MODE_25519);
else if (strcmp(alg_str, "ed25519-seed") == 0) {
rspamd_sig_pk_t pk;
rspamd_sig_sk_t sk;
- gchar *b64_data;
+ char *b64_data;
gsize b64_len;
rspamd_cryptobox_keypair_sig(pk, sk, RSPAMD_CRYPTOBOX_MODE_25519);
* @param {table} params optional parameters - NYI
* @return {rspamd_cryptobox_secretbox} opaque object with the key expanded
*/
-static gint
+static int
lua_cryptobox_secretbox_create(lua_State *L)
{
- const gchar *in;
+ const char *in;
gsize inlen;
}
-static gint
+static int
lua_cryptobox_secretbox_gc(lua_State *L)
{
struct rspamd_lua_cryptobox_secretbox *sbox =
* @param {table} params optional parameters - NYI
* @return {rspamd_text},{rspamd_text} output with mac + nonce or just output if nonce is there
*/
-static gint
+static int
lua_cryptobox_secretbox_encrypt(lua_State *L)
{
- const gchar *in, *nonce;
+ const char *in, *nonce;
gsize inlen, nlen;
struct rspamd_lua_cryptobox_secretbox *sbox =
lua_check_cryptobox_secretbox(L, 1);
return luaL_error(L, "bad nonce");
}
- guchar real_nonce[crypto_secretbox_NONCEBYTES];
+ unsigned char real_nonce[crypto_secretbox_NONCEBYTES];
memset(real_nonce, 0, sizeof(real_nonce));
memcpy(real_nonce, nonce, nlen);
out = lua_new_text(L, NULL, inlen + crypto_secretbox_MACBYTES,
TRUE);
- crypto_secretbox_easy((guchar *) out->start, in, inlen,
+ crypto_secretbox_easy((unsigned char *) out->start, in, inlen,
nonce, sbox->sk);
return 1;
TRUE);
random_nonce = lua_new_text(L, NULL, crypto_secretbox_NONCEBYTES, TRUE);
- randombytes_buf((guchar *) random_nonce->start, random_nonce->len);
- crypto_secretbox_easy((guchar *) out->start, in, inlen,
+ randombytes_buf((unsigned char *) random_nonce->start, random_nonce->len);
+ crypto_secretbox_easy((unsigned char *) out->start, in, inlen,
random_nonce->start, sbox->sk);
return 2; /* output + random nonce */
* @param {table} params optional parameters - NYI
* @return {boolean},{rspamd_text} decryption result + decrypted text
*/
-static gint
+static int
lua_cryptobox_secretbox_decrypt(lua_State *L)
{
- const gchar *in, *nonce;
+ const char *in, *nonce;
gsize inlen, nlen;
struct rspamd_lua_cryptobox_secretbox *sbox =
lua_check_cryptobox_secretbox(L, 1);
return 2;
}
- guchar real_nonce[crypto_secretbox_NONCEBYTES];
+ unsigned char real_nonce[crypto_secretbox_NONCEBYTES];
memset(real_nonce, 0, sizeof(real_nonce));
memcpy(real_nonce, nonce, nlen);
out = lua_new_text(L, NULL, inlen - crypto_secretbox_MACBYTES,
TRUE);
- gint text_pos = lua_gettop(L);
+ int text_pos = lua_gettop(L);
- if (crypto_secretbox_open_easy((guchar *) out->start, in, inlen,
+ if (crypto_secretbox_open_easy((unsigned char *) out->start, in, inlen,
nonce, sbox->sk) == 0) {
lua_pushboolean(L, true);
lua_pushvalue(L, text_pos); /* Prevent gc by copying in stack */
return 2;
}
-static gint
+static int
lua_load_pubkey(lua_State *L)
{
lua_newtable(L);
return 1;
}
-static gint
+static int
lua_load_keypair(lua_State *L)
{
lua_newtable(L);
return 1;
}
-static gint
+static int
lua_load_signature(lua_State *L)
{
lua_newtable(L);
return 1;
}
-static gint
+static int
lua_load_hash(lua_State *L)
{
lua_newtable(L);
return 1;
}
-static gint
+static int
lua_load_cryptobox_secretbox(lua_State *L)
{
lua_newtable(L);
return 1;
}
-static gint
+static int
lua_load_cryptobox(lua_State *L)
{
lua_newtable(L);
{"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}};
-static const gchar *M = "rspamd lua dns";
+static const char *M = "rspamd lua dns";
void lua_dns_callback(struct rdns_reply *reply, void *arg);
struct rspamd_async_session *s;
};
-static gint
+static int
lua_dns_request(lua_State *L)
{
GError *err = NULL;
struct rspamd_async_session *session = NULL;
struct rspamd_config *cfg = NULL;
struct lua_rspamd_dns_cbdata *cbdata = NULL;
- const gchar *to_resolve = NULL;
- const gchar *type_str = NULL;
+ const char *to_resolve = NULL;
+ const char *type_str = NULL;
struct rspamd_task *task = NULL;
rspamd_mempool_t *pool = NULL;
- gint ret = 0;
+ int ret = 0;
gboolean forced = FALSE;
/* Check arguments */
}
}
-static gint
+static int
lua_load_dns(lua_State *L)
{
lua_newtable(L);
end
*/
-static const gchar *M = "rspamd lua dns resolver";
+static const char *M = "rspamd lua dns resolver";
/* Lua bindings */
LUA_FUNCTION_DEF(dns_resolver, init);
{NULL, NULL}};
struct rspamd_dns_resolver *
-lua_check_dns_resolver(lua_State *L, gint pos)
+lua_check_dns_resolver(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_resolver_classname);
luaL_argcheck(L, ud != NULL, pos, "'resolver' expected");
struct rspamd_task *task;
rspamd_mempool_t *pool;
struct rspamd_dns_resolver *resolver;
- gint cbref;
- gchar *to_resolve;
- gchar *user_str;
+ int cbref;
+ char *to_resolve;
+ char *user_str;
struct rspamd_symcache_dynamic_item *item;
struct rspamd_async_session *s;
};
lua_dns_get_type(lua_State *L, int argno)
{
int type = RDNS_REQUEST_A;
- const gchar *strtype;
+ const char *strtype;
if (lua_type(L, argno) != LUA_TSTRING) {
lua_pushvalue(L, argno);
lua_State *L;
struct lua_callback_state cbs;
rspamd_mempool_t *pool;
- gint err_idx;
+ int err_idx;
pool = cd->pool;
lua_thread_pool_prepare_callback(cd->resolver->cfg->lua_thread_pool, &cbs);
lua_pushboolean(L, reply->flags & RDNS_AUTH);
- const gchar *servname = rdns_request_get_server(reply->request);
+ const char *servname = rdns_request_get_server(reply->request);
if (servname) {
lua_pushstring(L, servname);
void lua_push_dns_reply(lua_State *L, const struct rdns_reply *reply)
{
- gint i = 0, naddrs = 0;
+ int i = 0, naddrs = 0;
struct rdns_reply_entry *elt;
rspamd_inet_addr_t *addr;
LUA_TRACE_POINT;
struct rspamd_async_session *session = NULL;
rspamd_mempool_t *pool = NULL;
- const gchar *to_resolve = NULL, *user_str = NULL;
+ const char *to_resolve = NULL, *user_str = NULL;
struct lua_dns_cbdata *cbdata;
- gint cbref = -1, ret;
+ int cbref = -1, ret;
struct rspamd_task *task = NULL;
GError *err = NULL;
gboolean forced = FALSE;
{
struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver(L, 1);
gsize hlen;
- guint conv_len = 0;
- const gchar *hname = luaL_checklstring(L, 2, &hlen);
- gchar *converted;
+ unsigned int conv_len = 0;
+ const char *hname = luaL_checklstring(L, 2, &hlen);
+ char *converted;
rspamd_mempool_t *pool = rspamd_lua_check_udata_maybe(L, 3, rspamd_mempool_classname);
return 1;
}
-static gint
+static int
lua_load_dns_resolver(lua_State *L)
{
lua_newtable(L);
LUA_INTERFACE_DEF(expr, create),
{NULL, NULL}};
-static rspamd_expression_atom_t *lua_atom_parse(const gchar *line, gsize len,
+static rspamd_expression_atom_t *lua_atom_parse(const char *line, gsize len,
rspamd_mempool_t *pool, gpointer ud, GError **err);
-static gdouble lua_atom_process(gpointer runtime_ud, rspamd_expression_atom_t *atom);
+static double lua_atom_process(gpointer runtime_ud, rspamd_expression_atom_t *atom);
static const struct rspamd_atom_subr lua_atom_subr = {
.parse = lua_atom_parse,
struct lua_expression {
struct rspamd_expression *expr;
- gint parse_idx;
- gint process_idx;
+ int parse_idx;
+ int process_idx;
lua_State *L;
rspamd_mempool_t *pool;
};
}
struct lua_expression *
-rspamd_lua_expression(lua_State *L, gint pos)
+rspamd_lua_expression(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_expr_classname);
luaL_argcheck(L, ud != NULL, pos, "'expr' expected");
}
static rspamd_expression_atom_t *
-lua_atom_parse(const gchar *line, gsize len,
+lua_atom_parse(const char *line, gsize len,
rspamd_mempool_t *pool, gpointer ud, GError **err)
{
struct lua_expression *e = (struct lua_expression *) ud;
rspamd_expression_atom_t *atom;
gsize rlen;
- const gchar *tok;
+ const char *tok;
lua_rawgeti(e->L, LUA_REGISTRYINDEX, e->parse_idx);
lua_pushlstring(e->L, line, len);
struct lua_atom_process_data {
lua_State *L;
struct lua_expression *e;
- gint process_cb_pos;
- gint stack_item;
+ int process_cb_pos;
+ int stack_item;
};
-static gdouble
+static double
lua_atom_process(gpointer runtime_ud, rspamd_expression_atom_t *atom)
{
struct lua_atom_process_data *pd = (struct lua_atom_process_data *) runtime_ud;
- gdouble ret = 0;
- guint nargs;
- gint err_idx;
+ double ret = 0;
+ unsigned int nargs;
+ int err_idx;
if (pd->stack_item != -1) {
nargs = 2;
return ret;
}
-static gint
+static int
lua_expr_process(lua_State *L)
{
LUA_TRACE_POINT;
struct lua_expression *e = rspamd_lua_expression(L, 1);
struct lua_atom_process_data pd;
- gdouble res;
- gint flags = 0, old_top;
+ double res;
+ int flags = 0, old_top;
pd.L = L;
pd.e = e;
return 1;
}
-static gint
+static int
lua_expr_process_traced(lua_State *L)
{
LUA_TRACE_POINT;
struct lua_expression *e = rspamd_lua_expression(L, 1);
struct lua_atom_process_data pd;
- gdouble res;
- gint flags = 0, old_top;
+ double res;
+ int flags = 0, old_top;
GPtrArray *trace;
pd.L = L;
lua_createtable(L, trace->len, 0);
- for (guint i = 0; i < trace->len; i++) {
+ for (unsigned int i = 0; i < trace->len; i++) {
struct rspamd_expression_atom_s *atom = g_ptr_array_index(trace, i);
lua_pushlstring(L, atom->str, atom->len);
return 2;
}
-static gint
+static int
lua_expr_create(lua_State *L)
{
LUA_TRACE_POINT;
return 2;
}
-static gint
+static int
lua_expr_to_string(lua_State *L)
{
LUA_TRACE_POINT;
struct lua_expr_atoms_cbdata {
lua_State *L;
- gint idx;
+ int idx;
};
static void
lua_rawseti(cbdata->L, -2, cbdata->idx++);
}
-static gint
+static int
lua_expr_atoms(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_load_expression(lua_State *L)
{
lua_newtable(L);
{NULL, NULL}};
static struct rspamd::html::html_content *
-lua_check_html(lua_State *L, gint pos)
+lua_check_html(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_html_classname);
luaL_argcheck(L, ud != NULL, pos, "'html' expected");
};
static struct lua_html_tag *
-lua_check_html_tag(lua_State *L, gint pos)
+lua_check_html_tag(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_html_tag_classname);
luaL_argcheck(L, ud != NULL, pos, "'html_tag' expected");
return ud ? ((struct lua_html_tag *) ud) : NULL;
}
-static gint
+static int
lua_html_has_tag(lua_State *L)
{
LUA_TRACE_POINT;
auto *hc = lua_check_html(L, 1);
- const gchar *tagname = luaL_checkstring(L, 2);
+ const char *tagname = luaL_checkstring(L, 2);
gboolean ret = FALSE;
if (hc && tagname) {
{"data_urls", RSPAMD_HTML_FLAG_HAS_DATA_URLS},
});
-static gint
+static int
lua_html_has_property(lua_State *L)
{
LUA_TRACE_POINT;
auto *hc = lua_check_html(L, 1);
- const gchar *propname = luaL_checkstring(L, 2);
+ const char *propname = luaL_checkstring(L, 2);
gboolean ret = FALSE;
if (hc && propname) {
lua_settable(L, -3);
}
-static gint
+static int
lua_html_get_images(lua_State *L)
{
LUA_TRACE_POINT;
auto *hc = lua_check_html(L, 1);
- guint i = 1;
+ unsigned int i = 1;
if (hc != NULL) {
lua_createtable(L, hc->images.size(), 0);
lua_settable(L, -3);
}
-static gint
+static int
lua_html_foreach_tag(lua_State *L)
{
LUA_TRACE_POINT;
auto *hc = lua_check_html(L, 1);
- const gchar *tagname;
- gint id;
+ const char *tagname;
+ int id;
auto any = false;
ankerl::unordered_dense::set<int> tags;
return 0;
}
-static gint
+static int
lua_html_get_invisible(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_html_tag_get_type(lua_State *L)
{
LUA_TRACE_POINT;
struct lua_html_tag *ltag = lua_check_html_tag(L, 1);
- const gchar *tagname;
+ const char *tagname;
if (ltag != NULL) {
tagname = rspamd_html_tag_by_id(ltag->tag->id);
return 1;
}
-static gint
+static int
lua_html_tag_get_parent(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_html_tag_get_flags(lua_State *L)
{
LUA_TRACE_POINT;
struct lua_html_tag *ltag = lua_check_html_tag(L, 1);
- gint i = 1;
+ int i = 1;
if (ltag && ltag->tag) {
/* Push flags */
return 1;
}
-static gint
+static int
lua_html_tag_get_content(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_html_tag_get_content_length(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_html_tag_get_extra(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_html_tag_get_style(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_html_tag_get_attribute(lua_State *L)
{
LUA_TRACE_POINT;
struct lua_html_tag *ltag = lua_check_html_tag(L, 1);
gsize slen;
- const gchar *attr_name = luaL_checklstring(L, 2, &slen);
+ const char *attr_name = luaL_checklstring(L, 2, &slen);
if (ltag && attr_name) {
auto maybe_attr = ltag->tag->find_component(
#define MAX_HEADERS_SIZE 8192
-static const gchar *M = "rspamd lua http";
+static const char *M = "rspamd lua http";
LUA_FUNCTION_DEF(http, request);
struct rspamd_cryptobox_keypair *local_kp;
struct rspamd_cryptobox_pubkey *peer_pk;
rspamd_inet_addr_t *addr;
- gchar *mime_type;
- gchar *host;
- gchar *auth;
+ char *mime_type;
+ char *host;
+ char *auth;
struct upstream *up;
- const gchar *url;
+ const char *url;
gsize max_size;
- gint flags;
- gint fd;
- gint cbref;
+ int flags;
+ int fd;
+ int cbref;
struct thread_entry *thread;
ref_entry_t ref;
};
-static const gdouble default_http_timeout = 5.0;
+static const double default_http_timeout = 5.0;
static struct rspamd_dns_resolver *
lua_http_global_resolver(struct ev_loop *ev_base)
{
struct lua_http_cbdata *cbd = (struct lua_http_cbdata *) conn->ud;
struct rspamd_http_header *h;
- const gchar *body;
+ const char *body;
gsize body_len;
struct lua_callback_state lcbd;
{
struct lua_http_cbdata *cbd = (struct lua_http_cbdata *) conn->ud;
lua_State *L = cbd->thread->lua_state;
- const gchar *body;
+ const char *body;
gsize body_len;
struct rspamd_http_header *h;
lua_http_push_headers(lua_State *L, struct rspamd_http_message *msg)
{
const char *name, *value;
- gint i, sz;
+ int i, sz;
lua_pushnil(L);
while (lua_next(L, -2) != 0) {
* @return {boolean} `true`, in **async** mode, if a request has been successfully scheduled. If this value is `false` then some error occurred, the callback thus will not be called.
* @return In **sync** mode `string|nil, nil|table` In sync mode error message if any and response as table: `int` _code_, `string` _content_ and `table` _headers_ (header -> value)
*/
-static gint
+static int
lua_http_request(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_cryptobox_pubkey *peer_key = NULL;
struct rspamd_cryptobox_keypair *local_kp = NULL;
struct upstream *up = NULL;
- const gchar *url, *lua_body;
+ const char *url, *lua_body;
rspamd_fstring_t *body = NULL;
- gint cbref = -1;
+ int cbref = -1;
gsize bodylen;
- gdouble timeout = default_http_timeout;
- gint flags = 0;
- gchar *mime_type = NULL;
- gchar *auth = NULL;
+ double timeout = default_http_timeout;
+ int flags = 0;
+ char *mime_type = NULL;
+ char *auth = NULL;
gsize max_size = 0;
gboolean gzip = FALSE;
lua_gettable(L, 1);
if (lua_type(L, -1) == LUA_TSTRING) {
- const gchar *in;
+ const char *in;
gsize inlen;
in = lua_tolstring(L, -1, &inlen);
lua_gettable(L, 1);
if (lua_type(L, -1) == LUA_TSTRING) {
- const gchar *user = lua_tostring(L, -1);
+ const char *user = lua_tostring(L, -1);
lua_pushstring(L, "password");
lua_gettable(L, 1);
if (lua_type(L, -1) == LUA_TSTRING) {
- const gchar *password = lua_tostring(L, -1);
- gchar *tmpbuf;
+ const char *password = lua_tostring(L, -1);
+ char *tmpbuf;
gsize tlen;
tlen = strlen(user) + strlen(password) + 1;
/* Check if we can skip resolving */
gsize hostlen = 0;
- const gchar *host = rspamd_http_message_get_http_host(msg, &hostlen);
+ const char *host = rspamd_http_message_get_http_host(msg, &hostlen);
if (host) {
cbd->host = g_malloc(hostlen + 1);
return 1;
}
-static gint
+static int
lua_load_http(lua_State *L)
{
lua_newtable(L);
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
}
struct rspamd_lua_ip *
-lua_check_ip(lua_State *L, gint pos)
+lua_check_ip(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_ip_classname);
return ud ? *((struct rspamd_lua_ip **) ud) : NULL;
}
-static gint
+static int
lua_ip_to_table(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_ip *ip = lua_check_ip(L, 1);
- guint max, i;
- guint8 *ptr;
+ unsigned int max, i;
+ uint8_t *ptr;
if (ip != NULL && ip->addr) {
ptr = rspamd_inet_address_get_hash_key(ip->addr, &max);
return 1;
}
-static gint
+static int
lua_ip_str_octets(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_ip *ip = lua_check_ip(L, 1);
- guint max, i;
- guint8 *ptr;
- gint af;
+ unsigned int max, i;
+ uint8_t *ptr;
+ int af;
char numbuf[8];
if (ip != NULL && ip->addr) {
return 1;
}
-static gint
+static int
lua_ip_inversed_str_octets(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_ip *ip = lua_check_ip(L, 1);
- guint max, i;
- guint8 *ptr;
+ unsigned int max, i;
+ uint8_t *ptr;
char numbuf[4];
- gint af;
+ int af;
if (ip != NULL && ip->addr) {
ptr = rspamd_inet_address_get_hash_key(ip->addr, &max);
return 1;
}
-static gint
+static int
lua_ip_to_string(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_ip_get_port(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_ip_from_string(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_ip *ip;
- const gchar *ip_str;
+ const char *ip_str;
gsize len;
ip_str = luaL_checklstring(L, 1, &len);
if (!rspamd_parse_inet_address(&ip->addr,
ip_str, len, RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
- msg_warn("cannot parse ip: %*s", (gint) len, ip_str);
+ msg_warn("cannot parse ip: %*s", (int) len, ip_str);
ip->addr = NULL;
}
}
return 1;
}
-static gint
+static int
lua_ip_to_number(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_ip *ip = lua_check_ip(L, 1);
uint32_t c;
- guint max, i;
- guchar *ptr;
+ unsigned int max, i;
+ unsigned char *ptr;
if (ip != NULL && ip->addr) {
ptr = rspamd_inet_address_get_hash_key(ip->addr, &max);
}
-static gint
+static int
lua_ip_destroy(lua_State *L)
{
LUA_TRACE_POINT;
return 0;
}
-static gint
+static int
lua_ip_get_version(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_ip_is_valid(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_ip_apply_mask(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_ip *ip = lua_check_ip(L, 1), *nip;
- gint mask;
+ int mask;
mask = lua_tonumber(L, 2);
if (mask > 0 && ip != NULL && ip->addr) {
return 1;
}
-static gint
+static int
lua_ip_equal(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_ip_copy(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_ip_is_local(lua_State *L)
{
struct rspamd_lua_ip *ip = lua_check_ip(L, 1);
return 1;
}
-static gint
+static int
lua_ip_less_than(lua_State *L)
{
LUA_TRACE_POINT;
}
}
-void rspamd_lua_ip_push_fromstring(lua_State *L, const gchar *ip_str)
+void rspamd_lua_ip_push_fromstring(lua_State *L, const char *ip_str)
{
struct rspamd_lua_ip *ip, **pip;
}
}
-static gint
+static int
lua_load_ip(lua_State *L)
{
lua_newtable(L);
return result;
}
-static gint
+static int
lua_load_kann(lua_State *L)
{
lua_newtable(L);
static int
lua_kann_layer_input(lua_State *L)
{
- gint nnodes = luaL_checkinteger(L, 1);
+ int nnodes = luaL_checkinteger(L, 1);
if (nnodes > 0) {
kad_node_t *t;
lua_kann_layer_dense(lua_State *L)
{
kad_node_t *in = lua_check_kann_node(L, 1);
- gint nnodes = luaL_checkinteger(L, 2);
+ int nnodes = luaL_checkinteger(L, 2);
if (in != NULL && nnodes > 0) {
kad_node_t *t;
lua_kann_layer_rnn(lua_State *L)
{
kad_node_t *in = lua_check_kann_node(L, 1);
- gint nnodes = luaL_checkinteger(L, 2);
- gint rnnflags = 0;
+ int nnodes = luaL_checkinteger(L, 2);
+ int rnnflags = 0;
if (in != NULL && nnodes > 0) {
kad_node_t *t;
lua_kann_layer_lstm(lua_State *L)
{
kad_node_t *in = lua_check_kann_node(L, 1);
- gint nnodes = luaL_checkinteger(L, 2);
- gint rnnflags = 0;
+ int nnodes = luaL_checkinteger(L, 2);
+ int rnnflags = 0;
if (in != NULL && nnodes > 0) {
kad_node_t *t;
lua_kann_layer_gru(lua_State *L)
{
kad_node_t *in = lua_check_kann_node(L, 1);
- gint nnodes = luaL_checkinteger(L, 2);
- gint rnnflags = 0;
+ int nnodes = luaL_checkinteger(L, 2);
+ int rnnflags = 0;
if (in != NULL && nnodes > 0) {
kad_node_t *t;
static int
lua_kann_new_scalar(lua_State *L)
{
- gint flag = luaL_checkinteger(L, 1);
+ int flag = luaL_checkinteger(L, 1);
double x = luaL_checknumber(L, 2);
kad_node_t *t;
static int
lua_kann_new_weight(lua_State *L)
{
- gint nrow = luaL_checkinteger(L, 1);
- gint ncol = luaL_checkinteger(L, 2);
+ int nrow = luaL_checkinteger(L, 1);
+ int ncol = luaL_checkinteger(L, 2);
kad_node_t *t;
t = kann_new_weight(nrow, ncol);
static int
lua_kann_new_bias(lua_State *L)
{
- gint n = luaL_checkinteger(L, 1);
+ int n = luaL_checkinteger(L, 1);
kad_node_t *t;
t = kann_new_bias(n);
static int
lua_kann_new_weight_conv2d(lua_State *L)
{
- gint nout = luaL_checkinteger(L, 1);
- gint nin = luaL_checkinteger(L, 2);
- gint krow = luaL_checkinteger(L, 3);
- gint kcol = luaL_checkinteger(L, 4);
+ int nout = luaL_checkinteger(L, 1);
+ int nin = luaL_checkinteger(L, 2);
+ int krow = luaL_checkinteger(L, 3);
+ int kcol = luaL_checkinteger(L, 4);
kad_node_t *t;
t = kann_new_weight_conv2d(nout, nin, krow, kcol);
static int
lua_kann_new_weight_conv1d(lua_State *L)
{
- gint nout = luaL_checkinteger(L, 1);
- gint nin = luaL_checkinteger(L, 2);
- gint klen = luaL_checkinteger(L, 3);
+ int nout = luaL_checkinteger(L, 1);
+ int nin = luaL_checkinteger(L, 2);
+ int klen = luaL_checkinteger(L, 3);
kad_node_t *t;
t = kann_new_weight_conv1d(nout, nin, klen);
lua_getfield(L, 2, "filename");
if (lua_isstring(L, -1)) {
- const gchar *fname = lua_tostring(L, -1);
+ const char *fname = lua_tostring(L, -1);
FILE *f;
f = fopen(fname, "w");
t = lua_newuserdata(L, sizeof(*t));
rspamd_lua_setclass(L, rspamd_text_classname, -1);
t->flags = RSPAMD_TEXT_FLAG_OWN;
- t->start = (const gchar *) buf;
+ t->start = (const char *) buf;
t->len = buflen;
}
}
lua_getfield(L, 2, "filename");
if (lua_isstring(L, -1)) {
- const gchar *fname = lua_tostring(L, -1);
+ const char *fname = lua_tostring(L, -1);
f = fopen(fname, "rb");
}
}
else if (lua_isstring(L, 1)) {
gsize dlen;
- const gchar *data;
+ const char *data;
data = lua_tolstring(L, 1, &dlen);
struct rspamd_kann_train_cbdata {
lua_State *L;
kann_t *k;
- gint cbref;
+ int cbref;
};
static void
struct rspamd_kann_train_cbdata *cbd = (struct rspamd_kann_train_cbdata *) ud;
if (cbd->cbref != -1) {
- gint err_idx;
+ int err_idx;
lua_State *L = cbd->L;
lua_pushcfunction(L, &rspamd_lua_traceback);
int64_t max_epoch = 25;
int64_t max_drop_streak = 10;
double frac_val = 0.1;
- gint cbref = -1;
+ int cbref = -1;
if (k && lua_istable(L, 2) && lua_istable(L, 3)) {
int n = rspamd_lua_table_size(L, 2);
kann_feed_bind(k, KANN_F_IN, 0, &t->data);
kad_eval_at(k->n, k->v, i_out);
- gint outlen = kad_len(k->v[i_out]);
+ int outlen = kad_len(k->v[i_out]);
struct rspamd_lua_tensor *out;
out = lua_newtensor(L, 1, &outlen, false, false);
/* Ensure that kann and tensor have the same understanding of floats */
static void
lua_common_log_line(GLogLevelFlags level,
lua_State *L,
- const gchar *msg,
- const gchar *uid,
- const gchar *module,
- gint stack_level)
+ const char *msg,
+ const char *uid,
+ const char *module,
+ int stack_level)
{
lua_Debug d;
- gchar func_buf[128], *p;
+ char func_buf[128], *p;
if (lua_getstack(L, stack_level, &d) == 1) {
(void) lua_getinfo(L, "Sl", &d);
}
/*** Logger interface ***/
-static gint
+static int
lua_logger_err(lua_State *L)
{
return lua_logger_errx(L);
}
-static gint
+static int
lua_logger_warn(lua_State *L)
{
return lua_logger_warnx(L);
}
-static gint
+static int
lua_logger_info(lua_State *L)
{
return lua_logger_infox(L);
}
-static gint
+static int
lua_logger_message(lua_State *L)
{
return lua_logger_messagex(L);
}
-static gint
+static int
lua_logger_debug(lua_State *L)
{
return lua_logger_debugx(L);
}
static gsize
-lua_logger_out_str(lua_State *L, gint pos,
- gchar *outbuf, gsize len,
+lua_logger_out_str(lua_State *L, int pos,
+ char *outbuf, gsize len,
struct lua_logger_trace *trace,
enum lua_logger_escape_type esc_type)
{
gsize slen, flen;
- const gchar *str = lua_tolstring(L, pos, &slen);
- static const gchar hexdigests[16] = "0123456789abcdef";
+ const char *str = lua_tolstring(L, pos, &slen);
+ static const char hexdigests[16] = "0123456789abcdef";
gsize r = 0, s;
if (str) {
}
static gsize
-lua_logger_out_num(lua_State *L, gint pos, gchar *outbuf, gsize len,
+lua_logger_out_num(lua_State *L, int pos, char *outbuf, gsize len,
struct lua_logger_trace *trace)
{
- gdouble num = lua_tonumber(L, pos);
+ double num = lua_tonumber(L, pos);
glong inum;
gsize r = 0;
- if ((gdouble) (glong) num == num) {
+ if ((double) (glong) num == num) {
inum = num;
r = rspamd_snprintf(outbuf, len + 1, "%l", inum);
}
}
static gsize
-lua_logger_out_boolean(lua_State *L, gint pos, gchar *outbuf, gsize len,
+lua_logger_out_boolean(lua_State *L, int pos, char *outbuf, gsize len,
struct lua_logger_trace *trace)
{
gboolean val = lua_toboolean(L, pos);
}
static gsize
-lua_logger_out_userdata(lua_State *L, gint pos, gchar *outbuf, gsize len,
+lua_logger_out_userdata(lua_State *L, int pos, char *outbuf, gsize len,
struct lua_logger_trace *trace)
{
- gint r = 0, top;
- const gchar *str = NULL;
+ int r = 0, top;
+ const char *str = NULL;
gboolean converted_to_str = FALSE;
top = lua_gettop(L);
}
static gsize
-lua_logger_out_table(lua_State *L, gint pos, gchar *outbuf, gsize len,
+lua_logger_out_table(lua_State *L, int pos, char *outbuf, gsize len,
struct lua_logger_trace *trace,
enum lua_logger_escape_type esc_type)
{
- gchar *d = outbuf;
+ char *d = outbuf;
gsize remain = len, r;
gboolean first = TRUE;
gconstpointer self = NULL;
- gint i, tpos, last_seq = -1, old_top;
+ int i, tpos, last_seq = -1, old_top;
if (!lua_istable(L, pos) || remain == 0) {
return 0;
#undef MOVE_BUF
-gsize lua_logger_out_type(lua_State *L, gint pos,
- gchar *outbuf, gsize len,
+gsize lua_logger_out_type(lua_State *L, int pos,
+ char *outbuf, gsize len,
struct lua_logger_trace *trace,
enum lua_logger_escape_type esc_type)
{
- gint type;
+ int type;
gsize r = 0;
if (len == 0) {
return r;
}
-static const gchar *
-lua_logger_get_id(lua_State *L, gint pos, GError **err)
+static const char *
+lua_logger_get_id(lua_State *L, int pos, GError **err)
{
- const gchar *uid = NULL, *clsname;
+ const char *uid = NULL, *clsname;
if (lua_getmetatable(L, pos) != 0) {
uid = "";
}
static gboolean
-lua_logger_log_format(lua_State *L, gint fmt_pos, gboolean is_string,
- gchar *logbuf, gsize remain)
+lua_logger_log_format(lua_State *L, int fmt_pos, gboolean is_string,
+ char *logbuf, gsize remain)
{
- gchar *d;
- const gchar *s, *c;
+ char *d;
+ const char *s, *c;
gsize r, cpylen = 0;
- guint arg_num = 0, cur_arg;
+ unsigned int arg_num = 0, cur_arg;
bool num_arg = false;
struct lua_logger_trace tr;
enum {
s++;
}
- if (arg_num < 1 || arg_num > (guint) lua_gettop(L) + 1) {
+ if (arg_num < 1 || arg_num > (unsigned int) lua_gettop(L) + 1) {
msg_err("wrong argument number: %ud", arg_num);
return FALSE;
arg_num = cur_arg;
}
- if (arg_num < 1 || arg_num > (guint) lua_gettop(L) + 1) {
+ if (arg_num < 1 || arg_num > (unsigned int) lua_gettop(L) + 1) {
msg_err("wrong argument number: %ud", arg_num);
return FALSE;
return TRUE;
}
-static gint
+static int
lua_logger_do_log(lua_State *L,
GLogLevelFlags level,
gboolean is_string,
- gint start_pos)
+ int start_pos)
{
- gchar logbuf[RSPAMD_LOGBUF_SIZE - 128];
- const gchar *uid = NULL;
- gint fmt_pos = start_pos;
- gint ret;
+ char logbuf[RSPAMD_LOGBUF_SIZE - 128];
+ const char *uid = NULL;
+ int fmt_pos = start_pos;
+ int ret;
GError *err = NULL;
if (lua_type(L, start_pos) == LUA_TSTRING) {
return 0;
}
-static gint
+static int
lua_logger_errx(lua_State *L)
{
LUA_TRACE_POINT;
return lua_logger_do_log(L, G_LOG_LEVEL_CRITICAL, FALSE, 1);
}
-static gint
+static int
lua_logger_warnx(lua_State *L)
{
LUA_TRACE_POINT;
return lua_logger_do_log(L, G_LOG_LEVEL_WARNING, FALSE, 1);
}
-static gint
+static int
lua_logger_infox(lua_State *L)
{
LUA_TRACE_POINT;
return lua_logger_do_log(L, G_LOG_LEVEL_INFO, FALSE, 1);
}
-static gint
+static int
lua_logger_messagex(lua_State *L)
{
LUA_TRACE_POINT;
return lua_logger_do_log(L, G_LOG_LEVEL_MESSAGE, FALSE, 1);
}
-static gint
+static int
lua_logger_debugx(lua_State *L)
{
LUA_TRACE_POINT;
return lua_logger_do_log(L, G_LOG_LEVEL_DEBUG, FALSE, 1);
}
-static gint
+static int
lua_logger_logx(lua_State *L)
{
LUA_TRACE_POINT;
GLogLevelFlags flags = lua_tonumber(L, 1);
- const gchar *modname = lua_tostring(L, 2), *uid = NULL;
- gchar logbuf[RSPAMD_LOGBUF_SIZE - 128];
+ const char *modname = lua_tostring(L, 2), *uid = NULL;
+ char logbuf[RSPAMD_LOGBUF_SIZE - 128];
gboolean ret;
- gint stack_pos = 1;
+ int stack_pos = 1;
if (lua_type(L, 3) == LUA_TSTRING) {
uid = luaL_checkstring(L, 3);
}
-static gint
+static int
lua_logger_debugm(lua_State *L)
{
LUA_TRACE_POINT;
- gchar logbuf[RSPAMD_LOGBUF_SIZE - 128];
- const gchar *uid = NULL, *module = NULL;
- gint stack_pos = 1;
+ char logbuf[RSPAMD_LOGBUF_SIZE - 128];
+ const char *uid = NULL, *module = NULL;
+ int stack_pos = 1;
gboolean ret;
module = luaL_checkstring(L, 1);
}
-static gint
+static int
lua_logger_slog(lua_State *L)
{
return lua_logger_do_log(L, 0, TRUE, 1);
}
-static gint
+static int
lua_logger_log_level(lua_State *L)
{
- gint log_level = rspamd_log_get_log_level(NULL);
+ int log_level = rspamd_log_get_log_level(NULL);
lua_pushstring(L, rspamd_get_log_severity_string(log_level));
/*** Init functions ***/
-static gint
+static int
lua_load_logger(lua_State *L)
{
lua_newtable(L);
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
struct lua_map_callback_data {
lua_State *L;
- gint ref;
+ int ref;
gboolean opaque;
rspamd_fstring_t *data;
struct rspamd_lua_map *lua_map;
};
struct rspamd_lua_map *
-lua_check_map(lua_State *L, gint pos)
+lua_check_map(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_map_classname);
luaL_argcheck(L, ud != NULL, pos, "'map' expected");
return ud ? *((struct rspamd_lua_map **) ud) : NULL;
}
-gint lua_config_add_radix_map(lua_State *L)
+int lua_config_add_radix_map(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *map_line, *description;
+ const char *map_line, *description;
struct rspamd_lua_map *map, **pmap;
struct rspamd_map *m;
return 1;
}
-gint lua_config_radix_from_config(lua_State *L)
+int lua_config_radix_from_config(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *mname, *optname;
+ const char *mname, *optname;
const ucl_object_t *obj;
struct rspamd_lua_map *map, **pmap;
ucl_object_t *fake_obj;
}
-gint lua_config_radix_from_ucl(lua_State *L)
+int lua_config_radix_from_ucl(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
return 1;
}
-gint lua_config_add_hash_map(lua_State *L)
+int lua_config_add_hash_map(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *map_line, *description;
+ const char *map_line, *description;
struct rspamd_lua_map *map, **pmap;
struct rspamd_map *m;
return 1;
}
-gint lua_config_add_kv_map(lua_State *L)
+int lua_config_add_kv_map(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *map_line, *description;
+ const char *map_line, *description;
struct rspamd_lua_map *map, **pmap;
struct rspamd_map *m;
}
-static gchar *
-lua_map_read(gchar *chunk, gint len,
+static char *
+lua_map_read(char *chunk, int len,
struct map_cb_data *data,
gboolean final)
{
*pmap = cbdata->lua_map;
rspamd_lua_setclass(cbdata->L, rspamd_map_classname, -1);
- gint ret = lua_pcall(cbdata->L, 2, 0, err_idx);
+ int ret = lua_pcall(cbdata->L, 2, 0, err_idx);
if (ret != 0) {
msg_info_map("call to %s failed (%d): %s", "map fin function",
}
}
-gint lua_config_add_map(lua_State *L)
+int lua_config_add_map(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
const char *description = NULL;
- const gchar *type = NULL;
+ const char *type = NULL;
ucl_object_t *map_obj = NULL;
struct lua_map_callback_data *cbdata;
struct rspamd_lua_map *map, **pmap;
return 1;
}
-gint lua_config_get_maps(lua_State *L)
+int lua_config_get_maps(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
struct rspamd_lua_map *map, **pmap;
struct rspamd_map *m;
- gint i = 1;
+ int i = 1;
GList *cur;
if (cfg) {
return 1;
}
-static const gchar *
-lua_map_process_string_key(lua_State *L, gint pos, gsize *len)
+static const char *
+lua_map_process_string_key(lua_State *L, int pos, gsize *len)
{
struct rspamd_lua_text *t;
}
/* Radix and hash table functions */
-static gint
+static int
lua_map_get_key(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_map *map = lua_check_map(L, 1);
struct rspamd_radix_map_helper *radix;
struct rspamd_lua_ip *addr = NULL;
- const gchar *key, *value = NULL;
+ const char *key, *value = NULL;
gpointer ud;
gsize len;
uint32_t key_num = 0;
radix = map->data.radix;
if (lua_type(L, 2) == LUA_TSTRING) {
- const gchar *addr_str;
+ const char *addr_str;
addr_str = luaL_checklstring(L, 2, &len);
addr = g_alloca(sizeof(*addr));
}
else if (key_num != 0) {
if ((p = rspamd_match_radix_map(radix,
- (guint8 *) &key_num, sizeof(key_num))) != NULL) {
+ (uint8_t *) &key_num, sizeof(key_num))) != NULL) {
ret = TRUE;
}
else {
}
else if (map->type == RSPAMD_LUA_MAP_REGEXP_MULTIPLE) {
GPtrArray *ar;
- guint i;
- const gchar *val;
+ unsigned int i;
+ const char *val;
key = lua_map_process_string_key(L, 2, &len);
return TRUE;
}
-static gint
+static int
lua_map_get_stats(lua_State *L)
{
LUA_TRACE_POINT;
struct lua_map_traverse_cbdata {
lua_State *L;
- gint cbref;
+ int cbref;
gboolean use_text;
};
return TRUE;
}
-static gint
+static int
lua_map_foreach(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_map_get_data_digest(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_map *map = lua_check_map(L, 1);
- gchar numbuf[64];
+ char numbuf[64];
if (map != NULL) {
rspamd_snprintf(numbuf, sizeof(numbuf), "%uL", map->map->digest);
return 1;
}
-static gint
+static int
lua_map_get_nelts(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_map *map = lua_check_map(L, 1);
gboolean ret = FALSE;
struct rspamd_map_backend *bk;
- guint i;
+ unsigned int i;
if (map != NULL) {
if (map->map) {
{
LUA_TRACE_POINT;
struct rspamd_lua_map *map = lua_check_map(L, 1);
- const gchar *ret = "undefined";
+ const char *ret = "undefined";
struct rspamd_map_backend *bk;
- guint i;
+ unsigned int i;
if (map != NULL) {
for (i = 0; i < map->map->backends->len; i++) {
LUA_TRACE_POINT;
struct rspamd_lua_map *map = lua_check_map(L, 1);
struct rspamd_map_backend *bk;
- guint i;
+ unsigned int i;
GString *ret = NULL;
if (map != NULL) {
LUA_TRACE_POINT;
struct rspamd_lua_map *map = lua_check_map(L, 1);
struct rspamd_map_backend *bk;
- const gchar *pk_str;
+ const char *pk_str;
struct rspamd_cryptobox_pubkey *pk;
gsize len;
- guint i;
+ unsigned int i;
pk_str = lua_tolstring(L, 2, &len);
LUA_TRACE_POINT;
struct rspamd_lua_map *map = lua_check_map(L, 1);
struct rspamd_map_backend *bk;
- guint i;
+ unsigned int i;
if (map != NULL) {
for (i = 0; i < map->map->backends->len; i++) {
struct lua_map_on_load_cbdata {
lua_State *L;
- gint ref;
+ int ref;
};
static void
}
}
-static gint
+static int
lua_map_on_load(lua_State *L)
{
LUA_TRACE_POINT;
struct lua_mempool_udata {
lua_State *L;
- gint cbref;
+ int cbref;
rspamd_mempool_t *mempool;
};
struct memory_pool_s *
-rspamd_lua_check_mempool(lua_State *L, gint pos)
+rspamd_lua_check_mempool(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_mempool_classname);
luaL_argcheck(L, ud != NULL, pos, "'mempool' expected");
}
struct lua_numbers_bucket {
- guint nelts;
- gdouble elts[0];
+ unsigned int nelts;
+ double elts[0];
};
static int
{
LUA_TRACE_POINT;
struct memory_pool_s *mempool = rspamd_lua_check_mempool(L, 1);
- const gchar *var = luaL_checkstring(L, 2);
+ const char *var = luaL_checkstring(L, 2);
struct lua_numbers_bucket *bucket;
- gint nelts = luaL_checknumber(L, 3), i;
+ int nelts = luaL_checknumber(L, 3), i;
if (var && nelts > 0) {
bucket = rspamd_mempool_alloc(mempool,
- sizeof(*bucket) + sizeof(gdouble) * nelts);
+ sizeof(*bucket) + sizeof(double) * nelts);
bucket->nelts = nelts;
if (lua_type(L, 4) == LUA_TTABLE) {
{
LUA_TRACE_POINT;
struct memory_pool_s *mempool = rspamd_lua_check_mempool(L, 1);
- const gchar *var = luaL_checkstring(L, 2);
+ const char *var = luaL_checkstring(L, 2);
gpointer value;
struct lua_numbers_bucket *bucket;
- gchar *vp;
+ char *vp;
union {
- gdouble d;
- const gchar *s;
+ double d;
+ const char *s;
gboolean b;
} val;
gsize slen;
- gint i, j, len = 0, type;
+ int i, j, len = 0, type;
if (mempool && var) {
if (type == LUA_TNUMBER) {
/* We have some ambiguity here between integer and double */
- len += sizeof(gdouble);
+ len += sizeof(double);
}
else if (type == LUA_TBOOLEAN) {
len += sizeof(gboolean);
else if (type == LUA_TTABLE) {
/* We assume it as a bucket of numbers so far */
slen = rspamd_lua_table_size(L, i);
- len += sizeof(gdouble) * slen + sizeof(*bucket);
+ len += sizeof(double) * slen + sizeof(*bucket);
}
else {
msg_err("cannot handle lua type %s", lua_typename(L, type));
if (type == LUA_TNUMBER) {
val.d = lua_tonumber(L, i);
- memcpy(vp, &val, sizeof(gdouble));
- vp += sizeof(gdouble);
+ memcpy(vp, &val, sizeof(double));
+ vp += sizeof(double);
}
else if (type == LUA_TBOOLEAN) {
val.b = lua_toboolean(L, i);
lua_pop(L, 1);
}
- vp += sizeof(gdouble) * slen + sizeof(*bucket);
+ vp += sizeof(double) * slen + sizeof(*bucket);
}
else {
msg_err("cannot handle lua type %s", lua_typename(L, type));
{
LUA_TRACE_POINT;
struct memory_pool_s *mempool = rspamd_lua_check_mempool(L, 1);
- const gchar *var = luaL_checkstring(L, 2);
- const gchar *type = NULL, *pt;
+ const char *var = luaL_checkstring(L, 2);
+ const char *type = NULL, *pt;
struct lua_numbers_bucket bucket;
- const gchar *value, *pv;
- guint len, nvar, slen, i;
+ const char *value, *pv;
+ unsigned int len, nvar, slen, i;
if (mempool && var) {
value = rspamd_mempool_get_variable(mempool, var);
while ((len = strcspn(pt, ", ")) > 0) {
if (len == sizeof("double") - 1 &&
g_ascii_strncasecmp(pt, "double", len) == 0) {
- gdouble num;
- memcpy(&num, pv, sizeof(gdouble));
+ double num;
+ memcpy(&num, pv, sizeof(double));
lua_pushnumber(L, num);
- pv += sizeof(gdouble);
+ pv += sizeof(double);
}
else if (len == sizeof("int") - 1 &&
g_ascii_strncasecmp(pt, "int", len) == 0) {
- gint num;
- memcpy(&num, pv, sizeof(gint));
+ int num;
+ memcpy(&num, pv, sizeof(int));
lua_pushinteger(L, num);
- pv += sizeof(gint);
+ pv += sizeof(int);
}
else if (len == sizeof("int64") - 1 &&
g_ascii_strncasecmp(pt, "int64", len) == 0) {
}
else if (len == sizeof("string") - 1 &&
g_ascii_strncasecmp(pt, "string", len) == 0) {
- slen = strlen((const gchar *) pv);
- lua_pushlstring(L, (const gchar *) pv, slen);
+ slen = strlen((const char *) pv);
+ lua_pushlstring(L, (const char *) pv, slen);
pv += slen + 1;
}
else if (len == sizeof("gstring") - 1 &&
pv += sizeof(struct lua_numbers_bucket);
for (i = 0; i < bucket.nelts; i++) {
- gdouble num;
+ double num;
memcpy(&num, pv, sizeof(num));
lua_pushnumber(L, num);
lua_rawseti(L, -2, i + 1);
{
LUA_TRACE_POINT;
struct memory_pool_s *mempool = rspamd_lua_check_mempool(L, 1);
- const gchar *var = luaL_checkstring(L, 2);
+ const char *var = luaL_checkstring(L, 2);
gboolean ret = FALSE;
if (mempool && var) {
{
LUA_TRACE_POINT;
struct memory_pool_s *mempool = rspamd_lua_check_mempool(L, 1);
- const gchar *var = luaL_checkstring(L, 2);
+ const char *var = luaL_checkstring(L, 2);
gboolean ret = FALSE;
if (mempool && var) {
return 1;
}
-static gint
+static int
lua_mempool_topointer(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_load_mempool(lua_State *L)
{
lua_newtable(L);
}
-static gint
+static int
lua_textpart_is_utf(lua_State *L)
{
LUA_TRACE_POINT;
}
-static gint
+static int
lua_textpart_has_8bit_raw(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_textpart_has_8bit(lua_State *L)
{
LUA_TRACE_POINT;
}
-static gint
+static int
lua_textpart_get_content(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_mime_text_part *part = lua_check_textpart(L);
struct rspamd_lua_text *t;
gsize len;
- const gchar *start, *type = NULL;
+ const char *start, *type = NULL;
if (part == NULL) {
lua_pushnil(L);
return 1;
}
-static gint
+static int
lua_textpart_get_raw_content(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_textpart_get_content_oneline(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_textpart_get_length(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_textpart_get_raw_length(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_textpart_get_urls_length(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_mime_text_part *part = lua_check_textpart(L);
GList *cur;
- guint total = 0;
+ unsigned int total = 0;
struct rspamd_process_exception *ex;
if (part == NULL) {
return 1;
}
-static gint
+static int
lua_textpart_get_lines_count(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_textpart_get_words_count(lua_State *L)
{
LUA_TRACE_POINT;
}
static inline enum rspamd_lua_words_type
-word_extract_type_from_string(const gchar *how_str)
+word_extract_type_from_string(const char *how_str)
{
enum rspamd_lua_words_type how = RSPAMD_LUA_WORDS_MAX;
return how;
}
-static gint
+static int
lua_textpart_get_words(lua_State *L)
{
LUA_TRACE_POINT;
}
else {
if (lua_type(L, 2) == LUA_TSTRING) {
- const gchar *how_str = lua_tostring(L, 2);
+ const char *how_str = lua_tostring(L, 2);
how = word_extract_type_from_string(how_str);
return 1;
}
-static gint
+static int
lua_textpart_filter_words(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_mime_text_part *part = lua_check_textpart(L);
struct rspamd_lua_regexp *re = lua_check_regexp(L, 2);
- gint lim = -1;
+ int lim = -1;
enum rspamd_lua_words_type how = RSPAMD_LUA_WORDS_STEM;
if (part == NULL || re == NULL) {
}
else {
if (lua_type(L, 3) == LUA_TSTRING) {
- const gchar *how_str = lua_tostring(L, 3);
+ const char *how_str = lua_tostring(L, 3);
how = word_extract_type_from_string(how_str);
lim = lua_tointeger(L, 4);
}
- guint cnt, i;
+ unsigned int cnt, i;
lua_createtable(L, 8, 0);
return 1;
}
-static gint
+static int
lua_textpart_is_empty(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_textpart_is_html(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_textpart_get_html(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_textpart_get_language(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_textpart_get_charset(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_textpart_get_languages(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_mime_text_part *part = lua_check_textpart(L);
- guint i;
+ unsigned int i;
struct rspamd_lang_detector_res *cur;
if (part != NULL) {
static uint64_t
lua_shingles_filter(uint64_t *input, gsize count,
- gint shno, const guchar *key, gpointer ud)
+ int shno, const unsigned char *key, gpointer ud)
{
uint64_t minimal = G_MAXUINT64;
gsize i, min_idx = 0;
#undef STORE_TOKEN
-static gint
+static int
lua_textpart_get_fuzzy_hashes(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_mime_text_part *part = lua_check_textpart(L);
rspamd_mempool_t *pool = rspamd_lua_check_mempool(L, 2);
- guchar key[rspamd_cryptobox_HASHBYTES], digest[rspamd_cryptobox_HASHBYTES],
+ unsigned char key[rspamd_cryptobox_HASHBYTES], digest[rspamd_cryptobox_HASHBYTES],
hexdigest[rspamd_cryptobox_HASHBYTES * 2 + 1], numbuf[64];
struct rspamd_shingle *sgl;
- guint i;
+ unsigned int i;
struct lua_shingle_data *sd;
rspamd_cryptobox_hash_state_t st;
rspamd_stat_token_t *word;
return 2;
}
-static gint
+static int
lua_textpart_get_mimepart(lua_State *L)
{
LUA_TRACE_POINT;
* - `ascii_characters`: number of ascii characters
* @return {table} table of stats
*/
-static gint
+static int
lua_textpart_get_stats(lua_State *L)
{
LUA_TRACE_POINT;
/* Mimepart implementation */
-static gint
+static int
lua_mimepart_get_content(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_mimepart_get_raw_content(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_mimepart_get_length(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_mimepart_get_type_common(lua_State *L, struct rspamd_content_type *ct,
gboolean full)
{
return 3;
}
-static gint
+static int
lua_mimepart_get_type(lua_State *L)
{
LUA_TRACE_POINT;
return lua_mimepart_get_type_common(L, part->ct, FALSE);
}
-static gint
+static int
lua_mimepart_get_type_full(lua_State *L)
{
LUA_TRACE_POINT;
return lua_mimepart_get_type_common(L, part->ct, TRUE);
}
-static gint
+static int
lua_mimepart_get_detected_type(lua_State *L)
{
LUA_TRACE_POINT;
return lua_mimepart_get_type_common(L, part->detected_ct, FALSE);
}
-static gint
+static int
lua_mimepart_get_detected_type_full(lua_State *L)
{
LUA_TRACE_POINT;
return lua_mimepart_get_type_common(L, part->detected_ct, TRUE);
}
-static gint
+static int
lua_mimepart_get_detected_ext(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_mimepart_get_cte(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_mimepart_get_filename(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_mimepart_get_boundary(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_mimepart_get_enclosing_boundary(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_mimepart_get_header_common(lua_State *L, enum rspamd_lua_task_header_type how)
{
struct rspamd_mime_part *part = lua_check_mimepart(L);
- const gchar *name;
+ const char *name;
gboolean strong = FALSE;
name = luaL_checkstring(L, 2);
return 1;
}
-static gint
+static int
lua_mimepart_get_header_full(lua_State *L)
{
LUA_TRACE_POINT;
return lua_mimepart_get_header_common(L, RSPAMD_TASK_HEADER_PUSH_FULL);
}
-static gint
+static int
lua_mimepart_get_header(lua_State *L)
{
LUA_TRACE_POINT;
return lua_mimepart_get_header_common(L, RSPAMD_TASK_HEADER_PUSH_SIMPLE);
}
-static gint
+static int
lua_mimepart_get_header_raw(lua_State *L)
{
LUA_TRACE_POINT;
return lua_mimepart_get_header_common(L, RSPAMD_TASK_HEADER_PUSH_RAW);
}
-static gint
+static int
lua_mimepart_get_header_count(lua_State *L)
{
LUA_TRACE_POINT;
return lua_mimepart_get_header_common(L, RSPAMD_TASK_HEADER_PUSH_COUNT);
}
-static gint
+static int
lua_mimepart_get_raw_headers(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_mimepart_get_headers(lua_State *L)
{
LUA_TRACE_POINT;
}
-static gint
+static int
lua_mimepart_is_image(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_mimepart_is_archive(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_mimepart_is_multipart(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_mimepart_is_message(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_mimepart_is_attachment(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_mimepart_is_text(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_mimepart_is_broken(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_mimepart_get_image(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_mimepart_get_archive(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_mimepart_get_children(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_mime_part *part = lua_check_mimepart(L);
struct rspamd_mime_part **pcur, *cur;
- guint i;
+ unsigned int i;
if (part == NULL) {
return luaL_error(L, "invalid arguments");
return 1;
}
-static gint
+static int
lua_mimepart_get_parent(lua_State *L)
{
LUA_TRACE_POINT;
}
-static gint
+static int
lua_mimepart_get_text(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_mimepart_get_digest(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_mime_part *part = lua_check_mimepart(L);
- gchar digestbuf[rspamd_cryptobox_HASHBYTES * 2 + 1];
+ char digestbuf[rspamd_cryptobox_HASHBYTES * 2 + 1];
if (part == NULL) {
return luaL_error(L, "invalid arguments");
return 1;
}
-static gint
+static int
lua_mimepart_get_id(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_mimepart_headers_foreach(lua_State *L)
{
LUA_TRACE_POINT;
enum rspamd_lua_task_header_type how = RSPAMD_TASK_HEADER_PUSH_SIMPLE;
struct rspamd_lua_regexp *re = NULL;
struct rspamd_mime_header *hdr, *cur;
- gint old_top;
+ int old_top;
if (part && lua_isfunction(L, 2)) {
if (lua_istable(L, 3)) {
return 0;
}
-static gint
+static int
lua_mimepart_get_specific(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_mimepart_get_urls(lua_State *L)
{
LUA_TRACE_POINT;
struct lua_tree_cb_data cb;
struct rspamd_url *u;
- static const gint default_protocols_mask = PROTOCOL_HTTP | PROTOCOL_HTTPS |
- PROTOCOL_FILE | PROTOCOL_FTP;
+ static const int default_protocols_mask = PROTOCOL_HTTP | PROTOCOL_HTTPS |
+ PROTOCOL_FILE | PROTOCOL_FTP;
gsize sz, max_urls = 0, i;
if (part->urls == NULL) {
return 1;
}
-static gint
+static int
lua_mimepart_is_specific(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_mimepart_set_specific(lua_State *L)
{
LUA_TRACE_POINT;
part->specific.lua_specific.cbref = luaL_ref(L, LUA_REGISTRYINDEX);
/* Now stack has just a return value as luaL_ref removes value from stack */
- gint ltype = lua_type(L, 2);
+ int ltype = lua_type(L, 2);
switch (ltype) {
case LUA_TTABLE:
{NULL, NULL}};
-gint lua_parsers_tokenize_text(lua_State *L)
+int lua_parsers_tokenize_text(lua_State *L)
{
LUA_TRACE_POINT;
- const gchar *in = NULL;
+ const char *in = NULL;
gsize len = 0, pos, ex_len, i;
GList *exceptions = NULL, *cur;
struct rspamd_lua_text *t;
len,
&uc_err);
- res = rspamd_tokenize_text((gchar *) in, len,
+ res = rspamd_tokenize_text((char *) in, len,
&utxt,
RSPAMD_TOKENIZE_UTF, NULL,
exceptions,
return 1;
}
-gint lua_parsers_parse_html(lua_State *L)
+int lua_parsers_parse_html(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_text *t;
- const gchar *start = NULL;
+ const char *start = NULL;
gsize len;
GByteArray *in;
rspamd_mempool_t *pool;
return 1;
}
-gint lua_parsers_parse_mail_address(lua_State *L)
+int lua_parsers_parse_mail_address(lua_State *L)
{
LUA_TRACE_POINT;
GPtrArray *addrs;
gsize len;
- const gchar *str = luaL_checklstring(L, 1, &len);
- gint max_addrs = luaL_optinteger(L, 3, 10240);
+ const char *str = luaL_checklstring(L, 1, &len);
+ int max_addrs = luaL_optinteger(L, 3, 10240);
rspamd_mempool_t *pool;
gboolean own_pool = FALSE;
return 1;
}
-gint lua_parsers_parse_content_type(lua_State *L)
+int lua_parsers_parse_content_type(lua_State *L)
{
LUA_TRACE_POINT;
gsize len;
- const gchar *ct_str = luaL_checklstring(L, 1, &len);
+ const char *ct_str = luaL_checklstring(L, 1, &len);
rspamd_mempool_t *pool = rspamd_lua_check_mempool(L, 2);
struct rspamd_content_type *ct;
struct rspamd_content_type_param *param =
(struct rspamd_content_type_param *) v,
*cur;
- guint i = 1;
+ unsigned int i = 1;
lua_pushlstring(L, param->name.begin, param->name.len);
lua_createtable(L, 1, 0);
int lua_parsers_parse_smtp_date(lua_State *L)
{
gsize slen;
- const gchar *str = lua_tolstring(L, 1, &slen);
+ const char *str = lua_tolstring(L, 1, &slen);
GError *err = NULL;
if (str == NULL) {
return 1;
}
-static gint
+static int
lua_load_parsers(lua_State *L)
{
lua_newtable(L);
#define REDIS_DEFAULT_TIMEOUT 1.0
-static const gchar *M = "rspamd lua redis";
+static const char *M = "rspamd lua redis";
static void *redis_null;
/***
struct ev_loop *event_loop;
struct rspamd_config *cfg;
struct rspamd_redis_pool *pool;
- gchar *server;
- gchar log_tag[RSPAMD_LOG_ID_LEN + 1];
+ char *server;
+ char log_tag[RSPAMD_LOG_ID_LEN + 1];
struct lua_redis_request_specific_userdata *specific;
- gdouble timeout;
- guint16 port;
- guint16 terminated;
+ double timeout;
+ uint16_t port;
+ uint16_t terminated;
};
#define msg_debug_lua_redis(...) rspamd_conditional_debug_fast(NULL, NULL, \
#define IS_ASYNC(ctx) ((ctx)->flags & LUA_REDIS_ASYNC)
struct lua_redis_request_specific_userdata {
- gint cbref;
- guint nargs;
- gchar **args;
+ int cbref;
+ unsigned int nargs;
+ char **args;
gsize *arglens;
struct lua_redis_userdata *c;
struct lua_redis_ctx *ctx;
struct lua_redis_request_specific_userdata *next;
ev_timer timeout_ev;
- guint flags;
+ unsigned int flags;
};
struct lua_redis_ctx {
- guint flags;
+ unsigned int flags;
struct lua_redis_userdata async;
- guint cmds_pending;
+ unsigned int cmds_pending;
ref_entry_t ref;
GQueue *replies; /* for sync connection only */
GQueue *events_cleanup; /* for sync connection only */
struct lua_redis_result {
gboolean is_error;
- gint result_ref;
+ int result_ref;
struct rspamd_symcache_dynamic_item *item;
struct rspamd_async_session *s;
struct rspamd_task *task;
};
static struct lua_redis_ctx *
-lua_check_redis(lua_State *L, gint pos)
+lua_check_redis(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_redis_classname);
luaL_argcheck(L, ud != NULL, pos, "'redis' expected");
}
static void
-lua_redis_free_args(char **args, gsize *arglens, guint nargs)
+lua_redis_free_args(char **args, gsize *arglens, unsigned int nargs)
{
- guint i;
+ unsigned int i;
if (args) {
for (i = 0; i < nargs; i++) {
g_free(ctx);
}
-static gint
+static int
lua_redis_gc(lua_State *L)
{
struct lua_redis_ctx *ctx = lua_check_redis(L, 1);
* @param ud
*/
static void
-lua_redis_push_error(const gchar *err,
+lua_redis_push_error(const char *err,
struct lua_redis_ctx *ctx,
struct lua_redis_request_specific_userdata *sp_ud,
gboolean connected)
static void
lua_redis_push_reply(lua_State *L, const redisReply *r, gboolean text_data)
{
- guint i;
+ unsigned int i;
struct rspamd_lua_text *t;
switch (r->type) {
rspamd_symcache_set_cur_item(ud->task, ud->item);
}
- gint ret = lua_pcall(cbs.L, 2, 0, err_idx);
+ int ret = lua_pcall(cbs.L, 2, 0, err_idx);
if (ret != 0) {
msg_info("call to lua_redis callback failed (%d): %s",
REDIS_RELEASE(ctx);
}
-static gint
+static int
lua_redis_push_results(struct lua_redis_ctx *ctx, lua_State *L)
{
- gint results = g_queue_get_length(ctx->replies);
- gint i;
+ int results = g_queue_get_length(ctx->replies);
+ int i;
gboolean can_use_lua = TRUE;
results = g_queue_get_length(ctx->replies);
struct lua_redis_ctx *ctx;
struct lua_redis_userdata *ud;
struct thread_entry *thread;
- gint results;
+ int results;
ctx = sp_ud->ctx;
ud = sp_ud->c;
static void
-lua_redis_parse_args(lua_State *L, gint idx, const gchar *cmd,
- gchar ***pargs, gsize **parglens, guint *nargs)
+lua_redis_parse_args(lua_State *L, int idx, const char *cmd,
+ char ***pargs, gsize **parglens, unsigned int *nargs)
{
- gchar **args = NULL;
+ char **args = NULL;
gsize *arglens;
- gint top;
+ int top;
if (idx != 0 && lua_type(L, idx) == LUA_TTABLE) {
/* Get all arguments */
top = 0;
while (lua_next(L, -2) != 0) {
- gint type = lua_type(L, -1);
+ int type = lua_type(L, -1);
if (type == LUA_TNUMBER || type == LUA_TSTRING ||
type == LUA_TUSERDATA) {
lua_pop(L, 1);
}
- args = g_malloc((top + 1) * sizeof(gchar *));
+ args = g_malloc((top + 1) * sizeof(char *));
arglens = g_malloc((top + 1) * sizeof(gsize));
arglens[0] = strlen(cmd);
args[0] = g_malloc(arglens[0]);
lua_pushnil(L);
while (lua_next(L, -2) != 0) {
- gint type = lua_type(L, -1);
+ int type = lua_type(L, -1);
if (type == LUA_TSTRING) {
- const gchar *s;
+ const char *s;
s = lua_tolstring(L, -1, &arglens[top]);
args[top] = g_malloc(arglens[top]);
}
}
else if (type == LUA_TNUMBER) {
- gdouble val = lua_tonumber(L, -1);
- gint r;
- gchar numbuf[64];
+ double val = lua_tonumber(L, -1);
+ int r;
+ char numbuf[64];
- if (val == (gdouble) ((int64_t) val)) {
+ if (val == (double) ((int64_t) val)) {
r = rspamd_snprintf(numbuf, sizeof(numbuf), "%L",
(int64_t) val);
}
else {
/* Use merely cmd */
- args = g_malloc(sizeof(gchar *));
+ args = g_malloc(sizeof(char *));
arglens = g_malloc(sizeof(gsize));
arglens[0] = strlen(cmd);
args[0] = g_malloc(arglens[0]);
}
static struct lua_redis_ctx *
-rspamd_lua_redis_prepare_connection(lua_State *L, gint *pcbref, gboolean is_async)
+rspamd_lua_redis_prepare_connection(lua_State *L, int *pcbref, gboolean is_async)
{
struct lua_redis_ctx *ctx = NULL;
rspamd_inet_addr_t *ip = NULL;
struct lua_redis_userdata *ud = NULL;
struct rspamd_lua_ip *addr = NULL;
struct rspamd_task *task = NULL;
- const gchar *host = NULL;
- const gchar *username = NULL, *password = NULL, *dbname = NULL, *log_tag = NULL;
- gint cbref = -1;
+ const char *host = NULL;
+ const char *username = NULL, *password = NULL, *dbname = NULL, *log_tag = NULL;
+ int cbref = -1;
struct rspamd_config *cfg = NULL;
struct rspamd_async_session *session = NULL;
struct ev_loop *ev_base = NULL;
gboolean ret = FALSE;
- guint flags = 0;
+ unsigned int flags = 0;
if (lua_istable(L, 1)) {
/* Table version */
struct lua_redis_request_specific_userdata *sp_ud;
struct lua_redis_userdata *ud;
struct lua_redis_ctx *ctx, **pctx;
- const gchar *cmd = NULL;
- gdouble timeout = REDIS_DEFAULT_TIMEOUT;
- gint cbref = -1;
+ const char *cmd = NULL;
+ double timeout = REDIS_DEFAULT_TIMEOUT;
+ int cbref = -1;
gboolean ret = FALSE;
ctx = rspamd_lua_redis_prepare_connection(L, &cbref, TRUE);
lua_redis_callback,
sp_ud,
sp_ud->nargs,
- (const gchar **) sp_ud->args,
+ (const char **) sp_ud->args,
sp_ud->arglens);
if (ret == REDIS_OK) {
LUA_TRACE_POINT;
struct rspamd_lua_ip *addr = NULL;
rspamd_inet_addr_t *ip = NULL;
- const gchar *cmd = NULL, *host;
+ const char *cmd = NULL, *host;
struct timeval tv;
gboolean ret = FALSE;
- gdouble timeout = REDIS_DEFAULT_TIMEOUT;
- gchar **args = NULL;
+ double timeout = REDIS_DEFAULT_TIMEOUT;
+ char **args = NULL;
gsize *arglens = NULL;
- guint nargs = 0, flags = 0;
+ unsigned int nargs = 0, flags = 0;
redisContext *ctx;
redisReply *r;
r = redisCommandArgv(ctx,
nargs,
- (const gchar **) args,
+ (const char **) args,
arglens);
if (r != NULL) {
LUA_TRACE_POINT;
struct lua_redis_userdata *ud;
struct lua_redis_ctx *ctx, **pctx;
- gdouble timeout = REDIS_DEFAULT_TIMEOUT;
+ double timeout = REDIS_DEFAULT_TIMEOUT;
ctx = rspamd_lua_redis_prepare_connection(L, NULL, TRUE);
lua_redis_connect_sync(lua_State *L)
{
LUA_TRACE_POINT;
- gdouble timeout = REDIS_DEFAULT_TIMEOUT;
+ double timeout = REDIS_DEFAULT_TIMEOUT;
struct lua_redis_ctx *ctx, **pctx;
ctx = rspamd_lua_redis_prepare_connection(L, NULL, FALSE);
struct lua_redis_ctx *ctx = lua_check_redis(L, 1);
struct lua_redis_request_specific_userdata *sp_ud;
struct lua_redis_userdata *ud;
- const gchar *cmd = NULL;
- gint args_pos = 2;
- gint cbref = -1, ret;
+ const char *cmd = NULL;
+ int args_pos = 2;
+ int cbref = -1, ret;
if (ctx) {
if (ctx->flags & LUA_REDIS_TERMINATED) {
lua_redis_callback,
sp_ud,
sp_ud->nargs,
- (const gchar **) sp_ud->args,
+ (const char **) sp_ud->args,
sp_ud->arglens);
}
else {
lua_redis_callback_sync,
sp_ud,
sp_ud->nargs,
- (const gchar **) sp_ud->args,
+ (const char **) sp_ud->args,
sp_ud->arglens);
}
lua_error(L);
}
if (ctx->cmds_pending == 0 && g_queue_get_length(ctx->replies) > 0) {
- gint results = lua_redis_push_results(ctx, L);
+ int results = lua_redis_push_results(ctx, L);
return results;
}
else {
}
}
-static gint
+static int
lua_load_redis(lua_State *L)
{
lua_newtable(L);
return 1;
}
-static gint
+static int
lua_redis_null_idx(lua_State *L)
{
lua_pushnil(L);
rspamd_mempool_t *regexp_static_pool = NULL;
struct rspamd_lua_regexp *
-lua_check_regexp(lua_State *L, gint pos)
+lua_check_regexp(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_regexp_classname);
LUA_TRACE_POINT;
rspamd_regexp_t *re;
struct rspamd_lua_regexp *new, **pnew;
- const gchar *string, *flags_str = NULL;
+ const char *string, *flags_str = NULL;
GError *err = NULL;
string = luaL_checkstring(L, 1);
LUA_TRACE_POINT;
rspamd_regexp_t *re;
struct rspamd_lua_regexp *new, **pnew;
- const gchar *string, *flags_str = NULL;
- gchar *escaped;
+ const char *string, *flags_str = NULL;
+ char *escaped;
gsize pat_len;
GError *err = NULL;
LUA_TRACE_POINT;
rspamd_regexp_t *re;
struct rspamd_lua_regexp *new, **pnew;
- const gchar *string, *flags_str = NULL;
- gchar *escaped;
+ const char *string, *flags_str = NULL;
+ char *escaped;
gsize pat_len;
GError *err = NULL;
LUA_TRACE_POINT;
rspamd_regexp_t *re;
struct rspamd_lua_regexp *new, **pnew;
- const gchar *string, *flags_str = NULL;
+ const char *string, *flags_str = NULL;
string = luaL_checkstring(L, 1);
if (lua_gettop(L) == 2) {
LUA_TRACE_POINT;
rspamd_regexp_t *re;
struct rspamd_lua_regexp *new, **pnew;
- const gchar *string, *flags_str = NULL;
+ const char *string, *flags_str = NULL;
GError *err = NULL;
string = luaL_checkstring(L, 1);
{
LUA_TRACE_POINT;
struct rspamd_lua_regexp *re = lua_check_regexp(L, 1);
- guint lim;
+ unsigned int lim;
lim = luaL_checkinteger(L, 2);
{
LUA_TRACE_POINT;
struct rspamd_lua_regexp *re = lua_check_regexp(L, 1);
- const gchar *data = NULL;
+ const char *data = NULL;
struct rspamd_lua_text *t;
- const gchar *start = NULL, *end = NULL;
- gint i;
+ const char *start = NULL, *end = NULL;
+ int i;
gsize len = 0, capn;
gboolean matched = FALSE, capture = FALSE, raw = FALSE;
GArray *captures = NULL;
LUA_TRACE_POINT;
struct rspamd_lua_regexp *re = lua_check_regexp(L, 1);
struct rspamd_lua_text *t;
- const gchar *data = NULL;
+ const char *data = NULL;
gsize len = 0;
gboolean raw = FALSE;
LUA_TRACE_POINT;
struct rspamd_lua_regexp *re = lua_check_regexp(L, 1);
struct rspamd_lua_text *t;
- const gchar *data = NULL, *start = NULL, *end = NULL;
- gint max_matches, matches;
+ const char *data = NULL, *start = NULL, *end = NULL;
+ int max_matches, matches;
gsize len = 0;
gboolean raw = FALSE;
{
LUA_TRACE_POINT;
struct rspamd_lua_regexp *re = lua_check_regexp(L, 1);
- const gchar *data = NULL;
+ const char *data = NULL;
struct rspamd_lua_text *t;
gboolean matched = FALSE, is_text = FALSE;
gsize len = 0;
- const gchar *start = NULL, *end = NULL, *old_start;
- gint i;
+ const char *start = NULL, *end = NULL, *old_start;
+ int i;
if (re && !IS_DESTROYED(re)) {
if (lua_type(L, 2) == LUA_TSTRING) {
* @method re:destroy()
* Destroy regexp from caches if needed (the pointer is removed by garbage collector)
*/
-static gint
+static int
lua_regexp_destroy(lua_State *L)
{
LUA_TRACE_POINT;
return 0;
}
-static gint
+static int
lua_regexp_gc(lua_State *L)
{
LUA_TRACE_POINT;
return 0;
}
-static gint
+static int
lua_load_regexp(lua_State *L)
{
lua_newtable(L);
return ud ? *((rspamd_fstring_t **) ud) : NULL;
}
-static gint
+static int
lua_rsa_pubkey_load(lua_State *L)
{
RSA *rsa = NULL, **prsa;
- const gchar *filename;
+ const char *filename;
FILE *f;
filename = luaL_checkstring(L, 1);
return 1;
}
-static gint
+static int
lua_rsa_privkey_save(lua_State *L)
{
- const gchar *filename;
- const gchar *type = "pem";
+ const char *filename;
+ const char *type = "pem";
FILE *f;
int ret;
}
-static gint
+static int
lua_rsa_pubkey_create(lua_State *L)
{
RSA *rsa = NULL, **prsa;
- const gchar *buf;
+ const char *buf;
BIO *bp;
buf = luaL_checkstring(L, 1);
return 1;
}
-static gint
+static int
lua_rsa_pubkey_gc(lua_State *L)
{
RSA *rsa = lua_check_rsa_pubkey(L, 1);
return 0;
}
-static gint
+static int
lua_rsa_pubkey_tostring(lua_State *L)
{
RSA *rsa = lua_check_rsa_pubkey(L, 1);
if (rsa != NULL) {
BIO *pubout = BIO_new(BIO_s_mem());
- const gchar *pubdata;
+ const char *pubdata;
gsize publen;
int rc = i2d_RSA_PUBKEY_bio(pubout, rsa);
return 1;
}
-static gint
+static int
lua_rsa_privkey_load_file(lua_State *L)
{
RSA *rsa = NULL, **prsa;
- const gchar *filename;
+ const char *filename;
FILE *f;
filename = luaL_checkstring(L, 1);
return 1;
}
-static gint
+static int
lua_rsa_privkey_load_pem(lua_State *L)
{
RSA *rsa = NULL, **prsa;
BIO *b;
struct rspamd_lua_text *t;
- const gchar *data;
+ const char *data;
gsize len;
if (lua_isuserdata(L, 1)) {
return 1;
}
-static gint
+static int
lua_rsa_privkey_load_raw(lua_State *L)
{
RSA *rsa = NULL, **prsa;
BIO *b;
struct rspamd_lua_text *t;
- const gchar *data;
+ const char *data;
gsize len;
if (lua_isuserdata(L, 1)) {
return 1;
}
-static gint
+static int
lua_rsa_privkey_load_base64(lua_State *L)
{
RSA *rsa = NULL, **prsa;
BIO *b;
EVP_PKEY *evp = NULL;
struct rspamd_lua_text *t;
- const gchar *data;
- guchar *decoded;
+ const char *data;
+ unsigned char *decoded;
gsize len, dec_len;
if (lua_isuserdata(L, 1)) {
return 1;
}
-static gint
+static int
lua_rsa_privkey_create(lua_State *L)
{
RSA *rsa = NULL, **prsa;
- const gchar *buf;
+ const char *buf;
BIO *bp;
buf = luaL_checkstring(L, 1);
return 1;
}
-static gint
+static int
lua_rsa_privkey_gc(lua_State *L)
{
RSA *rsa = lua_check_rsa_privkey(L, 1);
return 0;
}
-static gint
+static int
lua_rsa_signature_load(lua_State *L)
{
rspamd_fstring_t *sig, **psig;
- const gchar *filename;
+ const char *filename;
gpointer data;
int fd;
struct stat st;
return 1;
}
-static gint
+static int
lua_rsa_signature_save(lua_State *L)
{
rspamd_fstring_t *sig;
- gint fd, flags;
- const gchar *filename;
+ int fd, flags;
+ const char *filename;
gboolean forced = FALSE, res = TRUE;
sig = lua_check_rsa_sign(L, 1);
return 1;
}
-static gint
+static int
lua_rsa_signature_create(lua_State *L)
{
rspamd_fstring_t *sig, **psig;
- const gchar *data;
+ const char *data;
gsize dlen;
data = luaL_checklstring(L, 1, &dlen);
return 1;
}
-static gint
+static int
lua_rsa_signature_gc(lua_State *L)
{
rspamd_fstring_t *sig = lua_check_rsa_sign(L, 1);
return 0;
}
-static gint
+static int
lua_rsa_signature_base64(lua_State *L)
{
rspamd_fstring_t *sig = lua_check_rsa_sign(L, 1);
- guint boundary = 0;
- gchar *b64;
+ unsigned int boundary = 0;
+ char *b64;
gsize outlen;
enum rspamd_newlines_type how = RSPAMD_TASK_NEWLINES_CRLF;
}
if (lua_isstring(L, 3)) {
- const gchar *how_str = lua_tostring(L, 3);
+ const char *how_str = lua_tostring(L, 3);
if (strcmp(how_str, "cr") == 0) {
how = RSPAMD_TASK_NEWLINES_CR;
* true - if string match rsa signature
* false - otherwise
*/
-static gint
+static int
lua_rsa_verify_memory(lua_State *L)
{
RSA *rsa;
rspamd_fstring_t *signature;
- const gchar *data;
+ const char *data;
gsize sz;
- gint ret;
+ int ret;
rsa = lua_check_rsa_pubkey(L, 1);
signature = lua_check_rsa_sign(L, 2);
* rspamd_signature object
* nil - otherwise
*/
-static gint
+static int
lua_rsa_sign_memory(lua_State *L)
{
RSA *rsa;
rspamd_fstring_t *signature, **psig;
- const gchar *data;
+ const char *data;
gsize sz;
- gint ret;
+ int ret;
rsa = lua_check_rsa_privkey(L, 1);
data = luaL_checklstring(L, 2, &sz);
if (rsa != NULL && data != NULL) {
signature = rspamd_fstring_sized_new(RSA_size(rsa));
- guint siglen = signature->len;
+ unsigned int siglen = signature->len;
ret = RSA_sign(NID_sha256, data, sz,
signature->str, &siglen, rsa);
return 1;
}
-static gint
+static int
lua_rsa_keypair(lua_State *L)
{
BIGNUM *e;
RSA *rsa, *pub_rsa, *priv_rsa, **prsa;
- gint bits = lua_gettop(L) > 0 ? lua_tointeger(L, 1) : 1024;
+ int bits = lua_gettop(L) > 0 ? lua_tointeger(L, 1) : 1024;
if (bits > 4096 || bits < 512) {
return luaL_error(L, "invalid bits count");
return 2;
}
-static gint
+static int
lua_load_pubkey(lua_State *L)
{
lua_newtable(L);
return 1;
}
-static gint
+static int
lua_load_privkey(lua_State *L)
{
lua_newtable(L);
return 1;
}
-static gint
+static int
lua_load_signature(lua_State *L)
{
lua_newtable(L);
return 1;
}
-static gint
+static int
lua_load_rsa(lua_State *L)
{
lua_newtable(L);
-/*-
- * Copyright 2019 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
struct rspamd_task *task;
lua_State *L;
struct rspamd_symcache_dynamic_item *item;
- gint cbref;
+ int cbref;
ref_entry_t ref;
};
-static gint
+static int
lua_load_spf(lua_State *L)
{
lua_newtable(L);
}
static void
-lua_spf_push_result(struct rspamd_lua_spf_cbdata *cbd, gint code_flags,
- struct spf_resolved *resolved, const gchar *err)
+lua_spf_push_result(struct rspamd_lua_spf_cbdata *cbd, int code_flags,
+ struct spf_resolved *resolved, const char *err)
{
g_assert(cbd != NULL);
REF_RETAIN(cbd);
lua_pushcfunction(cbd->L, &rspamd_lua_traceback);
- gint err_idx = lua_gettop(cbd->L);
+ int err_idx = lua_gettop(cbd->L);
lua_rawgeti(cbd->L, LUA_REGISTRYINDEX, cbd->cbref);
* @param {rspamd_task} task task
* @param {function} callback callback that is called on spf resolution
*/
-gint lua_spf_resolve(lua_State *L)
+int lua_spf_resolve(lua_State *L)
{
struct rspamd_task *task = lua_check_task(L, 1);
return 0;
}
-static gint
+static int
lua_spf_record_dtor(lua_State *L)
{
struct spf_resolved *record;
static void
lua_spf_push_spf_addr(lua_State *L, struct spf_addr *addr)
{
- gchar *addr_mask;
+ char *addr_mask;
lua_createtable(L, 0, 4);
}
}
-static gint
+static int
spf_check_element(lua_State *L, struct spf_resolved *rec, struct spf_addr *addr,
struct rspamd_lua_ip *ip)
{
gboolean res = FALSE;
- const guint8 *s, *d;
- guint af, mask, bmask, addrlen;
+ const uint8_t *s, *d;
+ unsigned int af, mask, bmask, addrlen;
if (addr->flags & RSPAMD_SPF_FLAG_TEMPFAIL) {
d = rspamd_inet_address_get_hash_key(ip->addr, &addrlen);
if (af == AF_INET6) {
- s = (const guint8 *) addr->addr6;
+ s = (const uint8_t *) addr->addr6;
mask = addr->m.dual.mask_v6;
}
else {
- s = (const guint8 *) addr->addr4;
+ s = (const uint8_t *) addr->addr4;
mask = addr->m.dual.mask_v4;
}
* @param {rspamd_ip|string} ip address
* @return {result,flag_or_policy,error_or_addr} - triplet
*/
-static gint
+static int
lua_spf_record_check_ip(lua_State *L)
{
struct spf_resolved *record;
struct spf_resolved,
record);
struct rspamd_lua_ip *ip = NULL;
- gint nres = 0;
+ int nres = 0;
gboolean need_free_ip = FALSE;
if (lua_type(L, 2) == LUA_TUSERDATA) {
ip = lua_check_ip(L, 2);
}
else if (lua_type(L, 2) == LUA_TSTRING) {
- const gchar *ip_str;
+ const char *ip_str;
gsize iplen;
ip = g_malloc0(sizeof(struct rspamd_lua_ip));
}
if (record && ip && ip->addr) {
- for (guint i = 0; i < record->elts->len; i++) {
+ for (unsigned int i = 0; i < record->elts->len; i++) {
struct spf_addr *addr = &g_array_index(record->elts, struct spf_addr, i);
if ((nres = spf_check_element(L, record, addr, ip)) > 0) {
if (need_free_ip) {
* @method rspamd_spf_record:get_domain()
* Returns domain for the specific spf record
*/
-static gint
+static int
lua_spf_record_get_domain(lua_State *L)
{
struct spf_resolved *record;
* @method rspamd_spf_record:get_ttl()
* Returns ttl for the specific spf record
*/
-static gint
+static int
lua_spf_record_get_ttl(lua_State *L)
{
struct spf_resolved *record;
* @method rspamd_spf_record:get_timestamp()
* Returns ttl for the specific spf record
*/
-static gint
+static int
lua_spf_record_get_timestamp(lua_State *L)
{
struct spf_resolved *record;
* @method rspamd_spf_record:get_digest()
* Returns string hex representation of the record digest (fast hash function)
*/
-static gint
+static int
lua_spf_record_get_digest(lua_State *L)
{
struct spf_resolved *record;
record);
if (record) {
- gchar hexbuf[64];
+ char hexbuf[64];
rspamd_snprintf(hexbuf, sizeof(hexbuf), "%xuL", record->digest);
lua_pushstring(L, hexbuf);
* - addr - address and mask as a string
* - str - string representation (if available)
*/
-static gint
+static int
lua_spf_record_get_elts(lua_State *L)
{
struct spf_resolved *record;
record);
if (record) {
- guint i;
+ unsigned int i;
struct spf_addr *addr;
lua_createtable(L, record->elts->len, 0);
* Configures SPF library according to the UCL config
* @param {table} object configuration object
*/
-gint lua_spf_config(lua_State *L)
+int lua_spf_config(lua_State *L)
{
ucl_object_t *config_obj = ucl_object_lua_import(L, 1);
static void lua_sqlite3_push_row(lua_State *L, sqlite3_stmt *stmt);
static sqlite3 *
-lua_check_sqlite3(lua_State *L, gint pos)
+lua_check_sqlite3(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_sqlite3_classname);
luaL_argcheck(L, ud != NULL, pos, "'sqlite3' expected");
}
static sqlite3_stmt *
-lua_check_sqlite3_stmt(lua_State *L, gint pos)
+lua_check_sqlite3_stmt(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_sqlite3_stmt_classname);
luaL_argcheck(L, ud != NULL, pos, "'sqlite3_stmt' expected");
* @param {string} path path to db
* @return {sqlite3} sqlite3 handle
*/
-static gint
+static int
lua_sqlite3_open(lua_State *L)
{
- const gchar *path = luaL_checkstring(L, 1);
+ const char *path = luaL_checkstring(L, 1);
sqlite3 *db, **pdb;
GError *err = NULL;
}
static void
-lua_sqlite3_bind_statements(lua_State *L, gint start, gint end,
+lua_sqlite3_bind_statements(lua_State *L, int start, int end,
sqlite3_stmt *stmt)
{
- gint i, type, num = 1;
- const gchar *str;
+ int i, type, num = 1;
+ const char *str;
gsize slen;
- gdouble n;
+ double n;
g_assert(start <= end && start > 0 && end > 0);
case LUA_TNUMBER:
n = lua_tonumber(L, i);
- if (n == (gdouble) ((int64_t) n)) {
+ if (n == (double) ((int64_t) n)) {
sqlite3_bind_int64(stmt, num, n);
}
else {
* @param {string|number} args... variable number of arguments
* @return {boolean} `true` if a statement has been successfully executed
*/
-static gint
+static int
lua_sqlite3_sql(lua_State *L)
{
LUA_TRACE_POINT;
sqlite3 *db = lua_check_sqlite3(L, 1);
- const gchar *query = luaL_checkstring(L, 2);
+ const char *query = luaL_checkstring(L, 2);
sqlite3_stmt *stmt;
gboolean ret = FALSE;
- gint top = 1, rc;
+ int top = 1, rc;
if (db && query) {
if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
static void
lua_sqlite3_push_row(lua_State *L, sqlite3_stmt *stmt)
{
- const gchar *str;
+ const char *str;
gsize slen;
int64_t num;
- gchar numbuf[32];
- gint nresults, i, type;
+ char numbuf[32];
+ int nresults, i, type;
nresults = sqlite3_column_count(stmt);
lua_createtable(L, 0, nresults);
}
}
-static gint
+static int
lua_sqlite3_next_row(lua_State *L)
{
LUA_TRACE_POINT;
sqlite3_stmt *stmt = *(sqlite3_stmt **) lua_touserdata(L, lua_upvalueindex(1));
- gint rc;
+ int rc;
if (stmt != NULL) {
rc = sqlite3_step(stmt);
print(string.format('%d -> %s', row.id, row.value))
end
*/
-static gint
+static int
lua_sqlite3_rows(lua_State *L)
{
LUA_TRACE_POINT;
sqlite3 *db = lua_check_sqlite3(L, 1);
- const gchar *query = luaL_checkstring(L, 2);
+ const char *query = luaL_checkstring(L, 2);
sqlite3_stmt *stmt, **pstmt;
- gint top;
+ int top;
if (db && query) {
if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
return 1;
}
-static gint
+static int
lua_sqlite3_close(lua_State *L)
{
LUA_TRACE_POINT;
return 0;
}
-static gint
+static int
lua_sqlite3_stmt_close(lua_State *L)
{
sqlite3_stmt *stmt = lua_check_sqlite3_stmt(L, 1);
return 0;
}
-static gint
+static int
lua_load_sqlite3(lua_State *L)
{
lua_newtable(L);
/* Utility functions */
struct rspamd_task *
-lua_check_task(lua_State *L, gint pos)
+lua_check_task(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_task_classname);
luaL_argcheck(L, ud != NULL, pos, "'task' expected");
}
struct rspamd_task *
-lua_check_task_maybe(lua_State *L, gint pos)
+lua_check_task_maybe(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata_maybe(L, pos, rspamd_task_classname);
}
static void
-lua_task_set_cached(lua_State *L, struct rspamd_task *task, const gchar *key,
- gint pos)
+lua_task_set_cached(lua_State *L, struct rspamd_task *task, const char *key,
+ int pos)
{
LUA_TRACE_POINT;
khiter_t k;
static gboolean
-lua_task_get_cached(lua_State *L, struct rspamd_task *task, const gchar *key)
+lua_task_get_cached(lua_State *L, struct rspamd_task *task, const char *key)
{
LUA_TRACE_POINT;
khiter_t k;
if (task) {
gsize final_len = 0;
- gchar *buf = NULL;
+ char *buf = NULL;
if (lua_type(L, 2) == LUA_TTABLE) {
/* Piecewise construct */
- guint vec_len = rspamd_lua_table_size(L, 2);
+ unsigned int vec_len = rspamd_lua_table_size(L, 2);
- for (guint i = 0; i < vec_len; i++) {
+ for (unsigned int i = 0; i < vec_len; i++) {
lua_rawgeti(L, 2, i + 1);
if (lua_type(L, -1) == LUA_TSTRING) {
}
if (final_len > 0) {
- gchar *pos;
+ char *pos;
buf = rspamd_mempool_alloc(task->task_pool, final_len);
pos = buf;
- for (guint i = 0; i < vec_len; i++) {
+ for (unsigned int i = 0; i < vec_len; i++) {
lua_rawgeti(L, 2, i + 1);
if (lua_type(L, -1) == LUA_TSTRING) {
gsize l;
- const gchar *s;
+ const char *s;
s = lua_tolstring(L, -1, &l);
memcpy(pos, s, l);
}
else {
if (lua_type(L, 2) == LUA_TSTRING) {
- const gchar *s;
+ const char *s;
s = lua_tolstring(L, -1, &final_len);
buf = rspamd_mempool_alloc(task->task_pool, final_len);
g_free(p);
}
-static gint
+static int
lua_task_load_from_file(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = NULL, **ptask;
- const gchar *fname = luaL_checkstring(L, 1), *err = NULL;
+ const char *fname = luaL_checkstring(L, 1), *err = NULL;
struct rspamd_config *cfg = NULL;
gboolean res = FALSE;
gpointer map;
if (strcmp(fname, "-") == 0) {
/* Read from stdin */
- gint fd = STDIN_FILENO;
+ int fd = STDIN_FILENO;
GString *data = g_string_sized_new(BUFSIZ);
- gchar buf[BUFSIZ];
+ char buf[BUFSIZ];
gssize r;
for (;;) {
return 2;
}
-static gint
+static int
lua_task_load_from_string(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = NULL, **ptask;
- const gchar *str_message;
+ const char *str_message;
gsize message_len;
struct rspamd_config *cfg = NULL;
task = rspamd_task_new(NULL, cfg, NULL, NULL, NULL, FALSE);
task->msg.begin = g_malloc(message_len);
- memcpy((gchar *) task->msg.begin, str_message, message_len);
+ memcpy((char *) task->msg.begin, str_message, message_len);
task->msg.len = message_len;
rspamd_mempool_add_destructor(task->task_pool, lua_task_free_dtor,
(gpointer) task->msg.begin);
return 2;
}
-static gint
+static int
lua_task_create(lua_State *L)
{
LUA_TRACE_POINT;
}
-static gint
+static int
lua_task_insert_result_common(lua_State *L, struct rspamd_scan_result *result,
- gint common_args_pos)
+ int common_args_pos)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *symbol_name;
+ const char *symbol_name;
double weight;
struct rspamd_symbol_result *s;
enum rspamd_symbol_insert_flags flags = RSPAMD_SYMBOL_INSERT_DEFAULT;
- gint i, top, args_start;
+ int i, top, args_start;
if (task != NULL) {
if (lua_isboolean(L, common_args_pos)) {
lua_pop(L, 1); /* Traceback string */
}
for (i = args_start + 2; i <= top; i++) {
- gint ltype = lua_type(L, i);
+ int ltype = lua_type(L, i);
if (ltype == LUA_TSTRING) {
gsize optlen;
else if (ltype == LUA_TTABLE) {
gsize objlen = rspamd_lua_table_size(L, i);
- for (guint j = 1; j <= objlen; j++) {
+ for (unsigned int j = 1; j <= objlen; j++) {
lua_rawgeti(L, i, j);
if (lua_type(L, -1) == LUA_TSTRING) {
}
}
else {
- const gchar *tname = lua_typename(L, lua_type(L, -1));
+ const char *tname = lua_typename(L, lua_type(L, -1));
lua_pop(L, 2);
return luaL_error(L, "not a string option in a table "
continue;
}
else {
- const gchar *tname = lua_typename(L, ltype);
+ const char *tname = lua_typename(L, ltype);
return luaL_error(L, "not a string/table option "
"when adding symbol %s: %s type",
return 0;
}
-static gint
+static int
lua_task_insert_result(lua_State *L)
{
return lua_task_insert_result_common(L, NULL, 2);
}
-static gint
+static int
lua_task_insert_result_named(lua_State *L)
{
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *named_result = luaL_checkstring(L, 2);
+ const char *named_result = luaL_checkstring(L, 2);
struct rspamd_scan_result *res;
if (task && named_result) {
return luaL_error(L, "invalid arguments");
}
-static gint
+static int
lua_task_adjust_result(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *symbol_name;
+ const char *symbol_name;
struct rspamd_scan_result *metric_res;
struct rspamd_symbol_result *s = NULL;
double weight;
- gint i, top;
+ int i, top;
if (task != NULL) {
else if (lua_type(L, i) == LUA_TTABLE) {
gsize objlen = rspamd_lua_table_size(L, i);
- for (guint j = 1; j <= objlen; j++) {
+ for (unsigned int j = 1; j <= objlen; j++) {
lua_rawgeti(L, i, j);
if (lua_type(L, -1) == LUA_TSTRING) {
return 0;
}
-static gint
+static int
lua_task_remove_result(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *symbol_name = luaL_checkstring(L, 2);
+ const char *symbol_name = luaL_checkstring(L, 2);
struct rspamd_scan_result *metric_res;
- const gchar *named_result = luaL_optstring(L, 3, NULL);
+ const char *named_result = luaL_optstring(L, 3, NULL);
if (task != NULL) {
metric_res = rspamd_find_metric_result(task, named_result);
return 1;
}
-static gint
+static int
lua_task_set_pre_result(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *message = NULL, *module = NULL, *fl_str = NULL, *act_str = NULL,
- *res_name = NULL;
- gdouble score = NAN;
+ const char *message = NULL, *module = NULL, *fl_str = NULL, *act_str = NULL,
+ *res_name = NULL;
+ double score = NAN;
struct rspamd_action *action;
- guint priority = RSPAMD_PASSTHROUGH_NORMAL, flags = 0;
+ unsigned int priority = RSPAMD_PASSTHROUGH_NORMAL, flags = 0;
if (task != NULL) {
RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT,
"*action=S;message=S;module=S;score=D;priority=i;flags=S;result=S",
&act_str, &message, &module, &score, &priority, &fl_str, &res_name)) {
- gint ret = luaL_error(L, "invalid arguments: %s", err->message);
+ int ret = luaL_error(L, "invalid arguments: %s", err->message);
g_error_free(err);
return ret;
return 0;
}
-static gint
+static int
lua_task_has_pre_result(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- gint nret = 1;
+ int nret = 1;
if (task) {
if (task->result->passthrough_result) {
return nret;
}
-static gint
+static int
lua_task_append_message(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *category;
+ const char *category;
if (task != NULL) {
if (lua_type(L, 3) == LUA_TSTRING) {
}
-static gint
+static int
lua_task_get_urls(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
struct lua_tree_cb_data cb;
struct rspamd_url *u;
- static const gint default_protocols_mask = PROTOCOL_HTTP | PROTOCOL_HTTPS |
- PROTOCOL_FILE | PROTOCOL_FTP;
+ static const int default_protocols_mask = PROTOCOL_HTTP | PROTOCOL_HTTPS |
+ PROTOCOL_FILE | PROTOCOL_FTP;
gsize sz, max_urls = 0;
if (task) {
if (cb.sort) {
struct rspamd_url **urls_sorted;
- gint i = 0;
+ int i = 0;
urls_sorted = g_new0(struct rspamd_url *, sz);
return 1;
}
-static gint
+static int
lua_task_get_urls_filtered(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
struct lua_tree_cb_data cb;
struct rspamd_url *u;
- static const gint default_protocols_mask = PROTOCOL_HTTP | PROTOCOL_HTTPS |
- PROTOCOL_FILE | PROTOCOL_FTP;
+ static const int default_protocols_mask = PROTOCOL_HTTP | PROTOCOL_HTTPS |
+ PROTOCOL_FILE | PROTOCOL_FTP;
gsize sz, max_urls = 0;
if (task) {
if (cb.sort) {
struct rspamd_url **urls_sorted;
- gint i = 0;
+ int i = 0;
urls_sorted = g_new0(struct rspamd_url *, sz);
return 1;
}
-static gint
+static int
lua_task_has_urls(lua_State *L)
{
LUA_TRACE_POINT;
return 2;
}
-static gint
+static int
lua_task_inject_url(lua_State *L)
{
LUA_TRACE_POINT;
return 0;
}
-static gint
+static int
lua_task_get_content(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_get_filename(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_get_rawbody(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_get_emails(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_get_text_parts(lua_State *L)
{
LUA_TRACE_POINT;
- guint i;
+ unsigned int i;
struct rspamd_task *task = lua_check_task(L, 1);
struct rspamd_mime_text_part *part, **ppart;
return 1;
}
-static gint
+static int
lua_task_get_parts(lua_State *L)
{
LUA_TRACE_POINT;
- guint i;
+ unsigned int i;
struct rspamd_task *task = lua_check_task(L, 1);
struct rspamd_mime_part *part, **ppart;
return 1;
}
-static gint
+static int
lua_task_get_request_header(lua_State *L)
{
LUA_TRACE_POINT;
rspamd_ftok_t *hdr;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *s;
+ const char *s;
struct rspamd_lua_text *t;
s = luaL_checkstring(L, 2);
return 1;
}
-static gint
+static int
lua_task_set_request_header(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *s, *v = NULL;
+ const char *s, *v = NULL;
rspamd_fstring_t *buf;
struct rspamd_lua_text *t;
rspamd_ftok_t *hdr, *new_name;
}
-gint rspamd_lua_push_header(lua_State *L, struct rspamd_mime_header *rh,
- enum rspamd_lua_task_header_type how)
+int rspamd_lua_push_header(lua_State *L, struct rspamd_mime_header *rh,
+ enum rspamd_lua_task_header_type how)
{
LUA_TRACE_POINT;
switch (how) {
return 1;
}
-gint rspamd_lua_push_header_array(lua_State *L,
- const gchar *name,
- struct rspamd_mime_header *rh,
- enum rspamd_lua_task_header_type how,
- gboolean strong)
+int rspamd_lua_push_header_array(lua_State *L,
+ const char *name,
+ struct rspamd_mime_header *rh,
+ enum rspamd_lua_task_header_type how,
+ gboolean strong)
{
LUA_TRACE_POINT;
struct rspamd_mime_header *cur;
- guint i;
- gint nret = 1;
+ unsigned int i;
+ int nret = 1;
if (rh == NULL) {
if (how == RSPAMD_TASK_HEADER_PUSH_HAS) {
return nret;
}
-static gint
+static int
lua_task_get_header_common(lua_State *L, enum rspamd_lua_task_header_type how)
{
LUA_TRACE_POINT;
gboolean strong = FALSE, need_modified = FALSE;
struct rspamd_task *task = lua_check_task(L, 1);
struct rspamd_mime_header *rh;
- const gchar *name;
+ const char *name;
name = luaL_checkstring(L, 2);
}
}
-static gint
+static int
lua_task_get_header_full(lua_State *L)
{
return lua_task_get_header_common(L, RSPAMD_TASK_HEADER_PUSH_FULL);
}
-static gint
+static int
lua_task_get_header(lua_State *L)
{
return lua_task_get_header_common(L, RSPAMD_TASK_HEADER_PUSH_SIMPLE);
}
-static gint
+static int
lua_task_get_header_raw(lua_State *L)
{
return lua_task_get_header_common(L, RSPAMD_TASK_HEADER_PUSH_RAW);
}
-static gint
+static int
lua_task_get_header_count(lua_State *L)
{
return lua_task_get_header_common(L, RSPAMD_TASK_HEADER_PUSH_COUNT);
}
-static gint
+static int
lua_task_has_header(lua_State *L)
{
return lua_task_get_header_common(L, RSPAMD_TASK_HEADER_PUSH_HAS);
}
-static gint
+static int
lua_task_get_headers(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_get_raw_headers(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_get_received_headers(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_get_queue_id(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_get_uid(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_get_resolver(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_set_resolver(lua_State *L)
{
LUA_TRACE_POINT;
return 0;
}
-static gint
+static int
lua_task_inc_dns_req(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- static guint warning_shown = 0;
+ static unsigned int warning_shown = 0;
if (warning_shown < 100) {
warning_shown++;
return 0;
}
-static gint
+static int
lua_task_get_dns_req(lua_State *L)
{
LUA_TRACE_POINT;
* for get_from/get_recipients
*/
static enum lua_email_address_type
-lua_task_str_to_get_type(lua_State *L, struct rspamd_task *task, gint pos, gint last_pos)
+lua_task_str_to_get_type(lua_State *L, struct rspamd_task *task, int pos, int last_pos)
{
- const gchar *type = NULL;
- gint ret = LUA_ADDRESS_ANY;
+ const char *type = NULL;
+ int ret = LUA_ADDRESS_ANY;
uint64_t h;
gsize sz;
ret = LUA_ADDRESS_SMTP;
break;
default:
- msg_err_task("invalid email type: %*s", (gint) sz, type);
+ msg_err_task("invalid email type: %*s", (int) sz, type);
break;
}
}
ret |= LUA_ADDRESS_ORIGINAL;
break;
default:
- msg_err_task("invalid email type: %*s", (gint) sz, type);
+ msg_err_task("invalid email type: %*s", (int) sz, type);
break;
}
}
void lua_push_emails_address_list(lua_State *L, GPtrArray *addrs, int flags)
{
struct rspamd_email_address *addr;
- guint i, pos = 1;
+ unsigned int i, pos = 1;
lua_createtable(L, addrs->len, 0);
static gboolean
lua_import_email_address(lua_State *L, struct rspamd_task *task,
- gint pos,
+ int pos,
struct rspamd_email_address **paddr)
{
struct rspamd_email_address *addr;
- const gchar *p;
- gchar *dst;
+ const char *p;
+ char *dst;
gsize len;
g_assert(paddr != NULL);
if (lua_type(L, -1) == LUA_TSTRING) {
p = lua_tolstring(L, -1, &len);
- addr->user = (const gchar *) rspamd_mempool_alloc(task->task_pool, len);
- memcpy((gchar *) addr->user, p, len);
+ addr->user = (const char *) rspamd_mempool_alloc(task->task_pool, len);
+ memcpy((char *) addr->user, p, len);
addr->user_len = len;
}
if (lua_type(L, -1) == LUA_TSTRING) {
p = lua_tolstring(L, -1, &len);
- addr->domain = (const gchar *) rspamd_mempool_alloc(task->task_pool, len);
- memcpy((gchar *) addr->domain, p, len);
+ addr->domain = (const char *) rspamd_mempool_alloc(task->task_pool, len);
+ memcpy((char *) addr->domain, p, len);
addr->domain_len = len;
}
if (lua_type(L, -1) == LUA_TSTRING) {
p = lua_tolstring(L, -1, &len);
- addr->addr = (const gchar *) rspamd_mempool_alloc(task->task_pool, len);
- memcpy((gchar *) addr->addr, p, len);
+ addr->addr = (const char *) rspamd_mempool_alloc(task->task_pool, len);
+ memcpy((char *) addr->addr, p, len);
addr->addr_len = len;
}
else {
/* Construct addr */
len = addr->domain_len + addr->user_len + 1;
- addr->addr = (const gchar *) rspamd_mempool_alloc(task->task_pool, len);
- addr->addr_len = rspamd_snprintf((gchar *) addr->addr, len, "%*s@%*s",
+ addr->addr = (const char *) rspamd_mempool_alloc(task->task_pool, len);
+ addr->addr_len = rspamd_snprintf((char *) addr->addr, len, "%*s@%*s",
(int) addr->user_len, addr->user,
(int) addr->domain_len, addr->domain);
}
lua_gettable(L, pos);
if (lua_type(L, -1) == LUA_TSTRING) {
- gchar *cpy;
+ char *cpy;
p = lua_tolstring(L, -1, &len);
cpy = rspamd_mempool_alloc(task->task_pool, len + 1);
memcpy(cpy, p, len);
return TRUE;
}
-static gint
+static int
lua_task_get_recipients(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
GPtrArray *ptrs = NULL;
- gint what = 0;
+ int what = 0;
if (task) {
if (lua_gettop(L) == 2) {
return 1;
}
-static gint
+static int
lua_task_set_recipients(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
GPtrArray *ptrs = NULL;
struct rspamd_email_address *addr = NULL;
- gint what = 0, pos = 3;
- const gchar *how = "add";
+ int what = 0, pos = 3;
+ const char *how = "add";
gboolean need_update_digest = FALSE;
if (task && lua_gettop(L) >= 3) {
break;
}
if (ptrs) {
- guint i, flags_existing = RSPAMD_EMAIL_ADDR_ORIGINAL, flags_add = 0;
+ unsigned int i, flags_existing = RSPAMD_EMAIL_ADDR_ORIGINAL, flags_add = 0;
struct rspamd_email_address *tmp;
if (strcmp(how, "alias") == 0) {
} \
} while (0)
-static gint
+static int
lua_task_has_from(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- gint what = 0, nrcpt = 0;
+ int what = 0, nrcpt = 0;
gboolean ret = FALSE;
if (task) {
static inline int
rspamd_check_real_recipients_array_size(GPtrArray *ar)
{
- gint ret = 0, i;
+ int ret = 0, i;
struct rspamd_email_address *addr;
PTR_ARRAY_FOREACH(ar, i, addr)
return ret;
}
-static gint
+static int
lua_task_has_recipients(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- gint what = 0, nrcpt = 0;
+ int what = 0, nrcpt = 0;
gboolean ret = FALSE;
if (task) {
return 2;
}
-static gint
+static int
lua_task_get_from(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
GPtrArray *addrs = NULL;
struct rspamd_email_address *addr = NULL;
- gint what = 0;
+ int what = 0;
if (task) {
if (lua_gettop(L) == 2) {
return 1;
}
-static gint
+static int
lua_task_set_from(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *how = "rewrite";
+ const char *how = "rewrite";
GPtrArray *addrs = NULL;
struct rspamd_email_address **paddr = NULL, *addr;
gboolean need_update_digest = FALSE;
- gint what = 0;
+ int what = 0;
if (task && lua_gettop(L) >= 3) {
what = lua_task_str_to_get_type(L, task, 2, -1);
if (addrs) {
if (lua_import_email_address(L, task, 3, &addr)) {
- guint i, flags_add = RSPAMD_EMAIL_ADDR_ORIGINAL;
+ unsigned int i, flags_add = RSPAMD_EMAIL_ADDR_ORIGINAL;
struct rspamd_email_address *tmp;
if (strcmp(how, "alias") == 0) {
return 1;
}
-static gint
+static int
lua_task_get_principal_recipient(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *r;
+ const char *r;
if (task) {
r = rspamd_task_get_principal_recipient(task);
return 1;
}
-static gint
+static int
lua_task_get_reply_sender(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_get_user(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_set_user(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *new_user;
+ const char *new_user;
if (task) {
return 1;
}
-static gint
+static int
lua_task_get_from_ip(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_set_from_ip(lua_State *L)
{
LUA_TRACE_POINT;
else {
if (lua_type(L, 2) == LUA_TSTRING) {
gsize len;
- const gchar *ip_str = lua_tolstring(L, 2, &len);
+ const char *ip_str = lua_tolstring(L, 2, &len);
if (!rspamd_parse_inet_address(&addr,
ip_str,
return 0;
}
-static gint
+static int
lua_task_get_from_ip_num(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_get_client_ip(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_get_helo(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_get_subject(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_set_helo(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *new_helo;
+ const char *new_helo;
if (task) {
new_helo = luaL_checkstring(L, 2);
return 0;
}
-static gint
+static int
lua_task_get_hostname(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_set_hostname(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *new_hostname;
+ const char *new_hostname;
if (task) {
new_hostname = luaL_checkstring(L, 2);
return 0;
}
-static gint
+static int
lua_task_get_images(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- guint nelt = 0, i;
+ unsigned int nelt = 0, i;
struct rspamd_mime_part *part;
struct rspamd_image **pimg;
return 1;
}
-static gint
+static int
lua_task_get_archives(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- guint nelt = 0, i;
+ unsigned int nelt = 0, i;
struct rspamd_mime_part *part;
struct rspamd_archive **parch;
return 1;
}
-static gint
+static int
lua_task_get_dkim_results(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- guint nelt = 0, i;
+ unsigned int nelt = 0, i;
struct rspamd_dkim_check_result **pres, **cur;
if (task) {
for (i = 0; i < nelt; i++) {
struct rspamd_dkim_check_result *res = pres[i];
- const gchar *result_str = "unknown";
+ const char *result_str = "unknown";
lua_createtable(L, 0, 4);
static inline gboolean
lua_push_symbol_result(lua_State *L,
struct rspamd_task *task,
- const gchar *symbol,
+ const char *symbol,
struct rspamd_symbol_result *symbol_result,
struct rspamd_scan_result *metric_res,
gboolean add_metric,
struct rspamd_symbol_result *s = NULL;
struct rspamd_symbol_option *opt;
struct rspamd_symbols_group *sym_group;
- guint i;
- gint j = 1, table_fields_cnt = 4;
+ unsigned int i;
+ int j = 1, table_fields_cnt = 4;
if (!metric_res) {
metric_res = task->result;
return FALSE;
}
-static gint
+static int
lua_task_get_symbol(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *symbol;
+ const char *symbol;
gboolean found = FALSE;
symbol = luaL_checkstring(L, 2);
return 1;
}
-static gint
+static int
lua_task_has_symbol(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
struct rspamd_symbol_result *s;
- const gchar *symbol;
+ const char *symbol;
gboolean found = FALSE;
symbol = luaL_checkstring(L, 2);
return 1;
}
-static gint
+static int
lua_task_enable_symbol(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *symbol;
+ const char *symbol;
gboolean found = FALSE;
symbol = luaL_checkstring(L, 2);
return 1;
}
-static gint
+static int
lua_task_disable_symbol(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *symbol;
+ const char *symbol;
gboolean found = FALSE;
symbol = luaL_checkstring(L, 2);
return 1;
}
-static gint
+static int
lua_task_get_symbols(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
struct rspamd_scan_result *mres;
- gint i = 1;
+ int i = 1;
struct rspamd_symbol_result *s;
if (task) {
return 2;
}
-static gint
+static int
lua_task_get_symbols_all(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_scan_result *mres;
struct rspamd_symbol_result *s;
gboolean found = FALSE;
- gint i = 1;
+ int i = 1;
if (task) {
mres = task->result;
}
-static gint
+static int
lua_task_get_symbols_numeric(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
struct rspamd_scan_result *mres;
- gint i = 1, id;
+ int i = 1, id;
struct rspamd_symbol_result *s;
if (task) {
return 2;
}
-static gint
+static int
lua_task_get_groups(lua_State *L)
{
LUA_TRACE_POINT;
gboolean need_private;
struct rspamd_scan_result *mres;
struct rspamd_symbols_group *gr;
- gdouble gr_score;
+ double gr_score;
if (task) {
mres = task->result;
struct tokens_foreach_cbdata {
struct rspamd_task *task;
lua_State *L;
- gint idx;
+ int idx;
gboolean normalize;
};
{
struct tokens_foreach_cbdata *cbd = ud;
struct rspamd_symbol_result *s;
- gint flags;
- const gchar *sym;
+ int flags;
+ const char *sym;
sym = rspamd_symcache_item_name(item);
flags = rspamd_symcache_item_flags(item);
lua_rawseti(cbd->L, -2, cbd->idx++);
}
-static gint
+static int
lua_task_get_symbols_tokens(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_process_ann_tokens(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- gint offset = luaL_checkinteger(L, 4);
- gdouble min_score = 0.0;
+ int offset = luaL_checkinteger(L, 4);
+ double min_score = 0.0;
if (task && lua_istable(L, 2) && lua_istable(L, 3)) {
- guint symlen = rspamd_lua_table_size(L, 2);
+ unsigned int symlen = rspamd_lua_table_size(L, 2);
if (lua_isnumber(L, 5)) {
min_score = lua_tonumber(L, 5);
}
- for (guint i = 1; i <= symlen; i++, offset++) {
- const gchar *sym;
+ for (unsigned int i = 1; i <= symlen; i++, offset++) {
+ const char *sym;
struct rspamd_symbol_result *sres;
lua_rawgeti(L, 2, i);
(!sres->sym ||
!(rspamd_symcache_item_flags(sres->sym->cache_item) & SYMBOL_TYPE_NOSTAT))) {
- gdouble norm_score;
+ double norm_score;
if (sres->sym && !isnan(sres->sym->score)) {
if (sres->sym->score == 0) {
static enum lua_date_type
lua_task_detect_date_type(struct rspamd_task *task,
- lua_State *L, gint idx, gboolean *gmt)
+ lua_State *L, int idx, gboolean *gmt)
{
enum lua_date_type type = DATE_CONNECT;
if (lua_type(L, idx) == LUA_TNUMBER) {
- gint num = lua_tonumber(L, idx);
+ int num = lua_tonumber(L, idx);
if (num >= DATE_CONNECT && num < DATE_INVALID) {
return num;
}
}
else if (lua_type(L, idx) == LUA_TTABLE) {
- const gchar *str;
+ const char *str;
lua_pushvalue(L, idx);
lua_pushstring(L, "format");
return type;
}
-static gint
+static int
lua_task_get_date(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
struct rspamd_mime_header *h;
- gdouble tim;
+ double tim;
enum lua_date_type type = DATE_CONNECT;
gboolean gmt = TRUE;
return 1;
}
-static gint
+static int
lua_task_get_message_id(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_get_timeval(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_get_scan_time(lua_State *L)
{
LUA_TRACE_POINT;
}
rspamd_task_set_finish_time(task);
- gdouble diff = task->time_real_finish - task->task_timestamp;
+ double diff = task->time_real_finish - task->task_timestamp;
lua_pushnumber(L, diff);
lua_pushnumber(L, diff);
return 2;
}
-static gint
+static int
lua_task_get_size(lua_State *L)
{
LUA_TRACE_POINT;
} \
} while (0)
-static gint
+static int
lua_task_set_flag(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *flag = luaL_checkstring(L, 2);
+ const char *flag = luaL_checkstring(L, 2);
gboolean set = TRUE, found = FALSE;
if (lua_gettop(L) >= 3) {
return 0;
}
-static gint
+static int
lua_task_has_flag(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *flag = luaL_checkstring(L, 2);
+ const char *flag = luaL_checkstring(L, 2);
gboolean found = FALSE;
if (task != NULL && flag != NULL) {
return 1;
}
-static gint
+static int
lua_task_get_flags(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- gint idx = 1;
- guint flags, bit, i;
+ int idx = 1;
+ unsigned int flags, bit, i;
if (task) {
lua_createtable(L, 8, 0);
return 1;
}
-static gint
+static int
lua_task_get_digest(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- gchar hexbuf[sizeof(MESSAGE_FIELD(task, digest)) * 2 + 1];
- gint r;
+ char hexbuf[sizeof(MESSAGE_FIELD(task, digest)) * 2 + 1];
+ int r;
if (task) {
if (task->message) {
return 1;
}
-static gint
+static int
lua_task_learn(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
gboolean is_spam = FALSE;
- const gchar *clname = NULL;
+ const char *clname = NULL;
GError *err = NULL;
int ret = 1;
return ret;
}
-static gint
+static int
lua_task_set_settings(lua_State *L)
{
LUA_TRACE_POINT;
const ucl_object_t *act, *metric_elt, *vars, *cur;
ucl_object_iter_t it = NULL;
struct rspamd_scan_result *mres;
- guint i;
+ unsigned int i;
settings = ucl_object_lua_import(L, 2);
it = NULL;
while ((cur = ucl_object_iterate(act, &it, true)) != NULL) {
- const gchar *act_name = ucl_object_key(cur);
+ const char *act_name = ucl_object_key(cur);
struct rspamd_action_config *action_config = NULL;
double act_score;
enum rspamd_action_type act_type;
return 0;
}
-static gint
+static int
lua_task_set_milter_reply(lua_State *L)
{
LUA_TRACE_POINT;
while ((cur = ucl_object_iterate(nadd_hdrs, &it, true)) != NULL) {
gsize klen;
- const gchar *key = ucl_object_keyl(cur, &klen);
+ const char *key = ucl_object_keyl(cur, &klen);
const ucl_object_t *existing;
existing = ucl_object_lookup_len(add_hdrs, key, klen);
return 0;
}
-static gint
+static int
lua_task_get_settings(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_lookup_settings(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *key = NULL;
+ const char *key = NULL;
const ucl_object_t *elt;
if (task != NULL) {
return 1;
}
-static gint
+static int
lua_task_get_settings_id(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_set_settings_id(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_cache_get(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *key = luaL_checkstring(L, 2);
+ const char *key = luaL_checkstring(L, 2);
if (task && key) {
if (!lua_task_get_cached(L, task, key)) {
return 1;
}
-static gint
+static int
lua_task_cache_set(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *key = luaL_checkstring(L, 2);
+ const char *key = luaL_checkstring(L, 2);
if (task && key && lua_gettop(L) >= 3) {
lua_task_set_cached(L, task, key, 3);
}
struct lua_file_cbdata {
- gchar *fname;
- gint fd;
+ char *fname;
+ int fd;
gboolean keep;
};
close(cbdata->fd);
}
-static gint
+static int
lua_task_store_in_file(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
gboolean force_new = FALSE, keep = FALSE;
- gchar fpath[PATH_MAX];
- const gchar *tmpmask = NULL, *fname = NULL;
- guint mode = 00600;
- gint fd;
+ char fpath[PATH_MAX];
+ const char *tmpmask = NULL, *fname = NULL;
+ unsigned int mode = 00600;
+ int fd;
struct lua_file_cbdata *cbdata;
GError *err = NULL;
}
else {
fd = rspamd_file_xopen(fname, O_WRONLY | O_CREAT | O_EXCL,
- (guint) mode, FALSE);
+ (unsigned int) mode, FALSE);
}
if (fd == -1) {
return 1;
}
-static gint
+static int
lua_task_process_regexp(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
struct rspamd_lua_regexp *re = NULL;
gboolean strong = FALSE;
- const gchar *type_str = NULL, *header_str = NULL;
+ const char *type_str = NULL, *header_str = NULL;
gsize header_len = 0;
GError *err = NULL;
- gint ret = 0;
+ int ret = 0;
enum rspamd_re_type type = RSPAMD_RE_BODY;
/*
return 1;
}
-static gint
+static int
lua_task_get_metric_result(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_get_metric_score(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- gdouble rs;
+ double rs;
struct rspamd_scan_result *metric_res;
if (task) {
return 1;
}
-static gint
+static int
lua_task_get_metric_action(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_set_metric_score(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
struct rspamd_scan_result *metric_res;
- gdouble nscore;
+ double nscore;
if (lua_isnumber(L, 2)) {
nscore = luaL_checknumber(L, 2);
return 1;
}
-static gint
+static int
lua_task_disable_action(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *action_name;
+ const char *action_name;
struct rspamd_action_config *action_res;
action_name = luaL_checkstring(L, 2);
if (task && action_name) {
- for (guint i = 0; i < task->result->nactions; i++) {
+ for (unsigned int i = 0; i < task->result->nactions; i++) {
action_res = &task->result->actions_config[i];
if (strcmp(action_name, action_res->action->name) == 0) {
return 1;
}
-static gint
+static int
lua_task_get_newlines_type(lua_State *L)
{
LUA_TRACE_POINT;
static void
lua_push_stat_token(lua_State *L, rspamd_token_t *tok)
{
- gchar numbuf[64];
+ char numbuf[64];
/* Table values
* - `data`: 64 bit number encoded as a string
lua_settable(L, -3);
}
-static gint
+static int
lua_task_get_stat_tokens(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- guint i;
+ unsigned int i;
rspamd_token_t *tok;
if (task) {
return 1;
}
-static gint
+static int
lua_task_set_metric_subject(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *subject;
+ const char *subject;
subject = luaL_checkstring(L, 2);
return 1;
}
-static gint
+static int
lua_task_get_protocol_reply(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- guint flags = 0;
+ unsigned int flags = 0;
ucl_object_t *obj;
if (!task) {
if (lua_istable(L, 2)) {
for (lua_pushnil(L); lua_next(L, 2); lua_pop(L, 1)) {
if (lua_isstring(L, -1)) {
- const gchar *str = lua_tostring(L, -1);
+ const char *str = lua_tostring(L, -1);
if (strcmp(str, "default") == 0) {
flags |= RSPAMD_PROTOCOL_DEFAULT;
return 1;
}
-static gint
+static int
lua_task_headers_foreach(lua_State *L)
{
LUA_TRACE_POINT;
enum rspamd_lua_task_header_type how = RSPAMD_TASK_HEADER_PUSH_SIMPLE;
struct rspamd_lua_regexp *re = NULL;
struct rspamd_mime_header *hdr, *cur;
- gint old_top;
+ int old_top;
if (task && lua_isfunction(L, 2)) {
if (task->message) {
return 0;
}
-static gint
+static int
lua_task_modify_header(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *hname = luaL_checkstring(L, 2);
+ const char *hname = luaL_checkstring(L, 2);
if (hname && task && lua_type(L, 3) == LUA_TTABLE) {
if (task->message) {
return 1;
}
-static gint
+static int
lua_task_get_meta_words(lua_State *L)
{
LUA_TRACE_POINT;
}
else {
if (lua_type(L, 2) == LUA_TSTRING) {
- const gchar *how_str = lua_tostring(L, 2);
+ const char *how_str = lua_tostring(L, 2);
if (strcmp(how_str, "stem") == 0) {
how = RSPAMD_LUA_WORDS_STEM;
return 1;
}
-static guint
+static unsigned int
lua_lookup_words_array(lua_State *L,
- gint cbpos,
+ int cbpos,
struct rspamd_task *task,
struct rspamd_lua_map *map,
GArray *words)
{
rspamd_stat_token_t *tok;
- guint i, nmatched = 0;
- gint err_idx;
+ unsigned int i, nmatched = 0;
+ int err_idx;
gboolean matched;
- const gchar *key;
+ const char *key;
gsize keylen;
for (i = 0; i < words->len; i++) {
return nmatched;
}
-static gint
+static int
lua_task_lookup_words(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_map *map = lua_check_map(L, 2);
struct rspamd_mime_text_part *tp;
- guint i, matches = 0;
+ unsigned int i, matches = 0;
if (task == NULL || map == NULL || task->message == NULL || lua_type(L, 3) != LUA_TFUNCTION) {
return luaL_error(L, "invalid arguments");
return 1;
}
-static gint
+static int
lua_task_topointer(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_task_add_named_result(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *name = luaL_checkstring(L, 2);
- gint cbref;
+ const char *name = luaL_checkstring(L, 2);
+ int cbref;
if (task && name && lua_isfunction(L, 3)) {
lua_pushvalue(L, 3);
return 0;
}
-static gint
+static int
lua_task_get_all_named_results(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task(L, 1);
if (task) {
- gint n = 0;
+ int n = 0;
struct rspamd_scan_result *res;
DL_COUNT(task->result, res, n);
/* Image functions */
-static gint
+static int
lua_image_get_width(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_image_get_height(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_image_get_type(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_image_get_size(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_image_get_filename(lua_State *L)
{
LUA_TRACE_POINT;
}
/* Archive methods */
-static gint
+static int
lua_archive_get_type(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_archive_get_files(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_archive *arch = lua_check_archive(L);
- guint i, max_files = 0;
+ unsigned int i, max_files = 0;
struct rspamd_archive_file *f;
if (arch != NULL) {
return 1;
}
-static gint
+static int
lua_archive_get_files_full(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_archive *arch = lua_check_archive(L);
- guint i, max_files = 0;
+ unsigned int i, max_files = 0;
struct rspamd_archive_file *f;
if (arch != NULL) {
return 1;
}
-static gint
+static int
lua_archive_is_encrypted(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_archive_is_obfuscated(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_archive_is_unreadable(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_archive_get_size(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_archive_get_filename(lua_State *L)
{
LUA_TRACE_POINT;
/* Init part */
-static gint
+static int
lua_load_task(lua_State *L)
{
lua_newtable(L);
#include "unix-std.h"
#include <math.h>
-static const gchar *M = "rspamd lua tcp";
+static const char *M = "rspamd lua tcp";
/***
* @module rspamd_tcp
{NULL, NULL}};
struct lua_tcp_read_handler {
- gchar *stop_pattern;
- guint plen;
- gint cbref;
+ char *stop_pattern;
+ unsigned int plen;
+ int cbref;
};
struct lua_tcp_write_handler {
struct iovec *iov;
- guint iovlen;
- gint cbref;
+ unsigned int iovlen;
+ int cbref;
gsize pos;
gsize total_bytes;
};
rspamd_inet_addr_t *addr;
GByteArray *in;
GQueue *handlers;
- gint fd;
- gint connect_cb;
- guint port;
- guint flags;
- gchar tag[7];
+ int fd;
+ int connect_cb;
+ unsigned int port;
+ unsigned int flags;
+ char tag[7];
struct rspamd_io_ev ev;
struct lua_tcp_dtor *dtors;
ref_entry_t ref;
struct thread_entry *thread;
struct rspamd_config *cfg;
struct rspamd_ssl_connection *ssl_conn;
- gchar *hostname;
+ char *hostname;
struct upstream *up;
gboolean eof;
};
{
}
-static const gdouble default_tcp_timeout = 5.0;
+static const double default_tcp_timeout = 5.0;
static struct rspamd_dns_resolver *
lua_tcp_global_resolver(struct ev_loop *ev_base,
}
static struct lua_tcp_cbdata *
-lua_check_tcp(lua_State *L, gint pos)
+lua_check_tcp(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_tcp_classname);
luaL_argcheck(L, ud != NULL, pos, "'tcp' expected");
const char *err, ...) __attribute__((format(printf, 3, 4)));
#endif
-static void lua_tcp_resume_thread_error_argp(struct lua_tcp_cbdata *cbd, const gchar *error, va_list argp);
+static void lua_tcp_resume_thread_error_argp(struct lua_tcp_cbdata *cbd, const char *error, va_list argp);
static void
lua_tcp_push_error(struct lua_tcp_cbdata *cbd, gboolean is_fatal,
va_list ap, ap_copy;
struct lua_tcp_cbdata **pcbd;
struct lua_tcp_handler *hdl;
- gint cbref, top;
+ int cbref, top;
struct lua_callback_state cbs;
lua_State *L;
gboolean callback_called = FALSE;
lua_thread_pool_restore_callback(&cbs);
}
-static void lua_tcp_resume_thread(struct lua_tcp_cbdata *cbd, const guint8 *str, gsize len);
+static void lua_tcp_resume_thread(struct lua_tcp_cbdata *cbd, const uint8_t *str, gsize len);
static void
-lua_tcp_push_data(struct lua_tcp_cbdata *cbd, const guint8 *str, gsize len)
+lua_tcp_push_data(struct lua_tcp_cbdata *cbd, const uint8_t *str, gsize len)
{
struct rspamd_lua_text *t;
struct lua_tcp_cbdata **pcbd;
struct lua_tcp_handler *hdl;
- gint cbref, arg_cnt, top;
+ int cbref, arg_cnt, top;
struct lua_callback_state cbs;
lua_State *L;
if (hdl->type == LUA_WANT_READ) {
t = lua_newuserdata(L, sizeof(*t));
rspamd_lua_setclass(L, rspamd_text_classname, -1);
- t->start = (const gchar *) str;
+ t->start = (const char *) str;
t->len = len;
t->flags = 0;
arg_cnt = 3;
}
static void
-lua_tcp_resume_thread_error_argp(struct lua_tcp_cbdata *cbd, const gchar *error, va_list argp)
+lua_tcp_resume_thread_error_argp(struct lua_tcp_cbdata *cbd, const char *error, va_list argp)
{
struct thread_entry *thread = cbd->thread;
lua_State *L = thread->lua_state;
}
static void
-lua_tcp_resume_thread(struct lua_tcp_cbdata *cbd, const guint8 *str, gsize len)
+lua_tcp_resume_thread(struct lua_tcp_cbdata *cbd, const uint8_t *str, gsize len)
{
/*
* typical call returns:
lua_tcp_write_helper(struct lua_tcp_cbdata *cbd)
{
struct iovec *start;
- guint niov, i;
- gint flags = 0;
+ unsigned int niov, i;
+ int flags = 0;
bool allocated_iov = false;
gsize remain;
gssize r;
else {
lua_tcp_push_error(cbd, TRUE,
"IO write error while trying to write %d bytes: %s",
- (gint) remain, strerror(errno));
+ (int) remain, strerror(errno));
msg_debug_tcp("write error, terminate connection");
TCP_RELEASE(cbd);
lua_tcp_process_read_handler(struct lua_tcp_cbdata *cbd,
struct lua_tcp_read_handler *rh, gboolean eof)
{
- guint slen;
+ unsigned int slen;
goffset pos;
if (rh->stop_pattern) {
static void
lua_tcp_process_read(struct lua_tcp_cbdata *cbd,
- guchar *in, gssize r)
+ unsigned char *in, gssize r)
{
struct lua_tcp_handler *hdl;
struct lua_tcp_read_handler *rh;
lua_tcp_handler(int fd, short what, gpointer ud)
{
struct lua_tcp_cbdata *cbd = ud;
- guchar inbuf[8192];
+ unsigned char inbuf[8192];
gssize r;
- gint so_error = 0;
+ int so_error = 0;
socklen_t so_len = sizeof(so_error);
struct lua_callback_state cbs;
lua_State *L;
if (cbd->connect_cb != -1) {
struct lua_tcp_cbdata **pcbd;
- gint top;
+ int top;
lua_thread_pool_prepare_callback(cbd->cfg->lua_thread_pool, &cbs);
L = cbs.L;
}
static gboolean
-lua_tcp_arg_toiovec(lua_State *L, gint pos, struct lua_tcp_cbdata *cbd,
+lua_tcp_arg_toiovec(lua_State *L, int pos, struct lua_tcp_cbdata *cbd,
struct iovec *vec)
{
struct rspamd_lua_text *t;
gsize len;
- const gchar *str;
+ const char *str;
struct lua_tcp_dtor *dtor;
if (lua_type(L, pos) == LUA_TUSERDATA) {
* - `upstream`: optional upstream object that would be used to get an address
* @return {boolean} true if request has been sent
*/
-static gint
+static int
lua_tcp_request(lua_State *L)
{
LUA_TRACE_POINT;
- const gchar *host;
- gchar *stop_pattern = NULL;
- guint port;
- gint cbref, tp, conn_cbref = -1;
+ const char *host;
+ char *stop_pattern = NULL;
+ unsigned int port;
+ int cbref, tp, conn_cbref = -1;
gsize plen = 0;
struct ev_loop *event_loop = NULL;
struct lua_tcp_cbdata *cbd;
struct rspamd_config *cfg = NULL;
struct iovec *iov = NULL;
struct upstream *up = NULL;
- guint niov = 0, total_out;
+ unsigned int niov = 0, total_out;
uint64_t h;
- gdouble timeout = default_tcp_timeout;
+ double timeout = default_tcp_timeout;
gboolean partial = FALSE, do_shutdown = FALSE, do_read = TRUE,
ssl = FALSE, ssl_noverify = FALSE;
lua_pushstring(L, "stop_pattern");
lua_gettable(L, -2);
if (lua_type(L, -1) == LUA_TSTRING) {
- const gchar *p;
+ const char *p;
p = lua_tolstring(L, -1, &plen);
* - `timeout`: floating point value that specifies timeout for IO operations in **seconds**
* @return {boolean} true if request has been sent
*/
-static gint
+static int
lua_tcp_connect_sync(lua_State *L)
{
LUA_TRACE_POINT;
GError *err = NULL;
int64_t port = -1;
- gdouble timeout = default_tcp_timeout;
- const gchar *host = NULL;
- gint ret;
+ double timeout = default_tcp_timeout;
+ const char *host = NULL;
+ int ret;
uint64_t h;
struct rspamd_task *task = NULL;
cbd = g_new0(struct lua_tcp_cbdata, 1);
if (task) {
- static const gchar hexdigests[16] = "0123456789abcdef";
+ static const char hexdigests[16] = "0123456789abcdef";
cfg = task->cfg;
ev_base = task->event_loop;
cbd->event_loop = ev_base;
cbd->flags |= LUA_TCP_FLAG_SYNC;
cbd->fd = -1;
- cbd->port = (guint16) port;
+ cbd->port = (uint16_t) port;
cbd->in = g_byte_array_new();
if (rspamd_parse_inet_address(&cbd->addr,
host, strlen(host), RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
- rspamd_inet_address_set_port(cbd->addr, (guint16) port);
+ rspamd_inet_address_set_port(cbd->addr, (uint16_t) port);
/* Host is numeric IP, no need to resolve */
if (!lua_tcp_make_connection(cbd)) {
lua_pushboolean(L, FALSE);
return lua_thread_yield(cbd->thread, 0);
}
-static gint
+static int
lua_tcp_close(lua_State *L)
{
LUA_TRACE_POINT;
return 0;
}
-static gint
+static int
lua_tcp_add_read(lua_State *L)
{
LUA_TRACE_POINT;
struct lua_tcp_cbdata *cbd = lua_check_tcp(L, 1);
struct lua_tcp_handler *rh;
- gchar *stop_pattern = NULL;
- const gchar *p;
+ char *stop_pattern = NULL;
+ const char *p;
gsize plen = 0;
- gint cbref = -1;
+ int cbref = -1;
if (cbd == NULL) {
return luaL_error(L, "invalid arguments");
return 0;
}
-static gint
+static int
lua_tcp_add_write(lua_State *L)
{
LUA_TRACE_POINT;
struct lua_tcp_cbdata *cbd = lua_check_tcp(L, 1);
struct lua_tcp_handler *wh;
- gint cbref = -1, tp;
+ int cbref = -1, tp;
struct iovec *iov = NULL;
- guint niov = 0, total_out = 0;
+ unsigned int niov = 0, total_out = 0;
if (cbd == NULL) {
return luaL_error(L, "invalid arguments");
return 1;
}
-static gint
+static int
lua_tcp_shift_callback(lua_State *L)
{
LUA_TRACE_POINT;
}
static struct lua_tcp_cbdata *
-lua_check_sync_tcp(lua_State *L, gint pos)
+lua_check_sync_tcp(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_tcp_sync_classname);
luaL_argcheck(L, ud != NULL, pos, "'tcp' expected");
LUA_TRACE_POINT;
struct lua_tcp_cbdata *cbd = lua_check_sync_tcp(L, 1);
struct lua_tcp_handler *wh;
- gint tp;
+ int tp;
struct iovec *iov = NULL;
- guint niov = 0;
+ unsigned int niov = 0;
gsize total_out = 0;
if (cbd == NULL) {
return lua_thread_yield(thread, 0);
}
-static gint
+static int
lua_tcp_sync_eof(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_tcp_sync_shutdown(lua_State *L)
{
LUA_TRACE_POINT;
return 0;
}
-static gint
+static int
lua_tcp_starttls(lua_State *L)
{
LUA_TRACE_POINT;
return 0;
}
-static gint
+static int
lua_tcp_sync_gc(lua_State *L)
{
struct lua_tcp_cbdata *cbd = lua_check_sync_tcp(L, 1);
return 0;
}
-static gint
+static int
lua_load_tcp(lua_State *L)
{
lua_newtable(L);
res->ndims = ndims;
res->size = 1;
- for (guint i = 0; i < ndims; i++) {
+ for (unsigned int i = 0; i < ndims; i++) {
res->size *= dim[i];
res->dim[i] = dim[i];
}
* Creates a new zero filled tensor with the specific number of dimensions
* @return
*/
-static gint
+static int
lua_tensor_new(lua_State *L)
{
- gint ndims = luaL_checkinteger(L, 1);
+ int ndims = luaL_checkinteger(L, 1);
if (ndims > 0 && ndims <= 2) {
- gint *dims = g_alloca(sizeof(gint) * ndims);
+ int *dims = g_alloca(sizeof(int) * ndims);
- for (guint i = 0; i < ndims; i++) {
+ for (unsigned int i = 0; i < ndims; i++) {
dims[i] = lua_tointeger(L, i + 2);
}
* Creates a new zero filled tensor with the specific number of dimensions
* @return
*/
-static gint
+static int
lua_tensor_fromtable(lua_State *L)
{
if (lua_istable(L, 1)) {
if (lua_isnumber(L, -1)) {
lua_pop(L, 1);
/* Input vector */
- gint dims[2];
+ int dims[2];
dims[0] = 1;
dims[1] = rspamd_lua_table_size(L, 1);
struct rspamd_lua_tensor *res = lua_newtensor(L, 2,
dims, false, true);
- for (guint i = 0; i < dims[1]; i++) {
+ for (unsigned int i = 0; i < dims[1]; i++) {
lua_rawgeti(L, 1, i + 1);
res->data[i] = lua_tonumber(L, -1);
lua_pop(L, 1);
lua_pop(L, 1);
/* Calculate the overall size */
- gint nrows = rspamd_lua_table_size(L, 1), ncols = 0;
- gint err;
+ int nrows = rspamd_lua_table_size(L, 1), ncols = 0;
+ int err;
- for (gint i = 0; i < nrows; i++) {
+ for (int i = 0; i < nrows; i++) {
lua_rawgeti(L, 1, i + 1);
if (ncols == 0) {
}
else {
if (ncols != rspamd_lua_table_size(L, -1)) {
- gint t = rspamd_lua_table_size(L, -1);
+ int t = rspamd_lua_table_size(L, -1);
lua_pop(L, 1);
err = luaL_error(L, "invalid params at pos %d: "
lua_pop(L, 1);
}
- gint dims[2];
+ int dims[2];
dims[0] = nrows;
dims[1] = ncols;
struct rspamd_lua_tensor *res = lua_newtensor(L, 2,
dims, false, true);
- for (gint i = 0; i < nrows; i++) {
+ for (int i = 0; i < nrows; i++) {
lua_rawgeti(L, 1, i + 1);
- for (gint j = 0; j < ncols; j++) {
+ for (int j = 0; j < ncols; j++) {
lua_rawgeti(L, -1, j + 1);
res->data[i * ncols + j] = lua_tonumber(L, -1);
* Tensor destructor
* @return
*/
-static gint
+static int
lua_tensor_destroy(lua_State *L)
{
struct rspamd_lua_tensor *t = lua_check_tensor(L, 1);
* Tensor serialisation function
* @return
*/
-static gint
+static int
lua_tensor_save(lua_State *L)
{
struct rspamd_lua_tensor *t = lua_check_tensor(L, 1);
- gint size;
+ int size;
if (t) {
if (t->size > 0) {
size = -(t->size);
}
- gsize sz = sizeof(gint) * 4 + size * sizeof(rspamd_tensor_num_t);
- guchar *data;
+ gsize sz = sizeof(int) * 4 + size * sizeof(rspamd_tensor_num_t);
+ unsigned char *data;
struct rspamd_lua_text *out = lua_new_text(L, NULL, 0, TRUE);
memcpy(data + 4 * sizeof(int), t->data,
size * sizeof(rspamd_tensor_num_t));
- out->start = (const gchar *) data;
+ out->start = (const char *) data;
out->len = sz;
}
else {
return 1;
}
-static gint
+static int
lua_tensor_tostring(lua_State *L)
{
struct rspamd_lua_tensor *t = lua_check_tensor(L, 1);
if (t->ndims == 1) {
/* Print as a vector */
- for (gint i = 0; i < t->dim[0]; i++) {
+ for (int i = 0; i < t->dim[0]; i++) {
rspamd_printf_gstring(out, "%.4f ", t->data[i]);
}
/* Trim last space */
out->len--;
}
else {
- for (gint i = 0; i < t->dim[0]; i++) {
- for (gint j = 0; j < t->dim[1]; j++) {
+ for (int i = 0; i < t->dim[0]; i++) {
+ for (int j = 0; j < t->dim[1]; j++) {
rspamd_printf_gstring(out, "%.4f ",
t->data[i * t->dim[1] + j]);
}
return 1;
}
-static gint
+static int
lua_tensor_index(lua_State *L)
{
struct rspamd_lua_tensor *t = lua_check_tensor(L, 1);
- gint idx;
+ int idx;
if (t) {
if (lua_isnumber(L, 2)) {
}
else {
/* Push row */
- gint dim = t->dim[1];
+ int dim = t->dim[1];
if (idx <= t->dim[0]) {
return 1;
}
-static gint
+static int
lua_tensor_newindex(lua_State *L)
{
struct rspamd_lua_tensor *t = lua_check_tensor(L, 1);
- gint idx;
+ int idx;
if (t) {
if (lua_isnumber(L, 2)) {
* Multiply two tensors (optionally transposed) and return a new tensor
* @return
*/
-static gint
+static int
lua_tensor_mul(lua_State *L)
{
struct rspamd_lua_tensor *t1 = lua_check_tensor(L, 1),
}
if (t1 && t2) {
- gint dims[2], shadow_dims[2];
+ int dims[2], shadow_dims[2];
dims[0] = abs(transA ? t1->dim[1] : t1->dim[0]);
shadow_dims[0] = abs(transB ? t2->dim[1] : t2->dim[0]);
dims[1] = abs(transB ? t2->dim[0] : t2->dim[1]);
* Deserialize tensor
* @return
*/
-static gint
+static int
lua_tensor_load(lua_State *L)
{
- const guchar *data;
+ const unsigned char *data;
gsize sz;
if (lua_type(L, 1) == LUA_TUSERDATA) {
return luaL_error(L, "invalid argument");
}
- data = (const guchar *) t->start;
+ data = (const unsigned char *) t->start;
sz = t->len;
}
else {
- data = (const guchar *) lua_tolstring(L, 1, &sz);
+ data = (const unsigned char *) lua_tolstring(L, 1, &sz);
}
- if (sz >= sizeof(gint) * 4) {
+ if (sz >= sizeof(int) * 4) {
int ndims, nelts, dims[2];
memcpy(&ndims, data, sizeof(int));
return 1;
}
-static gint
+static int
lua_tensor_len(lua_State *L)
{
struct rspamd_lua_tensor *t = lua_check_tensor(L, 1);
- gint nret = 1;
+ int nret = 1;
if (t) {
/* Return the main dimension first */
return nret;
}
-static gint
+static int
lua_tensor_eigen(lua_State *L)
{
struct rspamd_lua_tensor *t = lua_check_tensor(L, 1), *eigen;
return sum / (rspamd_tensor_num_t) n;
}
-static gint
+static int
lua_tensor_mean(lua_State *L)
{
struct rspamd_lua_tensor *t = lua_check_tensor(L, 1);
return 1;
}
-static gint
+static int
lua_tensor_transpose(lua_State *L)
{
struct rspamd_lua_tensor *t = lua_check_tensor(L, 1), *res;
return 1;
}
-static gint
+static int
lua_tensor_has_blas(lua_State *L)
{
#ifdef HAVE_CBLAS
return 1;
}
-static gint
+static int
lua_tensor_scatter_matrix(lua_State *L)
{
struct rspamd_lua_tensor *t = lua_check_tensor(L, 1), *res;
return 1;
}
-static gint
+static int
lua_load_tensor(lua_State *L)
{
lua_newtable(L);
{NULL, NULL}};
struct rspamd_lua_text *
-lua_check_text(lua_State *L, gint pos)
+lua_check_text(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_text_classname);
luaL_argcheck(L, ud != NULL, pos, "'text' expected");
}
struct rspamd_lua_text *
-lua_check_text_or_string(lua_State *L, gint pos)
+lua_check_text_or_string(lua_State *L, int pos)
{
- gint pos_type = lua_type(L, pos);
+ int pos_type = lua_type(L, pos);
if (pos_type == LUA_TUSERDATA) {
void *ud = rspamd_lua_check_udata(L, pos, rspamd_text_classname);
}
struct rspamd_lua_text *
-lua_new_text(lua_State *L, const gchar *start, gsize len, gboolean own)
+lua_new_text(lua_State *L, const char *start, gsize len, gboolean own)
{
struct rspamd_lua_text *t;
t->flags = 0;
if (own) {
- gchar *storage;
+ char *storage;
if (len > 0) {
storage = g_malloc(len);
struct rspamd_lua_text *
lua_new_text_task(lua_State *L, struct rspamd_task *task,
- const gchar *start, gsize len, gboolean own)
+ const char *start, gsize len, gboolean own)
{
struct rspamd_lua_text *t;
t->flags = 0;
if (own) {
- gchar *storage;
+ char *storage;
if (len > 0) {
storage = rspamd_mempool_alloc(task->task_pool, len);
}
-static gint
+static int
lua_text_fromstring(lua_State *L)
{
LUA_TRACE_POINT;
- const gchar *str;
+ const char *str;
gsize l = 0;
gboolean transparent = FALSE;
return 1;
}
-static gint
+static int
lua_text_null(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_text_randombytes(lua_State *L)
{
LUA_TRACE_POINT;
- guint nbytes = luaL_checkinteger(L, 1);
+ unsigned int nbytes = luaL_checkinteger(L, 1);
struct rspamd_lua_text *out;
out = lua_new_text(L, NULL, nbytes, TRUE);
#define MAX_REC 10
static void
-lua_text_tbl_length(lua_State *L, gsize dlen, gsize *dest, guint rec)
+lua_text_tbl_length(lua_State *L, gsize dlen, gsize *dest, unsigned int rec)
{
gsize tblen, stlen;
struct rspamd_lua_text *elt;
static void
lua_text_tbl_append(lua_State *L,
- const gchar *delim,
+ const char *delim,
gsize dlen,
- gchar **dest,
- guint rec)
+ char **dest,
+ unsigned int rec)
{
- const gchar *st;
+ const char *st;
gsize tblen, stlen;
struct rspamd_lua_text *elt;
tblen = rspamd_lua_table_size(L, -1);
- for (guint i = 0; i < tblen; i++) {
+ for (unsigned int i = 0; i < tblen; i++) {
lua_rawgeti(L, -1, i + 1);
if (lua_type(L, -1) == LUA_TSTRING) {
}
}
-static gint
+static int
lua_text_fromtable(lua_State *L)
{
LUA_TRACE_POINT;
- const gchar *delim = "";
+ const char *delim = "";
struct rspamd_lua_text *t;
gsize textlen = 0, dlen, oldtop = lua_gettop(L);
- gchar *dest;
+ char *dest;
if (!lua_istable(L, 1)) {
return luaL_error(L, "invalid arguments");
lua_text_tbl_append(L, delim, dlen, &dest, 0);
lua_pop(L, 1); /* Table arg */
- gint newtop = lua_gettop(L);
+ int newtop = lua_gettop(L);
g_assert(newtop == oldtop + 1);
return 1;
}
-static gint
+static int
lua_text_len(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_text_str(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_text_ptr(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_text_take_ownership(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_text *t = lua_check_text(L, 1);
- gchar *dest;
+ char *dest;
if (t != NULL) {
if (t->flags & RSPAMD_TEXT_FLAG_OWN) {
return 1;
}
-static gint
+static int
lua_text_span(lua_State *L)
{
LUA_TRACE_POINT;
/* Helpers to behave exactly as Lua does */
static inline gsize
-relative_pos_start(gint pos, gsize len)
+relative_pos_start(int pos, gsize len)
{
if (pos > 0) {
return pos;
else if (pos == 0) {
return 1;
}
- else if (pos < -((gint) len)) {
+ else if (pos < -((int) len)) {
return 1;
}
}
static inline gsize
-relative_pos_end(gint pos, gsize len)
+relative_pos_end(int pos, gsize len)
{
- if (pos > (gint) len) {
+ if (pos > (int) len) {
return len;
}
else if (pos >= 0) {
return (size_t) pos;
}
- else if (pos < -((gint) len)) {
+ else if (pos < -((int) len)) {
return 0;
}
return len + ((gsize) pos) + 1;
}
-static gint
+static int
lua_text_sub(lua_State *L)
{
LUA_TRACE_POINT;
rspamd_lua_text_push_line(lua_State *L,
struct rspamd_lua_text *t,
int64_t start_offset,
- const gchar *sep_pos,
+ const char *sep_pos,
gboolean stringify)
{
- const gchar *start;
+ const char *start;
gsize len;
int64_t ret;
return ret;
}
-static gint
+static int
rspamd_lua_text_readline(lua_State *L)
{
struct rspamd_lua_text *t = lua_touserdata(L, lua_upvalueindex(1));
int64_t pos = lua_tointeger(L, lua_upvalueindex(3));
if (pos < 0) {
- return luaL_error(L, "invalid pos: %d", (gint) pos);
+ return luaL_error(L, "invalid pos: %d", (int) pos);
}
if (pos >= t->len) {
return 0;
}
- const gchar *sep_pos;
+ const char *sep_pos;
/* We look just for `\n` ignoring `\r` as it is very rare nowadays */
sep_pos = memchr(t->start + pos, '\n', t->len - pos);
return 1;
}
-static gint
+static int
lua_text_lines(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
rspamd_lua_text_regexp_split(lua_State *L)
{
struct rspamd_lua_text *t = lua_touserdata(L, lua_upvalueindex(1)),
gboolean matched;
if (pos < 0) {
- return luaL_error(L, "invalid pos: %d", (gint) pos);
+ return luaL_error(L, "invalid pos: %d", (int) pos);
}
if (pos >= t->len) {
return 0;
}
- const gchar *start, *end, *old_start;
+ const char *start, *end, *old_start;
end = t->start + pos;
return 1;
}
-static gint
+static int
lua_text_split(lua_State *L)
{
LUA_TRACE_POINT;
c_re = rspamd_regexp_new(lua_tostring(L, 2), NULL, &err);
if (c_re == NULL) {
- gint ret = luaL_error(L, "cannot parse regexp: %s, error: %s",
- lua_tostring(L, 2),
- err == NULL ? "undefined" : err->message);
+ int ret = luaL_error(L, "cannot parse regexp: %s, error: %s",
+ lua_tostring(L, 2),
+ err == NULL ? "undefined" : err->message);
if (err) {
g_error_free(err);
}
}
-static gint
+static int
lua_text_at(lua_State *L)
{
return lua_text_byte(L);
}
-static gint
+static int
lua_text_byte(lua_State *L)
{
LUA_TRACE_POINT;
return end - start;
}
-static gint
+static int
lua_text_memchr(lua_State *L)
{
LUA_TRACE_POINT;
}
else {
gsize l;
- const gchar *str = lua_tolstring(L, 2, &l);
+ const char *str = lua_tolstring(L, 2, &l);
if (str) {
c = str[0];
return 1;
}
-static gint
+static int
lua_text_bytes(lua_State *L)
{
LUA_TRACE_POINT;
lua_createtable(L, t->len, 0);
for (gsize i = 0; i < t->len; i++) {
- lua_pushinteger(L, (guchar) t->start[i]);
+ lua_pushinteger(L, (unsigned char) t->start[i]);
lua_rawseti(L, -2, i + 1);
}
}
return 1;
}
-static gint
+static int
lua_text_save_in_file(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_text *t = lua_check_text(L, 1);
- const gchar *fname = NULL;
- guint mode = 00644;
- gint fd = -1;
+ const char *fname = NULL;
+ unsigned int mode = 00644;
+ int fd = -1;
gboolean need_close = FALSE;
if (t != NULL) {
return 1;
}
-static gint
+static int
lua_text_gc(lua_State *L)
{
LUA_TRACE_POINT;
if (t->flags & RSPAMD_TEXT_FLAG_OWN) {
if (t->flags & RSPAMD_TEXT_FLAG_WIPE) {
- rspamd_explicit_memzero((guchar *) t->start, t->len);
+ rspamd_explicit_memzero((unsigned char *) t->start, t->len);
}
if (t->flags & RSPAMD_TEXT_FLAG_MMAPED) {
return 0;
}
-static gint
+static int
lua_text_eq(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_text_lt(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_text_concat(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_text_wipe(lua_State *L)
{
LUA_TRACE_POINT;
if (t != NULL) {
if (t->flags & RSPAMD_TEXT_FLAG_OWN) {
- rspamd_explicit_memzero((guchar *) t->start, t->len);
+ rspamd_explicit_memzero((unsigned char *) t->start, t->len);
}
else {
return luaL_error(L, "cannot wipe not owned text");
return 0;
}
-static gint
+static int
lua_text_base32(lua_State *L)
{
LUA_TRACE_POINT;
}
out = lua_new_text(L, NULL, t->len * 8 / 5 + 2, TRUE);
- out->len = rspamd_encode_base32_buf(t->start, t->len, (gchar *) out->start,
+ out->len = rspamd_encode_base32_buf(t->start, t->len, (char *) out->start,
out->len, btype);
}
else {
return 1;
}
-static gint
+static int
lua_text_base64(lua_State *L)
{
LUA_TRACE_POINT;
enum rspamd_newlines_type how = RSPAMD_TASK_NEWLINES_CRLF;
if (lua_type(L, 3) == LUA_TSTRING) {
- const gchar *how_str = lua_tostring(L, 3);
+ const char *how_str = lua_tostring(L, 3);
if (g_ascii_strcasecmp(how_str, "cr") == 0) {
how = RSPAMD_TASK_NEWLINES_CR;
return 1;
}
-static gint
+static int
lua_text_hex(lua_State *L)
{
LUA_TRACE_POINT;
if (t != NULL) {
out = lua_new_text(L, NULL, t->len * 2, TRUE);
- out->len = rspamd_encode_hex_buf(t->start, t->len, (gchar *) out->start,
+ out->len = rspamd_encode_hex_buf(t->start, t->len, (char *) out->start,
out->len);
}
else {
return 1;
}
-static gint
+static int
lua_text_find(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_text *t = lua_check_text(L, 1);
gsize patlen, init = 1;
- const gchar *pat = luaL_checklstring(L, 2, &patlen);
+ const char *pat = luaL_checklstring(L, 2, &patlen);
if (t != NULL && pat != NULL) {
#define BITOP(a, b, op) \
((a)[(uint64_t) (b) / (8u * sizeof *(a))] op(uint64_t) 1 << ((uint64_t) (b) % (8u * sizeof *(a))))
-static gint
+static int
lua_text_exclude_chars(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_text *t = lua_check_text(L, 1);
gssize patlen;
- const gchar *pat = lua_tolstring(L, 2, &patlen), *p, *end;
- gchar *dest, *d;
+ const char *pat = lua_tolstring(L, 2, &patlen), *p, *end;
+ char *dest, *d;
uint64_t byteset[32 / sizeof(uint64_t)]; /* Bitset for ascii */
gboolean copy = TRUE;
- guint *plen;
+ unsigned int *plen;
if (t != NULL && pat && patlen > 0) {
if (lua_isboolean(L, 3)) {
}
if (!copy) {
- dest = (gchar *) t->start;
+ dest = (char *) t->start;
plen = &t->len;
lua_pushvalue(L, 1); /* Push text as a result */
}
*/
switch (*pat) {
case '%':
- BITOP(byteset, *(guchar *) pat, |=);
+ BITOP(byteset, *(unsigned char *) pat, |=);
break;
case 's':
/* "\r\n\t\f " */
}
else {
/* Last '%' */
- BITOP(byteset, (guchar) '%', |=);
+ BITOP(byteset, (unsigned char) '%', |=);
}
}
else {
- BITOP(byteset, *(guchar *) pat, |=);
+ BITOP(byteset, *(unsigned char *) pat, |=);
}
pat++;
patlen--;
}
- for (; patlen > 0 && BITOP(byteset, *(guchar *) pat, |=); pat++, patlen--)
+ for (; patlen > 0 && BITOP(byteset, *(unsigned char *) pat, |=); pat++, patlen--)
;
p = t->start;
d = dest;
while (p < end) {
- if (!BITOP(byteset, *(guchar *) p, &)) {
+ if (!BITOP(byteset, *(unsigned char *) p, &)) {
*d++ = *p;
}
return 1;
}
-static gint
+static int
lua_text_oneline(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_text *t = lua_check_text(L, 1);
- const gchar *p, *end;
- gchar *dest, *d;
+ const char *p, *end;
+ char *dest, *d;
uint64_t byteset[32 / sizeof(uint64_t)]; /* Bitset for ascii */
gboolean copy = TRUE, seen_8bit = FALSE;
- guint *plen;
+ unsigned int *plen;
if (t != NULL) {
if (lua_isboolean(L, 2)) {
}
if (!copy) {
- dest = (gchar *) t->start;
+ dest = (char *) t->start;
plen = &t->len;
lua_pushvalue(L, 1); /* Push text as a result */
}
d = dest;
while (p < end) {
- if (!BITOP(byteset, *(guchar *) p, &)) {
+ if (!BITOP(byteset, *(unsigned char *) p, &)) {
*d++ = *p;
}
else {
- if ((*(guchar *) p) & 0x80) {
+ if ((*(unsigned char *) p) & 0x80) {
seen_8bit = TRUE;
*d++ = *p;
}
UChar32 uc;
goffset err_offset;
gsize remain = d - dest;
- gchar *nd = dest;
+ char *nd = dest;
while (remain > 0 && (err_offset = rspamd_fast_utf8_validate(nd, remain)) > 0) {
- gint i = 0;
+ int i = 0;
err_offset--; /* As it returns it 1 indexed */
nd += err_offset;
/* Each invalid character of input requires 3 bytes of output (+2 bytes) */
while (i < remain) {
- gint old_pos = i;
+ int old_pos = i;
U8_NEXT(nd, i, remain, uc);
if (uc < 0) {
return 1;
}
-static gint
+static int
lua_text_lower(lua_State *L)
{
LUA_TRACE_POINT;
}
if (!is_utf8) {
- rspamd_str_lc((gchar *) nt->start, nt->len);
+ rspamd_str_lc((char *) nt->start, nt->len);
}
else {
- rspamd_str_lc_utf8((gchar *) nt->start, nt->len);
+ rspamd_str_lc_utf8((char *) nt->start, nt->len);
}
}
else {
return 1;
}
-static gint
+static int
lua_text_strtoul(lua_State *L)
{
LUA_TRACE_POINT;
}
/* Used to distinguish lua text metatable */
-static const guint rspamd_lua_text_cookie = 0x2b21ef6fU;
+static const unsigned int rspamd_lua_text_cookie = 0x2b21ef6fU;
-static gint
+static int
lua_load_text(lua_State *L)
{
lua_newtable(L);
struct lua_thread_pool {
std::vector<struct thread_entry *> available_items;
lua_State *L;
- gint max_items;
+ int max_items;
struct thread_entry *running_entry;
static const int default_max_items = 100;
- lua_thread_pool(lua_State *L, gint max_items = default_max_items)
+ lua_thread_pool(lua_State *L, int max_items = default_max_items)
: L(L), max_items(max_items)
{
running_entry = nullptr;
return ent;
}
- auto return_thread(struct thread_entry *thread_entry, const gchar *loc) -> void
+ auto return_thread(struct thread_entry *thread_entry, const char *loc) -> void
{
/* we can't return a running/yielded thread into the pool */
g_assert(lua_status(thread_entry->lua_state) == 0);
}
auto terminate_thread(struct thread_entry *thread_entry,
- const gchar *loc,
+ const char *loc,
bool enforce) -> void
{
struct thread_entry *ent = NULL;
}
void lua_thread_pool_return_full(struct lua_thread_pool *pool,
- struct thread_entry *thread_entry, const gchar *loc)
+ struct thread_entry *thread_entry, const char *loc)
{
pool->return_thread(thread_entry, loc);
}
void lua_thread_pool_terminate_entry_full(struct lua_thread_pool *pool,
- struct thread_entry *thread_entry, const gchar *loc,
+ struct thread_entry *thread_entry, const char *loc,
bool enforce)
{
pool->terminate_thread(thread_entry, loc, enforce);
struct thread_entry *
lua_thread_pool_get_running_entry_full(struct lua_thread_pool *pool,
- const gchar *loc)
+ const char *loc)
{
msg_debug_lua_threads("%s: lua_thread_pool_get_running_entry_full", loc);
return pool->get_running_entry();
void lua_thread_pool_set_running_entry_full(struct lua_thread_pool *pool,
struct thread_entry *thread_entry,
- const gchar *loc)
+ const char *loc)
{
msg_debug_lua_threads("%s: lua_thread_pool_set_running_entry_full", loc);
pool->set_running_entry(thread_entry);
static void
lua_thread_pool_set_running_entry_for_thread(struct thread_entry *thread_entry,
- const gchar *loc)
+ const char *loc)
{
struct lua_thread_pool *pool;
void lua_thread_pool_prepare_callback_full(struct lua_thread_pool *pool,
struct lua_callback_state *cbs,
- const gchar *loc)
+ const char *loc)
{
msg_debug_lua_threads("%s: lua_thread_pool_prepare_callback_full", loc);
cbs->thread_pool = pool;
}
void lua_thread_pool_restore_callback_full(struct lua_callback_state *cbs,
- const gchar *loc)
+ const char *loc)
{
lua_thread_pool_return_full(cbs->thread_pool, cbs->my_thread, loc);
lua_thread_pool_set_running_entry_full(cbs->thread_pool,
cbs->previous_thread, loc);
}
-static gint
-lua_do_resume_full(lua_State *L, gint narg, const gchar *loc)
+static int
+lua_do_resume_full(lua_State *L, int narg, const char *loc)
{
#if LUA_VERSION_NUM >= 504
int nres;
static void
lua_resume_thread_internal_full(struct thread_entry *thread_entry,
- gint narg, const gchar *loc)
+ int narg, const char *loc)
{
- gint ret;
+ int ret;
struct lua_thread_pool *pool;
struct rspamd_task *task;
}
}
-void lua_thread_resume_full(struct thread_entry *thread_entry, gint narg,
- const gchar *loc)
+void lua_thread_resume_full(struct thread_entry *thread_entry, int narg,
+ const char *loc)
{
/*
* The only state where we can resume from is LUA_YIELD
}
void lua_thread_call_full(struct thread_entry *thread_entry,
- int narg, const gchar *loc)
+ int narg, const char *loc)
{
g_assert(lua_status(thread_entry->lua_state) == 0); /* we can't call running/yielded thread */
g_assert(thread_entry->task != NULL || thread_entry->cfg != NULL); /* we can't call without pool */
lua_resume_thread_internal_full(thread_entry, narg, loc);
}
-gint lua_thread_yield_full(struct thread_entry *thread_entry,
- gint nresults,
- const gchar *loc)
+int lua_thread_yield_full(struct thread_entry *thread_entry,
+ int nresults,
+ const char *loc)
{
g_assert(lua_status(thread_entry->lua_state) == 0);
struct thread_entry {
lua_State *lua_state;
- gint thread_index;
+ int thread_index;
gpointer cd;
/* function to handle result of called method, can be NULL */
*/
void lua_thread_pool_return_full(struct lua_thread_pool *pool,
struct thread_entry *thread_entry,
- const gchar *loc);
+ const char *loc);
#define lua_thread_pool_return(pool, thread_entry) \
lua_thread_pool_return_full(pool, thread_entry, G_STRLOC)
*/
struct thread_entry *
lua_thread_pool_get_running_entry_full(struct lua_thread_pool *pool,
- const gchar *loc);
+ const char *loc);
#define lua_thread_pool_get_running_entry(pool) \
lua_thread_pool_get_running_entry_full(pool, G_STRLOC)
*/
void lua_thread_pool_set_running_entry_full(struct lua_thread_pool *pool,
struct thread_entry *thread_entry,
- const gchar *loc);
+ const char *loc);
#define lua_thread_pool_set_running_entry(pool, thread_entry) \
lua_thread_pool_set_running_entry_full(pool, thread_entry, G_STRLOC)
* @param cbs
*/
void lua_thread_pool_prepare_callback_full(struct lua_thread_pool *pool,
- struct lua_callback_state *cbs, const gchar *loc);
+ struct lua_callback_state *cbs, const char *loc);
#define lua_thread_pool_prepare_callback(pool, cbs) \
lua_thread_pool_prepare_callback_full(pool, cbs, G_STRLOC)
* @param cbs
*/
void lua_thread_pool_restore_callback_full(struct lua_callback_state *cbs,
- const gchar *loc);
+ const char *loc);
#define lua_thread_pool_restore_callback(cbs) \
lua_thread_pool_restore_callback_full(cbs, G_STRLOC)
*/
void lua_thread_call_full(struct thread_entry *thread_entry,
int narg,
- const gchar *loc);
+ const char *loc);
#define lua_thread_call(thread_entry, narg) \
lua_thread_call_full(thread_entry, narg, G_STRLOC)
* @return
*/
int lua_thread_yield_full(struct thread_entry *thread_entry, int nresults,
- const gchar *loc);
+ const char *loc);
#define lua_thread_yield(thread_entry, narg) \
lua_thread_yield_full(thread_entry, narg, G_STRLOC)
*/
void lua_thread_resume_full(struct thread_entry *thread_entry,
int narg,
- const gchar *loc);
+ const char *loc);
#define lua_thread_resume(thread_entry, narg) \
lua_thread_resume_full(thread_entry, narg, G_STRLOC)
*/
void lua_thread_pool_terminate_entry_full(struct lua_thread_pool *pool,
struct thread_entry *thread_entry,
- const gchar *loc, bool enforce);
+ const char *loc, bool enforce);
#define lua_thread_pool_terminate_entry(pool, thread_entry) \
lua_thread_pool_terminate_entry_full(pool, thread_entry, G_STRLOC, false)
{NULL, NULL}};
static struct rspamd_multipattern *
-lua_check_trie(lua_State *L, gint idx)
+lua_check_trie(lua_State *L, int idx)
{
void *ud = rspamd_lua_check_udata(L, 1, rspamd_trie_classname);
return ud ? *((struct rspamd_multipattern **) ud) : NULL;
}
-static gint
+static int
lua_trie_destroy(lua_State *L)
{
struct rspamd_multipattern *trie = lua_check_trie(L, 1);
*
* @return {bool} true if hyperscan is supported
*/
-static gint
+static int
lua_trie_has_hyperscan(lua_State *L)
{
lua_pushboolean(L, rspamd_multipattern_has_hyperscan());
* @param {table} array of string patterns
* @return {trie} new trie object
*/
-static gint
+static int
lua_trie_create(lua_State *L)
{
struct rspamd_multipattern *trie, **ptrie;
- gint npat = 0, flags = RSPAMD_MULTIPATTERN_ICASE | RSPAMD_MULTIPATTERN_GLOB;
+ int npat = 0, flags = RSPAMD_MULTIPATTERN_ICASE | RSPAMD_MULTIPATTERN_GLOB;
GError *err = NULL;
if (lua_isnumber(L, 2)) {
while (lua_next(L, -2) != 0) {
if (lua_isstring(L, -1)) {
- const gchar *pat;
+ const char *pat;
gsize patlen;
pat = lua_tolstring(L, -1, &patlen);
} while (0)
/* Normal callback type */
-static gint
+static int
lua_trie_lua_cb_callback(struct rspamd_multipattern *mp,
- guint strnum,
- gint match_start,
- gint textpos,
- const gchar *text,
+ unsigned int strnum,
+ int match_start,
+ int textpos,
+ const char *text,
gsize len,
void *context)
{
lua_State *L = context;
- gint ret;
+ int ret;
gboolean report_start = lua_toboolean(L, -1);
}
/* Table like callback, expect result table on top of the stack */
-static gint
+static int
lua_trie_table_callback(struct rspamd_multipattern *mp,
- guint strnum,
- gint match_start,
- gint textpos,
- const gchar *text,
+ unsigned int strnum,
+ int match_start,
+ int textpos,
+ const char *text,
gsize len,
void *context)
{
lua_State *L = context;
- gint report_start = lua_toboolean(L, -2);
+ int report_start = lua_toboolean(L, -2);
/* Set table, indexed by pattern number */
lua_rawgeti(L, -1, strnum + 1);
/*
* We assume that callback argument is at pos 3 and icase is in position 4
*/
-static gint
+static int
lua_trie_search_str(lua_State *L, struct rspamd_multipattern *trie,
- const gchar *str, gsize len, rspamd_multipattern_cb_t cb)
+ const char *str, gsize len, rspamd_multipattern_cb_t cb)
{
- gint ret;
- guint nfound = 0;
+ int ret;
+ unsigned int nfound = 0;
if ((ret = rspamd_multipattern_lookup(trie, str, len,
cb, L, &nfound)) == 0) {
* @param {boolean} report_start report both start and end offset when matching patterns
* @return {boolean} `true` if any pattern has been found (`cb` might be called multiple times however). If `cb` is not defined then it returns a table of match positions indexed by pattern number
*/
-static gint
+static int
lua_trie_match(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_multipattern *trie = lua_check_trie(L, 1);
- const gchar *text;
+ const char *text;
gsize len;
gboolean found = FALSE, report_start = FALSE;
struct rspamd_lua_text *t;
rspamd_multipattern_cb_t cb = lua_trie_lua_cb_callback;
- gint old_top = lua_gettop(L);
+ int old_top = lua_gettop(L);
if (trie) {
if (lua_type(L, 3) != LUA_TFUNCTION) {
* @param {boolean} caseless if `true` then match ignores symbols case (ASCII only)
* @return {boolean} `true` if any pattern has been found (`cb` might be called multiple times however)
*/
-static gint
+static int
lua_trie_search_mime(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_multipattern *trie = lua_check_trie(L, 1);
struct rspamd_task *task = lua_check_task(L, 2);
struct rspamd_mime_text_part *part;
- const gchar *text;
+ const char *text;
gsize len, i;
gboolean found = FALSE;
rspamd_multipattern_cb_t cb = lua_trie_lua_cb_callback;
* @param {boolean} caseless if `true` then match ignores symbols case (ASCII only)
* @return {boolean} `true` if any pattern has been found (`cb` might be called multiple times however)
*/
-static gint
+static int
lua_trie_search_rawmsg(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_multipattern *trie = lua_check_trie(L, 1);
struct rspamd_task *task = lua_check_task(L, 2);
- const gchar *text;
+ const char *text;
gsize len;
gboolean found = FALSE;
* @param {boolean} caseless if `true` then match ignores symbols case (ASCII only)
* @return {boolean} `true` if any pattern has been found (`cb` might be called multiple times however)
*/
-static gint
+static int
lua_trie_search_rawbody(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_multipattern *trie = lua_check_trie(L, 1);
struct rspamd_task *task = lua_check_task(L, 2);
- const gchar *text;
+ const char *text;
gsize len;
gboolean found = FALSE;
return 1;
}
-static gint
+static int
lua_load_trie(lua_State *L)
{
lua_newtable(L);
#include <math.h>
#include <src/libutil/libev_helper.h>
-static const gchar *M = "rspamd lua udp";
+static const char *M = "rspamd lua udp";
/***
* @module rspamd_udp
struct rspamd_async_session *s;
struct iovec *iov;
lua_State *L;
- guint retransmits;
- guint iovlen;
- gint sock;
- gint cbref;
+ unsigned int retransmits;
+ unsigned int iovlen;
+ int sock;
+ int cbref;
gboolean sent;
};
static inline void
lua_fill_iov(lua_State *L, rspamd_mempool_t *pool,
- struct iovec *iov, gint pos)
+ struct iovec *iov, int pos)
{
if (lua_type(L, pos) == LUA_TUSERDATA) {
struct rspamd_lua_text *t = lua_check_text(L, pos);
}
}
else {
- const gchar *s;
+ const char *s;
gsize len;
s = lua_tolstring(L, pos, &len);
lua_try_send_request(struct lua_udp_cbdata *cbd)
{
struct msghdr msg;
- gint r;
+ int r;
memset(&msg, 0, sizeof(msg));
msg.msg_iov = cbd->iov;
}
static void
-lua_udp_maybe_push_error(struct lua_udp_cbdata *cbd, const gchar *err)
+lua_udp_maybe_push_error(struct lua_udp_cbdata *cbd, const char *err)
{
if (cbd->cbref != -1) {
- gint top;
+ int top;
lua_State *L = cbd->L;
top = lua_gettop(L);
}
static void
-lua_udp_push_data(struct lua_udp_cbdata *cbd, const gchar *data,
+lua_udp_push_data(struct lua_udp_cbdata *cbd, const char *data,
gssize len)
{
if (cbd->cbref != -1) {
- gint top;
+ int top;
lua_State *L = cbd->L;
top = lua_gettop(L);
}
static void
-lua_udp_io_handler(gint fd, short what, gpointer p)
+lua_udp_io_handler(int fd, short what, gpointer p)
{
struct lua_udp_cbdata *cbd = (struct lua_udp_cbdata *) p;
gssize r;
}
}
else if (what == EV_READ) {
- guchar udpbuf[4096];
+ unsigned char udpbuf[4096];
socklen_t slen;
struct sockaddr *sa;
* - `callback`: optional callback if reply should be read
* @return {boolean} true if request has been sent (additional string if it has not)
*/
-static gint
+static int
lua_udp_sendto(lua_State *L)
{
LUA_TRACE_POINT;
- const gchar *host;
- guint port;
+ const char *host;
+ unsigned int port;
struct ev_loop *ev_base = NULL;
struct lua_udp_cbdata *cbd;
struct rspamd_async_session *session = NULL;
struct rspamd_task *task = NULL;
rspamd_inet_addr_t *addr;
rspamd_mempool_t *pool = NULL;
- gdouble timeout = default_udp_timeout;
+ double timeout = default_udp_timeout;
if (lua_type(L, 1) == LUA_TTABLE) {
lua_pushstring(L, "port");
return 1;
}
-static gint
+static int
lua_load_udp(lua_State *L)
{
lua_newtable(L);
* Get ip of upstream
* @return {ip} ip address object
*/
-static gint
+static int
lua_upstream_get_addr(lua_State *L)
{
LUA_TRACE_POINT;
* Get name of upstream
* @return {string} name of the upstream
*/
-static gint
+static int
lua_upstream_get_name(lua_State *L)
{
LUA_TRACE_POINT;
* Get port of upstream
* @return {int} port of the upstream
*/
-static gint
+static int
lua_upstream_get_port(lua_State *L)
{
LUA_TRACE_POINT;
* @method upstream:fail()
* Indicate upstream failure. After certain amount of failures during specified time frame, an upstream is marked as down and does not participate in rotations.
*/
-static gint
+static int
lua_upstream_fail(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_upstream *up = lua_check_upstream(L, 1);
gboolean fail_addr = FALSE;
- const gchar *reason = "unknown";
+ const char *reason = "unknown";
if (up) {
* @method upstream:ok()
* Indicates upstream success. Resets errors count for an upstream.
*/
-static gint
+static int
lua_upstream_ok(lua_State *L)
{
LUA_TRACE_POINT;
return 0;
}
-static gint
+static int
lua_upstream_destroy(lua_State *L)
{
LUA_TRACE_POINT;
}
static struct rspamd_lua_upstream *
-lua_push_upstream(lua_State *L, gint up_idx, struct upstream *up)
+lua_push_upstream(lua_State *L, int up_idx, struct upstream *up)
{
struct rspamd_lua_upstream *lua_ups;
* @param {number} default_port default port for upstreams
* @return {upstream_list} upstream list structure
*/
-static gint
+static int
lua_upstream_list_create(lua_State *L)
{
LUA_TRACE_POINT;
struct upstream_list *new = NULL, **pnew;
struct rspamd_config *cfg = NULL;
- const gchar *def;
- guint default_port = 0;
- gint top;
+ const char *def;
+ unsigned int default_port = 0;
+ int top;
if (lua_type(L, 1) == LUA_TUSERDATA) {
* @param L
* @return
*/
-static gint
+static int
lua_upstream_list_destroy(lua_State *L)
{
LUA_TRACE_POINT;
* @param {string} key a string used as input for stable hash algorithm
* @return {upstream} upstream from a list corresponding to the given key
*/
-static gint
+static int
lua_upstream_list_get_upstream_by_hash(lua_State *L)
{
LUA_TRACE_POINT;
struct upstream_list *upl;
struct upstream *selected;
- const gchar *key;
+ const char *key;
gsize keyl;
upl = lua_check_upstream_list(L);
key = luaL_checklstring(L, 2, &keyl);
if (key) {
selected = rspamd_upstream_get(upl, RSPAMD_UPSTREAM_HASHED, key,
- (guint) keyl);
+ (unsigned int) keyl);
if (selected) {
lua_push_upstream(L, 1, selected);
* Get upstream round robin (by current weight)
* @return {upstream} upstream from a list in round-robin matter
*/
-static gint
+static int
lua_upstream_list_get_upstream_round_robin(lua_State *L)
{
LUA_TRACE_POINT;
* Get upstream master slave order (by static priority)
* @return {upstream} upstream from a list in master-slave order
*/
-static gint
+static int
lua_upstream_list_get_upstream_master_slave(lua_State *L)
{
LUA_TRACE_POINT;
struct upstream_foreach_cbdata {
lua_State *L;
- gint ups_pos;
+ int ups_pos;
};
-static void lua_upstream_inserter(struct upstream *up, guint idx, void *ud)
+static void lua_upstream_inserter(struct upstream *up, unsigned int idx, void *ud)
{
struct upstream_foreach_cbdata *cbd = (struct upstream_foreach_cbdata *) ud;
* Returns all upstreams for this list
* @return {table|upstream} all upstreams defined
*/
-static gint
+static int
lua_upstream_list_all_upstreams(lua_State *L)
{
LUA_TRACE_POINT;
}
static inline enum rspamd_upstreams_watch_event
-lua_str_to_upstream_flag(const gchar *str)
+lua_str_to_upstream_flag(const char *str)
{
enum rspamd_upstreams_watch_event fl = 0;
return fl;
}
-static inline const gchar *
+static inline const char *
lua_upstream_flag_to_str(enum rspamd_upstreams_watch_event fl)
{
- const gchar *res = "unknown";
+ const char *res = "unknown";
/* Works with single flags, not combinations */
if (fl & RSPAMD_UPSTREAM_WATCH_SUCCESS) {
struct rspamd_lua_upstream_watcher_cbdata {
lua_State *L;
- gint cbref;
- gint parent_cbref; /* Reference to the upstream list */
+ int cbref;
+ int parent_cbref; /* Reference to the upstream list */
struct upstream_list *upl;
};
static void
lua_upstream_watch_func(struct upstream *up,
enum rspamd_upstreams_watch_event event,
- guint cur_errors,
+ unsigned int cur_errors,
void *ud)
{
struct rspamd_lua_upstream_watcher_cbdata *cdata =
(struct rspamd_lua_upstream_watcher_cbdata *) ud;
lua_State *L;
- const gchar *what;
- gint err_idx;
+ const char *what;
+ int err_idx;
L = cdata->L;
what = lua_upstream_flag_to_str(event);
ups:add_watcher({'online', 'offline'}, function(what, up, cur_errors) ... end)
* @return nothing
*/
-static gint
+static int
lua_upstream_list_add_watcher(lua_State *L)
{
LUA_TRACE_POINT;
return 0;
}
-static gint
+static int
lua_load_upstream_list(lua_State *L)
{
lua_newtable(L);
{NULL, NULL}};
struct rspamd_lua_url *
-lua_check_url(lua_State *L, gint pos)
+lua_check_url(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_url_classname);
luaL_argcheck(L, ud != NULL, pos, "'url' expected");
* Get length of the url
* @return {number} length of url in bytes
*/
-static gint
+static int
lua_url_get_length(lua_State *L)
{
LUA_TRACE_POINT;
* Get domain part of the url
* @return {string} domain part of URL
*/
-static gint
+static int
lua_url_get_host(lua_State *L)
{
LUA_TRACE_POINT;
* Get port of the url
* @return {number} url port
*/
-static gint
+static int
lua_url_get_port(lua_State *L)
{
LUA_TRACE_POINT;
* Get user part of the url (e.g. username in email)
* @return {string} user part of URL
*/
-static gint
+static int
lua_url_get_user(lua_State *L)
{
LUA_TRACE_POINT;
* Get path of the url
* @return {string} path part of URL
*/
-static gint
+static int
lua_url_get_path(lua_State *L)
{
LUA_TRACE_POINT;
* Get query of the url
* @return {string} query part of URL
*/
-static gint
+static int
lua_url_get_query(lua_State *L)
{
LUA_TRACE_POINT;
* Get fragment of the url
* @return {string} fragment part of URL
*/
-static gint
+static int
lua_url_get_fragment(lua_State *L)
{
LUA_TRACE_POINT;
* Get full content of the url
* @return {string} url string
*/
-static gint
+static int
lua_url_get_text(lua_State *L)
{
LUA_TRACE_POINT;
* Get full content of the url or user@domain in case of email
* @return {string} url as a string
*/
-static gint
+static int
lua_url_tostring(lua_State *L)
{
LUA_TRACE_POINT;
if (url != NULL && url->url != NULL) {
if (url->url->protocol == PROTOCOL_MAILTO) {
- gchar *tmp = g_malloc(url->url->userlen + 1 +
- url->url->hostlen);
+ char *tmp = g_malloc(url->url->userlen + 1 +
+ url->url->hostlen);
if (url->url->userlen) {
memcpy(tmp, url->url->string + url->url->usershift, url->url->userlen);
}
* Get URL suitable for HTTP request (e.g. by trimming fragment and user parts)
* @return {string} url as a string
*/
-static gint
+static int
lua_url_to_http(lua_State *L)
{
LUA_TRACE_POINT;
len--;
}
}
- gchar *nstr = g_malloc(len);
- gchar *d = nstr, *end = nstr + len;
+ char *nstr = g_malloc(len);
+ char *d = nstr, *end = nstr + len;
memcpy(nstr, url->url->string, url->url->protocollen);
d += url->url->protocollen;
*d++ = ':';
* Get full content of the url as it was parsed (e.g. with urldecode)
* @return {string} url string
*/
-static gint
+static int
lua_url_get_raw(lua_State *L)
{
LUA_TRACE_POINT;
* Check whether URL is treated as phished
* @return {boolean} `true` if URL is phished
*/
-static gint
+static int
lua_url_is_phished(lua_State *L)
{
LUA_TRACE_POINT;
* Check whether URL was redirected
* @return {boolean} `true` if URL is redirected
*/
-static gint
+static int
lua_url_is_redirected(lua_State *L)
{
LUA_TRACE_POINT;
* Check whether URL is treated as obscured or obfuscated (e.g. numbers in IP address or other hacks)
* @return {boolean} `true` if URL is obscured
*/
-static gint
+static int
lua_url_is_obscured(lua_State *L)
{
LUA_TRACE_POINT;
* Check whether URL is just displayed in HTML (e.g. NOT a real href)
* @return {boolean} `true` if URL is displayed only
*/
-static gint
+static int
lua_url_is_html_displayed(lua_State *L)
{
LUA_TRACE_POINT;
* Check whether URL is found in subject
* @return {boolean} `true` if URL is found in subject
*/
-static gint
+static int
lua_url_is_subject(lua_State *L)
{
LUA_TRACE_POINT;
* Get another URL that pretends to be this URL (e.g. used in phishing)
* @return {url} phished URL
*/
-static gint
+static int
lua_url_get_phished(lua_State *L)
{
LUA_TRACE_POINT;
* @param {pool} pool memory pool to allocate memory if needed
* @return {url} parsed redirected url (if needed)
*/
-static gint
+static int
lua_url_set_redirected(lua_State *L)
{
LUA_TRACE_POINT;
}
gsize len;
- const gchar *urlstr = lua_tolstring(L, 2, &len);
+ const char *urlstr = lua_tolstring(L, 2, &len);
rspamd_url_find_single(pool, urlstr, len, RSPAMD_URL_FIND_ALL,
lua_url_single_inserter, L);
* Get effective second level domain part (eSLD) of the url host
* @return {string} effective second level domain part (eSLD) of the url host
*/
-static gint
+static int
lua_url_get_tld(lua_State *L)
{
LUA_TRACE_POINT;
* Get protocol name
* @return {string} protocol as a string
*/
-static gint
+static int
lua_url_get_protocol(lua_State *L)
{
LUA_TRACE_POINT;
* Return number of occurrences for this particular URL
* @return {number} number of occurrences
*/
-static gint
+static int
lua_url_get_count(lua_State *L)
{
LUA_TRACE_POINT;
* Get visible part of the url with html tags stripped
* @return {string} url string
*/
-static gint
+static int
lua_url_get_visible(lua_State *L)
{
LUA_TRACE_POINT;
* - `protocol`: url protocol
* @return {table} URL as a table
*/
-static gint
+static int
lua_url_to_table(lua_State *L)
{
LUA_TRACE_POINT;
* @param {string} text that contains URL (can also contain other stuff)
* @return {url} new url object that exists as long as the corresponding mempool exists
*/
-static gint
+static int
lua_url_create(lua_State *L)
{
LUA_TRACE_POINT;
/* Add flags */
for (lua_pushnil(L); lua_next(L, 3); lua_pop(L, 1)) {
int nmask = 0;
- const gchar *fname = lua_tostring(L, -1);
+ const char *fname = lua_tostring(L, -1);
if (rspamd_url_flag_from_string(fname, &nmask)) {
u->url->flags |= nmask;
* @param {string} tld_file path to effective_tld_names.dat file (public suffix list)
* @return nothing
*/
-static gint
+static int
lua_url_init(lua_State *L)
{
- const gchar *tld_path;
+ const char *tld_path;
tld_path = luaL_checkstring(L, 1);
{
lua_State *L = ud;
struct rspamd_lua_url *lua_url;
- gint n;
+ int n;
n = rspamd_lua_table_size(L, -1);
lua_url = lua_newuserdata(L, sizeof(struct rspamd_lua_url));
}
-static gint
+static int
lua_url_all(lua_State *L)
{
LUA_TRACE_POINT;
rspamd_mempool_t *pool = rspamd_lua_check_mempool(L, 1);
- const gchar *text;
+ const char *text;
size_t length;
if (pool == NULL) {
} \
} while (0)
-static gint
+static int
lua_url_get_flags(lua_State *L)
{
LUA_TRACE_POINT;
lua_createtable(L, 0, 4);
- for (gint i = 0; i < RSPAMD_URL_MAX_FLAG_SHIFT; i++) {
+ for (int i = 0; i < RSPAMD_URL_MAX_FLAG_SHIFT; i++) {
PUSH_FLAG(1u << i);
}
}
#undef PUSH_FLAG
-static gint
+static int
lua_url_get_flags_num(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_url_get_order(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_url_get_part_order(lua_State *L)
{
LUA_TRACE_POINT;
}
if (cb->skip_prob > 0) {
- gdouble coin = rspamd_random_double_fast_seed(&cb->random_seed);
+ double coin = rspamd_random_double_fast_seed(&cb->random_seed);
if (coin < cb->skip_prob) {
return;
gboolean
lua_url_cbdata_fill(lua_State *L,
- gint pos,
+ int pos,
struct lua_tree_cb_data *cbd,
- guint default_protocols,
- guint default_flags,
+ unsigned int default_protocols,
+ unsigned int default_flags,
gsize max_urls)
{
- gint protocols_mask = 0;
+ int protocols_mask = 0;
- gint pos_arg_type = lua_type(L, pos);
- guint flags_mask = default_flags;
+ int pos_arg_type = lua_type(L, pos);
+ unsigned int flags_mask = default_flags;
gboolean seen_flags = FALSE, seen_protocols = FALSE;
memset(cbd, 0, sizeof(*cbd));
lua_getfield(L, pos, "flags");
if (lua_istable(L, -1)) {
- gint top = lua_gettop(L);
+ int top = lua_gettop(L);
lua_getfield(L, pos, "flags_mode");
if (lua_isstring(L, -1)) {
- const gchar *mode_str = lua_tostring(L, -1);
+ const char *mode_str = lua_tostring(L, -1);
if (strcmp(mode_str, "explicit") == 0) {
cbd->flags_mode = url_flags_mode_include_explicit;
if (lua_type(L, -1) == LUA_TSTRING) {
- const gchar *fname = lua_tostring(L, -1);
+ const char *fname = lua_tostring(L, -1);
if (rspamd_url_flag_from_string(fname, &nmask)) {
lua_getfield(L, pos, "protocols");
if (lua_istable(L, -1)) {
- gint top = lua_gettop(L);
+ int top = lua_gettop(L);
for (lua_pushnil(L); lua_next(L, top); lua_pop(L, 1)) {
int nmask;
- const gchar *pname = lua_tostring(L, -1);
+ const char *pname = lua_tostring(L, -1);
nmask = rspamd_url_protocol_from_string(pname);
/* Plain table of the protocols */
for (lua_pushnil(L); lua_next(L, pos); lua_pop(L, 1)) {
int nmask;
- const gchar *pname = lua_tostring(L, -1);
+ const char *pname = lua_tostring(L, -1);
nmask = rspamd_url_protocol_from_string(pname);
lua_pop(L, 1); /* After rspamd_lua_geti */
}
else if (pos_arg_type == LUA_TSTRING) {
- const gchar *plist = lua_tostring(L, pos);
- gchar **strvec;
- gchar *const *cvec;
+ const char *plist = lua_tostring(L, pos);
+ char **strvec;
+ char *const *cvec;
strvec = g_strsplit_set(plist, ",;", -1);
cvec = strvec;
gboolean
lua_url_cbdata_fill_exclude_include(lua_State *L,
- gint pos,
+ int pos,
struct lua_tree_cb_data *cbd,
- guint default_protocols,
+ unsigned int default_protocols,
gsize max_urls)
{
- guint protocols_mask = default_protocols;
- guint include_flags_mask, exclude_flags_mask;
+ unsigned int protocols_mask = default_protocols;
+ unsigned int include_flags_mask, exclude_flags_mask;
- gint pos_arg_type = lua_type(L, pos);
+ int pos_arg_type = lua_type(L, pos);
memset(cbd, 0, sizeof(*cbd));
cbd->flags_mode = url_flags_mode_exclude_include;
int nmask = 0;
if (lua_type(L, -1) == LUA_TSTRING) {
- const gchar *fname = lua_tostring(L, -1);
+ const char *fname = lua_tostring(L, -1);
if (rspamd_url_flag_from_string(fname, &nmask)) {
include_flags_mask |= nmask;
int nmask = 0;
if (lua_type(L, -1) == LUA_TSTRING) {
- const gchar *fname = lua_tostring(L, -1);
+ const char *fname = lua_tostring(L, -1);
if (rspamd_url_flag_from_string(fname, &nmask)) {
exclude_flags_mask |= nmask;
for (lua_pushnil(L); lua_next(L, pos + 2); lua_pop(L, 1)) {
int nmask;
- const gchar *pname = lua_tostring(L, -1);
+ const char *pname = lua_tostring(L, -1);
nmask = rspamd_url_protocol_from_string(pname);
}
gsize lua_url_adjust_skip_prob(float timestamp,
- guchar digest[16],
+ unsigned char digest[16],
struct lua_tree_cb_data *cb,
gsize sz)
{
if (cb->max_urls > 0 && sz > cb->max_urls) {
- cb->skip_prob = 1.0 - ((gdouble) cb->max_urls) / (gdouble) sz;
+ cb->skip_prob = 1.0 - ((double) cb->max_urls) / (double) sz;
/*
* Use task dependent probabilistic seed to ensure that
* consequent task:get_urls return the same list of urls
return sz;
}
-static gint
+static int
lua_url_eq(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_url_lt(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_load_url(lua_State *L)
{
lua_newtable(L);
/* Push flags */
lua_createtable(L, 0, RSPAMD_URL_MAX_FLAG_SHIFT);
for (int i = 0; i < RSPAMD_URL_MAX_FLAG_SHIFT; i++) {
- guint flag = 1u << i;
+ unsigned int flag = 1u << i;
lua_pushinteger(L, flag);
lua_setfield(L, -2, rspamd_url_flag_to_string(flag));
lua_State *L;
int i;
int metatable_pos;
- guint flags_mask;
- guint flags_exclude_mask;
- guint protocols_mask;
+ unsigned int flags_mask;
+ unsigned int flags_exclude_mask;
+ unsigned int protocols_mask;
enum {
url_flags_mode_include_any,
url_flags_mode_include_explicit,
} flags_mode;
gboolean sort;
gsize max_urls;
- gdouble skip_prob;
+ double skip_prob;
uint64_t random_seed;
};
* @param cbd
* @return
*/
-gboolean lua_url_cbdata_fill(lua_State *L, gint pos,
+gboolean lua_url_cbdata_fill(lua_State *L, int pos,
struct lua_tree_cb_data *cbd,
- guint default_protocols,
- guint default_flags,
+ unsigned int default_protocols,
+ unsigned int default_flags,
gsize max_urls);
-gboolean lua_url_cbdata_fill_exclude_include(lua_State *L, gint pos,
+gboolean lua_url_cbdata_fill_exclude_include(lua_State *L, int pos,
struct lua_tree_cb_data *cbd,
- guint default_protocols,
+ unsigned int default_protocols,
gsize max_urls);
/**
* @return
*/
gsize lua_url_adjust_skip_prob(float timestamp,
- guchar digest[16],
+ unsigned char digest[16],
struct lua_tree_cb_data *cb,
gsize sz);
{NULL, NULL}};
static int64_t
-lua_check_int64(lua_State *L, gint pos)
+lua_check_int64(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_int64_classname);
luaL_argcheck(L, ud != NULL, pos, "'int64' expected");
}
-static gint
+static int
lua_util_create_event_base(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_util_load_rspamd_config(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg, **pcfg;
- const gchar *cfg_name;
+ const char *cfg_name;
cfg_name = luaL_checkstring(L, 1);
return 1;
}
-static gint
+static int
parse_config_options(const char *str_options)
{
- gint ret = 0;
- gchar **vec;
- const gchar *str;
- guint i, l;
+ int ret = 0;
+ char **vec;
+ const char *str;
+ unsigned int i, l;
vec = g_strsplit_set(str_options, ",;", -1);
if (vec) {
return ret;
}
-static gint
+static int
lua_util_config_from_ucl(lua_State *L)
{
LUA_TRACE_POINT;
GError *err = NULL;
ucl_object_t *obj;
const char *str_options = NULL;
- gint int_options = 0;
+ int int_options = 0;
obj = ucl_object_lua_import(L, 1);
return TRUE;
}
-static gint
+static int
lua_util_process_message(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config(L, 1);
- const gchar *message;
+ const char *message;
gsize mlen;
struct rspamd_task *task;
struct ev_loop *base;
return 1;
}
-static gint
+static int
lua_util_encode_base64(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_text *t;
- gchar *out;
+ char *out;
gsize outlen;
long str_lim = 0;
gboolean fold = FALSE;
enum rspamd_newlines_type how = RSPAMD_TASK_NEWLINES_CRLF;
if (lua_type(L, 3) == LUA_TSTRING) {
- const gchar *how_str = lua_tostring(L, 3);
+ const char *how_str = lua_tostring(L, 3);
if (g_ascii_strcasecmp(how_str, "cr") == 0) {
how = RSPAMD_TASK_NEWLINES_CR;
return 1;
}
-static gint
+static int
lua_util_encode_qp(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_text *t;
- const gchar *s = NULL;
- gchar *out;
+ const char *s = NULL;
+ char *out;
gsize inlen, outlen;
- guint str_lim = 0;
+ unsigned int str_lim = 0;
if (lua_type(L, 1) == LUA_TSTRING) {
s = luaL_checklstring(L, 1, &inlen);
enum rspamd_newlines_type how = RSPAMD_TASK_NEWLINES_CRLF;
if (lua_type(L, 3) == LUA_TSTRING) {
- const gchar *how_str = lua_tostring(L, 3);
+ const char *how_str = lua_tostring(L, 3);
if (g_ascii_strcasecmp(how_str, "cr") == 0) {
how = RSPAMD_TASK_NEWLINES_CR;
return 1;
}
-static gint
+static int
lua_util_decode_qp(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_text *t, *out;
- const gchar *s = NULL;
+ const char *s = NULL;
gsize inlen = 0;
gssize outlen;
rspamd_lua_setclass(L, rspamd_text_classname, -1);
out->start = g_malloc(inlen + 1);
out->flags = RSPAMD_TEXT_FLAG_OWN;
- outlen = rspamd_decode_qp_buf(s, inlen, (gchar *) out->start, inlen + 1);
+ outlen = rspamd_decode_qp_buf(s, inlen, (char *) out->start, inlen + 1);
if (outlen > 0) {
out->len = outlen;
return 1;
}
-static gint
+static int
lua_util_decode_base64(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_text *t;
- const gchar *s = NULL;
+ const char *s = NULL;
gsize inlen = 0, outlen;
if (lua_type(L, 1) == LUA_TSTRING) {
t->len = (inlen / 4) * 3 + 3;
t->start = g_malloc(t->len);
- rspamd_cryptobox_base64_decode(s, inlen, (guchar *) t->start,
+ rspamd_cryptobox_base64_decode(s, inlen, (unsigned char *) t->start,
&outlen);
t->len = outlen;
t->flags = RSPAMD_TEXT_FLAG_OWN;
return 1;
}
-static gint
+static int
lua_util_encode_base32(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_text *t;
- const gchar *s = NULL;
- gchar *out;
+ const char *s = NULL;
+ char *out;
enum rspamd_base32_type btype = RSPAMD_BASE32_DEFAULT;
gsize inlen, outlen;
return 1;
}
-static gint
+static int
lua_util_decode_base32(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_text *t;
- const gchar *s = NULL;
+ const char *s = NULL;
gsize inlen, outlen;
enum rspamd_base32_type btype = RSPAMD_BASE32_DEFAULT;
}
if (s != NULL) {
- guchar *decoded;
+ unsigned char *decoded;
decoded = rspamd_decode_base32(s, inlen, &outlen, btype);
if (decoded) {
t = lua_newuserdata(L, sizeof(*t));
rspamd_lua_setclass(L, rspamd_text_classname, -1);
- t->start = (const gchar *) decoded;
+ t->start = (const char *) decoded;
t->len = outlen;
t->flags = RSPAMD_TEXT_FLAG_OWN;
}
return 1;
}
-static gint
+static int
lua_util_decode_url(lua_State *L)
{
LUA_TRACE_POINT;
}
-static gint
+static int
lua_util_tokenize_text(lua_State *L)
{
return lua_parsers_tokenize_text(L);
}
-static gint
+static int
lua_util_tanh(lua_State *L)
{
LUA_TRACE_POINT;
- gdouble in = luaL_checknumber(L, 1);
+ double in = luaL_checknumber(L, 1);
lua_pushnumber(L, tanh(in));
return 1;
}
-static gint
+static int
lua_util_parse_html(lua_State *L)
{
return lua_parsers_parse_html(L);
}
-static gint
+static int
lua_util_levenshtein_distance(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_text *t1, *t2;
- gint dist = 0;
- guint replace_cost = 1;
+ int dist = 0;
+ unsigned int replace_cost = 1;
t1 = lua_check_text_or_string(L, 1);
t2 = lua_check_text_or_string(L, 2);
return 1;
}
-static gint
+static int
lua_util_fold_header(lua_State *L)
{
LUA_TRACE_POINT;
- const gchar *how, *stop_chars = NULL;
+ const char *how, *stop_chars = NULL;
struct rspamd_lua_text *name, *value;
GString *folded;
return 1;
}
-static gint
+static int
lua_util_is_uppercase(lua_State *L)
{
LUA_TRACE_POINT;
int32_t i = 0;
UChar32 uc;
- guint nlc = 0, nuc = 0;
+ unsigned int nlc = 0, nuc = 0;
struct rspamd_lua_text *t = lua_check_text_or_string(L, 1);
if (t) {
return 1;
}
-static gint
+static int
lua_util_humanize_number(lua_State *L)
{
LUA_TRACE_POINT;
int64_t number = luaL_checkinteger(L, 1);
- gchar numbuf[32];
+ char numbuf[32];
rspamd_snprintf(numbuf, sizeof(numbuf), "%hL", number);
return 1;
}
-static gint
+static int
lua_util_get_tld(lua_State *L)
{
LUA_TRACE_POINT;
- const gchar *host;
+ const char *host;
gsize hostlen;
rspamd_ftok_t tld;
}
-static gint
+static int
lua_util_glob(lua_State *L)
{
LUA_TRACE_POINT;
- const gchar *pattern;
+ const char *pattern;
glob_t gl;
- gint top, i, flags = 0;
+ int top, i, flags = 0;
top = lua_gettop(L);
memset(&gl, 0, sizeof(gl));
lua_createtable(L, gl.gl_pathc, 0);
/* Push results */
- for (i = 0; i < (gint) gl.gl_pathc; i++) {
+ for (i = 0; i < (int) gl.gl_pathc; i++) {
lua_pushstring(L, gl.gl_pathv[i]);
lua_rawseti(L, -2, i + 1);
}
return 1;
}
-static gint
+static int
lua_util_parse_mail_address(lua_State *L)
{
return lua_parsers_parse_mail_address(L);
}
-static gint
+static int
lua_util_strlen_utf8(lua_State *L)
{
LUA_TRACE_POINT;
UChar32 uc;
while (i < t->len) {
- U8_NEXT((guint8 *) t->start, i, t->len, uc);
+ U8_NEXT((uint8_t *) t->start, i, t->len, uc);
nchars++;
}
return 1;
}
-static gint
+static int
lua_util_lower_utf8(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_text *t;
- gchar *dst;
+ char *dst;
UChar32 uc;
UBool err = 0;
int32_t i = 0, j = 0;
dst = g_malloc(t->len);
while (i < t->len && err == 0) {
- U8_NEXT((guint8 *) t->start, i, t->len, uc);
+ U8_NEXT((uint8_t *) t->start, i, t->len, uc);
uc = u_tolower(uc);
U8_APPEND(dst, j, t->len, uc, err);
}
return 1;
}
-static gint
+static int
lua_util_normalize_utf8(lua_State *L)
{
LUA_TRACE_POINT;
return 2;
}
-static gint
+static int
lua_util_transliterate(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_util_strequal_caseless(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_text *t1, *t2;
- gint ret = -1;
+ int ret = -1;
t1 = lua_check_text_or_string(L, 1);
t2 = lua_check_text_or_string(L, 2);
return 1;
}
-static gint
+static int
lua_util_strequal_caseless_utf8(lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_lua_text *t1, *t2;
- gint ret = -1;
+ int ret = -1;
t1 = lua_check_text_or_string(L, 1);
t2 = lua_check_text_or_string(L, 2);
return 1;
}
-static gint
+static int
lua_util_get_ticks(lua_State *L)
{
LUA_TRACE_POINT;
- gdouble ticks;
+ double ticks;
gboolean rdtsc = FALSE;
if (lua_isboolean(L, 1)) {
return 1;
}
-static gint
+static int
lua_util_get_time(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_util_time_to_string(lua_State *L)
{
LUA_TRACE_POINT;
- gdouble seconds;
+ double seconds;
char timebuf[128];
if (lua_isnumber(L, 1)) {
return 1;
}
-static gint
+static int
lua_util_stat(lua_State *L)
{
LUA_TRACE_POINT;
- const gchar *fpath;
+ const char *fpath;
struct stat st;
fpath = luaL_checkstring(L, 1);
return 2;
}
-static gint
+static int
lua_util_unlink(lua_State *L)
{
LUA_TRACE_POINT;
- const gchar *fpath;
- gint ret;
+ const char *fpath;
+ int ret;
fpath = luaL_checkstring(L, 1);
return 1;
}
-static gint
+static int
lua_util_lock_file(lua_State *L)
{
LUA_TRACE_POINT;
- const gchar *fpath;
- gint fd = -1;
+ const char *fpath;
+ int fd = -1;
gboolean own = FALSE;
#if !HAVE_FLOCK
return 1;
}
-static gint
+static int
lua_util_unlock_file(lua_State *L)
{
LUA_TRACE_POINT;
- gint fd = -1, ret, serrno;
+ int fd = -1, ret, serrno;
gboolean do_close = TRUE;
#if !HAVE_FLOCK
return 1;
}
-static gint
+static int
lua_util_create_file(lua_State *L)
{
LUA_TRACE_POINT;
- gint fd, mode = 00644;
- const gchar *fpath;
+ int fd, mode = 00644;
+ const char *fpath;
fpath = luaL_checkstring(L, 1);
return 1;
}
-static gint
+static int
lua_util_close_file(lua_State *L)
{
LUA_TRACE_POINT;
- gint fd = -1;
+ int fd = -1;
if (lua_isnumber(L, 1)) {
fd = lua_tointeger(L, 1);
return 1;
}
-static gint
+static int
lua_util_random_hex(lua_State *L)
{
LUA_TRACE_POINT;
- gchar *buf;
- gint buflen;
+ char *buf;
+ int buflen;
buflen = lua_tointeger(L, 1);
return 1;
}
-static gint
+static int
lua_util_zstd_compress(lua_State *L)
{
return lua_compress_zstd_compress(L);
}
-static gint
+static int
lua_util_zstd_decompress(lua_State *L)
{
return lua_compress_zstd_decompress(L);
}
-static gint
+static int
lua_util_gzip_compress(lua_State *L)
{
return lua_compress_zlib_compress(L);
}
-static gint
+static int
lua_util_gzip_decompress(lua_State *L)
{
return lua_compress_zlib_decompress(L, true);
}
-static gint
+static int
lua_util_inflate(lua_State *L)
{
return lua_compress_zlib_decompress(L, false);
}
-static gint
+static int
lua_util_normalize_prob(lua_State *L)
{
LUA_TRACE_POINT;
- gdouble x, bias = 0.5;
+ double x, bias = 0.5;
x = lua_tonumber(L, 1);
return 1;
}
-static gint
+static int
lua_util_caseless_hash(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_util_caseless_hash_fast(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_util_is_utf_spoofed(lua_State *L)
{
LUA_TRACE_POINT;
gsize l1, l2;
- gint ret, nres = 2;
- const gchar *s1 = lua_tolstring(L, 1, &l1),
- *s2 = lua_tolstring(L, 2, &l2);
+ int ret, nres = 2;
+ const char *s1 = lua_tolstring(L, 1, &l1),
+ *s2 = lua_tolstring(L, 2, &l2);
static USpoofChecker *spc, *spc_sgl;
UErrorCode uc_err = U_ZERO_ERROR;
return nres;
}
-static gint
+static int
lua_util_is_utf_mixed_script(lua_State *L)
{
LUA_TRACE_POINT;
gsize len_of_string;
- const guchar *string_to_check = lua_tolstring(L, 1, &len_of_string);
+ const unsigned char *string_to_check = lua_tolstring(L, 1, &len_of_string);
UScriptCode last_script_code = USCRIPT_INVALID_CODE;
UErrorCode uc_err = U_ZERO_ERROR;
return 1;
}
-static gint
+static int
lua_util_get_string_stats(lua_State *L)
{
LUA_TRACE_POINT;
- gint num_of_digits = 0, num_of_letters = 0;
+ int num_of_digits = 0, num_of_letters = 0;
struct rspamd_lua_text *t;
t = lua_check_text_or_string(L, 1);
if (t) {
- const gchar *p = t->start, *end = t->start + t->len;
+ const char *p = t->start, *end = t->start + t->len;
while (p < end) {
if (g_ascii_isdigit(*p)) {
num_of_digits++;
}
-static gint
+static int
lua_util_is_utf_outside_range(lua_State *L)
{
LUA_TRACE_POINT;
- gint ret;
+ int ret;
struct rspamd_lua_text *t = lua_check_text_or_string(L, 1);
uint32_t range_start = lua_tointeger(L, 2);
uint32_t range_end = lua_tointeger(L, 3);
}
-static gint
+static int
lua_util_get_hostname(lua_State *L)
{
LUA_TRACE_POINT;
- gchar *hostbuf;
+ char *hostbuf;
gsize hostlen;
hostlen = sysconf(_SC_HOST_NAME_MAX);
return 1;
}
-static gint
+static int
lua_util_parse_content_type(lua_State *L)
{
return lua_parsers_parse_content_type(L);
}
-static gint
+static int
lua_util_mime_header_encode(lua_State *L)
{
LUA_TRACE_POINT;
gsize len;
- const gchar *hdr = luaL_checklstring(L, 1, &len);
- gchar *encoded;
+ const char *hdr = luaL_checklstring(L, 1, &len);
+ char *encoded;
if (!hdr) {
return luaL_error(L, "invalid arguments");
return 1;
}
-static gint
+static int
lua_util_is_valid_utf8(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_util_has_obscured_unicode(lua_State *L)
{
LUA_TRACE_POINT;
return 1;
}
-static gint
+static int
lua_util_readline(lua_State *L)
{
LUA_TRACE_POINT;
- const gchar *prompt = "";
- gchar *input = NULL;
+ const char *prompt = "";
+ char *input = NULL;
if (lua_type(L, 1) == LUA_TSTRING) {
prompt = lua_tostring(L, 1);
replxx_history_add(rx_instance, "");
}
- input = (gchar *) replxx_input(rx_instance, prompt);
+ input = (char *) replxx_input(rx_instance, prompt);
if (input) {
lua_pushstring(L, input);
return 1;
}
-static gint
+static int
lua_util_readpassphrase(lua_State *L)
{
LUA_TRACE_POINT;
- gchar test_password[8192];
+ char test_password[8192];
gsize r;
r = rspamd_read_passphrase(test_password, sizeof(test_password), 0, NULL);
return 1;
}
-static gint
+static int
lua_util_file_exists(lua_State *L)
{
LUA_TRACE_POINT;
- const gchar *fname = luaL_checkstring(L, 1);
- gint serrno;
+ const char *fname = luaL_checkstring(L, 1);
+ int serrno;
if (fname) {
if (access(fname, R_OK) == -1) {
return 2;
}
-static gint
+static int
lua_util_mkdir(lua_State *L)
{
LUA_TRACE_POINT;
- const gchar *dname = luaL_checkstring(L, 1);
+ const char *dname = luaL_checkstring(L, 1);
gboolean recursive = FALSE;
- gint r = -1;
+ int r = -1;
if (dname) {
if (lua_isboolean(L, 2)) {
}
-static gint
+static int
lua_util_umask(lua_State *L)
{
LUA_TRACE_POINT;
mode_t mask = 0, old;
if (lua_type(L, 1) == LUA_TSTRING) {
- const gchar *str = lua_tostring(L, 1);
+ const char *str = lua_tostring(L, 1);
if (str[0] == '0') {
/* e.g. '022' */
return 1;
}
-static gint
+static int
lua_util_isatty(lua_State *L)
{
LUA_TRACE_POINT;
}
for (lua_pushnil(L); lua_next(L, 1); lua_pop(L, 1)) {
- guint8 c0 = c >> 35;
+ uint8_t c0 = c >> 35;
uint64_t d = lua_tointeger(L, -1);
c = ((c & 0x07ffffffff) << 5) ^ d;
}
-static gint
+static int
lua_load_util(lua_State *L)
{
lua_newtable(L);
return 1;
}
-static gint
+static int
lua_load_int64(lua_State *L)
{
lua_newtable(L);
lua_int64_tostring(lua_State *L)
{
int64_t n = lua_check_int64(L, 1);
- gchar buf[32];
+ char buf[32];
bool is_signed = false;
if (lua_isboolean(L, 2)) {
lua_int64_tonumber(lua_State *L)
{
int64_t n = lua_check_int64(L, 1);
- gdouble d;
+ double d;
d = n;
lua_pushinteger(L, d);
lua_int64_hex(lua_State *L)
{
int64_t n = lua_check_int64(L, 1);
- gchar buf[32];
+ char buf[32];
rspamd_snprintf(buf, sizeof(buf), "%XL", n);
lua_pushstring(L, buf);
{NULL, NULL}};
static struct rspamd_worker *
-lua_check_worker(lua_State *L, gint pos)
+lua_check_worker(lua_State *L, int pos)
{
void *ud = rspamd_lua_check_udata(L, pos, rspamd_worker_classname);
luaL_argcheck(L, ud != NULL, pos, "'worker' expected");
return ud ? *((struct rspamd_worker **) ud) : NULL;
}
-static gint
+static int
lua_worker_get_stat(lua_State *L)
{
struct rspamd_worker *w = lua_check_worker(L, 1);
rspamd_mempool_stat_t mem_st;
struct rspamd_stat *stat, stat_copy;
ucl_object_t *top, *sub;
- gint i;
+ int i;
uint64_t spam = 0, ham = 0;
memset(&mem_st, 0, sizeof(mem_st));
return 1;
}
-static gint
+static int
lua_worker_get_name(lua_State *L)
{
struct rspamd_worker *w = lua_check_worker(L, 1);
return 1;
}
-static gint
+static int
lua_worker_get_index(lua_State *L)
{
struct rspamd_worker *w = lua_check_worker(L, 1);
return 1;
}
-static gint
+static int
lua_worker_get_count(lua_State *L)
{
struct rspamd_worker *w = lua_check_worker(L, 1);
return 1;
}
-static gint
+static int
lua_worker_get_pid(lua_State *L)
{
struct rspamd_worker *w = lua_check_worker(L, 1);
}
-static gint
+static int
lua_worker_is_scanner(lua_State *L)
{
struct rspamd_worker *w = lua_check_worker(L, 1);
return 1;
}
-static gint
+static int
lua_worker_is_primary_controller(lua_State *L)
{
struct rspamd_worker *w = lua_check_worker(L, 1);
struct ev_loop *event_loop;
struct rspamd_async_session *session;
enum rspamd_control_type cmd;
- gint cbref;
- gint fd;
+ int cbref;
+ int fd;
};
static gboolean
static gboolean
lua_worker_control_handler(struct rspamd_main *rspamd_main,
struct rspamd_worker *worker,
- gint fd,
- gint attached_fd,
+ int fd,
+ int attached_fd,
struct rspamd_control_command *cmd,
gpointer ud)
{
struct rspamd_control_cbdata *cbd = (struct rspamd_control_cbdata *) ud;
rspamd_mempool_t *pool;
lua_State *L;
- gint err_idx, status;
+ int err_idx, status;
L = cbd->L;
pool = cbd->pool;
return TRUE;
}
-static gint
+static int
lua_worker_add_control_handler(lua_State *L)
{
struct rspamd_worker *w = lua_check_worker(L, 1);
struct rspamd_config *cfg = lua_check_config(L, 2);
struct ev_loop *event_loop = lua_check_ev_base(L, 3);
- const gchar *cmd_name = luaL_checkstring(L, 4);
+ const char *cmd_name = luaL_checkstring(L, 4);
enum rspamd_control_type cmd;
struct rspamd_control_cbdata *cbd;
}
#endif
-static gint
+static int
lua_worker_get_mem_stats(lua_State *L)
{
struct rspamd_worker *w = lua_check_worker(L, 1);
}
struct rspamd_lua_process_cbdata {
- gint sp[2];
- gint func_cbref;
- gint cb_cbref;
+ int sp[2];
+ int func_cbref;
+ int cb_cbref;
gboolean replied;
gboolean is_error;
pid_t cpid;
rspamd_lua_execute_lua_subprocess(lua_State *L,
struct rspamd_lua_process_cbdata *cbdata)
{
- gint err_idx, r;
+ int err_idx, r;
uint64_t wlen = 0;
lua_pushcfunction(L, &rspamd_lua_traceback);
lua_rawgeti(L, LUA_REGISTRYINDEX, cbdata->func_cbref);
if (lua_pcall(L, 0, 1, err_idx) != 0) {
- const gchar *s = lua_tostring(L, -1);
+ const char *s = lua_tostring(L, -1);
gsize slen = strlen(s);
msg_err("call to subprocess failed: %s", s);
static void
rspamd_lua_call_on_complete(lua_State *L,
struct rspamd_lua_process_cbdata *cbdata,
- const gchar *err_msg,
- const gchar *data, gsize datalen)
+ const char *err_msg,
+ const char *data, gsize datalen)
{
- gint err_idx;
+ int err_idx;
lua_pushcfunction(L, &rspamd_lua_traceback);
err_idx = lua_gettop(L);
struct rspamd_srv_command srv_cmd;
lua_State *L;
pid_t died;
- gint res = 0;
+ int res = 0;
/* Are we called by a correct children ? */
died = waitpid(cbdata->cpid, &res, WNOHANG);
cbdata->io_buf->len += r;
if (cbdata->io_buf->len == sizeof(uint64_t)) {
- memcpy((guchar *) &sz, cbdata->io_buf->str, sizeof(sz));
+ memcpy((unsigned char *) &sz, cbdata->io_buf->str, sizeof(sz));
if (sz & (1ULL << 63)) {
cbdata->is_error = TRUE;
cbdata->io_buf->len += r;
if (cbdata->io_buf->len == cbdata->sz) {
- gchar rep[4];
+ char rep[4];
ev_io_stop(cbdata->event_loop, &cbdata->ev);
/* Finished reading data */
}
}
-static gint
+static int
lua_worker_spawn_process(lua_State *L)
{
struct rspamd_worker *w = lua_check_worker(L, 1);
struct rspamd_lua_process_cbdata *cbdata;
struct rspamd_abstract_worker_ctx *actx;
struct rspamd_srv_command srv_cmd;
- const gchar *cmdline = NULL, *input = NULL, *proctitle = NULL;
+ const char *cmdline = NULL, *input = NULL, *proctitle = NULL;
gsize inputlen = 0;
pid_t pid;
GError *err = NULL;
- gint func_cbref, cb_cbref;
+ int func_cbref, cb_cbref;
if (!rspamd_lua_parse_table_arguments(L, 2, &err,
RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT,
}
else if (pid == 0) {
/* Child */
- gint rc;
- gchar inbuf[4];
+ int rc;
+ char inbuf[4];
rspamd_log_on_fork(w->cf->type, w->srv->cfg, w->srv->logger);
rc = ottery_init(w->srv->cfg->libs_ctx->ottery_cfg);
struct lua_xmlrpc_ud {
enum lua_xmlrpc_state parser_state;
GQueue *st;
- gint param_count;
+ int param_count;
gboolean got_text;
lua_State *L;
};
static void xmlrpc_start_element(GMarkupParseContext *context,
- const gchar *name,
- const gchar **attribute_names,
- const gchar **attribute_values,
+ const char *name,
+ const char **attribute_names,
+ const char **attribute_values,
gpointer user_data,
GError **error);
static void xmlrpc_end_element(GMarkupParseContext *context,
- const gchar *element_name,
+ const char *element_name,
gpointer user_data,
GError **error);
static void xmlrpc_error(GMarkupParseContext *context,
GError *error,
gpointer user_data);
static void xmlrpc_text(GMarkupParseContext *context,
- const gchar *text,
+ const char *text,
gsize text_len,
gpointer user_data,
GError **error);
static void
xmlrpc_start_element(GMarkupParseContext *context,
- const gchar *name,
- const gchar **attribute_names,
- const gchar **attribute_values,
+ const char *name,
+ const char **attribute_names,
+ const char **attribute_values,
gpointer user_data,
GError **error)
{
static void
xmlrpc_end_element(GMarkupParseContext *context,
- const gchar *name,
+ const char *name,
gpointer user_data,
GError **error)
{
case read_array_element:
/* Got tag value */
if (g_ascii_strcasecmp(name, "value") == 0) {
- guint tbl_len = rspamd_lua_table_size(ud->L, -2);
+ unsigned int tbl_len = rspamd_lua_table_size(ud->L, -2);
lua_rawseti(ud->L, -2, tbl_len + 1);
msg_debug_xmlrpc("set array element idx: %d", tbl_len + 1);
ud->parser_state = read_array_value;
static void
xmlrpc_text(GMarkupParseContext *context,
- const gchar *text,
+ const char *text,
gsize text_len,
gpointer user_data,
GError **error)
{
struct lua_xmlrpc_ud *ud = user_data;
gulong num;
- gdouble dnum;
+ double dnum;
/* Strip line */
while (text_len > 0 && g_ascii_isspace(*text)) {
msg_err("xmlrpc parser error: %s", error->message);
}
-static gint
+static int
lua_xmlrpc_parse_reply(lua_State *L)
{
LUA_TRACE_POINT;
- const gchar *data;
+ const char *data;
GMarkupParseContext *ctx;
GError *err = NULL;
struct lua_xmlrpc_ud ud;
return 1;
}
-static gint
+static int
lua_xmlrpc_parse_table(lua_State *L,
- gint pos,
- gchar *databuf,
- gint pr,
+ int pos,
+ char *databuf,
+ int pr,
gsize size)
{
- gint r = pr, num;
+ int r = pr, num;
double dnum;
r += rspamd_snprintf(databuf + r, size - r, "<struct>");
* Internal limitation: xmlrpc request must NOT be more than
* BUFSIZ * 2 (16384 bytes)
*/
-static gint
+static int
lua_xmlrpc_make_request(lua_State *L)
{
LUA_TRACE_POINT;
- gchar databuf[BUFSIZ * 2];
- const gchar *func;
- gint r, top, i, num;
+ char databuf[BUFSIZ * 2];
+ const char *func;
+ int r, top, i, num;
double dnum;
func = luaL_checkstring(L, 1);
return 1;
}
-static gint
+static int
lua_load_xmlrpc(lua_State *L)
{
lua_newtable(L);
INIT_LOG_MODULE(chartable)
/* Initialization */
-gint chartable_module_init(struct rspamd_config *cfg, struct module_ctx **ctx);
+int chartable_module_init(struct rspamd_config *cfg, struct module_ctx **ctx);
-gint chartable_module_config(struct rspamd_config *cfg, bool validate);
+int chartable_module_config(struct rspamd_config *cfg, bool validate);
-gint chartable_module_reconfig(struct rspamd_config *cfg);
+int chartable_module_reconfig(struct rspamd_config *cfg);
module_t chartable_module = {
"chartable",
chartable_module_reconfig,
nullptr,
RSPAMD_MODULE_VER,
- (guint) -1,
+ (unsigned int) -1,
};
struct chartable_ctx {
struct module_ctx ctx;
- const gchar *symbol;
- const gchar *url_symbol;
+ const char *symbol;
+ const char *url_symbol;
double threshold;
- guint max_word_len;
+ unsigned int max_word_len;
};
static inline struct chartable_ctx *
struct rspamd_symcache_dynamic_item *item,
void *unused);
-gint chartable_module_init(struct rspamd_config *cfg, struct module_ctx **ctx)
+int chartable_module_init(struct rspamd_config *cfg, struct module_ctx **ctx)
{
struct chartable_ctx *chartable_module_ctx;
}
-gint chartable_module_config(struct rspamd_config *cfg, bool _)
+int chartable_module_config(struct rspamd_config *cfg, bool _)
{
const ucl_object_t *value;
- gint res = TRUE;
+ int res = TRUE;
struct chartable_ctx *chartable_module_ctx = chartable_get_context(cfg);
if (!rspamd_config_is_module_enabled(cfg, "chartable")) {
return res;
}
-gint chartable_module_reconfig(struct rspamd_config *cfg)
+int chartable_module_reconfig(struct rspamd_config *cfg)
{
return chartable_module_config(cfg, false);
}
};
static gboolean
-rspamd_can_alias_latin(gint ch)
+rspamd_can_alias_latin(int ch)
{
return latin_confusable.contains(ch);
}
-static gdouble
+static double
rspamd_chartable_process_word_utf(struct rspamd_task *task,
rspamd_stat_token_t *w,
gboolean is_url,
- guint *ncap,
+ unsigned int *ncap,
struct chartable_ctx *chartable_module_ctx,
gboolean ignore_diacritics)
{
const UChar32 *p, *end;
- gdouble badness = 0.0;
+ double badness = 0.0;
UChar32 uc;
UBlockCode sc;
- guint cat;
- gint last_is_latin = -1;
- guint same_script_count = 0, nsym = 0, nspecial = 0;
+ unsigned int cat;
+ int last_is_latin = -1;
+ unsigned int same_script_count = 0, nsym = 0, nspecial = 0;
enum {
start_process = 0,
got_alpha,
if (sc != UBLOCK_BASIC_LATIN && last_is_latin) {
if (rspamd_can_alias_latin(uc)) {
- badness += 1.0 / (gdouble) same_script_count;
+ badness += 1.0 / (double) same_script_count;
}
last_is_latin = 0;
}
msg_debug_chartable("word %*s, badness: %.2f",
- (gint) w->normalized.len, w->normalized.begin,
+ (int) w->normalized.len, w->normalized.begin,
badness);
return badness;
}
-static gdouble
+static double
rspamd_chartable_process_word_ascii(struct rspamd_task *task,
rspamd_stat_token_t *w,
gboolean is_url,
struct chartable_ctx *chartable_module_ctx)
{
- gdouble badness = 0.0;
+ double badness = 0.0;
enum {
ascii = 1,
non_ascii
} sc,
last_sc;
- gint same_script_count = 0, seen_alpha = FALSE;
+ int same_script_count = 0, seen_alpha = FALSE;
enum {
start_process = 0,
got_alpha,
if (same_script_count > 0) {
if (sc != last_sc) {
- badness += 1.0 / (gdouble) same_script_count;
+ badness += 1.0 / (double) same_script_count;
last_sc = sc;
same_script_count = 1;
}
}
msg_debug_chartable("word %*s, badness: %.2f",
- (gint) w->normalized.len, w->normalized.begin,
+ (int) w->normalized.len, w->normalized.begin,
badness);
return badness;
gboolean ignore_diacritics)
{
rspamd_stat_token_t *w;
- guint i, ncap = 0;
- gdouble cur_score = 0.0;
+ unsigned int i, ncap = 0;
+ double cur_score = 0.0;
if (part == nullptr || part->utf_words == nullptr ||
part->utf_words->len == 0 || part->nwords == 0) {
*/
part->capital_letters += ncap;
- cur_score /= (gdouble) part->nwords;
+ cur_score /= (double) part->nwords;
if (cur_score > 1.0) {
cur_score = 1.0;
struct rspamd_symcache_dynamic_item *item,
void *_)
{
- guint i;
+ unsigned int i;
struct rspamd_mime_text_part *part;
struct chartable_ctx *chartable_module_ctx = chartable_get_context(task->cfg);
gboolean ignore_diacritics = TRUE, seen_violated_part = FALSE;
{
if (part->languages && part->languages->len > 0) {
auto *lang = (struct rspamd_lang_detector_res *) g_ptr_array_index(part->languages, 0);
- gint flags;
+ int flags;
flags = rspamd_language_detector_elt_flags(lang->elt);
if (task->meta_words != nullptr && task->meta_words->len > 0) {
rspamd_stat_token_t *w;
- gdouble cur_score = 0;
+ double cur_score = 0;
gsize arlen = task->meta_words->len;
for (i = 0; i < arlen; i++) {
nullptr, chartable_module_ctx, ignore_diacritics);
}
- cur_score /= (gdouble) (arlen + 1);
+ cur_score /= (double) (arlen + 1);
if (cur_score > 1.0) {
cur_score = 1.0;
GHashTableIter it;
gpointer k, v;
rspamd_stat_token_t w;
- gdouble cur_score = 0.0;
+ double cur_score = 0.0;
struct chartable_ctx *chartable_module_ctx = chartable_get_context (task->cfg);
g_hash_table_iter_init (&it, task->urls);
#define DEFAULT_TIME_JITTER 60
#define DEFAULT_MAX_SIGS 5
-static const gchar *M = "rspamd dkim plugin";
-
-static const gchar default_sign_headers[] = ""
- "(o)from:(x)sender:(o)reply-to:(o)subject:(x)date:(x)message-id:"
- "(o)to:(o)cc:(x)mime-version:(x)content-type:(x)content-transfer-encoding:"
- "resent-to:resent-cc:resent-from:resent-sender:resent-message-id:"
- "(x)in-reply-to:(x)references:list-id:list-help:list-owner:list-unsubscribe:"
- "list-unsubscribe-post:list-subscribe:list-post:(x)openpgp:(x)autocrypt";
-static const gchar default_arc_sign_headers[] = ""
- "(o)from:(x)sender:(o)reply-to:(o)subject:(x)date:(x)message-id:"
- "(o)to:(o)cc:(x)mime-version:(x)content-type:(x)content-transfer-encoding:"
- "resent-to:resent-cc:resent-from:resent-sender:resent-message-id:"
- "(x)in-reply-to:(x)references:list-id:list-help:list-owner:list-unsubscribe:"
- "list-unsubscribe-post:list-subscribe:list-post:dkim-signature:(x)openpgp:"
- "(x)autocrypt";
+static const char *M = "rspamd dkim plugin";
+
+static const char default_sign_headers[] = ""
+ "(o)from:(x)sender:(o)reply-to:(o)subject:(x)date:(x)message-id:"
+ "(o)to:(o)cc:(x)mime-version:(x)content-type:(x)content-transfer-encoding:"
+ "resent-to:resent-cc:resent-from:resent-sender:resent-message-id:"
+ "(x)in-reply-to:(x)references:list-id:list-help:list-owner:list-unsubscribe:"
+ "list-unsubscribe-post:list-subscribe:list-post:(x)openpgp:(x)autocrypt";
+static const char default_arc_sign_headers[] = ""
+ "(o)from:(x)sender:(o)reply-to:(o)subject:(x)date:(x)message-id:"
+ "(o)to:(o)cc:(x)mime-version:(x)content-type:(x)content-transfer-encoding:"
+ "resent-to:resent-cc:resent-from:resent-sender:resent-message-id:"
+ "(x)in-reply-to:(x)references:list-id:list-help:list-owner:list-unsubscribe:"
+ "list-unsubscribe-post:list-subscribe:list-post:dkim-signature:(x)openpgp:"
+ "(x)autocrypt";
struct dkim_ctx {
struct module_ctx ctx;
- const gchar *symbol_reject;
- const gchar *symbol_tempfail;
- const gchar *symbol_allow;
- const gchar *symbol_na;
- const gchar *symbol_permfail;
+ const char *symbol_reject;
+ const char *symbol_tempfail;
+ const char *symbol_allow;
+ const char *symbol_na;
+ const char *symbol_permfail;
struct rspamd_radix_map_helper *whitelist_ip;
struct rspamd_hash_map_helper *dkim_domains;
- guint strict_multiplier;
- guint time_jitter;
+ unsigned int strict_multiplier;
+ unsigned int time_jitter;
rspamd_lru_hash_t *dkim_hash;
rspamd_lru_hash_t *dkim_sign_hash;
- const gchar *sign_headers;
- const gchar *arc_sign_headers;
- guint max_sigs;
+ const char *sign_headers;
+ const char *arc_sign_headers;
+ unsigned int max_sigs;
gboolean trusted_only;
gboolean check_local;
gboolean check_authed;
rspamd_dkim_key_t *key;
struct rspamd_task *task;
struct rspamd_dkim_check_result *res;
- gdouble mult_allow;
- gdouble mult_deny;
+ double mult_allow;
+ double mult_deny;
struct rspamd_symcache_dynamic_item *item;
struct dkim_check_result *next, *prev, *first;
};
struct rspamd_symcache_dynamic_item *item,
void *unused);
-static gint lua_dkim_sign_handler(lua_State *L);
-static gint lua_dkim_verify_handler(lua_State *L);
-static gint lua_dkim_canonicalize_handler(lua_State *L);
+static int lua_dkim_sign_handler(lua_State *L);
+static int lua_dkim_verify_handler(lua_State *L);
+static int lua_dkim_canonicalize_handler(lua_State *L);
/* Initialization */
-gint dkim_module_init(struct rspamd_config *cfg, struct module_ctx **ctx);
-gint dkim_module_config(struct rspamd_config *cfg, bool validate);
-gint dkim_module_reconfig(struct rspamd_config *cfg);
+int dkim_module_init(struct rspamd_config *cfg, struct module_ctx **ctx);
+int dkim_module_config(struct rspamd_config *cfg, bool validate);
+int dkim_module_reconfig(struct rspamd_config *cfg);
module_t dkim_module = {
"dkim",
dkim_module_reconfig,
NULL,
RSPAMD_MODULE_VER,
- (guint) -1,
+ (unsigned int) -1,
};
static inline struct dkim_ctx *
g_list_free_full((GList *) k, rspamd_gstring_free_hard);
}
-gint dkim_module_init(struct rspamd_config *cfg, struct module_ctx **ctx)
+int dkim_module_init(struct rspamd_config *cfg, struct module_ctx **ctx)
{
struct dkim_ctx *dkim_module_ctx;
return 0;
}
-gint dkim_module_config(struct rspamd_config *cfg, bool validate)
+int dkim_module_config(struct rspamd_config *cfg, bool validate)
{
const ucl_object_t *value;
- gint res = TRUE, cb_id = -1;
- guint cache_size, sign_cache_size;
+ int res = TRUE, cb_id = -1;
+ unsigned int cache_size, sign_cache_size;
gboolean got_trusted = FALSE;
struct dkim_ctx *dkim_module_ctx = dkim_get_context(cfg);
rspamd_dkim_sign_key_t *
dkim_module_load_key_format(struct rspamd_task *task,
struct dkim_ctx *dkim_module_ctx,
- const gchar *key, gsize keylen,
+ const char *key, gsize keylen,
enum rspamd_dkim_key_format key_format)
{
- guchar h[rspamd_cryptobox_HASHBYTES],
+ unsigned char h[rspamd_cryptobox_HASHBYTES],
hex_hash[rspamd_cryptobox_HASHBYTES * 2 + 1];
rspamd_dkim_sign_key_t *ret = NULL;
GError *err = NULL;
return ret;
}
-static gint
+static int
lua_dkim_sign_handler(lua_State *L)
{
struct rspamd_task *task = lua_check_task(L, 1);
GError *err = NULL;
GString *hdr;
GList *sigs = NULL;
- const gchar *selector = NULL, *domain = NULL, *key = NULL, *rawkey = NULL,
- *headers = NULL, *sign_type_str = NULL, *arc_cv = NULL,
- *pubkey = NULL;
+ const char *selector = NULL, *domain = NULL, *key = NULL, *rawkey = NULL,
+ *headers = NULL, *sign_type_str = NULL, *arc_cv = NULL,
+ *pubkey = NULL;
rspamd_dkim_sign_context_t *ctx;
rspamd_dkim_sign_key_t *dkim_key;
gsize rawlen = 0, keylen = 0;
return 2;
}
-gint dkim_module_reconfig(struct rspamd_config *cfg)
+int dkim_module_reconfig(struct rspamd_config *cfg)
{
return dkim_module_config(cfg, false);
}
* Parse strict value for domain in format: 'reject_multiplier:deny_multiplier'
*/
static gboolean
-dkim_module_parse_strict(const gchar *value, gdouble *allow, gdouble *deny)
+dkim_module_parse_strict(const char *value, double *allow, double *deny)
{
- const gchar *colon;
- gchar *err = NULL;
- gdouble val;
- gchar numbuf[64];
+ const char *colon;
+ char *err = NULL;
+ double val;
+ char numbuf[64];
colon = strchr(value, ':');
if (colon) {
dkim_module_check(struct dkim_check_result *res)
{
gboolean all_done = TRUE;
- const gchar *strict_value;
+ const char *strict_value;
struct dkim_check_result *first, *cur = NULL;
struct dkim_ctx *dkim_module_ctx = dkim_get_context(res->task->cfg);
struct rspamd_task *task = res->task;
if (dkim_module_ctx->dkim_domains != NULL) {
/* Perform strict check */
- const gchar *domain = rspamd_dkim_get_domain(cur->ctx);
+ const char *domain = rspamd_dkim_get_domain(cur->ctx);
if ((strict_value =
rspamd_match_hash_map(dkim_module_ctx->dkim_domains,
if (all_done) {
/* Create zero terminated array of results */
struct rspamd_dkim_check_result **pres;
- guint nres = 0, i = 0;
+ unsigned int nres = 0, i = 0;
DL_FOREACH(first, cur)
{
DL_FOREACH(first, cur)
{
- const gchar *symbol = NULL, *trace = NULL;
- gdouble symbol_weight = 1.0;
+ const char *symbol = NULL, *trace = NULL;
+ double symbol_weight = 1.0;
if (cur->ctx == NULL || cur->res == NULL) {
continue;
}
if (symbol != NULL) {
- const gchar *domain = rspamd_dkim_get_domain(cur->ctx);
- const gchar *selector = rspamd_dkim_get_selector(cur->ctx);
+ const char *domain = rspamd_dkim_get_domain(cur->ctx);
+ const char *selector = rspamd_dkim_get_selector(cur->ctx);
gsize tracelen;
- gchar *tracebuf;
+ char *tracebuf;
tracelen = strlen(domain) + strlen(selector) + 4;
tracebuf = rspamd_mempool_alloc(task->task_pool,
GError *err = NULL;
struct rspamd_mime_header *rh, *rh_cur;
struct dkim_check_result *res = NULL, *cur;
- guint checked = 0;
- gdouble *dmarc_checks;
+ unsigned int checked = 0;
+ double *dmarc_checks;
struct dkim_ctx *dkim_module_ctx = dkim_get_context(task->cfg);
/* Allow dmarc */
else {
/* Get key */
cur->ctx = ctx;
- const gchar *domain = rspamd_dkim_get_domain(cur->ctx);
+ const char *domain = rspamd_dkim_get_domain(cur->ctx);
if (dkim_module_ctx->trusted_only &&
(dkim_module_ctx->dkim_domains == NULL ||
struct rspamd_task *task;
lua_State *L;
rspamd_dkim_key_t *key;
- gint cbref;
+ int cbref;
};
static void
struct rspamd_dkim_check_result *res, GError *err)
{
struct rspamd_task **ptask, *task;
- const gchar *error_str = "unknown error";
+ const char *error_str = "unknown error";
gboolean success = FALSE;
task = cbd->task;
dkim_module_lua_push_verify_result(cbd, res, NULL);
}
-static gint
+static int
lua_dkim_verify_handler(lua_State *L)
{
struct rspamd_task *task = lua_check_task(L, 1);
- const gchar *sig = luaL_checkstring(L, 2);
+ const char *sig = luaL_checkstring(L, 2);
rspamd_dkim_context_t *ctx;
struct rspamd_dkim_lua_verify_cbdata *cbd;
rspamd_dkim_key_t *key;
struct rspamd_dkim_check_result *ret;
GError *err = NULL;
- const gchar *type_str = NULL;
+ const char *type_str = NULL;
enum rspamd_dkim_type type = RSPAMD_DKIM_NORMAL;
struct dkim_ctx *dkim_module_ctx;
return 2;
}
-static gint
+static int
lua_dkim_canonicalize_handler(lua_State *L)
{
gsize nlen, vlen;
- const gchar *hname = luaL_checklstring(L, 1, &nlen),
- *hvalue = luaL_checklstring(L, 2, &vlen);
- static gchar st_buf[8192];
- gchar *buf;
- guint inlen;
+ const char *hname = luaL_checklstring(L, 1, &nlen),
+ *hvalue = luaL_checklstring(L, 2, &vlen);
+ static char st_buf[8192];
+ char *buf;
+ unsigned int inlen;
gboolean allocated = FALSE;
goffset r;
#define RSPAMD_FUZZY_PLUGIN_VERSION RSPAMD_FUZZY_VERSION
-static const gint rspamd_fuzzy_hash_len = 5;
-static const gchar *M = "fuzzy check";
+static const int rspamd_fuzzy_hash_len = 5;
+static const char *M = "fuzzy check";
struct fuzzy_ctx;
struct fuzzy_mapping {
uint64_t fuzzy_flag;
- const gchar *symbol;
+ const char *symbol;
double weight;
};
struct fuzzy_rule {
struct upstream_list *servers;
- const gchar *symbol;
- const gchar *algorithm_str;
- const gchar *name;
+ const char *symbol;
+ const char *algorithm_str;
+ const char *name;
const ucl_object_t *ucl_obj;
enum rspamd_shingle_alg alg;
GHashTable *mappings;
GPtrArray *fuzzy_headers;
GString *hash_key;
GString *shingles_key;
- gdouble io_timeout;
+ double io_timeout;
struct rspamd_cryptobox_keypair *local_key;
struct rspamd_cryptobox_pubkey *peer_key;
double max_score;
gboolean skip_unknown;
gboolean no_share;
gboolean no_subject;
- gint learn_condition_cb;
+ int learn_condition_cb;
uint32_t retransmits;
struct rspamd_hash_map_helper *skip_map;
struct fuzzy_ctx *ctx;
- gint lua_id;
+ int lua_id;
};
struct fuzzy_ctx {
rspamd_mempool_t *fuzzy_pool;
GPtrArray *fuzzy_rules;
struct rspamd_config *cfg;
- const gchar *default_symbol;
+ const char *default_symbol;
struct rspamd_radix_map_helper *whitelist;
struct rspamd_keypair_cache *keypairs_cache;
- guint max_errors;
- gdouble revive_time;
- gdouble io_timeout;
- gint check_mime_part_ref; /* Lua callback */
- gint process_rule_ref; /* Lua callback */
- gint cleanup_rules_ref;
+ unsigned int max_errors;
+ double revive_time;
+ double io_timeout;
+ int check_mime_part_ref; /* Lua callback */
+ int process_rule_ref; /* Lua callback */
+ int cleanup_rules_ref;
uint32_t retransmits;
gboolean enabled;
};
};
struct fuzzy_client_result {
- const gchar *symbol;
- gchar *option;
- gdouble score;
- gdouble prob;
+ const char *symbol;
+ char *option;
+ double score;
+ double prob;
enum fuzzy_result_type type;
};
struct fuzzy_rule *rule;
struct ev_loop *event_loop;
struct rspamd_io_ev ev;
- gint state;
- gint fd;
- guint retransmits;
+ int state;
+ int fd;
+ unsigned int retransmits;
};
struct fuzzy_learn_session {
GPtrArray *commands;
- gint *saved;
+ int *saved;
struct {
- const gchar *error_message;
- gint error_code;
+ const char *error_message;
+ int error_code;
} err;
struct rspamd_http_connection_entry *http_entry;
struct rspamd_async_session *session;
struct rspamd_task *task;
struct ev_loop *event_loop;
struct rspamd_io_ev ev;
- gint fd;
- guint retransmits;
+ int fd;
+ unsigned int retransmits;
};
#define FUZZY_CMD_FLAG_REPLIED (1 << 0)
void *unused);
/* Initialization */
-gint fuzzy_check_module_init(struct rspamd_config *cfg,
- struct module_ctx **ctx);
-gint fuzzy_check_module_config(struct rspamd_config *cfg, bool valdate);
-gint fuzzy_check_module_reconfig(struct rspamd_config *cfg);
-static gint fuzzy_attach_controller(struct module_ctx *ctx,
- GHashTable *commands);
-static gint fuzzy_lua_learn_handler(lua_State *L);
-static gint fuzzy_lua_unlearn_handler(lua_State *L);
-static gint fuzzy_lua_gen_hashes_handler(lua_State *L);
-static gint fuzzy_lua_hex_hashes_handler(lua_State *L);
-static gint fuzzy_lua_list_storages(lua_State *L);
-static gint fuzzy_lua_ping_storage(lua_State *L);
+int fuzzy_check_module_init(struct rspamd_config *cfg,
+ struct module_ctx **ctx);
+int fuzzy_check_module_config(struct rspamd_config *cfg, bool valdate);
+int fuzzy_check_module_reconfig(struct rspamd_config *cfg);
+static int fuzzy_attach_controller(struct module_ctx *ctx,
+ GHashTable *commands);
+static int fuzzy_lua_learn_handler(lua_State *L);
+static int fuzzy_lua_unlearn_handler(lua_State *L);
+static int fuzzy_lua_gen_hashes_handler(lua_State *L);
+static int fuzzy_lua_hex_hashes_handler(lua_State *L);
+static int fuzzy_lua_list_storages(lua_State *L);
+static int fuzzy_lua_ping_storage(lua_State *L);
module_t fuzzy_check_module = {
"fuzzy_check",
fuzzy_check_module_reconfig,
fuzzy_attach_controller,
RSPAMD_MODULE_VER,
- (guint) -1,
+ (unsigned int) -1,
};
static inline struct fuzzy_ctx *
parse_flags(struct fuzzy_rule *rule,
struct rspamd_config *cfg,
const ucl_object_t *val,
- gint cb_id)
+ int cb_id)
{
const ucl_object_t *elt;
struct fuzzy_mapping *map;
- const gchar *sym = NULL;
+ const char *sym = NULL;
if (val->type == UCL_STRING) {
msg_err_config(
}
static GPtrArray *
-parse_fuzzy_headers(struct rspamd_config *cfg, const gchar *str)
+parse_fuzzy_headers(struct rspamd_config *cfg, const char *str)
{
- gchar **strvec;
- gint num, i;
+ char **strvec;
+ int num, i;
GPtrArray *res;
strvec = g_strsplit_set(str, ",", 0);
}
}
-static gint
+static int
fuzzy_parse_rule(struct rspamd_config *cfg, const ucl_object_t *obj,
- const gchar *name, gint cb_id)
+ const char *name, int cb_id)
{
const ucl_object_t *value, *cur;
struct fuzzy_rule *rule;
it = NULL;
while ((cur = ucl_object_iterate(value, &it, value->type == UCL_ARRAY)) != NULL) {
GPtrArray *tmp;
- guint i;
+ unsigned int i;
gpointer ptr;
tmp = parse_fuzzy_headers(cfg, ucl_obj_tostring(cur));
* it allows to configure error_rate threshold and upstream dead timer
*/
rspamd_upstreams_set_limits(rule->servers,
- (gdouble) fuzzy_module_ctx->revive_time, NAN, NAN, NAN,
- (guint) fuzzy_module_ctx->max_errors, 0);
+ (double) fuzzy_module_ctx->revive_time, NAN, NAN, NAN,
+ (unsigned int) fuzzy_module_ctx->max_errors, 0);
rspamd_mempool_add_destructor(cfg->cfg_pool,
(rspamd_mempool_destruct_t) rspamd_upstreams_destroy,
/*
* Process rule in Lua
*/
- gint err_idx, ret;
+ int err_idx, ret;
lua_State *L = (lua_State *) cfg->lua_state;
lua_pushcfunction(L, &rspamd_lua_traceback);
return 0;
}
-gint fuzzy_check_module_init(struct rspamd_config *cfg, struct module_ctx **ctx)
+int fuzzy_check_module_init(struct rspamd_config *cfg, struct module_ctx **ctx)
{
struct fuzzy_ctx *fuzzy_module_ctx;
return 0;
}
-gint fuzzy_check_module_config(struct rspamd_config *cfg, bool validate)
+int fuzzy_check_module_config(struct rspamd_config *cfg, bool validate)
{
const ucl_object_t *value, *cur, *elt;
ucl_object_iter_t it;
- gint res = TRUE, cb_id, nrules = 0;
+ int res = TRUE, cb_id, nrules = 0;
lua_State *L = cfg->lua_state;
struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context(cfg);
return res;
}
-gint fuzzy_check_module_reconfig(struct rspamd_config *cfg)
+int fuzzy_check_module_reconfig(struct rspamd_config *cfg)
{
struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context(cfg);
if (fuzzy_module_ctx->cleanup_rules_ref != -1) {
/* Sync lua_fuzzy rules */
- gint err_idx, ret;
+ int err_idx, ret;
lua_State *L = (lua_State *) cfg->lua_state;
lua_pushcfunction(L, &rspamd_lua_traceback);
static void
fuzzy_encrypt_cmd(struct fuzzy_rule *rule,
struct rspamd_fuzzy_encrypted_req_hdr *hdr,
- guchar *data, gsize datalen)
+ unsigned char *data, gsize datalen)
{
- const guchar *pk;
- guint pklen;
+ const unsigned char *pk;
+ unsigned int pklen;
g_assert(hdr != NULL);
g_assert(data != NULL);
static struct fuzzy_cmd_io *
fuzzy_cmd_stat(struct fuzzy_rule *rule,
int c,
- gint flag,
+ int flag,
uint32_t weight,
rspamd_mempool_t *pool)
{
memcpy(&io->cmd, cmd, sizeof(io->cmd));
if (rule->peer_key && enccmd) {
- fuzzy_encrypt_cmd(rule, &enccmd->hdr, (guchar *) cmd, sizeof(*cmd));
+ fuzzy_encrypt_cmd(rule, &enccmd->hdr, (unsigned char *) cmd, sizeof(*cmd));
io->io.iov_base = enccmd;
io->io.iov_len = sizeof(*enccmd);
}
memcpy(&io->cmd, cmd, sizeof(io->cmd));
if (rule->peer_key && enccmd) {
- fuzzy_encrypt_cmd(rule, &enccmd->hdr, (guchar *) cmd, sizeof(*cmd));
+ fuzzy_encrypt_cmd(rule, &enccmd->hdr, (unsigned char *) cmd, sizeof(*cmd));
io->io.iov_base = enccmd;
io->io.iov_len = sizeof(*enccmd);
}
fuzzy_cmd_hash(struct fuzzy_rule *rule,
int c,
const rspamd_ftok_t *hash,
- gint flag,
+ int flag,
uint32_t weight,
rspamd_mempool_t *pool)
{
memcpy(&io->cmd, cmd, sizeof(io->cmd));
if (rule->peer_key && enccmd) {
- fuzzy_encrypt_cmd(rule, &enccmd->hdr, (guchar *) cmd, sizeof(*cmd));
+ fuzzy_encrypt_cmd(rule, &enccmd->hdr, (unsigned char *) cmd, sizeof(*cmd));
io->io.iov_base = enccmd;
io->io.iov_len = sizeof(*enccmd);
}
struct rspamd_cached_shingles {
struct rspamd_shingle *sh;
- guchar digest[rspamd_cryptobox_HASHBYTES];
- guint additional_length;
- guchar *additional_data;
+ unsigned char digest[rspamd_cryptobox_HASHBYTES];
+ unsigned int additional_length;
+ unsigned char *additional_data;
};
struct rspamd_task *task,
struct rspamd_mime_part *mp)
{
- gchar key[32];
- gint key_part;
+ char key[32];
+ int key_part;
struct rspamd_cached_shingles **cached;
memcpy(&key_part, rule->shingles_key->str, sizeof(key_part));
struct rspamd_mime_part *mp,
struct rspamd_cached_shingles *data)
{
- gchar key[32];
- gint key_part;
+ char key[32];
+ int key_part;
struct rspamd_cached_shingles **cached;
memcpy(&key_part, rule->shingles_key->str, sizeof(key_part));
{
lua_State *L = (lua_State *) task->cfg->lua_state;
- gint old_top = lua_gettop(L);
+ int old_top = lua_gettop(L);
if (rule->lua_id != -1 && rule->ctx->check_mime_part_ref != -1) {
- gint err_idx, ret;
+ int err_idx, ret;
struct rspamd_task **ptask;
struct rspamd_mime_part **ppart;
#define MAX_FUZZY_DOMAIN 64
-static guint
+static unsigned int
fuzzy_cmd_extension_length(struct rspamd_task *task,
struct fuzzy_rule *rule)
{
- guint total = 0;
+ unsigned int total = 0;
if (rule->no_share) {
return 0;
return total;
}
-static guint
+static unsigned int
fuzzy_cmd_write_extensions(struct rspamd_task *task,
struct fuzzy_rule *rule,
- guchar *dest,
+ unsigned char *dest,
gsize available)
{
- guint written = 0;
+ unsigned int written = 0;
if (rule->no_share) {
return 0;
struct rspamd_email_address *addr = g_ptr_array_index(MESSAGE_FIELD(task,
from_mime),
0);
- guint to_write = MIN(MAX_FUZZY_DOMAIN, addr->domain_len) + 2;
+ unsigned int to_write = MIN(MAX_FUZZY_DOMAIN, addr->domain_len) + 2;
if (to_write > 0 && to_write <= available) {
*dest++ = RSPAMD_FUZZY_EXT_SOURCE_DOMAIN;
if (task->from_addr && rspamd_inet_address_get_af(task->from_addr) == AF_INET) {
if (available >= sizeof(struct in_addr) + 1) {
- guint klen;
- guchar *inet_data = rspamd_inet_address_get_hash_key(task->from_addr, &klen);
+ unsigned int klen;
+ unsigned char *inet_data = rspamd_inet_address_get_hash_key(task->from_addr, &klen);
*dest++ = RSPAMD_FUZZY_EXT_SOURCE_IP4;
}
else if (task->from_addr && rspamd_inet_address_get_af(task->from_addr) == AF_INET6) {
if (available >= sizeof(struct in6_addr) + 1) {
- guint klen;
- guchar *inet_data = rspamd_inet_address_get_hash_key(task->from_addr, &klen);
+ unsigned int klen;
+ unsigned char *inet_data = rspamd_inet_address_get_hash_key(task->from_addr, &klen);
*dest++ = RSPAMD_FUZZY_EXT_SOURCE_IP6;
fuzzy_cmd_from_text_part(struct rspamd_task *task,
struct fuzzy_rule *rule,
int c,
- gint flag,
+ int flag,
uint32_t weight,
gboolean short_text,
struct rspamd_mime_text_part *part,
struct rspamd_fuzzy_encrypted_cmd *enccmd = NULL;
struct rspamd_cached_shingles *cached = NULL;
struct rspamd_shingle *sh = NULL;
- guint i;
+ unsigned int i;
rspamd_cryptobox_hash_state_t st;
rspamd_stat_token_t *word;
GArray *words;
struct fuzzy_cmd_io *io;
- guint additional_length;
- guchar *additional_data;
+ unsigned int additional_length;
+ unsigned char *additional_data;
cached = fuzzy_cmd_get_cached(rule, task, mp);
memcpy(cmd->digest, cached->digest,
sizeof(cached->digest));
cmd->shingles_count = 0;
- memcpy(((guchar *) enccmd) + sizeof(*enccmd), additional_data,
+ memcpy(((unsigned char *) enccmd) + sizeof(*enccmd), additional_data,
additional_length);
}
else if (cached->sh) {
memcpy(&shcmd->sgl, cached->sh, sizeof(struct rspamd_shingle));
memcpy(shcmd->basic.digest, cached->digest,
sizeof(cached->digest));
- memcpy(((guchar *) encshcmd) + sizeof(*encshcmd), additional_data,
+ memcpy(((unsigned char *) encshcmd) + sizeof(*encshcmd), additional_data,
additional_length);
shcmd->basic.shingles_count = RSPAMD_SHINGLE_SIZE;
}
* occasional encryption
*/
cached->additional_length = additional_length;
- cached->additional_data = ((guchar *) cached) + sizeof(*cached);
+ cached->additional_data = ((unsigned char *) cached) + sizeof(*cached);
if (additional_length > 0) {
fuzzy_cmd_write_extensions(task, rule, cached->additional_data,
memcpy(cached->digest, cmd->digest, sizeof(cached->digest));
cached->sh = NULL;
- additional_data = ((guchar *) enccmd) + sizeof(*enccmd);
+ additional_data = ((unsigned char *) enccmd) + sizeof(*enccmd);
memcpy(additional_data, cached->additional_data, additional_length);
}
else {
cached->sh = sh;
memcpy(cached->digest, shcmd->basic.digest, sizeof(cached->digest));
- additional_data = ((guchar *) encshcmd) + sizeof(*encshcmd);
+ additional_data = ((unsigned char *) encshcmd) + sizeof(*encshcmd);
memcpy(additional_data, cached->additional_data, additional_length);
}
if (rule->peer_key) {
/* Encrypt data */
if (!short_text) {
- fuzzy_encrypt_cmd(rule, &encshcmd->hdr, (guchar *) shcmd,
+ fuzzy_encrypt_cmd(rule, &encshcmd->hdr, (unsigned char *) shcmd,
sizeof(*shcmd) + additional_length);
io->io.iov_base = encshcmd;
io->io.iov_len = sizeof(*encshcmd) + additional_length;
}
else {
- fuzzy_encrypt_cmd(rule, &enccmd->hdr, (guchar *) cmd,
+ fuzzy_encrypt_cmd(rule, &enccmd->hdr, (unsigned char *) cmd,
sizeof(*cmd) + additional_length);
io->io.iov_base = enccmd;
io->io.iov_len = sizeof(*enccmd) + additional_length;
static struct fuzzy_cmd_io *
fuzzy_cmd_from_image_part (struct fuzzy_rule *rule,
int c,
- gint flag,
+ int flag,
uint32_t weight,
struct rspamd_task *task,
struct rspamd_image *img,
}
rspamd_cryptobox_hash (shcmd->basic.digest,
- (const guchar *)img->dct, RSPAMD_DCT_LEN / NBBY,
+ (const unsigned char *)img->dct, RSPAMD_DCT_LEN / NBBY,
rule->hash_key->str, rule->hash_key->len);
msg_debug_task ("loading shingles of type %s with key %*xs",
if (rule->peer_key) {
/* Encrypt data */
- fuzzy_encrypt_cmd (rule, &encshcmd->hdr, (guchar *) shcmd, sizeof (*shcmd));
+ fuzzy_encrypt_cmd (rule, &encshcmd->hdr, (unsigned char *) shcmd, sizeof (*shcmd));
io->io.iov_base = encshcmd;
io->io.iov_len = sizeof (*encshcmd);
}
static struct fuzzy_cmd_io *
fuzzy_cmd_from_data_part(struct fuzzy_rule *rule,
int c,
- gint flag,
+ int flag,
uint32_t weight,
struct rspamd_task *task,
- guchar digest[rspamd_cryptobox_HASHBYTES],
+ unsigned char digest[rspamd_cryptobox_HASHBYTES],
struct rspamd_mime_part *mp)
{
struct rspamd_fuzzy_cmd *cmd;
struct rspamd_fuzzy_encrypted_cmd *enccmd = NULL;
struct fuzzy_cmd_io *io;
- guint additional_length;
- guchar *additional_data;
+ unsigned int additional_length;
+ unsigned char *additional_data;
additional_length = fuzzy_cmd_extension_length(task, rule);
enccmd = rspamd_mempool_alloc0(task->task_pool,
sizeof(*enccmd) + additional_length);
cmd = &enccmd->cmd;
- additional_data = ((guchar *) enccmd) + sizeof(*enccmd);
+ additional_data = ((unsigned char *) enccmd) + sizeof(*enccmd);
}
else {
cmd = rspamd_mempool_alloc0(task->task_pool,
sizeof(*cmd) + additional_length);
- additional_data = ((guchar *) cmd) + sizeof(*cmd);
+ additional_data = ((unsigned char *) cmd) + sizeof(*cmd);
}
cmd->cmd = c;
if (rule->peer_key) {
g_assert(enccmd != NULL);
- fuzzy_encrypt_cmd(rule, &enccmd->hdr, (guchar *) cmd,
+ fuzzy_encrypt_cmd(rule, &enccmd->hdr, (unsigned char *) cmd,
sizeof(*cmd) + additional_length);
io->io.iov_base = enccmd;
io->io.iov_len = sizeof(*enccmd) + additional_length;
}
static gboolean
-fuzzy_cmd_to_wire(gint fd, struct iovec *io)
+fuzzy_cmd_to_wire(int fd, struct iovec *io)
{
struct msghdr msg;
}
static gboolean
-fuzzy_cmd_vector_to_wire(gint fd, GPtrArray *v)
+fuzzy_cmd_vector_to_wire(int fd, GPtrArray *v)
{
- guint i;
+ unsigned int i;
gboolean all_sent = TRUE, all_replied = TRUE;
struct fuzzy_cmd_io *io;
gboolean processed = FALSE;
* Read replies one-by-one and remove them from req array
*/
static const struct rspamd_fuzzy_reply *
-fuzzy_process_reply(guchar **pos, gint *r, GPtrArray *req,
+fuzzy_process_reply(unsigned char **pos, int *r, GPtrArray *req,
struct fuzzy_rule *rule, struct rspamd_fuzzy_cmd **pcmd,
struct fuzzy_cmd_io **pio)
{
- guchar *p = *pos;
- gint remain = *r;
- guint i, required_size;
+ unsigned char *p = *pos;
+ int remain = *r;
+ unsigned int i, required_size;
struct fuzzy_cmd_io *io;
const struct rspamd_fuzzy_reply *rep;
struct rspamd_fuzzy_encrypted_reply encrep;
required_size = sizeof(*rep);
}
- if (remain <= 0 || (guint) remain < required_size) {
+ if (remain <= 0 || (unsigned int) remain < required_size) {
return NULL;
}
rspamd_keypair_cache_process(rule->ctx->keypairs_cache,
rule->local_key, rule->peer_key);
- if (!rspamd_cryptobox_decrypt_nm_inplace((guchar *) &encrep.rep,
+ if (!rspamd_cryptobox_decrypt_nm_inplace((unsigned char *) &encrep.rep,
sizeof(encrep.rep),
encrep.hdr.nonce,
rspamd_pubkey_get_nm(rule->peer_key, rule->local_key),
const struct rspamd_fuzzy_reply *rep,
struct rspamd_fuzzy_cmd *cmd,
struct fuzzy_cmd_io *io,
- guint flag)
+ unsigned int flag)
{
- const gchar *symbol;
+ const char *symbol;
struct fuzzy_mapping *map;
struct rspamd_task *task = session->task;
double weight;
double nval;
- guchar buf[2048];
- const gchar *type = "bin";
+ unsigned char buf[2048];
+ const char *type = "bin";
struct fuzzy_client_result *res;
gboolean is_fuzzy = FALSE;
- gchar hexbuf[rspamd_cryptobox_HASHBYTES * 2 + 1];
+ char hexbuf[rspamd_cryptobox_HASHBYTES * 2 + 1];
/* Discriminate scores for small images */
- static const guint short_image_limit = 32 * 1024;
+ static const unsigned int short_image_limit = 32 * 1024;
/* Get mapping by flag */
if ((map =
if (map != NULL || !session->rule->skip_unknown) {
GList *fuzzy_var;
rspamd_fstring_t *hex_result;
- gchar timebuf[64];
+ char timebuf[64];
struct tm tm_split;
if (session->rule->skip_map) {
"%.2f, probability %.2f, in list: %s:%d%s; added on %s",
type,
hexbuf,
- (gint) sizeof(cmd->digest), cmd->digest,
+ (int) sizeof(cmd->digest), cmd->digest,
nval,
- (gdouble) rep->v1.prob,
+ (double) rep->v1.prob,
symbol,
rep->v1.flag,
map == NULL ? "(unknown)" : "",
type,
hexbuf,
nval,
- (gdouble) rep->v1.prob,
+ (double) rep->v1.prob,
symbol,
rep->v1.flag,
map == NULL ? "(unknown)" : "",
sizeof(buf),
"%d:%*s:%.2f:%s",
rep->v1.flag,
- (gint) MIN(rspamd_fuzzy_hash_len * 2, sizeof(rep->digest) * 2), hexbuf,
+ (int) MIN(rspamd_fuzzy_hash_len * 2, sizeof(rep->digest) * 2), hexbuf,
rep->v1.prob,
type);
res->option = rspamd_mempool_strdup(task->task_pool, buf);
}
}
-static gint
+static int
fuzzy_check_try_read(struct fuzzy_client_session *session)
{
struct rspamd_task *task;
const struct rspamd_fuzzy_reply *rep;
struct rspamd_fuzzy_cmd *cmd = NULL;
struct fuzzy_cmd_io *io = NULL;
- gint r, ret;
- guchar buf[2048], *p;
+ int r, ret;
+ unsigned char buf[2048], *p;
task = session->task;
GPtrArray *results)
{
struct fuzzy_client_result *res;
- guint i;
+ unsigned int i;
gboolean seen_text_hash = FALSE,
seen_img_hash = FALSE,
seen_text_part = FALSE,
seen_long_text = FALSE;
- gdouble prob_txt = 0.0, mult;
+ double prob_txt = 0.0, mult;
struct rspamd_mime_text_part *tp;
/* About 5 words */
}
}
- gdouble weight = res->score * mult;
+ double weight = res->score * mult;
if (!isnan(rule->weight_threshold)) {
if (weight >= rule->weight_threshold) {
fuzzy_check_session_is_completed(struct fuzzy_client_session *session)
{
struct fuzzy_cmd_io *io;
- guint nreplied = 0, i;
+ unsigned int nreplied = 0, i;
rspamd_upstream_ok(session->server);
/* Fuzzy check timeout callback */
static void
-fuzzy_check_timer_callback(gint fd, short what, void *arg)
+fuzzy_check_timer_callback(int fd, short what, void *arg)
{
struct fuzzy_client_session *session = arg;
struct rspamd_task *task;
/* Fuzzy check callback */
static void
-fuzzy_check_io_callback(gint fd, short what, void *arg)
+fuzzy_check_io_callback(int fd, short what, void *arg)
{
struct fuzzy_client_session *session = arg;
struct rspamd_task *task;
- gint r;
+ int r;
enum {
return_error = 0,
/* Controller IO */
static void
-fuzzy_controller_timer_callback(gint fd, short what, void *arg)
+fuzzy_controller_timer_callback(int fd, short what, void *arg)
{
struct fuzzy_learn_session *session = arg;
struct rspamd_task *task;
}
static void
-fuzzy_controller_io_callback(gint fd, short what, void *arg)
+fuzzy_controller_io_callback(int fd, short what, void *arg)
{
struct fuzzy_learn_session *session = arg;
const struct rspamd_fuzzy_reply *rep;
struct fuzzy_mapping *map;
struct rspamd_task *task;
- guchar buf[2048], *p;
+ unsigned char buf[2048], *p;
struct fuzzy_cmd_io *io;
struct rspamd_fuzzy_cmd *cmd = NULL;
- const gchar *symbol, *ftype;
- gint r;
+ const char *symbol, *ftype;
+ int r;
enum {
return_error = 0,
return_want_more,
return_finished
} ret = return_want_more;
- guint i, nreplied;
- const gchar *op = "process";
+ unsigned int i, nreplied;
+ const char *op = "process";
task = session->task;
"message <%s>",
op,
ftype,
- (gint) sizeof(rep->digest), rep->digest,
+ (int) sizeof(rep->digest), rep->digest,
symbol,
rep->v1.flag,
MESSAGE_FIELD_CHECK(session->task, message_id));
ftype,
op,
MESSAGE_FIELD_CHECK(session->task, message_id),
- (gint) sizeof(rep->digest), rep->digest,
+ (int) sizeof(rep->digest), rep->digest,
symbol,
rep->v1.flag);
ftype,
op,
MESSAGE_FIELD_CHECK(session->task, message_id),
- (gint) sizeof(rep->digest), rep->digest,
+ (int) sizeof(rep->digest), rep->digest,
symbol,
rep->v1.flag,
rep->v1.value);
if (session->http_entry) {
ucl_object_t *reply, *hashes;
- gchar hexbuf[rspamd_cryptobox_HASHBYTES * 2 + 1];
+ char hexbuf[rspamd_cryptobox_HASHBYTES * 2 + 1];
reply = ucl_object_typed_new(UCL_OBJECT);
io = g_ptr_array_index(session->commands, i);
rspamd_snprintf(hexbuf, sizeof(hexbuf), "%*xs",
- (gint) sizeof(io->cmd.digest), io->cmd.digest);
+ (int) sizeof(io->cmd.digest), io->cmd.digest);
ucl_array_append(hashes, ucl_object_fromstring(hexbuf));
}
static GPtrArray *
fuzzy_generate_commands(struct rspamd_task *task, struct fuzzy_rule *rule,
- gint c, gint flag, uint32_t value, guint flags)
+ int c, int flag, uint32_t value, unsigned int flags)
{
struct rspamd_mime_text_part *part;
struct rspamd_mime_part *mime_part;
struct rspamd_image *image;
struct fuzzy_cmd_io *io, *cur;
- guint i, j;
+ unsigned int i, j;
GPtrArray *res = NULL;
gboolean check_part, fuzzy_check;
if (lua_spec->type == RSPAMD_LUA_PART_TABLE) {
lua_State *L = (lua_State *) task->cfg->lua_state;
- gint old_top;
+ int old_top;
old_top = lua_gettop(L);
/* Push table */
lua_gettable(L, -2);
if (lua_type(L, -1) == LUA_TTABLE) {
- gint tbl_pos = lua_gettop(L);
+ int tbl_pos = lua_gettop(L);
for (lua_pushnil(L); lua_next(L, tbl_pos);
lua_pop(L, 1)) {
- const gchar *h = NULL;
+ const char *h = NULL;
gsize hlen = 0;
if (lua_isstring(L, -1)) {
io = fuzzy_cmd_from_data_part(rule, c,
flag, value,
task,
- (guchar *) h,
+ (unsigned char *) h,
mime_part);
if (io) {
struct fuzzy_client_session *session;
struct upstream *selected;
rspamd_inet_addr_t *addr;
- gint sock;
+ int sock;
if (!rspamd_session_blocked(task->s)) {
/* Get upstream */
void *unused)
{
struct fuzzy_rule *rule;
- guint i;
+ unsigned int i;
GPtrArray *commands;
struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context(task->cfg);
void fuzzy_stat_command(struct rspamd_task *task)
{
struct fuzzy_rule *rule;
- guint i;
+ unsigned int i;
GPtrArray *commands;
struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context(task->cfg);
}
}
-static inline gint
+static inline int
register_fuzzy_controller_call(struct rspamd_http_connection_entry *entry,
struct fuzzy_rule *rule,
struct rspamd_task *task,
GPtrArray *commands,
- gint *saved)
+ int *saved)
{
struct fuzzy_learn_session *s;
struct upstream *selected;
rspamd_inet_addr_t *addr;
struct rspamd_controller_session *session = entry->ud;
- gint sock;
- gint ret = -1;
+ int sock;
+ int ret = -1;
/* Get upstream */
static void
fuzzy_process_handler(struct rspamd_http_connection_entry *conn_ent,
- struct rspamd_http_message *msg, gint cmd, gint value, gint flag,
- struct fuzzy_ctx *ctx, gboolean is_hash, guint flags)
+ struct rspamd_http_message *msg, int cmd, int value, int flag,
+ struct fuzzy_ctx *ctx, gboolean is_hash, unsigned int flags)
{
struct fuzzy_rule *rule;
struct rspamd_controller_session *session = conn_ent->ud;
struct rspamd_task *task, **ptask;
gboolean processed = FALSE, skip = FALSE;
- gint res = 0;
- guint i;
+ int res = 0;
+ unsigned int i;
GPtrArray *commands;
lua_State *L;
- gint r, *saved, rules = 0, err_idx;
+ int r, *saved, rules = 0, err_idx;
struct fuzzy_ctx *fuzzy_module_ctx;
/* Prepare task */
task = rspamd_task_new(session->wrk, session->cfg, NULL,
session->lang_det, conn_ent->rt->event_loop, FALSE);
task->cfg = ctx->cfg;
- saved = rspamd_mempool_alloc0(session->pool, sizeof(gint));
+ saved = rspamd_mempool_alloc0(session->pool, sizeof(int));
fuzzy_module_ctx = fuzzy_get_context(ctx->cfg);
if (!is_hash) {
msg_info_task("learn condition changed flag from %d to "
"%d",
flag,
- (gint) lua_tonumber(L, err_idx + 2));
+ (int) lua_tonumber(L, err_idx + 2));
flag = lua_tonumber(L, err_idx + 2);
}
}
if (is_hash) {
GPtrArray *args;
const rspamd_ftok_t *arg;
- guint j;
+ unsigned int j;
args = rspamd_http_message_find_header_multiple(msg, "Hash");
static int
fuzzy_controller_handler(struct rspamd_http_connection_entry *conn_ent,
- struct rspamd_http_message *msg, struct module_ctx *ctx, gint cmd,
+ struct rspamd_http_message *msg, struct module_ctx *ctx, int cmd,
gboolean is_hash)
{
const rspamd_ftok_t *arg;
/* Search flag by symbol */
if (arg) {
struct fuzzy_rule *rule;
- guint i;
+ unsigned int i;
GHashTableIter it;
gpointer k, v;
struct fuzzy_mapping *map;
return 0;
}
-static inline gint
+static inline int
fuzzy_check_send_lua_learn(struct fuzzy_rule *rule,
struct rspamd_task *task,
GPtrArray *commands,
- gint *saved)
+ int *saved)
{
struct fuzzy_learn_session *s;
struct upstream *selected;
rspamd_inet_addr_t *addr;
- gint sock;
- gint ret = -1;
+ int sock;
+ int ret = -1;
/* Get upstream */
if (!rspamd_session_blocked(task->s)) {
static gboolean
fuzzy_check_lua_process_learn(struct rspamd_task *task,
- gint cmd, gint value, gint flag, guint send_flags)
+ int cmd, int value, int flag, unsigned int send_flags)
{
struct fuzzy_rule *rule;
gboolean processed = FALSE, res = TRUE;
- guint i;
+ unsigned int i;
GPtrArray *commands;
- gint *saved, rules = 0;
+ int *saved, rules = 0;
struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context(task->cfg);
- saved = rspamd_mempool_alloc0(task->task_pool, sizeof(gint));
+ saved = rspamd_mempool_alloc0(task->task_pool, sizeof(int));
PTR_ARRAY_FOREACH(fuzzy_module_ctx->fuzzy_rules, i, rule)
{
return TRUE;
}
-static gint
+static int
fuzzy_lua_learn_handler(lua_State *L)
{
struct rspamd_task *task = lua_check_task(L, 1);
return luaL_error(L, "invalid arguments");
}
- guint flag = 0, weight = 1, send_flags = 0;
- const gchar *symbol;
+ unsigned int flag = 0, weight = 1, send_flags = 0;
+ const char *symbol;
struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context(task->cfg);
if (lua_type(L, 2) == LUA_TNUMBER) {
}
else if (lua_type(L, 2) == LUA_TSTRING) {
struct fuzzy_rule *rule;
- guint i;
+ unsigned int i;
GHashTableIter it;
gpointer k, v;
struct fuzzy_mapping *map;
}
if (lua_type(L, 4) == LUA_TTABLE) {
- const gchar *sf;
+ const char *sf;
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
sf = lua_tostring(L, -1);
return 1;
}
-static gint
+static int
fuzzy_lua_unlearn_handler(lua_State *L)
{
struct rspamd_task *task = lua_check_task(L, 1);
return luaL_error(L, "invalid arguments");
}
- guint flag = 0, weight = 1.0, send_flags = 0;
- const gchar *symbol;
+ unsigned int flag = 0, weight = 1.0, send_flags = 0;
+ const char *symbol;
struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context(task->cfg);
if (lua_type(L, 2) == LUA_TNUMBER) {
}
else if (lua_type(L, 2) == LUA_TSTRING) {
struct fuzzy_rule *rule;
- guint i;
+ unsigned int i;
GHashTableIter it;
gpointer k, v;
struct fuzzy_mapping *map;
}
if (lua_type(L, 4) == LUA_TTABLE) {
- const gchar *sf;
+ const char *sf;
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
sf = lua_tostring(L, -1);
return 1;
}
-static gint
+static int
fuzzy_lua_gen_hashes_handler(lua_State *L)
{
struct rspamd_task *task = lua_check_task(L, 1);
return luaL_error(L, "invalid arguments");
}
- guint flag = 0, weight = 1, send_flags = 0;
- const gchar *symbol;
+ unsigned int flag = 0, weight = 1, send_flags = 0;
+ const char *symbol;
struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context(task->cfg);
struct fuzzy_rule *rule;
GPtrArray *commands;
- gint cmd = FUZZY_WRITE;
- gint i;
+ int cmd = FUZZY_WRITE;
+ int i;
if (lua_type(L, 2) == LUA_TNUMBER) {
flag = lua_tonumber(L, 2);
/* Flags */
if (lua_type(L, 4) == LUA_TTABLE) {
- const gchar *sf;
+ const char *sf;
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
sf = lua_tostring(L, -1);
/* Type */
if (lua_type(L, 5) == LUA_TSTRING) {
- const gchar *cmd_name = lua_tostring(L, 5);
+ const char *cmd_name = lua_tostring(L, 5);
if (strcmp(cmd_name, "add") == 0 || strcmp(cmd_name, "write") == 0) {
cmd = FUZZY_WRITE;
if (commands != NULL) {
struct fuzzy_cmd_io *io;
- gint j;
+ int j;
lua_pushstring(L, rule->name);
lua_createtable(L, commands->len, 0);
return 1;
}
-static gint
+static int
fuzzy_lua_hex_hashes_handler(lua_State *L)
{
struct rspamd_task *task = lua_check_task(L, 1);
return luaL_error(L, "invalid arguments");
}
- guint flag = 0, weight = 1, send_flags = 0;
- const gchar *symbol;
+ unsigned int flag = 0, weight = 1, send_flags = 0;
+ const char *symbol;
struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context(task->cfg);
struct fuzzy_rule *rule;
GPtrArray *commands;
- gint i;
+ int i;
if (lua_type(L, 2) == LUA_TNUMBER) {
flag = lua_tonumber(L, 2);
* get hex hashes
*/
struct rspamd_mime_part *mp;
- gint j, part_idx = 1;
+ int j, part_idx = 1;
PTR_ARRAY_FOREACH(MESSAGE_FIELD(task, parts), j, mp)
{
cached = fuzzy_cmd_get_cached(rule, task, mp);
if (cached) {
- gchar hexbuf[rspamd_cryptobox_HASHBYTES * 2 + 1];
- gint r = rspamd_encode_hex_buf(cached->digest, sizeof(cached->digest), hexbuf,
- sizeof(hexbuf));
+ char hexbuf[rspamd_cryptobox_HASHBYTES * 2 + 1];
+ int r = rspamd_encode_hex_buf(cached->digest, sizeof(cached->digest), hexbuf,
+ sizeof(hexbuf));
lua_pushlstring(L, hexbuf, r);
lua_rawseti(L, -2, part_idx++);
}
/* TODO: move to a separate unit, as this file is now a bit too hard to read */
static void
-lua_upstream_str_inserter(struct upstream *up, guint idx, void *ud)
+lua_upstream_str_inserter(struct upstream *up, unsigned int idx, void *ud)
{
lua_State *L = (lua_State *) ud;
lua_rawseti(L, -2, idx + 1);
}
-static gint
+static int
fuzzy_lua_list_storages(lua_State *L)
{
struct rspamd_config *cfg = lua_check_config(L, 1);
struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context(cfg);
struct fuzzy_rule *rule;
- guint i;
+ unsigned int i;
lua_createtable(L, 0, fuzzy_module_ctx->fuzzy_rules->len);
PTR_ARRAY_FOREACH(fuzzy_module_ctx->fuzzy_rules, i, rule)
GPtrArray *commands;
struct fuzzy_rule *rule;
struct rspamd_io_ev ev;
- gint cbref;
- gint fd;
+ int cbref;
+ int fd;
};
static void
fuzzy_lua_session_is_completed(struct fuzzy_lua_session *session)
{
struct fuzzy_cmd_io *io;
- guint nreplied = 0, i;
+ unsigned int nreplied = 0, i;
for (i = 0; i < session->commands->len; i++) {
}
static void
-fuzzy_lua_push_result(struct fuzzy_lua_session *session, gdouble latency)
+fuzzy_lua_push_result(struct fuzzy_lua_session *session, double latency)
{
lua_rawgeti(session->L, LUA_REGISTRYINDEX, session->cbref);
lua_pushboolean(session->L, TRUE);
#ifdef __GNUC__
static void
-fuzzy_lua_push_error(struct fuzzy_lua_session *session, const gchar *err_fmt, ...) __attribute__((format(printf, 2, 3)));
+fuzzy_lua_push_error(struct fuzzy_lua_session *session, const char *err_fmt, ...) __attribute__((format(printf, 2, 3)));
#endif
static void
-fuzzy_lua_push_error(struct fuzzy_lua_session *session, const gchar *err_fmt, ...)
+fuzzy_lua_push_error(struct fuzzy_lua_session *session, const char *err_fmt, ...)
{
va_list v;
lua_pcall(session->L, 3, 0, 0);
}
-static gint
+static int
fuzzy_lua_try_read(struct fuzzy_lua_session *session)
{
const struct rspamd_fuzzy_reply *rep;
struct rspamd_fuzzy_cmd *cmd = NULL;
struct fuzzy_cmd_io *io = NULL;
- gint r, ret;
- guchar buf[2048], *p;
+ int r, ret;
+ unsigned char buf[2048], *p;
if ((r = read(session->fd, buf, sizeof(buf) - 1)) == -1) {
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
/* Fuzzy check callback */
static void
-fuzzy_lua_io_callback(gint fd, short what, void *arg)
+fuzzy_lua_io_callback(int fd, short what, void *arg)
{
struct fuzzy_lua_session *session = arg;
- gint r;
+ int r;
enum {
return_error = 0,
* @function fuzzy_check.ping_storage(task, callback, rule, timeout[, server_override])
* @return
*/
-static gint
+static int
fuzzy_lua_ping_storage(lua_State *L)
{
struct rspamd_task *task = lua_check_task(L, 1);
rspamd_inet_addr_t *addr = NULL;
if (lua_type(L, 5) == LUA_TSTRING) {
- const gchar *server_name = lua_tostring(L, 5);
+ const char *server_name = lua_tostring(L, 5);
enum rspamd_parse_host_port_result res;
GPtrArray *addrs = g_ptr_array_new();
struct regexp_module_item {
uint64_t magic;
struct rspamd_expression *expr;
- const gchar *symbol;
+ const char *symbol;
struct ucl_lua_funcdata *lua_function;
};
/* Initialization */
-gint regexp_module_init(struct rspamd_config *cfg, struct module_ctx **ctx);
-gint regexp_module_config(struct rspamd_config *cfg, bool validate);
-gint regexp_module_reconfig(struct rspamd_config *cfg);
+int regexp_module_init(struct rspamd_config *cfg, struct module_ctx **ctx);
+int regexp_module_config(struct rspamd_config *cfg, bool validate);
+int regexp_module_reconfig(struct rspamd_config *cfg);
module_t regexp_module = {
"regexp",
regexp_module_reconfig,
NULL,
RSPAMD_MODULE_VER,
- (guint) -1,
+ (unsigned int) -1,
};
static gboolean
read_regexp_expression(rspamd_mempool_t *pool,
struct regexp_module_item *chain,
- const gchar *symbol,
- const gchar *line,
+ const char *symbol,
+ const char *line,
struct rspamd_mime_expr_ud *ud)
{
struct rspamd_expression *e = NULL;
/* Init function */
-gint regexp_module_init(struct rspamd_config *cfg, struct module_ctx **ctx)
+int regexp_module_init(struct rspamd_config *cfg, struct module_ctx **ctx)
{
struct regexp_ctx *regexp_module_ctx;
return 0;
}
-gint regexp_module_config(struct rspamd_config *cfg, bool validate)
+int regexp_module_config(struct rspamd_config *cfg, bool validate)
{
struct regexp_ctx *regexp_module_ctx = regexp_get_context(cfg);
struct regexp_module_item *cur_item = NULL;
const ucl_object_t *sec, *value, *elt;
ucl_object_iter_t it = NULL;
- gint res = TRUE, nre = 0, nlua = 0, nshots = cfg->default_max_shots;
+ int res = TRUE, nre = 0, nlua = 0, nshots = cfg->default_max_shots;
if (!rspamd_config_is_module_enabled(cfg, "regexp")) {
return TRUE;
nlua++;
}
else if (value->type == UCL_OBJECT) {
- const gchar *description = NULL, *group = NULL;
- gdouble score = 0.0;
- guint flags = 0, priority = 0;
+ const char *description = NULL, *group = NULL;
+ double score = 0.0;
+ unsigned int flags = 0, priority = 0;
gboolean is_lua = FALSE, valid_expression = TRUE;
struct rspamd_mime_expr_ud ud;
return res;
}
-gint regexp_module_reconfig(struct rspamd_config *cfg)
+int regexp_module_reconfig(struct rspamd_config *cfg)
{
return regexp_module_config(cfg, false);
}
static gboolean
rspamd_lua_call_expression_func(struct ucl_lua_funcdata *lua_data,
struct rspamd_task *task,
- GArray *args, gdouble *res,
- const gchar *symbol)
+ GArray *args, double *res,
+ const char *symbol)
{
lua_State *L = lua_data->L;
struct rspamd_task **ptask;
struct expression_argument *arg;
- gint pop = 0, i, nargs = 0;
+ int pop = 0, i, nargs = 0;
lua_rawgeti(L, LUA_REGISTRYINDEX, lua_data->idx);
/* Now we got function in top of stack */
/* Now push all arguments */
if (args) {
- for (i = 0; i < (gint) args->len; i++) {
+ for (i = 0; i < (int) args->len; i++) {
arg = &g_array_index(args, struct expression_argument, i);
if (arg) {
switch (arg->type) {
case EXPRESSION_ARGUMENT_NORMAL:
- lua_pushstring(L, (const gchar *) arg->data);
+ lua_pushstring(L, (const char *) arg->data);
break;
case EXPRESSION_ARGUMENT_BOOL:
lua_pushboolean(L, (gboolean) GPOINTER_TO_SIZE(arg->data));
void *user_data)
{
struct regexp_module_item *item = user_data;
- gdouble res = FALSE;
+ double res = FALSE;
/* Non-threaded version */
if (item->lua_function) {
%% write data;
gboolean
-rspamd_rfc2047_parser (const gchar *in, gsize len, gint *pencoding,
- const gchar **charset, gsize *charset_len,
- const gchar **encoded, gsize *encoded_len)
+rspamd_rfc2047_parser (const char *in, gsize len, int *pencoding,
+ const char **charset, gsize *charset_len,
+ const char **encoded, gsize *encoded_len)
{
const char *p = in, *pe = in + len,
*encoded_start = NULL, *encoded_end = NULL,
*charset_start = NULL, *charset_end = NULL,
*eof = in + len;
- gint encoding = RSPAMD_RFC2047_QP, cs = 0;
+ int encoding = RSPAMD_RFC2047_QP, cs = 0;
%% write init;
%% write exec;
const unsigned char *p = data, *pe = data + len, *eof = data + len, *tmp = data;
struct tm tm;
glong tz = 0;
- gint cs = 0, *stack = NULL;;
+ int cs = 0, *stack = NULL;;
gsize top = 0;
memset (&tm, 0, sizeof (tm));
const char *p = data, *pe = data + len, *eof = data + len;
const char *ip_start = NULL, *ip_end = NULL;
gboolean in_v6 = FALSE;
- gint cs = 0;
+ int cs = 0;
%% write init;
%% write exec;
const struct rspamadm_command *
-rspamadm_search_command(const gchar *name, GPtrArray *all_commands)
+rspamadm_search_command(const char *name, GPtrArray *all_commands)
{
const struct rspamadm_command *ret = NULL, *cmd;
- const gchar *alias;
- guint i, j;
+ const char *alias;
+ unsigned int i, j;
if (name == NULL) {
name = "help";
void rspamadm_fill_internal_commands(GPtrArray *dest)
{
- guint i;
+ unsigned int i;
for (i = 0; i < G_N_ELEMENTS(commands); i++) {
if (commands[i]) {
}
static void
-rspamadm_lua_command_run(gint argc, gchar **argv,
+rspamadm_lua_command_run(int argc, char **argv,
const struct rspamadm_command *cmd)
{
struct thread_entry *thread = lua_thread_pool_get_for_config(rspamd_main->cfg);
lua_State *L = thread->lua_state;
- gint table_idx = GPOINTER_TO_INT(cmd->command_data);
- gint i;
+ int table_idx = GPOINTER_TO_INT(cmd->command_data);
+ int i;
/* Function */
lua_rawgeti(L, LUA_REGISTRYINDEX, table_idx);
lua_settop(L, 0);
}
-static const gchar *
+static const char *
rspamadm_lua_command_help(gboolean full_help,
const struct rspamadm_command *cmd)
{
- gint table_idx = GPOINTER_TO_INT(cmd->command_data);
+ int table_idx = GPOINTER_TO_INT(cmd->command_data);
if (full_help) {
struct thread_entry *thread = lua_thread_pool_get_for_config(rspamd_main->cfg);
void rspamadm_fill_lua_commands(lua_State *L, GPtrArray *dest)
{
- gint i;
+ int i;
GPtrArray *lua_paths;
GError *err = NULL;
- const gchar *lualibdir = RSPAMD_LUALIBDIR, *path;
+ const char *lualibdir = RSPAMD_LUALIBDIR, *path;
struct rspamadm_command *lua_cmd;
- gchar search_dir[PATH_MAX];
+ char search_dir[PATH_MAX];
if (g_hash_table_lookup(ucl_vars, "LUALIBDIR")) {
lualibdir = g_hash_table_lookup(ucl_vars, "LUALIBDIR");
}
else {
goffset ext_pos;
- gchar *name;
+ char *name;
name = g_path_get_basename(path);
/* Remove .lua */
static gboolean symbol_groups_only = FALSE;
static gboolean symbol_full_details = FALSE;
static gboolean skip_template = FALSE;
-static gchar *config = NULL;
+static char *config = NULL;
extern struct rspamd_main *rspamd_main;
/* Defined in modules.c */
extern module_t *modules[];
extern worker_t *workers[];
-static void rspamadm_configdump(gint argc, gchar **argv, const struct rspamadm_command *);
+static void rspamadm_configdump(int argc, char **argv, const struct rspamadm_command *);
static const char *rspamadm_configdump_help(gboolean full_help, const struct rspamadm_command *);
struct rspamadm_command configdump_command = {
}
__attribute__((noreturn)) static void
-rspamadm_configdump(gint argc, gchar **argv, const struct rspamadm_command *cmd)
+rspamadm_configdump(int argc, char **argv, const struct rspamadm_command *cmd)
{
GOptionContext *context;
GError *error = NULL;
- const gchar *confdir;
+ const char *confdir;
const ucl_object_t *obj = NULL, *cur, *doc_obj;
struct rspamd_config *cfg = rspamd_main->cfg;
gboolean ret = TRUE;
worker_t **pworker;
- gint i;
+ int i;
context = g_option_context_new(
"configdump - dumps Rspamd configuration");
const ucl_object_t *all_symbols_ucl = ucl_object_lookup(cfg->cfg_ucl_obj, "symbols");
while (g_hash_table_iter_next(&it, &sk, &sv)) {
- const gchar *sym_name = (const gchar *) sk;
+ const char *sym_name = (const char *) sk;
struct rspamd_symbol *s = (struct rspamd_symbol *) sv;
ucl_object_t *this_sym_ucl = ucl_object_typed_new(UCL_OBJECT);
if (s->groups) {
ucl_object_t *add_groups = ucl_object_typed_new(UCL_ARRAY);
- guint j;
+ unsigned int j;
struct rspamd_symbols_group *add_gr;
bool has_extra_groups = false;
g_hash_table_iter_init(&it, cfg->groups);
while (g_hash_table_iter_next(&it, &k, &v)) {
- const gchar *gr_name = (const gchar *) k;
+ const char *gr_name = (const char *) k;
struct rspamd_symbols_group *gr = (struct rspamd_symbols_group *) v;
ucl_object_t *gr_ucl = ucl_object_typed_new(UCL_OBJECT);
ucl_object_t *sym_ucl = ucl_object_typed_new(UCL_OBJECT);
while (g_hash_table_iter_next(&sit, &sk, &sv)) {
- const gchar *sym_name = (const gchar *) sk;
+ const char *sym_name = (const char *) sk;
struct rspamd_symbol *s = (struct rspamd_symbol *) sv;
ucl_object_t *spec_sym = ucl_object_typed_new(UCL_OBJECT);
}
ucl_object_t *add_groups = ucl_object_typed_new(UCL_ARRAY);
- guint j;
+ unsigned int j;
struct rspamd_symbols_group *add_gr;
PTR_ARRAY_FOREACH(s->groups, j, add_gr)
static gboolean json = FALSE;
static gboolean compact = FALSE;
static gboolean keyword = FALSE;
-static const gchar *plugins_path = RSPAMD_PLUGINSDIR;
+static const char *plugins_path = RSPAMD_PLUGINSDIR;
extern struct rspamd_main *rspamd_main;
/* Defined in modules.c */
extern module_t *modules[];
extern worker_t *workers[];
-static void rspamadm_confighelp(gint argc, gchar **argv,
+static void rspamadm_confighelp(int argc, char **argv,
const struct rspamadm_command *cmd);
static const char *rspamadm_confighelp_help(gboolean full_help,
}
static void
-rspamadm_confighelp_show(struct rspamd_config *cfg, gint argc, gchar **argv,
+rspamadm_confighelp_show(struct rspamd_config *cfg, int argc, char **argv,
const char *key, const ucl_object_t *obj)
{
rspamd_fstring_t *out;
static void
rspamadm_confighelp_search_word_step(const ucl_object_t *obj,
ucl_object_t *res,
- const gchar *str,
+ const char *str,
gsize len,
GString *path)
{
ucl_object_iter_t it = NULL;
const ucl_object_t *cur, *elt;
- const gchar *dot_pos;
+ const char *dot_pos;
while ((cur = ucl_object_iterate(obj, &it, true)) != NULL) {
if (cur->keylen > 0) {
}
static ucl_object_t *
-rspamadm_confighelp_search_word(const ucl_object_t *obj, const gchar *str)
+rspamadm_confighelp_search_word(const ucl_object_t *obj, const char *str)
{
gsize len = strlen(str);
GString *path = g_string_new("");
}
__attribute__((noreturn)) static void
-rspamadm_confighelp(gint argc, gchar **argv, const struct rspamadm_command *cmd)
+rspamadm_confighelp(int argc, char **argv, const struct rspamadm_command *cmd)
{
struct rspamd_config *cfg;
ucl_object_t *doc_obj;
module_t *mod, **pmod;
worker_t **pworker;
struct module_ctx *mod_ctx;
- gint i, ret = 0, processed_args = 0;
+ int i, ret = 0, processed_args = 0;
context = g_option_context_new(
"confighelp - displays help for the configuration options");
#include "lua/lua_common.h"
static gboolean quiet = FALSE;
-static gchar *config = NULL;
+static char *config = NULL;
static gboolean strict = FALSE;
static gboolean skip_template = FALSE;
extern struct rspamd_main *rspamd_main;
extern module_t *modules[];
extern worker_t *workers[];
-static void rspamadm_configtest(gint argc, gchar **argv,
+static void rspamadm_configtest(int argc, char **argv,
const struct rspamadm_command *cmd);
static const char *rspamadm_configtest_help(gboolean full_help,
const struct rspamadm_command *cmd);
}
static void
-rspamadm_configtest(gint argc, gchar **argv, const struct rspamadm_command *cmd)
+rspamadm_configtest(int argc, char **argv, const struct rspamadm_command *cmd)
{
GOptionContext *context;
GError *error = NULL;
- const gchar *confdir;
+ const char *confdir;
struct rspamd_config *cfg = rspamd_main->cfg;
gboolean ret = TRUE;
worker_t **pworker;
g_option_context_free(context);
if (config == NULL) {
- static gchar fbuf[PATH_MAX];
+ static char fbuf[PATH_MAX];
if ((confdir = g_hash_table_lookup(ucl_vars, "CONFDIR")) == NULL) {
confdir = RSPAMD_CONFDIR;
#include "libutil/util.h"
#include "lua/lua_common.h"
-static gchar *control_path = RSPAMD_DBDIR "/rspamd.sock";
+static char *control_path = RSPAMD_DBDIR "/rspamd.sock";
static gboolean json = FALSE;
static gboolean ucl = TRUE;
static gboolean compact = FALSE;
-static gdouble timeout = 1.0;
+static double timeout = 1.0;
-static void rspamadm_control(gint argc, gchar **argv,
+static void rspamadm_control(int argc, char **argv,
const struct rspamadm_command *cmd);
static const char *rspamadm_control_help(gboolean full_help,
const struct rspamadm_command *cmd);
};
struct rspamadm_control_cbdata {
- const gchar *path;
- gint argc;
- gchar **argv;
+ const char *path;
+ int argc;
+ char **argv;
};
static GOptionEntry entries[] = {
ev_break(rspamd_main->event_loop, EVBREAK_ALL);
}
-static gint
+static int
rspamd_control_finish_handler(struct rspamd_http_connection *conn,
struct rspamd_http_message *msg)
{
struct ucl_parser *parser;
ucl_object_t *obj;
rspamd_fstring_t *out;
- const gchar *body;
+ const char *body;
gsize body_len;
struct rspamadm_control_cbdata *cbdata = conn->ud;
}
static void
-rspamadm_control(gint argc, gchar **argv, const struct rspamadm_command *_cmd)
+rspamadm_control(int argc, char **argv, const struct rspamadm_command *_cmd)
{
GOptionContext *context;
GError *error = NULL;
- const gchar *cmd, *path = NULL;
+ const char *cmd, *path = NULL;
struct rspamd_http_connection *conn;
struct rspamd_http_message *msg;
rspamd_inet_addr_t *addr;
#include "rspamadm.h"
#include "lua/lua_common.h"
-static gchar *source_db = NULL;
-static gchar *redis_host = NULL;
-static gchar *redis_db = NULL;
-static gchar *redis_username = NULL;
-static gchar *redis_password = NULL;
+static char *source_db = NULL;
+static char *redis_host = NULL;
+static char *redis_db = NULL;
+static char *redis_username = NULL;
+static char *redis_password = NULL;
static int64_t fuzzy_expiry = 0;
-static void rspamadm_fuzzyconvert(gint argc, gchar **argv,
+static void rspamadm_fuzzyconvert(int argc, char **argv,
const struct rspamadm_command *cmd);
static const char *rspamadm_fuzzyconvert_help(gboolean full_help,
const struct rspamadm_command *cmd);
}
static void
-rspamadm_fuzzyconvert(gint argc, gchar **argv, const struct rspamadm_command *cmd)
+rspamadm_fuzzyconvert(int argc, char **argv, const struct rspamadm_command *cmd)
{
GOptionContext *context;
GError *error = NULL;
#include <luajit.h>
#endif
-static gchar **paths = NULL;
-static gchar **scripts = NULL;
-static gchar **lua_args = NULL;
-static gchar *histfile = NULL;
-static guint max_history = 2000;
-static gchar *serve = NULL;
-static gchar *exec_line = NULL;
-static gint batch = -1;
+static char **paths = NULL;
+static char **scripts = NULL;
+static char **lua_args = NULL;
+static char *histfile = NULL;
+static unsigned int max_history = 2000;
+static char *serve = NULL;
+static char *exec_line = NULL;
+static int batch = -1;
extern struct rspamd_async_session *rspamadm_session;
static const char *default_history_file = ".rspamd_repl.hist";
#endif
#define MULTILINE_PROMPT "... "
-static void rspamadm_lua(gint argc, gchar **argv,
+static void rspamadm_lua(int argc, char **argv,
const struct rspamadm_command *cmd);
static const char *rspamadm_lua_help(gboolean full_help,
const struct rspamadm_command *cmd);
/*
* Dot commands
*/
-typedef void (*rspamadm_lua_dot_handler)(lua_State *L, gint argc, gchar **argv);
+typedef void (*rspamadm_lua_dot_handler)(lua_State *L, int argc, char **argv);
struct rspamadm_lua_dot_command {
- const gchar *name;
- const gchar *description;
+ const char *name;
+ const char *description;
rspamadm_lua_dot_handler handler;
};
-static void rspamadm_lua_help_handler(lua_State *L, gint argc, gchar **argv);
-static void rspamadm_lua_load_handler(lua_State *L, gint argc, gchar **argv);
-static void rspamadm_lua_exec_handler(lua_State *L, gint argc, gchar **argv);
-static void rspamadm_lua_message_handler(lua_State *L, gint argc, gchar **argv);
+static void rspamadm_lua_help_handler(lua_State *L, int argc, char **argv);
+static void rspamadm_lua_load_handler(lua_State *L, int argc, char **argv);
+static void rspamadm_lua_exec_handler(lua_State *L, int argc, char **argv);
+static void rspamadm_lua_message_handler(lua_State *L, int argc, char **argv);
static void lua_thread_error_cb(struct thread_entry *thread, int ret, const char *msg);
static void lua_thread_finish_cb(struct thread_entry *thread, int ret);
}
static void
-rspamadm_lua_add_path(lua_State *L, const gchar *path)
+rspamadm_lua_add_path(lua_State *L, const char *path)
{
- const gchar *old_path;
+ const char *old_path;
gsize len;
GString *new_path;
}
static gboolean
-rspamadm_lua_load_script(lua_State *L, const gchar *path)
+rspamadm_lua_load_script(lua_State *L, const char *path)
{
struct thread_entry *thread = lua_thread_pool_get_for_config(rspamd_main->cfg);
L = thread->lua_state;
}
static void
-rspamadm_exec_input(lua_State *L, const gchar *input)
+rspamadm_exec_input(lua_State *L, const char *input)
{
GString *tb;
- gint i, cbref;
+ int i, cbref;
int top = 0;
- gchar outbuf[8192];
+ char outbuf[8192];
struct lua_logger_trace tr;
struct thread_entry *thread = lua_thread_pool_get_for_config(rspamd_main->cfg);
msg_debug("finished events waiting, terminating session");
}
-gint lua_repl_thread_call(struct thread_entry *thread, gint narg, gpointer ud, lua_thread_error_t error_func)
+int lua_repl_thread_call(struct thread_entry *thread, int narg, gpointer ud, lua_thread_error_t error_func)
{
int ret;
struct lua_call_data *cd = g_new0(struct lua_call_data, 1);
}
static void
-rspamadm_lua_help_handler(lua_State *L, gint argc, gchar **argv)
+rspamadm_lua_help_handler(lua_State *L, int argc, char **argv)
{
- guint i;
+ unsigned int i;
struct rspamadm_lua_dot_command *cmd;
if (argv[1] == NULL) {
}
static void
-rspamadm_lua_load_handler(lua_State *L, gint argc, gchar **argv)
+rspamadm_lua_load_handler(lua_State *L, int argc, char **argv)
{
- guint i;
+ unsigned int i;
gboolean ret;
for (i = 1; argv[i] != NULL; i++) {
}
static void
-rspamadm_lua_exec_handler(lua_State *L, gint argc, gchar **argv)
+rspamadm_lua_exec_handler(lua_State *L, int argc, char **argv)
{
- gint i;
+ int i;
struct thread_entry *thread = lua_thread_pool_get_for_config(rspamd_main->cfg);
L = thread->lua_state;
}
static void
-rspamadm_lua_message_handler(lua_State *L, gint argc, gchar **argv)
+rspamadm_lua_message_handler(lua_State *L, int argc, char **argv)
{
gulong cbref;
- gint old_top, func_idx, i, j;
+ int old_top, func_idx, i, j;
struct rspamd_task *task, **ptask;
gpointer map;
gsize len;
- gchar outbuf[8192];
+ char outbuf[8192];
struct lua_logger_trace tr;
if (argv[1] == NULL) {
static gboolean
-rspamadm_lua_try_dot_command(lua_State *L, const gchar *input)
+rspamadm_lua_try_dot_command(lua_State *L, const char *input)
{
struct rspamadm_lua_dot_command *cmd;
- gchar **argv;
+ char **argv;
argv = g_strsplit_set(input + 1, " ", -1);
}
#ifdef WITH_LUA_REPL
-static gint lex_ref_idx = -1;
+static int lex_ref_idx = -1;
static void
lua_syntax_highlighter(const char *str, ReplxxColor *colours, int size, void *ud)
* 3 - line num (int), always 1...
* 4 - column num (must be less than size)
*/
- const gchar *what;
+ const char *what;
gsize column, tlen, cur_top, elt_pos;
ReplxxColor elt_color = REPLXX_COLOR_DEFAULT;
static void
rspamadm_lua_run_repl(lua_State *L, bool is_batch)
{
- gchar *input = NULL;
+ char *input = NULL;
#ifdef WITH_LUA_REPL
gboolean is_multiline = FALSE;
GString *tb = NULL;
L);
if (!is_multiline) {
- input = (gchar *) replxx_input(rx_instance, MAIN_PROMPT);
+ input = (char *) replxx_input(rx_instance, MAIN_PROMPT);
if (input == NULL) {
return;
lua_settop(L, 0);
}
else {
- input = (gchar *) replxx_input(rx_instance, MULTILINE_PROMPT);
+ input = (char *) replxx_input(rx_instance, MULTILINE_PROMPT);
if (input == NULL) {
g_string_free(tb, TRUE);
struct rspamd_http_connection_router *rt;
rspamd_inet_addr_t *addr;
struct rspamadm_lua_repl_context *ctx;
- gint sock;
+ int sock;
};
static void
(struct rspamadm_lua_repl_context *) w->data;
rspamd_inet_addr_t *addr = NULL;
struct rspamadm_lua_repl_session *session;
- gint nfd;
+ int nfd;
if ((nfd =
rspamd_accept_from_socket(w->fd, &addr, NULL, NULL)) == -1) {
struct rspamd_http_message *msg)
{
GString *tb;
- gint err_idx, i;
+ int err_idx, i;
lua_State *L;
ucl_object_t *obj, *elt;
- const gchar *body;
+ const char *body;
gsize body_len;
struct thread_entry *thread = lua_thread_pool_get_for_config(rspamd_main->cfg);
/* First try return + input */
tb = g_string_sized_new(body_len + sizeof("return "));
- rspamd_printf_gstring(tb, "return %*s", (gint) body_len, body);
+ rspamd_printf_gstring(tb, "return %*s", (int) body_len, body);
if (luaL_loadstring(L, tb->str) != 0) {
/* Reset stack */
}
static void
-rspamadm_lua(gint argc, gchar **argv, const struct rspamadm_command *cmd)
+rspamadm_lua(int argc, char **argv, const struct rspamadm_command *cmd)
{
GOptionContext *context;
GError *error = NULL;
- gchar **elt;
- guint i;
+ char **elt;
+ unsigned int i;
lua_State *L = rspamd_main->cfg->lua_state;
context = g_option_context_new("lua - run lua interpreter");
if (serve) {
/* HTTP Server mode */
GPtrArray *addrs = NULL;
- gchar *name = NULL;
+ char *name = NULL;
struct ev_loop *ev_base;
struct rspamd_http_connection_router *http;
- gint fd;
+ int fd;
struct rspamadm_lua_repl_context *ctx;
if (rspamd_parse_host_port_priority(serve, &addrs, NULL, &name,
}
if (histfile == NULL) {
- const gchar *homedir;
+ const char *homedir;
GString *hist_path;
homedir = getenv("HOME");
#include "rspamadm.h"
#include "unix-std.h"
-static void rspamadm_pw(gint argc, gchar **argv,
+static void rspamadm_pw(int argc, char **argv,
const struct rspamadm_command *cmd);
static const char *rspamadm_pw_help(gboolean full_help,
const struct rspamadm_command *cmd);
static gboolean do_check = FALSE;
static gboolean quiet = FALSE;
static gboolean list = FALSE;
-static gchar *type = "catena";
-static gchar *password = NULL;
+static char *type = "catena";
+static char *password = NULL;
struct rspamadm_command pw_command = {
.name = "pw",
rspamadm_get_pbkdf(void)
{
const struct rspamd_controller_pbkdf *pbkdf;
- guint i;
+ unsigned int i;
for (i = 0; i < RSPAMD_PBKDF_ID_MAX - 1; i++) {
pbkdf = &pbkdf_list[i];
rspamadm_pw_encrypt(char *password)
{
const struct rspamd_controller_pbkdf *pbkdf;
- guchar *salt, *key;
- gchar *encoded_salt, *encoded_key;
+ unsigned char *salt, *key;
+ char *encoded_salt, *encoded_key;
GString *result;
gsize plen;
return password;
}
-static const gchar *
-rspamd_encrypted_password_get_str(const gchar *password, gsize skip,
+static const char *
+rspamd_encrypted_password_get_str(const char *password, gsize skip,
gsize *length)
{
- const gchar *str, *start, *end;
+ const char *str, *start, *end;
gsize size;
start = password + skip;
rspamadm_pw_check(void)
{
const struct rspamd_controller_pbkdf *pbkdf = NULL;
- const gchar *salt, *hash;
- const gchar *start, *end;
- guchar *salt_decoded, *key_decoded, *local_key;
+ const char *salt, *hash;
+ const char *start, *end;
+ unsigned char *salt_decoded, *key_decoded, *local_key;
gsize salt_len, key_len, size;
- gchar test_password[8192], encrypted_password[8192];
+ char test_password[8192], encrypted_password[8192];
gsize plen, i;
- gint id;
+ int id;
gboolean ret = FALSE;
if (password == NULL) {
}
if (size > 0) {
- gchar *endptr;
+ char *endptr;
id = strtoul(start, &endptr, 10);
if ((endptr == NULL || *endptr == *end)) {
}
}
-static gint
+static int
rspamadm_pw_lua_encrypt(lua_State *L)
{
- const gchar *pw_in = NULL;
- gchar *ret, *tmp = NULL;
+ const char *pw_in = NULL;
+ char *ret, *tmp = NULL;
if (lua_type(L, 1) == LUA_TSTRING) {
pw_in = lua_tostring(L, 1);
rspamadm_alg_list(void)
{
const struct rspamd_controller_pbkdf *pbkdf;
- guint i;
+ unsigned int i;
for (i = 0; i < RSPAMD_PBKDF_ID_MAX - 1; i++) {
pbkdf = &pbkdf_list[i];
}
static void
-rspamadm_pw(gint argc, gchar **argv, const struct rspamadm_command *cmd)
+rspamadm_pw(int argc, char **argv, const struct rspamadm_command *cmd)
{
GOptionContext *context;
GError *error = NULL;
}
if (do_encrypt) {
- gchar *encr = rspamadm_pw_encrypt(password);
+ char *encr = rspamadm_pw_encrypt(password);
rspamd_printf("%s\n", encr);
g_free(encr);
}
static gboolean show_help = FALSE;
static gboolean show_version = FALSE;
GHashTable *ucl_vars = NULL;
-gchar **lua_env = NULL;
+char **lua_env = NULL;
struct rspamd_main *rspamd_main = NULL;
struct rspamd_async_session *rspamadm_session = NULL;
lua_State *L = NULL;
extern module_t *modules[];
extern worker_t *workers[];
-static void rspamadm_help(gint argc, gchar **argv, const struct rspamadm_command *);
+static void rspamadm_help(int argc, char **argv, const struct rspamadm_command *);
static const char *rspamadm_help_help(gboolean full_help, const struct rspamadm_command *);
struct rspamadm_command help_command = {
.help = rspamadm_help_help,
.run = rspamadm_help};
-static gboolean rspamadm_parse_ucl_var(const gchar *option_name,
- const gchar *value, gpointer data,
+static gboolean rspamadm_parse_ucl_var(const char *option_name,
+ const char *value, gpointer data,
GError **error);
static void
rspamadm_usage(GOptionContext *context)
{
- gchar *help_str;
+ char *help_str;
help_str = g_option_context_get_help(context, TRUE, NULL);
rspamd_printf("%s", help_str);
rspamadm_commands(GPtrArray *all_commands)
{
const struct rspamadm_command *cmd;
- guint i;
+ unsigned int i;
rspamd_printf("Rspamadm %s\n", RVERSION);
rspamd_printf("Usage: rspamadm [global_options] command [command_options]\n");
}
static void
-rspamadm_help(gint argc, gchar **argv, const struct rspamadm_command *command)
+rspamadm_help(int argc, char **argv, const struct rspamadm_command *command)
{
- const gchar *cmd_name;
+ const char *cmd_name;
const struct rspamadm_command *cmd;
GPtrArray *all_commands = (GPtrArray *) command->command_data;
}
if (strcmp(cmd_name, "help") == 0) {
- guint i;
+ unsigned int i;
rspamd_printf("Available commands:\n");
PTR_ARRAY_FOREACH(all_commands, i, cmd)
}
static gboolean
-rspamadm_parse_ucl_var(const gchar *option_name,
- const gchar *value, gpointer data,
+rspamadm_parse_ucl_var(const char *option_name,
+ const char *value, gpointer data,
GError **error)
{
- gchar *k, *v, *t;
+ char *k, *v, *t;
t = strchr(value, '=');
}
gboolean
-rspamadm_execute_lua_ucl_subr(gint argc, gchar **argv,
+rspamadm_execute_lua_ucl_subr(int argc, char **argv,
const ucl_object_t *res,
- const gchar *script_name,
+ const char *script_name,
gboolean rspamadm_subcommand)
{
struct thread_entry *thread = lua_thread_pool_get_for_config(rspamd_main->cfg);
lua_State *L = thread->lua_state;
- gint i;
- gchar str[PATH_MAX];
+ int i;
+ char str[PATH_MAX];
g_assert(script_name != NULL);
g_assert(res != NULL);
return TRUE;
}
-static gint
+static int
rspamdadm_commands_sort_func(gconstpointer a, gconstpointer b)
{
const struct rspamadm_command *cmda = *((struct rspamadm_command const **) a),
}
static gboolean
-rspamadm_command_maybe_match_name(const gchar *cmd, const gchar *input)
+rspamadm_command_maybe_match_name(const char *cmd, const char *input)
{
gsize clen, inplen;
}
}
-gint main(gint argc, gchar **argv, gchar **env)
+int main(int argc, char **argv, char **env)
{
GError *error = NULL;
GOptionContext *context;
GOptionGroup *og;
struct rspamd_config *cfg;
GQuark process_quark;
- gchar **nargv, **targv;
- const gchar *cmd_name;
+ char **nargv, **targv;
+ const char *cmd_name;
const struct rspamadm_command *cmd;
struct rspamd_dns_resolver *resolver;
GPtrArray *all_commands = g_ptr_array_new_full(32,
rspamadm_cmd_dtor); /* Discovered during check */
- gint i, nargc, targc;
+ int i, nargc, targc;
worker_t **pworker;
gboolean lua_file = FALSE;
- gint retcode = 0;
+ int retcode = 0;
ucl_vars = g_hash_table_new_full(rspamd_strcase_hash,
rspamd_strcase_equal, g_free, g_free);
help_command.command_data = all_commands;
/* Now read options and store everything till the first non-dash argument */
- nargv = g_malloc0(sizeof(gchar *) * (argc + 1));
+ nargv = g_malloc0(sizeof(char *) * (argc + 1));
nargv[0] = g_strdup(argv[0]);
for (i = 1, nargc = 1; i < argc; i++) {
rspamd_fprintf(stderr, "Suggested commands:\n");
PTR_ARRAY_FOREACH(all_commands, i, cmd)
{
- guint j;
- const gchar *alias;
+ unsigned int j;
+ const char *alias;
if (rspamadm_command_maybe_match_name(cmd->name, cmd_name)) {
rspamd_fprintf(stderr, "%s\n", cmd->name);
if (nargc < argc) {
if (lua_file) {
- nargv = g_malloc0(sizeof(gchar *) * (argc - nargc + 2));
+ nargv = g_malloc0(sizeof(char *) * (argc - nargc + 2));
nargv[1] = g_strdup(argv[nargc]);
i = 2;
argc++;
}
else {
- nargv = g_malloc0(sizeof(gchar *) * (argc - nargc + 1));
+ nargv = g_malloc0(sizeof(char *) * (argc - nargc + 1));
i = 1;
}
#endif
extern GHashTable *ucl_vars;
-extern gchar **lua_env;
+extern char **lua_env;
extern struct rspamd_main *rspamd_main;
GQuark rspamadm_error(void);
struct rspamadm_command;
-typedef const gchar *(*rspamadm_help_func)(gboolean full_help,
- const struct rspamadm_command *cmd);
+typedef const char *(*rspamadm_help_func)(gboolean full_help,
+ const struct rspamadm_command *cmd);
-typedef void (*rspamadm_run_func)(gint argc, gchar **argv,
+typedef void (*rspamadm_run_func)(int argc, char **argv,
const struct rspamadm_command *cmd);
typedef void (*rspamadm_lua_exports_func)(gpointer lua_state);
#define RSPAMADM_FLAG_DYNAMIC (1u << 2u)
struct rspamadm_command {
- const gchar *name;
- guint flags;
+ const char *name;
+ unsigned int flags;
rspamadm_help_func help;
rspamadm_run_func run;
rspamadm_lua_exports_func lua_subrs;
extern const struct rspamadm_command *commands[];
extern struct rspamadm_command help_command;
-const struct rspamadm_command *rspamadm_search_command(const gchar *name,
+const struct rspamadm_command *rspamadm_search_command(const char *name,
GPtrArray *all_commands);
void rspamadm_fill_internal_commands(GPtrArray *dest);
void rspamadm_fill_lua_commands(lua_State *L, GPtrArray *dest);
-gboolean rspamadm_execute_lua_ucl_subr(gint argc, gchar **argv,
+gboolean rspamadm_execute_lua_ucl_subr(int argc, char **argv,
const ucl_object_t *res,
- const gchar *script_name,
+ const char *script_name,
gboolean rspamadm_subcommand);
struct thread_entry;
struct lua_call_data {
- gint top;
- gint ret;
+ int top;
+ int ret;
gpointer ud;
};
-gint lua_repl_thread_call(struct thread_entry *thread, gint narg,
- gpointer ud, lua_thread_error_t error_func);
+int lua_repl_thread_call(struct thread_entry *thread, int narg,
+ gpointer ud, lua_thread_error_t error_func);
#ifdef __cplusplus
}
static gboolean openssl = FALSE;
static gboolean verify = FALSE;
static gboolean quiet = FALSE;
-static gchar *suffix = NULL;
-static gchar *pubkey_file = NULL;
-static gchar *pubkey = NULL;
-static gchar *pubout = NULL;
-static gchar *keypair_file = NULL;
-static gchar *editor = NULL;
+static char *suffix = NULL;
+static char *pubkey_file = NULL;
+static char *pubkey = NULL;
+static char *pubout = NULL;
+static char *keypair_file = NULL;
+static char *editor = NULL;
static gboolean edit = FALSE;
enum rspamd_cryptobox_mode mode = RSPAMD_CRYPTOBOX_MODE_25519;
-static void rspamadm_signtool(gint argc, gchar **argv,
+static void rspamadm_signtool(int argc, char **argv,
const struct rspamadm_command *cmd);
static const char *rspamadm_signtool_help(gboolean full_help,
const struct rspamadm_command *cmd);
return help_str;
}
-static gint
-rspamadm_edit_file(const gchar *fname)
+static int
+rspamadm_edit_file(const char *fname)
{
- gchar tmppath[PATH_MAX], run_cmdline[PATH_MAX];
- guchar *map;
+ char tmppath[PATH_MAX], run_cmdline[PATH_MAX];
+ unsigned char *map;
gsize len = 0;
- gint fd_out, retcode, child_argc;
+ int fd_out, retcode, child_argc;
GPid child_pid;
- gchar *tmpdir, **child_argv = NULL;
+ char *tmpdir, **child_argv = NULL;
struct stat st;
GError *err = NULL;
}
static bool
-rspamadm_sign_file(const gchar *fname, struct rspamd_cryptobox_keypair *kp)
+rspamadm_sign_file(const char *fname, struct rspamd_cryptobox_keypair *kp)
{
- gint fd_sig, fd_input;
- guchar sig[rspamd_cryptobox_MAX_SIGBYTES], *map;
- gchar sigpath[PATH_MAX];
+ int fd_sig, fd_input;
+ unsigned char sig[rspamd_cryptobox_MAX_SIGBYTES], *map;
+ char sigpath[PATH_MAX];
FILE *pub_fp;
struct stat st;
- const guchar *sk;
+ const unsigned char *sk;
if (suffix == NULL) {
suffix = ".sig";
}
static bool
-rspamadm_verify_file(const gchar *fname, const guchar *pk)
+rspamadm_verify_file(const char *fname, const unsigned char *pk)
{
- gint fd_sig, fd_input;
- guchar *map, *map_sig;
- gchar sigpath[PATH_MAX];
+ int fd_sig, fd_input;
+ unsigned char *map, *map_sig;
+ char sigpath[PATH_MAX];
struct stat st, st_sig;
bool ret;
if (st_sig.st_size != rspamd_cryptobox_signature_bytes(mode)) {
close(fd_sig);
rspamd_fprintf(stderr, "invalid signature size %s: %ud\n", fname,
- (guint) st_sig.st_size);
+ (unsigned int) st_sig.st_size);
munmap(map, st.st_size);
exit(EXIT_FAILURE);
}
static void
-rspamadm_signtool(gint argc, gchar **argv, const struct rspamadm_command *cmd)
+rspamadm_signtool(int argc, char **argv, const struct rspamadm_command *cmd)
{
GOptionContext *context;
GError *error = NULL;
struct rspamd_cryptobox_pubkey *pk;
struct rspamd_cryptobox_keypair *kp;
gsize fsize, flen;
- gint i;
+ int i;
context = g_option_context_new(
"keypair - create encryption keys");
g_assert(pubkey || pubkey_file);
if (pubkey_file) {
- gint fd;
- gchar *map;
+ int fd;
+ char *map;
struct stat st;
fd = open(pubkey_file, O_RDONLY);
if (pk == NULL) {
rspamd_fprintf(stderr, "bad size %s: %ud, %ud expected\n",
pubkey_file,
- (guint) flen,
+ (unsigned int) flen,
rspamd_cryptobox_pk_sig_bytes(mode));
exit(EXIT_FAILURE);
}
if (pk == NULL) {
rspamd_fprintf(stderr, "bad size %s: %ud, %ud expected\n",
pubkey_file,
- (guint) strlen(pubkey),
+ (unsigned int) strlen(pubkey),
rspamd_cryptobox_pk_sig_bytes(mode));
exit(EXIT_FAILURE);
}
#include "contrib/uthash/utlist.h"
/* Common */
-static gchar *config_file = NULL;
-static gchar *symbol_ham = NULL;
-static gchar *symbol_spam = NULL;
+static char *config_file = NULL;
+static char *symbol_ham = NULL;
+static char *symbol_spam = NULL;
-static gdouble expire = 0.0;
+static double expire = 0.0;
/* Inputs */
-static gchar *spam_db = NULL;
-static gchar *ham_db = NULL;
-static gchar *cache_db = NULL;
+static char *spam_db = NULL;
+static char *ham_db = NULL;
+static char *cache_db = NULL;
/* Outputs */
-static gchar *redis_host = NULL;
-static gchar *redis_db = NULL;
-static gchar *redis_username = NULL;
-static gchar *redis_password = NULL;
+static char *redis_host = NULL;
+static char *redis_db = NULL;
+static char *redis_username = NULL;
+static char *redis_password = NULL;
static gboolean reset_previous = FALSE;
-static void rspamadm_statconvert(gint argc, gchar **argv,
+static void rspamadm_statconvert(int argc, char **argv,
const struct rspamadm_command *cmd);
static const char *rspamadm_statconvert_help(gboolean full_help,
const struct rspamadm_command *cmd);
}
static void
-rspamadm_statconvert(gint argc, gchar **argv, const struct rspamadm_command *cmd)
+rspamadm_statconvert(int argc, char **argv, const struct rspamadm_command *cmd)
{
GOptionContext *context;
GError *error = NULL;
/*
- * Copyright 2023 Vsevolod Stakhov
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
struct rspamd_worker *wrk);
/* Control socket */
-static gint control_fd;
+static int control_fd;
static ev_io control_ev;
static struct rspamd_stat old_stat;
static ev_timer stat_ev;
/* Cmdline options */
static gboolean no_fork = FALSE;
static gboolean show_version = FALSE;
-static gchar **cfg_names = NULL;
-static gchar *rspamd_user = NULL;
-static gchar *rspamd_group = NULL;
-static gchar *rspamd_pidfile = NULL;
+static char **cfg_names = NULL;
+static char *rspamd_user = NULL;
+static char *rspamd_group = NULL;
+static char *rspamd_pidfile = NULL;
static gboolean is_debug = FALSE;
static gboolean is_insecure = FALSE;
static GHashTable *ucl_vars = NULL;
-static gchar **lua_env = NULL;
+static char **lua_env = NULL;
static gboolean skip_template = FALSE;
-static gint term_attempts = 0;
+static int term_attempts = 0;
/* List of active listen sockets indexed by worker type */
static GHashTable *listen_sockets = NULL;
extern worker_t *workers[];
/* Command line options */
-static gboolean rspamd_parse_var(const gchar *option_name,
- const gchar *value, gpointer data,
+static gboolean rspamd_parse_var(const char *option_name,
+ const char *value, gpointer data,
GError **error);
static GOptionEntry entries[] =
{
{NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}};
static gboolean
-rspamd_parse_var(const gchar *option_name,
- const gchar *value, gpointer data,
+rspamd_parse_var(const char *option_name,
+ const char *value, gpointer data,
GError **error)
{
- gchar *k, *v, *t;
+ char *k, *v, *t;
t = strchr(value, '=');
}
static void
-read_cmd_line(gint *argc, gchar ***argv, struct rspamd_config *cfg)
+read_cmd_line(int *argc, char ***argv, struct rspamd_config *cfg)
{
GError *error = NULL;
GOptionContext *context;
- guint cfg_num;
+ unsigned int cfg_num;
context = g_option_context_new("- run rspamd daemon");
#if defined(GIT_VERSION) && GIT_VERSION == 1
reread_config(struct rspamd_main *rspamd_main)
{
struct rspamd_config *tmp_cfg, *old_cfg;
- gchar *cfg_file;
+ char *cfg_file;
int load_opts = RSPAMD_CONFIG_INIT_VALIDATE | RSPAMD_CONFIG_INIT_SYMCACHE |
RSPAMD_CONFIG_INIT_LIBS | RSPAMD_CONFIG_INIT_URL;
struct rspamd_main *rspamd_main;
struct ev_timer wait_ev;
struct rspamd_worker_conf *cf;
- guint oldindex;
+ unsigned int oldindex;
};
static void
static void
rspamd_fork_delayed(struct rspamd_worker_conf *cf,
- guint index,
+ unsigned int index,
struct rspamd_main *rspamd_main)
{
struct waiting_worker *nw;
}
static GList *
-create_listen_socket(GPtrArray *addrs, guint cnt,
+create_listen_socket(GPtrArray *addrs, unsigned int cnt,
enum rspamd_worker_socket_type listen_type)
{
GList *result = NULL;
- gint fd;
- guint i;
+ int fd;
+ unsigned int i;
static const int listen_opts = RSPAMD_INET_ADDRESS_LISTEN_ASYNC;
struct rspamd_worker_listen_socket *ls;
}
static GList *
-systemd_get_socket(struct rspamd_main *rspamd_main, const gchar *fdname)
+systemd_get_socket(struct rspamd_main *rspamd_main, const char *fdname)
{
int number, sock, num_passed, flags;
GList *result = NULL;
- const gchar *e;
- gchar **fdnames;
- gchar *end;
+ const char *e;
+ char **fdnames;
+ char *end;
struct stat st;
static const int sd_listen_fds_start = 3; /* SD_LISTEN_FDS_START */
struct rspamd_worker_listen_socket *ls;
struct sockaddr_in6 s6;
} addr_storage;
socklen_t slen = sizeof(addr_storage);
- gint stype;
+ int stype;
number = strtoul(fdname, &end, 10);
if (end != NULL && *end != '\0') {
pass_signal_cb(gpointer key, gpointer value, gpointer ud)
{
struct rspamd_worker *cur = value;
- gint signo = GPOINTER_TO_INT(ud);
+ int signo = GPOINTER_TO_INT(ud);
kill(cur->pid, signo);
}
static void
-rspamd_pass_signal(GHashTable *workers, gint signo)
+rspamd_pass_signal(GHashTable *workers, int signo)
{
g_hash_table_foreach(workers, pass_signal_cb, GINT_TO_POINTER(signo));
}
make_listen_key(struct rspamd_worker_bind_conf *cf)
{
rspamd_cryptobox_fast_hash_state_t st;
- guint i, keylen = 0;
- guint8 *key;
+ unsigned int i, keylen = 0;
+ uint8_t *key;
rspamd_inet_addr_t *addr;
- guint16 port;
+ uint16_t port;
rspamd_cryptobox_fast_hash_init(&st, rspamd_hash_seed());
if (cf->is_systemd) {
spawn_worker_type(struct rspamd_main *rspamd_main, struct ev_loop *event_loop,
struct rspamd_worker_conf *cf)
{
- gint i;
+ int i;
if (cf->count < 0) {
msg_info_main("skip spawning of worker %s: disabled in configuration",
gboolean listen_ok = FALSE;
GPtrArray *seen_mandatory_workers;
worker_t **cw, *wrk;
- guint i;
+ unsigned int i;
/* Special hack for hs_helper if it's not defined in a config */
seen_mandatory_workers = g_ptr_array_new();
static struct core_check_cbdata cores_cbdata;
-static gint
-rspamd_check_core_cb(const gchar *path, const struct stat *st,
- gint flag, struct FTW *ft)
+static int
+rspamd_check_core_cb(const char *path, const struct stat *st,
+ int flag, struct FTW *ft)
{
if (S_ISREG(st->st_mode)) {
cores_cbdata.total_count++;
shutdown_ts = MAX(SOFT_SHUTDOWN_TIME,
rspamd_main->cfg->task_timeout * 2.0);
msg_info_main("catch termination signal, waiting for %d children for %.2f seconds",
- (gint) g_hash_table_size(rspamd_main->workers),
+ (int) g_hash_table_size(rspamd_main->workers),
valgrind_mode ? shutdown_ts * 10 : shutdown_ts);
/* Stop srv events to avoid false notifications */
g_hash_table_foreach(rspamd_main->workers, stop_srv_ev, rspamd_main);
{
struct rspamd_main *rspamd_main = (struct rspamd_main *) w->data;
struct rspamd_stat cur_stat;
- gchar proctitle[128];
+ char proctitle[128];
memcpy(&cur_stat, rspamd_main->stat, sizeof(cur_stat));
if (old_stat.messages_scanned > 0 &&
cur_stat.messages_scanned > old_stat.messages_scanned) {
- gdouble rate = (double) (cur_stat.messages_scanned - old_stat.messages_scanned) /
- w->repeat;
- gdouble old_spam = old_stat.actions_stat[METRIC_ACTION_REJECT] +
- old_stat.actions_stat[METRIC_ACTION_ADD_HEADER] +
- old_stat.actions_stat[METRIC_ACTION_REWRITE_SUBJECT];
- gdouble old_ham = old_stat.actions_stat[METRIC_ACTION_NOACTION];
- gdouble new_spam = cur_stat.actions_stat[METRIC_ACTION_REJECT] +
- cur_stat.actions_stat[METRIC_ACTION_ADD_HEADER] +
- cur_stat.actions_stat[METRIC_ACTION_REWRITE_SUBJECT];
- gdouble new_ham = cur_stat.actions_stat[METRIC_ACTION_NOACTION];
+ double rate = (double) (cur_stat.messages_scanned - old_stat.messages_scanned) /
+ w->repeat;
+ double old_spam = old_stat.actions_stat[METRIC_ACTION_REJECT] +
+ old_stat.actions_stat[METRIC_ACTION_ADD_HEADER] +
+ old_stat.actions_stat[METRIC_ACTION_REWRITE_SUBJECT];
+ double old_ham = old_stat.actions_stat[METRIC_ACTION_NOACTION];
+ double new_spam = cur_stat.actions_stat[METRIC_ACTION_REJECT] +
+ cur_stat.actions_stat[METRIC_ACTION_ADD_HEADER] +
+ cur_stat.actions_stat[METRIC_ACTION_REWRITE_SUBJECT];
+ double new_ham = cur_stat.actions_stat[METRIC_ACTION_NOACTION];
gsize cnt = MAX_AVG_TIME_SLOTS;
float sum = rspamd_sum_floats(cur_stat.avg_time.avg_time, &cnt);
{
struct rspamd_main *rspamd_main = (struct rspamd_main *) w->data;
rspamd_inet_addr_t *addr = NULL;
- gint nfd;
+ int nfd;
if ((nfd =
rspamd_accept_from_socket(w->fd, &addr, NULL, NULL)) == -1) {
rspamd_control_process_client_socket(rspamd_main, nfd, addr);
}
-static guint
+static unsigned int
rspamd_spair_hash(gconstpointer p)
{
return rspamd_cryptobox_fast_hash(p, PAIR_ID_LEN, rspamd_hash_seed());
static void
rspamd_spair_close(gpointer p)
{
- gint *fds = p;
+ int *fds = p;
close(fds[0]);
close(fds[1]);
return TRUE;
}
-gint main(gint argc, gchar **argv, gchar **env)
+int main(int argc, char **argv, char **env)
{
- gint i, res = 0;
+ int i, res = 0;
struct sigaction signals, sigpipe_act;
worker_t **pworker;
GQuark type;
/* Parse variables */
for (i = 0; i < argc; i++) {
if (strchr(argv[i], '=') != NULL) {
- gchar *k, *v, *t;
+ char *k, *v, *t;
k = g_strdup(argv[i]);
t = strchr(k, '=');
if (event_loop) {
int loop_type = ev_backend(event_loop);
gboolean effective_backend;
- const gchar *loop_str;
+ const char *loop_str;
loop_str =
rspamd_config_ev_backend_to_string(loop_type, &effective_backend);
struct rspamd_worker {
pid_t pid; /**< pid of worker */
pid_t ppid; /**< pid of parent */
- guint index; /**< index number */
- guint nconns; /**< current connections count */
+ unsigned int index; /**< index number */
+ unsigned int nconns; /**< current connections count */
enum rspamd_worker_state state; /**< current worker state */
gboolean cores_throttled; /**< set to true if cores throttling took place */
- gdouble start_time; /**< start time */
+ double start_time; /**< start time */
struct rspamd_main *srv; /**< pointer to server structure */
GQuark type; /**< process type */
GHashTable *signal_events; /**< signal events */
struct rspamd_worker_accept_event *accept_events; /**< socket events */
struct rspamd_worker_conf *cf; /**< worker config data */
gpointer ctx; /**< worker's specific data */
- gint flags; /**< worker's flags (enum rspamd_worker_flags) */
- gint control_pipe[2]; /**< control pipe. [0] is used by main process,
+ int flags; /**< worker's flags (enum rspamd_worker_flags) */
+ int control_pipe[2]; /**< control pipe. [0] is used by main process,
[1] is used by a worker */
- gint srv_pipe[2]; /**< used by workers to request something from the
+ int srv_pipe[2]; /**< used by workers to request something from the
main process. [0] - main, [1] - worker */
ev_io srv_ev; /**< used by main for read workers' requests */
struct rspamd_worker_heartbeat hb; /**< heartbeat data */
};
struct rspamd_worker_signal_handler {
- gint signo;
+ int signo;
gboolean enabled;
ev_signal ev_sig;
struct ev_loop *event_loop;
struct module_s;
struct module_ctx {
- gint (*filter)(struct rspamd_task *task); /**< pointer to headers process function */
- struct module_s *mod; /**< module pointer */
- gboolean enabled; /**< true if module is enabled in configuration */
+ int (*filter)(struct rspamd_task *task); /**< pointer to headers process function */
+ struct module_s *mod; /**< module pointer */
+ gboolean enabled; /**< true if module is enabled in configuration */
};
#ifndef WITH_HYPERSCAN
* Module
*/
typedef struct module_s {
- const gchar *name;
+ const char *name;
int (*module_init_func)(struct rspamd_config *cfg, struct module_ctx **ctx);
int (*module_attach_controller_func)(struct module_ctx *ctx,
GHashTable *custom_commands);
- guint module_version;
+ unsigned int module_version;
uint64_t rspamd_version;
- const gchar *rspamd_features;
- guint ctx_offset;
+ const char *rspamd_features;
+ unsigned int ctx_offset;
} module_t;
enum rspamd_worker_socket_type {
struct rspamd_worker_listen_socket {
const rspamd_inet_addr_t *addr;
- gint fd;
+ int fd;
enum rspamd_worker_socket_type type;
bool is_systemd;
};
typedef struct worker_s {
- const gchar *name;
+ const char *name;
gpointer (*worker_init_func)(struct rspamd_config *cfg);
int flags;
int listen_type;
- guint worker_version;
+ unsigned int worker_version;
uint64_t rspamd_version;
- const gchar *rspamd_features;
+ const char *rspamd_features;
} worker_t;
/**
* Server statistics
*/
struct RSPAMD_ALIGNED(64) rspamd_stat {
- guint messages_scanned; /**< total number of messages scanned */
- guint actions_stat[METRIC_ACTION_MAX]; /**< statistic for each action */
- guint connections_count; /**< total connections count */
- guint control_connections_count; /**< connections count to control interface */
- guint messages_learned; /**< messages learned */
- struct rspamd_avg_time avg_time; /**< average time stats */
+ unsigned int messages_scanned; /**< total number of messages scanned */
+ unsigned int actions_stat[METRIC_ACTION_MAX]; /**< statistic for each action */
+ unsigned int connections_count; /**< total connections count */
+ unsigned int control_connections_count; /**< connections count to control interface */
+ unsigned int messages_learned; /**< messages learned */
+ struct rspamd_avg_time avg_time; /**< average time stats */
};
/**
struct controller_command;
struct controller_session;
-typedef gboolean (*controller_func_t)(gchar **args,
+typedef gboolean (*controller_func_t)(char **args,
struct controller_session *session);
struct controller_session {
struct rspamd_worker *worker; /**< pointer to worker structure (controller in fact) */
- gint sock; /**< socket descriptor */
+ int sock; /**< socket descriptor */
struct controller_command *cmd; /**< real command */
struct rspamd_config *cfg; /**< pointer to config file */
GList *parts; /**< extracted mime parts */
struct zstd_dictionary {
void *dict;
gsize size;
- guint id;
+ unsigned int id;
};
struct rspamd_external_libs_ctx {
/**
* Register custom controller function
*/
-void register_custom_controller_command(const gchar *name,
+void register_custom_controller_command(const char *name,
controller_func_t handler,
gboolean privileged,
gboolean require_message);
RSPAMD_WORKER_VER};
struct rspamd_http_upstream {
- gchar *name;
- gchar *settings_id;
+ char *name;
+ char *settings_id;
struct upstream_list *u;
struct rspamd_cryptobox_pubkey *key;
- gdouble timeout;
- gint parser_from_ref;
- gint parser_to_ref;
+ double timeout;
+ int parser_from_ref;
+ int parser_to_ref;
gboolean local;
gboolean self_scan;
gboolean compress;
};
struct rspamd_http_mirror {
- gchar *name;
- gchar *settings_id;
+ char *name;
+ char *settings_id;
struct upstream_list *u;
struct rspamd_cryptobox_pubkey *key;
- gdouble prob;
- gdouble timeout;
- gint parser_from_ref;
- gint parser_to_ref;
+ double prob;
+ double timeout;
+ int parser_from_ref;
+ int parser_to_ref;
gboolean local;
gboolean compress;
};
/* Config */
struct rspamd_config *cfg;
/* END OF COMMON PART */
- gdouble timeout;
+ double timeout;
/* Encryption key for clients */
struct rspamd_cryptobox_keypair *key;
/* HTTP context */
/* Array of callback functions called on end of scan to compare results */
GArray *cmp_refs;
/* Maximum count for retries */
- guint max_retries;
+ unsigned int max_retries;
gboolean encrypted_only;
/* If we have self_scanning backends, we need to work as a normal worker */
gboolean has_self_scan;
/* Quarantine messages instead of rejecting them */
gboolean quarantine_on_reject;
/* Milter spam header */
- gchar *spam_header;
+ char *spam_header;
/* CA name that can be used for client certificates */
- gchar *client_ca_name;
+ char *client_ca_name;
/* Milter rejection message */
- gchar *reject_message;
+ char *reject_message;
/* Sessions cache */
void *sessions_cache;
struct rspamd_milter_context milter_ctx;
/* Language detector */
struct rspamd_lang_detector *lang_det;
- gdouble task_timeout;
+ double task_timeout;
};
enum rspamd_backend_flags {
struct rspamd_proxy_session;
struct rspamd_proxy_backend_connection {
- const gchar *name;
+ const char *name;
struct rspamd_cryptobox_keypair *local_key;
struct rspamd_cryptobox_pubkey *remote_key;
struct upstream *up;
struct rspamd_http_connection *backend_conn;
ucl_object_t *results;
- const gchar *err;
+ const char *err;
struct rspamd_proxy_session *s;
- gint backend_sock;
+ int backend_sock;
ev_tstamp timeout;
enum rspamd_backend_flags flags;
- gint parser_from_ref;
- gint parser_to_ref;
+ int parser_from_ref;
+ int parser_to_ref;
struct rspamd_task *task;
};
struct rspamd_milter_session *client_milter_conn;
struct rspamd_http_upstream *backend;
gpointer map;
- gchar *fname;
+ char *fname;
gpointer shmem_ref;
struct rspamd_proxy_backend_connection *master_conn;
struct rspamd_http_message *client_message;
GPtrArray *mirror_conns;
gsize map_len;
- gint client_sock;
+ int client_sock;
enum rspamd_proxy_legacy_support legacy_support;
- gint retries;
+ int retries;
ref_entry_t ref;
};
static gboolean
rspamd_proxy_parse_lua_parser(lua_State *L, const ucl_object_t *obj,
- gint *ref_from, gint *ref_to, GError **err)
+ int *ref_from, int *ref_to, GError **err)
{
- const gchar *lua_script;
+ const char *lua_script;
gsize slen;
- gint err_idx, ref_idx;
+ int err_idx, ref_idx;
gboolean has_ref = FALSE;
g_assert(obj != NULL);
struct rspamd_proxy_ctx *ctx;
struct rspamd_rcl_struct_parser *pd = ud;
lua_State *L;
- const gchar *lua_script;
+ const char *lua_script;
gsize slen;
- gint err_idx, ref_idx;
+ int err_idx, ref_idx;
struct stat st;
ctx = pd->user_struct;
(rspamd_mempool_destruct_t) rspamd_ptr_array_free_hard, ctx->mirrors);
ctx->cfg = cfg;
ctx->lua_state = cfg->lua_state;
- ctx->cmp_refs = g_array_new(FALSE, FALSE, sizeof(gint));
+ ctx->cmp_refs = g_array_new(FALSE, FALSE, sizeof(int));
rspamd_mempool_add_destructor(cfg->cfg_pool,
(rspamd_mempool_destruct_t) rspamd_array_free_hard, ctx->cmp_refs);
ctx->max_retries = DEFAULT_RETRIES;
static gboolean
proxy_backend_parse_results(struct rspamd_proxy_session *session,
struct rspamd_proxy_backend_connection *conn,
- lua_State *L, gint parser_ref,
+ lua_State *L, int parser_ref,
struct rspamd_http_message *msg,
goffset *body_offset,
const rspamd_ftok_t *ct)
{
struct ucl_parser *parser;
- gint err_idx;
- const gchar *in = msg->body_buf.begin;
+ int err_idx;
+ const char *in = msg->body_buf.begin;
gsize inlen = msg->body_buf.len;
const rspamd_ftok_t *offset_hdr;
parser = ucl_parser_new(0);
if (!ucl_parser_add_chunk(parser, in, inlen)) {
- gchar *encoded;
+ char *encoded;
encoded = rspamd_encode_base64(in, inlen, 0, NULL);
msg_err_session("cannot parse input: %s", ucl_parser_get_error(
}
static void
-proxy_call_cmp_script(struct rspamd_proxy_session *session, gint cbref)
+proxy_call_cmp_script(struct rspamd_proxy_session *session, int cbref)
{
- gint err_idx;
- guint i;
+ int err_idx;
+ unsigned int i;
struct rspamd_proxy_backend_connection *conn;
lua_State *L;
}
}
- gchar log_tag[RSPAMD_LOG_ID_LEN + 1];
+ char log_tag[RSPAMD_LOG_ID_LEN + 1];
rspamd_strlcpy(log_tag, session->pool->tag.uid, sizeof(log_tag));
lua_pushstring(L, log_tag);
static void
proxy_session_dtor(struct rspamd_proxy_session *session)
{
- guint i;
- gint cbref;
+ unsigned int i;
+ int cbref;
struct rspamd_proxy_backend_connection *conn;
if (session->master_conn && session->master_conn->results) {
for (i = 0; i < session->ctx->cmp_refs->len; i++) {
- cbref = g_array_index(session->ctx->cmp_refs, gint, i);
+ cbref = g_array_index(session->ctx->cmp_refs, int, i);
proxy_call_cmp_script(session, cbref);
}
}
static void
proxy_request_compress(struct rspamd_http_message *msg)
{
- guint flags;
+ unsigned int flags;
ZSTD_CCtx *zctx;
rspamd_fstring_t *body;
- const gchar *in;
+ const char *in;
gsize inlen;
flags = rspamd_http_message_get_flags(msg);
proxy_request_decompress(struct rspamd_http_message *msg)
{
rspamd_fstring_t *body;
- const gchar *in;
+ const char *in;
gsize inlen, outlen, r;
ZSTD_DStream *zstream;
ZSTD_inBuffer zin;
{
const rspamd_ftok_t *tok, *key_tok;
rspamd_ftok_t srch;
- gchar *file_str;
+ char *file_str;
GHashTable *query_args;
GHashTableIter it;
gpointer k, v;
REF_RELEASE(bk_conn->s);
}
-static gint
+static int
proxy_backend_mirror_finish_handler(struct rspamd_http_connection *conn,
struct rspamd_http_message *msg)
{
static void
proxy_open_mirror_connections(struct rspamd_proxy_session *session)
{
- gdouble coin;
+ double coin;
struct rspamd_http_mirror *m;
- guint i;
+ unsigned int i;
struct rspamd_proxy_backend_connection *bk_conn;
struct rspamd_http_message *msg;
GError *err = NULL;
}
static void
-proxy_client_write_error(struct rspamd_proxy_session *session, gint code,
- const gchar *status)
+proxy_client_write_error(struct rspamd_proxy_session *session, int code,
+ const char *status)
{
struct rspamd_http_message *reply;
}
}
-static gint
+static int
proxy_backend_master_finish_handler(struct rspamd_http_connection *conn,
struct rspamd_http_message *msg)
{
rspamd_http_message_free(msg);
}
else {
- const gchar *passed_ct = NULL;
+ const char *passed_ct = NULL;
if (orig_ct) {
passed_ct = rspamd_mempool_ftokdup(session->pool, orig_ct);
nsession = proxy_session_refresh(session);
if (task->flags & RSPAMD_TASK_FLAG_MESSAGE_REWRITE) {
- const gchar *start;
+ const char *start;
goffset len, hdr_off;
start = task->msg.begin;
{
struct rspamd_task *task;
struct rspamd_http_message *msg;
- const gchar *data;
+ const char *data;
gsize len;
msg = session->client_message;
struct rspamd_http_upstream *backend = NULL;
const rspamd_ftok_t *host;
GError *err = NULL;
- gchar hostbuf[512];
+ char hostbuf[512];
host = rspamd_http_message_find_header(session->client_message, "Host");
}
/* Provide hash key if hashing based on source address is desired */
- guint hash_len;
+ unsigned int hash_len;
gpointer hash_key = rspamd_inet_address_get_hash_key(session->client_addr,
&hash_len);
REF_RELEASE(session);
}
-static gint
+static int
proxy_client_finish_handler(struct rspamd_http_connection *conn,
struct rspamd_http_message *msg)
{
}
static void
-proxy_milter_finish_handler(gint fd,
+proxy_milter_finish_handler(int fd,
struct rspamd_milter_session *rms,
void *ud)
{
}
static void
-proxy_milter_error_handler(gint fd,
+proxy_milter_error_handler(int fd,
struct rspamd_milter_session *rms, /* unused */
void *ud, GError *err)
{
struct rspamd_proxy_ctx *ctx;
rspamd_inet_addr_t *addr = NULL;
struct rspamd_proxy_session *session;
- gint nfd;
+ int nfd;
ctx = worker->ctx;
#endif
if (rspamd_inet_address_get_af(addr) != AF_UNIX) {
- gint sopt = 1;
+ int sopt = 1;
if (setsockopt(nfd, SOL_TCP, TCP_NODELAY, &sopt, sizeof(sopt)) ==
-1) {
struct rspamd_worker_session {
int64_t magic;
struct rspamd_task *task;
- gint fd;
+ int fd;
rspamd_inet_addr_t *addr;
struct rspamd_worker_ctx *ctx;
struct rspamd_http_connection *http_conn;
}
}
-static gint
+static int
rspamd_worker_body_handler(struct rspamd_http_connection *conn,
struct rspamd_http_message *msg,
- const gchar *chunk, gsize len)
+ const char *chunk, gsize len)
{
struct rspamd_worker_session *session = (struct rspamd_worker_session *) conn->ud;
struct rspamd_task *task;
}
}
-static gint
+static int
rspamd_worker_finish_handler(struct rspamd_http_connection *conn,
struct rspamd_http_message *msg)
{
struct rspamd_worker_ctx *ctx;
struct rspamd_worker_session *session;
rspamd_inet_addr_t *addr = NULL;
- gint nfd, http_opts = 0;
+ int nfd, http_opts = 0;
ctx = worker->ctx;
enum rspamd_cryptobox_mode mode = RSPAMD_CRYPTOBOX_MODE_25519;
static void *
-create_mapping(int mapping_len, guchar **beg, guchar **end)
+create_mapping(int mapping_len, unsigned char **beg, unsigned char **end)
{
void *map;
int psize = getpagesize();
memset(map, 0, mapping_len + psize * 3);
mprotect(map, psize, PROT_NONE);
/* Misalign pointer */
- *beg = ((guchar *) map) + psize + 1;
+ *beg = ((unsigned char *) map) + psize + 1;
*end = *beg + mapping_len;
mprotect(*beg + mapping_len - 1 + psize, psize, PROT_NONE);
static void
check_result(const rspamd_nm_t key, const rspamd_nonce_t nonce,
- const rspamd_mac_t mac, guchar *begin, guchar *end)
+ const rspamd_mac_t mac, unsigned char *begin, unsigned char *end)
{
uint64_t *t = (uint64_t *) begin;
static int
create_random_split(struct rspamd_cryptobox_segment *seg, int mseg,
- guchar *begin, guchar *end)
+ unsigned char *begin, unsigned char *end)
{
gsize remain = end - begin;
- gint used = 0;
+ int used = 0;
while (remain > 0 && used < mseg - 1) {
seg->data = begin;
static int
create_realistic_split(struct rspamd_cryptobox_segment *seg, int mseg,
- guchar *begin, guchar *end)
+ unsigned char *begin, unsigned char *end)
{
gsize remain = end - begin;
- gint used = 0;
+ int used = 0;
static const int small_seg = 512, medium_seg = 2048;
while (remain > 0 && used < mseg - 1) {
static int
create_constrained_split(struct rspamd_cryptobox_segment *seg, int mseg,
int constraint,
- guchar *begin, guchar *end)
+ unsigned char *begin, unsigned char *end)
{
gsize remain = end - begin;
- gint used = 0;
+ int used = 0;
while (remain > 0 && used < mseg - 1) {
seg->data = begin;
void rspamd_cryptobox_test_func(void)
{
void *map;
- guchar *begin, *end;
+ unsigned char *begin, *end;
rspamd_nm_t key;
rspamd_nonce_t nonce;
rspamd_mac_t mac;
struct rspamd_cryptobox_segment *seg;
double t1, t2;
- gint i, cnt, ms;
+ int i, cnt, ms;
gboolean checked_openssl = FALSE;
map = create_mapping(mapping_size, &begin, &end);
#include "rspamd.h"
#include "dkim.h"
-static const gchar test_dkim_sig[] = "v=1; a=rsa-sha256; c=relaxed/relaxed; "
- "d=highsecure.ru; s=dkim; t=1410516996; "
- "bh=guFoWYHWVzFRqVyAQebnvPcdm7bUQo7pRHt/uIHD7gs=; "
- "h=Message-ID:Date:From:MIME-Version:To:Subject:Content-Type:Content-Transfer-Encoding; "
- "b=PCiECkOaPFb99DW+gApgfmdlTUo6XN6YXjnj52Cxoz2FoA857B0ZHFgeQe4JAKHuhW"
- "oq3BLHap0GcMTTpSOgfQOKa8Df35Ns11JoOFjdBQ8GpM99kOrJP+vZcT8b7AMfthYm0Kwy"
- "D9TjlkpScuoY5LjsWVnijh9dSNVLFqLatzg=;";
+static const char test_dkim_sig[] = "v=1; a=rsa-sha256; c=relaxed/relaxed; "
+ "d=highsecure.ru; s=dkim; t=1410516996; "
+ "bh=guFoWYHWVzFRqVyAQebnvPcdm7bUQo7pRHt/uIHD7gs=; "
+ "h=Message-ID:Date:From:MIME-Version:To:Subject:Content-Type:Content-Transfer-Encoding; "
+ "b=PCiECkOaPFb99DW+gApgfmdlTUo6XN6YXjnj52Cxoz2FoA857B0ZHFgeQe4JAKHuhW"
+ "oq3BLHap0GcMTTpSOgfQOKa8Df35Ns11JoOFjdBQ8GpM99kOrJP+vZcT8b7AMfthYm0Kwy"
+ "D9TjlkpScuoY5LjsWVnijh9dSNVLFqLatzg=;";
extern struct ev_loop *event_loop;
#if 0
#include "async_session.h"
#include "cfg_file.h"
-static guint requests = 0;
+static unsigned int requests = 0;
extern struct ev_loop *event_loop;
struct rspamd_dns_resolver *resolver;
#include "heap.h"
#include "ottery.h"
-static const guint niter = 100500;
-static const guint nrem = 100;
+static const unsigned int niter = 100500;
+static const unsigned int nrem = 100;
static inline struct rspamd_min_heap_elt *
-new_elt(guint pri)
+new_elt(unsigned int pri)
{
struct rspamd_min_heap_elt *elt;
return elt;
}
-static gdouble
-heap_nelts_test(guint nelts)
+static double
+heap_nelts_test(unsigned int nelts)
{
struct rspamd_min_heap *heap;
struct rspamd_min_heap_elt *elts;
- gdouble t1, t2;
- guint i;
+ double t1, t2;
+ unsigned int i;
heap = rspamd_min_heap_create(nelts);
/* Preallocate all elts */
{
struct rspamd_min_heap *heap;
struct rspamd_min_heap_elt *elt, *telt;
- guint i;
- guint prev;
- gdouble t[16];
+ unsigned int i;
+ unsigned int prev;
+ double t[16];
/* Push + update */
heap = rspamd_min_heap_create(32);
#include "unix-std.h"
static const char *lua_src_name = "lua/pcall_test.lua";
-extern gchar *argv0_dirname;
+extern char *argv0_dirname;
extern struct rspamd_main *rspamd_main;
const int N = 20000;
-static gdouble
-test_pcall(lua_State *L, gint function_call)
+static double
+test_pcall(lua_State *L, int function_call)
{
- gdouble t1, t2;
- gint i;
+ double t1, t2;
+ int i;
t1 = rspamd_get_virtual_ticks();
for (i = 0; i < N; i++) {
return t2 - t1;
}
-static gdouble
-test_resume(lua_State *L, gint function_call)
+static double
+test_resume(lua_State *L, int function_call)
{
- gdouble t1, t2;
- gint i;
+ double t1, t2;
+ int i;
t1 = rspamd_get_virtual_ticks();
for (i = 0; i < N; i++) {
return t2 - t1;
}
-static gdouble
-test_resume_get_thread(gint function_call)
+static double
+test_resume_get_thread(int function_call)
{
- gdouble t1, t2;
- gint i;
+ double t1, t2;
+ int i;
struct thread_entry *ent;
t1 = rspamd_get_virtual_ticks();
return t2 - t1;
}
-static gdouble
-test_resume_get_new_thread(gint function_call)
+static double
+test_resume_get_new_thread(int function_call)
{
- gdouble t1, t2;
- gint i;
+ double t1, t2;
+ int i;
struct thread_entry *ent;
t1 = rspamd_get_virtual_ticks();
void rspamd_lua_lua_pcall_vs_resume_test_func(void)
{
lua_State *L = rspamd_main->cfg->lua_state;
- gchar *lua_src;
- gdouble t1, reference;
+ char *lua_src;
+ double t1, reference;
lua_src = g_build_filename(argv0_dirname, lua_src_name, NULL);
if (luaL_dofile(L, lua_src) != 0) {
}
g_free(lua_src);
- gint function_call = luaL_ref(L, LUA_REGISTRYINDEX);
+ int function_call = luaL_ref(L, LUA_REGISTRYINDEX);
msg_info("calling");
reference = t1 = test_pcall(L, function_call);
- msg_notice("pcall stat: ts: %1.5f, avg:%1.5f, slow=%1.2f", t1, t1 / (gdouble) N, t1 / reference);
+ msg_notice("pcall stat: ts: %1.5f, avg:%1.5f, slow=%1.2f", t1, t1 / (double) N, t1 / reference);
t1 = test_resume(L, function_call);
- msg_notice("resume stat: ts: %1.5f, avg:%1.5f, slow=%1.2f", t1, t1 / (gdouble) N, t1 / reference);
+ msg_notice("resume stat: ts: %1.5f, avg:%1.5f, slow=%1.2f", t1, t1 / (double) N, t1 / reference);
t1 = test_resume_get_thread(function_call);
- msg_notice("resume+get thread stat: ts: %1.5f, avg:%1.5f, slow=%1.2f", t1, t1 / (gdouble) N, t1 / reference);
+ msg_notice("resume+get thread stat: ts: %1.5f, avg:%1.5f, slow=%1.2f", t1, t1 / (double) N, t1 / reference);
t1 = test_resume_get_new_thread(function_call);
- msg_notice("resume+get [new] thread stat: ts: %1.5f, avg:%1.5f, slow=%1.2f", t1, t1 / (gdouble) N, t1 / reference);
+ msg_notice("resume+get [new] thread stat: ts: %1.5f, avg:%1.5f, slow=%1.2f", t1, t1 / (double) N, t1 / reference);
}
#endif
static const char *lua_src_name = "lua/tests.lua";
-extern gchar *lua_test;
-extern gchar *lua_test_case;
-extern gchar *argv0_dirname;
+extern char *lua_test;
+extern char *lua_test_case;
+extern char *argv0_dirname;
extern struct rspamd_main *rspamd_main;
static int
rspamd_lua_test_func(void)
{
lua_State *L = (lua_State *) rspamd_main->cfg->lua_state;
- gchar *lua_src, *rp, rp_buf[PATH_MAX], path_buf[PATH_MAX], *tmp, *dir, *pattern;
- const gchar *old_path;
+ char *lua_src, *rp, rp_buf[PATH_MAX], path_buf[PATH_MAX], *tmp, *dir, *pattern;
+ const char *old_path;
glob_t globbuf;
- gint i, len;
+ int i, len;
rspamd_lua_set_env(L, NULL, NULL, NULL);
rspamd_lua_set_globals(rspamd_main->cfg, L);
pattern = g_malloc(len);
rspamd_snprintf(pattern, len, "%s/unit/%s", dir, "*.lua");
- gint lua_test_len = 0;
- gint inserted_file = 1;
- gint path_start;
+ int lua_test_len = 0;
+ int inserted_file = 1;
+ int path_start;
if (lua_test) {
lua_test_len = strlen(lua_test);
}
if (glob(pattern, GLOB_DOOFFS, NULL, &globbuf) == 0) {
- for (i = 0; i < (gint) globbuf.gl_pathc; i++) {
+ for (i = 0; i < (int) globbuf.gl_pathc; i++) {
if (lua_test) {
path_start = strlen(globbuf.gl_pathv[i]) - lua_test_len;
if (path_start < 0 ||
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
#include "btrie.h"
const gsize max_elts = 500 * 1024;
-const gint lookup_cycles = 1 * 1024;
-const gint lookup_divisor = 10;
+const int lookup_cycles = 1 * 1024;
+const int lookup_divisor = 10;
const uint masks[] = {
8,
const char *nip;
const char *m;
uint32_t mask;
- guint8 *addr;
- guint8 *naddr;
+ uint8_t *addr;
+ uint8_t *naddr;
gsize len;
} test_vec[] = {
{"192.168.1.1", "192.168.1.2", "32", 0, 0, 0, 0},
struct {
uint32_t addr;
uint32_t mask;
- guint8 addr6[16];
+ uint8_t addr6[16];
uint32_t mask6;
- guint8 addr64[16];
+ uint8_t addr64[16];
} *addrs;
gsize nelts, i, check;
- gint lc;
+ int lc;
gboolean all_good = TRUE;
- gdouble ts1, ts2;
+ double ts1, ts2;
double diff;
/* Test suite for the compressed trie */
msg_notice("Checked %hz elements in %.0f ticks (%.2f ticks per lookup)",
nelts * lookup_cycles / lookup_divisor, diff,
- diff / ((gdouble) nelts * lookup_cycles / lookup_divisor));
+ diff / ((double) nelts * lookup_cycles / lookup_divisor));
rspamd_mempool_delete(pool);
/*
ts1 = rspamd_get_ticks(TRUE);
for (i = 0; i < nelts; i++) {
- btrie_add_prefix(btrie, (guchar *) &addrs[i].addr,
+ btrie_add_prefix(btrie, (unsigned char *) &addrs[i].addr,
addrs[i].mask, GSIZE_TO_POINTER(i + 1));
}
ts2 = rspamd_get_ticks(TRUE);
for (i = 0; i < nelts / lookup_divisor; i++) {
check = rspamd_random_uint64_fast() % nelts;
- if (btrie_lookup(btrie, (guchar *) &addrs[check].addr, sizeof(addrs[check].addr) * 8) == NULL) {
+ if (btrie_lookup(btrie, (unsigned char *) &addrs[check].addr, sizeof(addrs[check].addr) * 8) == NULL) {
char ipbuf[INET6_ADDRSTRLEN + 1];
all_good = FALSE;
- inet_ntop(AF_INET, (guchar *) &addrs[check].addr, ipbuf, sizeof(ipbuf));
+ inet_ntop(AF_INET, (unsigned char *) &addrs[check].addr, ipbuf, sizeof(ipbuf));
msg_notice("BAD btrie: {\"%s\", NULL, \"%ud\", 0, 0, 0, 0},",
ipbuf,
addrs[check].mask);
msg_notice("Checked %hz elements in %.0f ticks (%.2f ticks per lookup)",
nelts * lookup_cycles / lookup_divisor, diff,
- diff / ((gdouble) nelts * lookup_cycles / lookup_divisor));
+ diff / ((double) nelts * lookup_cycles / lookup_divisor));
rspamd_mempool_delete(pool);
/*
all_good = FALSE;
- inet_ntop(AF_INET, (guchar *) &addrs[check].addr, ipbuf, sizeof(ipbuf));
+ inet_ntop(AF_INET, (unsigned char *) &addrs[check].addr, ipbuf, sizeof(ipbuf));
msg_notice("BAD btrie: {\"%s\", NULL, \"%ud\", 0, 0, 0, 0},",
ipbuf,
addrs[check].mask);
msg_notice("Checked %hz elements in %.0f ticks (%.2f ticks per lookup)",
nelts * lookup_cycles / lookup_divisor, diff,
- diff / ((gdouble) nelts * lookup_cycles / lookup_divisor));
+ diff / ((double) nelts * lookup_cycles / lookup_divisor));
rspamd_mempool_delete(pool);
g_free(addrs);
void rspamd_rrd_test_func(void)
{
- gchar tmpfile[PATH_MAX];
+ char tmpfile[PATH_MAX];
struct rrd_rra_def rra[4];
struct rrd_ds_def ds[2];
GArray ar;
GError *err = NULL;
struct rspamd_rrd_file *rrd;
- gdouble ticks;
- gint i;
- gdouble t[2], cnt = 0.0;
+ double ticks;
+ int i;
+ double t[2], cnt = 0.0;
rspamd_snprintf(tmpfile, sizeof(tmpfile), "/tmp/rspamd_rrd.rrd");
unlink(tmpfile);
#include "ottery.h"
#include <math.h>
-static const gchar *
+static const char *
algorithm_to_string(enum rspamd_shingle_alg alg)
{
- const gchar *ret = "unknown";
+ const char *ret = "unknown";
switch (alg) {
case RSPAMD_SHINGLES_OLD:
}
static void
-permute_vector(GArray *in, gdouble prob)
+permute_vector(GArray *in, double prob)
{
gsize i, total = 0;
rspamd_ftok_t *w;
for (i = 0; i < in->len; i++) {
if (ottery_rand_unsigned() <= G_MAXUINT * prob) {
w = &g_array_index(in, rspamd_ftok_t, i);
- generate_random_string((gchar *) w->begin, w->len);
+ generate_random_string((char *) w->begin, w->len);
total++;
}
}
}
static void
-test_case(gsize cnt, gsize max_len, gdouble perm_factor,
+test_case(gsize cnt, gsize max_len, double perm_factor,
enum rspamd_shingle_alg alg)
{
GArray *input;
struct rspamd_shingle *sgl, *sgl_permuted;
- gdouble res;
- guchar key[16];
- gdouble ts1, ts2;
+ double res;
+ unsigned char key[16];
+ double ts1, ts2;
ottery_rand_bytes(key, sizeof(key));
input = generate_fuzzy_words(cnt, max_len);
{
enum rspamd_shingle_alg alg = RSPAMD_SHINGLES_OLD;
struct rspamd_shingle *sgl;
- guchar key[16];
+ unsigned char key[16];
GArray *input;
rspamd_ftok_t tok;
int i;
input = g_array_sized_new(FALSE, FALSE, sizeof(rspamd_ftok_t), 5);
for (i = 0; i < 5; i++) {
- gchar *b = g_alloca(8);
+ char *b = g_alloca(8);
memset(b, 0, 8);
memcpy(b + 1, "test", 4);
b[0] = 'a' + i;
struct ev_loop *event_loop = NULL;
worker_t *workers[] = {NULL};
-gchar *lua_test = NULL;
-gchar *lua_test_case = NULL;
+char *lua_test = NULL;
+char *lua_test_case = NULL;
gboolean verbose = FALSE;
-gchar *argv0_dirname = NULL;
+char *argv0_dirname = NULL;
static GOptionEntry entries[] =
{
static void
rspamd_upstream_test_method(struct upstream_list *ls,
- enum rspamd_upstream_rotation rot, const gchar *expected)
+ enum rspamd_upstream_rotation rot, const char *expected)
{
struct upstream *up;
struct upstream *up, *upn;
struct rspamd_dns_resolver *resolver;
struct rspamd_config *cfg;
- gint i, success = 0;
- const gint assumptions = 100500;
- gdouble p;
+ int i, success = 0;
+ const int assumptions = 100500;
+ double p;
static ev_timer ev;
rspamd_inet_addr_t *addr, *next_addr, *paddr;
}
}
- p = 1.0 - fabs(3.0 / 4.0 - (gdouble) success / (gdouble) assumptions);
+ p = 1.0 - fabs(3.0 / 4.0 - (double) success / (double) assumptions);
/*
* P value is calculated as following:
* when we add/remove M upstreams from the list, the probability of hash
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
#include "cryptobox.h"
#include "unix-std.h"
-static gdouble total_time = 0;
+static double total_time = 0;
static void
-rspamd_process_file(const gchar *fname, gint decode)
+rspamd_process_file(const char *fname, int decode)
{
- gint fd;
+ int fd;
gpointer map;
struct stat st;
- guint8 *dest;
+ uint8_t *dest;
gsize destlen;
fd = open(fname, O_RDONLY);
dest = rspamd_encode_base64(map, st.st_size, 80, &destlen);
}
- rspamd_printf("%*s", (gint) destlen, dest);
+ rspamd_printf("%*s", (int) destlen, dest);
g_free(dest);
munmap(map, st.st_size);
int main(int argc, char **argv)
{
- gint i, start = 1, decode = 0;
+ int i, start = 1, decode = 0;
if (argc > 2 && *argv[1] == '-') {
start = 2;
#include <sys/wait.h>
#endif
-static guint port = 43000;
-static gchar *host = "127.0.0.1";
-static gchar *server_key = NULL;
-static guint cache_size = 10;
-static guint nworkers = 1;
+static unsigned int port = 43000;
+static char *host = "127.0.0.1";
+static char *server_key = NULL;
+static unsigned int cache_size = 10;
+static unsigned int nworkers = 1;
static gboolean openssl_mode = FALSE;
-static guint file_size = 500;
-static guint pconns = 100;
-static gdouble test_time = 10.0;
-static gchar *latencies_file = NULL;
+static unsigned int file_size = 500;
+static unsigned int pconns = 100;
+static double test_time = 10.0;
+static char *latencies_file = NULL;
static gboolean csv_output = FALSE;
/* Dynamic vars */
static rspamd_inet_addr_t *addr;
static uint32_t workers_left = 0;
static uint32_t *conns_done = NULL;
-static const guint store_latencies = 1000;
+static const unsigned int store_latencies = 1000;
static uint32_t conns_pending = 0;
static GOptionEntry entries[] = {
{NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}};
struct lat_elt {
- gdouble lat;
- guchar checked;
+ double lat;
+ unsigned char checked;
};
static struct lat_elt *latencies;
-static gint
+static int
rspamd_client_body(struct rspamd_http_connection *conn,
struct rspamd_http_message *msg,
- const gchar *chunk, gsize len)
+ const char *chunk, gsize len)
{
g_assert(chunk[0] == '\0');
struct client_cbdata {
struct lat_elt *lat;
uint32_t *wconns;
- gdouble ts;
+ double ts;
struct ev_loop *ev_base;
};
rspamd_http_connection_unref(conn);
}
-static gint
+static int
rspamd_client_finish(struct rspamd_http_connection *conn,
struct rspamd_http_message *msg)
{
{
struct rspamd_http_message *msg;
struct rspamd_http_connection *conn;
- gchar urlbuf[PATH_MAX];
+ char urlbuf[PATH_MAX];
struct client_cbdata *cb;
- gint fd, flags;
+ int fd, flags;
fd = rspamd_inet_address_connect(addr, SOCK_STREAM, TRUE);
g_assert(fd != -1);
static void
rspamd_worker_func(struct lat_elt *plat, uint32_t *wconns)
{
- guint i, j;
+ unsigned int i, j;
struct ev_loop *ev_base;
struct itimerval itv;
struct rspamd_keypair_cache *c = NULL;
double
rspamd_http_calculate_mean(struct lat_elt *lats, double *std)
{
- guint i, cnt, checked = 0;
- gdouble mean = 0., dev = 0.;
+ unsigned int i, cnt, checked = 0;
+ double mean = 0., dev = 0.;
cnt = store_latencies * pconns;
qsort(lats, cnt, sizeof(*lats), cmpd);
static void
rspamd_http_start_workers(pid_t *sfd)
{
- guint i;
+ unsigned int i;
for (i = 0; i < nworkers; i++) {
sfd[i] = fork();
g_assert(sfd[i] != -1);
static void
rspamd_http_stop_workers(pid_t *sfd)
{
- guint i;
- gint res;
+ unsigned int i;
+ int res;
for (i = 0; i < nworkers; i++) {
kill(sfd[i], SIGTERM);
static void
rspamd_http_bench_cld(int fd, short what, void *arg)
{
- gint res;
+ int res;
while (waitpid(-1, &res, WNOHANG) > 0) {
if (--workers_left == 0) {
struct event term_ev, int_ev, cld_ev;
uint64_t total_done;
FILE *lat_file;
- gdouble mean, std;
- guint i;
+ double mean, std;
+ unsigned int i;
rspamd_init_libs();
#include <sys/wait.h>
#endif
-static guint port = 43000;
-static guint cache_size = 10;
-static guint nworkers = 1;
+static unsigned int port = 43000;
+static unsigned int cache_size = 10;
+static unsigned int nworkers = 1;
static gboolean openssl_mode = FALSE;
static GHashTable *maps = NULL;
-static gchar *key = NULL;
+static char *key = NULL;
static struct rspamd_keypair_cache *c;
static struct rspamd_cryptobox_keypair *server_key;
static struct timeval io_tv = {
struct rspamd_http_server_session {
struct rspamd_http_connection *conn;
struct ev_loop *ev_base;
- guint req_size;
+ unsigned int req_size;
gboolean reply;
- gint fd;
+ int fd;
};
static void
struct rspamd_http_server_session *session = conn->ud;
struct rspamd_http_message *reply;
gulong size;
- const gchar *url_str;
- guint url_len;
+ const char *url_str;
+ unsigned int url_len;
rspamd_fstring_t *body;
if (!session->reply) {
}
static void
-rspamd_server_accept(gint fd, short what, void *arg)
+rspamd_server_accept(int fd, short what, void *arg)
{
struct ev_loop *ev_base = arg;
struct rspamd_http_server_session *session;
rspamd_inet_addr_t *addr;
- gint nfd;
+ int nfd;
do {
if ((nfd =
}
static void
-rspamd_http_term_handler(gint fd, short what, void *arg)
+rspamd_http_term_handler(int fd, short what, void *arg)
{
struct ev_loop *ev_base = arg;
struct timeval tv = {0, 0};
}
static void
-rspamd_http_server_func(gint fd, rspamd_inet_addr_t *addr)
+rspamd_http_server_func(int fd, rspamd_inet_addr_t *addr)
{
struct ev_loop *ev_base = event_init();
struct event accept_ev, term_ev;
static void
rspamd_http_start_servers(pid_t *sfd, rspamd_inet_addr_t *addr)
{
- guint i;
- gint fd;
+ unsigned int i;
+ int fd;
fd = rspamd_inet_address_listen(addr, SOCK_STREAM, TRUE);
g_assert(fd != -1);
static void
rspamd_http_stop_servers(pid_t *sfd)
{
- guint i;
- gint res;
+ unsigned int i;
+ int res;
for (i = 0; i < nworkers; i++) {
kill(sfd[i], SIGTERM);
event_loopexit(NULL);
}
-int main(int argc, gchar **argv)
+int main(int argc, char **argv)
{
GOptionContext *context;
GError *error = NULL;