Exemple #1
0
static struct patterns_data* parse_config(const char* line, struct plugin_handle* plugin)
{
	struct patterns_data* data = (struct patterns_data*) hub_malloc_zero(sizeof(struct patterns_data));
	struct cfg_tokens* tokens = cfg_tokenize(line);
	char* token = cfg_token_get_first(tokens);

	if (!data)
		return 0;
  
	while (token)
	{
		struct cfg_settings* setting = cfg_settings_split(token);

		if (!setting)
		{
			set_error_message(plugin, "Unable to parse startup parameters");
			cfg_tokens_free(tokens);
			hub_free(data);
			return 0;
		}

		if (strcmp(cfg_settings_get_key(setting), "file") == 0)
		{
			if (!data->db)
			{
				if (sqlite3_open(cfg_settings_get_value(setting), &data->db))
				{
					cfg_tokens_free(tokens);
					cfg_settings_free(setting);
					hub_free(data);
					set_error_message(plugin, "Unable to open database file");
					return 0;
				}
			}
		}
		else
		{
			set_error_message(plugin, "Unknown startup parameters given");
			cfg_tokens_free(tokens);
			cfg_settings_free(setting);
			hub_free(data);
			return 0;
		}

		cfg_settings_free(setting);
		token = cfg_token_get_next(tokens);
	}
	cfg_tokens_free(tokens);

	if (!data->db)
	{
	      set_error_message(plugin, "No database file is given, use file=<database>");
	      hub_free(data);
	      return 0;
	}
	return data;
}
Exemple #2
0
static struct log_data* parse_config(const char* line, struct plugin_handle* plugin)
{
	struct log_data* data = (struct log_data*) hub_malloc_zero(sizeof(struct log_data));
	struct cfg_tokens* tokens = cfg_tokenize(line);
	char* token = cfg_token_get_first(tokens);

	uhub_assert(data != NULL);

	data->srvtdiff = 0;

	while (token)
	{
		struct cfg_settings* setting = cfg_settings_split(token);

		if (!setting)
		{
			set_error_message(plugin, "Unable to parse startup parameters");
			cfg_tokens_free(tokens);
			hub_free(data);
			return 0;
		}

		if (strcmp(cfg_settings_get_key(setting), "file") == 0)
		{
			if (!data->db)
			{
				if (sqlite3_open(cfg_settings_get_value(setting), &data->db))
				{
					cfg_tokens_free(tokens);
					cfg_settings_free(setting);
					hub_free(data);
					set_error_message(plugin, "Unable to open database file");
					return 0;
				}
			}
		}
		else if (strcmp(cfg_settings_get_key(setting), "server_time_diff") == 0)
		{
			data->srvtdiff = uhub_atoi(cfg_settings_get_value(setting));
		}
		else
		{
			set_error_message(plugin, "Unknown startup parameters given");
			cfg_tokens_free(tokens);
			cfg_settings_free(setting);
			hub_free(data);
			return 0;
		}

		cfg_settings_free(setting);
		token = cfg_token_get_next(tokens);
	}
	cfg_tokens_free(tokens);

	return data;
}
Exemple #3
0
static struct chat_history_data* parse_config(const char* line, struct plugin_handle* plugin)
{
	struct chat_history_data* data = (struct chat_history_data*) hub_malloc_zero(sizeof(struct chat_history_data));
	struct cfg_tokens* tokens = cfg_tokenize(line);
	char* token = cfg_token_get_first(tokens);

	uhub_assert(data != NULL);

	data->history_max = 200;
	data->history_default = 25;
	data->history_connect = 5;
	data->chat_history = list_create();

	while (token)
	{
		struct cfg_settings* setting = cfg_settings_split(token);

		if (!setting)
		{
			set_error_message(plugin, "Unable to parse startup parameters");
			cfg_tokens_free(tokens);
			hub_free(data);
			return 0;
		}

		if (strcmp(cfg_settings_get_key(setting), "history_max") == 0)
		{
			data->history_max = (size_t) uhub_atoi(cfg_settings_get_value(setting));
		}
		else if (strcmp(cfg_settings_get_key(setting), "history_default") == 0)
		{
			data->history_default = (size_t) uhub_atoi(cfg_settings_get_value(setting));
		}
		else if (strcmp(cfg_settings_get_key(setting), "history_connect") == 0)
		{
			data->history_connect = (size_t) uhub_atoi(cfg_settings_get_value(setting));
		}
		else
		{
			set_error_message(plugin, "Unknown startup parameters given");
			cfg_tokens_free(tokens);
			cfg_settings_free(setting);
			hub_free(data);
			return 0;
		}

		cfg_settings_free(setting);
		token = cfg_token_get_next(tokens);
	}
	cfg_tokens_free(tokens);
	return data;
}
Exemple #4
0
static int create_patterns_table(struct plugin_handle* plugin, struct patterns_data* data)
{
	sqlite3_stmt *res;
	int rc;
	int count = 0;
	
	const char* table_create_patterns = "CREATE TABLE patterns(id INTEGER PRIMARY KEY,regexp CHAR NOT NULL,type INT NOT NULL,min_cred_protect CHAR NOT NULL DEFAULT('user'),max_cred_protect CHAR NOT NULL DEFAULT('admin'));";
	const char* table_alter_patterns = "ALTER TABLE patterns ADD COLUMN max_cred_protect CHAR NOT NULL DEFAULT('admin');";

	rc = sqlite3_prepare_v2(data->db, "PRAGMA table_info(patterns);", 29, &res, NULL);
	
	if (rc == SQLITE_OK)
	{
		while (sqlite3_step(res) == SQLITE_ROW)
			count++;
	}
	
	sqlite3_finalize(res);
		
	if (count == 5)
		return 1; // New schema
	
	if (count == 0) // Table does not exist
	{
		rc = sqlite3_exec(data->db, table_create_patterns, NULL, NULL, NULL);

		if (rc != SQLITE_OK)
		{
			set_error_message(plugin, "Unable to create patterns table.");
			return 0;
		}
		else
		    return 1;
	}
	
	if (count > 0 && count < 5) // Table exists, but scheme is old
	{
		rc = sqlite3_exec(data->db, table_alter_patterns, NULL, NULL, NULL);

		if (rc != SQLITE_OK)
		{
			set_error_message(plugin, "Unable to alter patterns table.");
			return 0;
		}
		else
			return 1;
	}
	
	set_error_message(plugin, "Unable to create or alter patterns table (unknown reason).");
	return 0;
}
Exemple #5
0
bool http_request_parse(HttpRequest* request, const char* text) {
  // Clear the error buffer. If set during this function, there was an error.
  clear_error_message(request);

  // Clear any existing data and reset the object
  http_request_free(request);

  // Copy the text
  char* textcopy = strdup(text);
  char* textcopy_start = textcopy;

  // Parse the HTTP request line (the first line): HTTP method, URI, version
  char* curline = strsep(&textcopy, "\n");
  http_request_parse_request_line(request, curline);

  // Parse headers
  while(textcopy) {
    // Get next line. Break if "\r\n" is reached (or in our case, "\r\0").
    curline = strsep(&textcopy, "\n");
    if(!curline) {
      set_error_message(request, "Unexpected end of text while parsing HTTP request\n");
      break;
    }
    if(curline[0] == '\r' && curline[1] == '\0') {
      break;
    }

    // Store header key and value
    char* curline_orig = curline;
    if(!http_request_parse_header_line(request, curline)) {
      set_error_message(request, "Error parsing HTTP header line %s", curline_orig);
      continue;
    }
  }

  // Store the remaining text as the body
  if(textcopy && textcopy[0]) {
    const size_t textlen = strlen(textcopy);
    request->body = malloc(textlen + 1);
    memcpy(request->body, textcopy, textlen + 1);
    request->body[textlen] = 0;
  }

  // Clean up our copy of the text
  free(textcopy_start);

  // Return success if there was no error
  return !request->error;
}
Exemple #6
0
static struct sql_data* parse_config(const char* line, struct plugin_handle* plugin)
{
	struct sql_data* data = (struct sql_data*) hub_malloc_zero(sizeof(struct sql_data));
	struct cfg_tokens* tokens = cfg_tokenize(line);
	char* token = cfg_token_get_first(tokens);

	if (!data)
		return 0;

	while (token)
	{
		char* split = strchr(token, '=');
		size_t len = strlen(token);
		size_t key = split ? (split - token) : len;
		if (key == 4 && strncmp(token, "file", 4) == 0 && data->db == 0)
		{
			if (sqlite3_open(split + 1, &data->db))
			{
				cfg_tokens_free(tokens);
				hub_free(data);
				set_error_message(plugin, "Unable to open database file");
				return 0;
			}
		}
		else if (key == 9 && strncmp(token, "exclusive", 9) == 0)
		{
			if (!string_to_boolean(split + 1, &data->exclusive))
				data->exclusive = 1;
		}
		else
		{
			set_error_message(plugin, "Unable to parse startup parameters");
			cfg_tokens_free(tokens);
			hub_free(data);
			return 0;
		}
		token = cfg_token_get_next(tokens);
	}
	cfg_tokens_free(tokens);

	if (!data->db)
	{
	      set_error_message(plugin, "No database file is given, use file=<database>");
	      hub_free(data);
	      return 0;
	}
	return data;
}
Exemple #7
0
Exception::Exception(uint32_t error_code, const char* error_message)
  : error_message(NULL) {
  set_error_code(error_code);
  if (error_message != NULL) {
    set_error_message(error_message);
  }
}
Exemple #8
0
int plugin_unregister(struct plugin_handle* plugin)
{
	struct patterns_data* pdata;
	set_error_message(plugin, 0);
	pdata = (struct patterns_data*) plugin->ptr;

	if (pdata)
	{
		plugin->hub.command_del(plugin, pdata->command_patternadd_handle);
		plugin->hub.command_del(plugin, pdata->command_patterndel_handle);
		plugin->hub.command_del(plugin, pdata->command_patternlist_handle);
		plugin->hub.command_del(plugin, pdata->command_patterntest_handle);
		plugin->hub.command_del(plugin, pdata->command_patternexadd_handle);
		plugin->hub.command_del(plugin, pdata->command_patternexdel_handle);
		plugin->hub.command_del(plugin, pdata->command_patternexlist_handle);
		hub_free(pdata->command_patternadd_handle);
		hub_free(pdata->command_patterndel_handle);
		hub_free(pdata->command_patternlist_handle);
		hub_free(pdata->command_patterntest_handle);
		hub_free(pdata->command_patternexadd_handle);
		hub_free(pdata->command_patternexdel_handle);
		hub_free(pdata->command_patternexlist_handle);
		sqlite3_close(pdata->db);
	}
    
	hub_free(pdata);
	return 0;
}
Exemple #9
0
int plugin_unregister(struct plugin_handle* plugin)
{
	struct extras_data* extrasdata;
	set_error_message(plugin, 0);
	extrasdata = (struct extras_data*) plugin->ptr;

	if (extrasdata)
	{
		plugin->hub.command_del(plugin, extrasdata->command_hubadd_handle);
		plugin->hub.command_del(plugin, extrasdata->command_hubdel_handle);
		plugin->hub.command_del(plugin, extrasdata->command_hublist_handle);
		plugin->hub.command_del(plugin, extrasdata->command_newsadd_handle);
		plugin->hub.command_del(plugin, extrasdata->command_newsdel_handle);
		plugin->hub.command_del(plugin, extrasdata->command_news_handle);
		plugin->hub.command_del(plugin, extrasdata->command_releaseadd_handle);
		plugin->hub.command_del(plugin, extrasdata->command_releasedel_handle);
		plugin->hub.command_del(plugin, extrasdata->command_releases_handle);
		
		hub_free(extrasdata->command_hubadd_handle);
		hub_free(extrasdata->command_hubdel_handle);
		hub_free(extrasdata->command_hublist_handle);
		hub_free(extrasdata->command_newsadd_handle);
		hub_free(extrasdata->command_newsdel_handle);
		hub_free(extrasdata->command_news_handle);
		hub_free(extrasdata->command_releaseadd_handle);
		hub_free(extrasdata->command_releasedel_handle);
		hub_free(extrasdata->command_releases_handle);

		sqlite3_close(extrasdata->db);
	}
  
	hub_free(extrasdata);
	return 0;
}
Exemple #10
0
int plugin_unregister(struct plugin_handle* plugin)
{
	set_error_message(plugin, 0);
	struct sql_data* sql = (struct sql_data*) plugin->ptr;
	sqlite3_close(sql->db);
	hub_free(sql);
	return 0;
}
Exemple #11
0
SSLException::SSLException()
    : Exception(ERR_peek_error()) {
    SSL_load_error_strings();

    char error_message[256];
    ERR_error_string_n(ERR_peek_error(), error_message, 256);
    set_error_message(error_message);
}
Exemple #12
0
void
mono_error_set_error (MonoError *oerror, int error_code, const char *msg_format, ...)
{
	MonoErrorInternal *error = (MonoErrorInternal*)oerror;
	mono_error_prepare (error);

	error->error_code = error_code;
	set_error_message ();
}
Exemple #13
0
void
mono_error_set_invalid_program (MonoError *oerror, const char *msg_format, ...)
{
	MonoErrorInternal *error = (MonoErrorInternal*)oerror;

	mono_error_prepare (error);
	error->error_code = MONO_ERROR_INVALID_PROGRAM;

	set_error_message ();
}
Exemple #14
0
void
mono_error_set_bad_image (MonoError *oerror, MonoImage *image, const char *msg_format, ...)
{
	MonoErrorInternal *error = (MonoErrorInternal*)oerror;
	mono_error_prepare (error);

	error->error_code = MONO_ERROR_BAD_IMAGE;
	error->assembly_name = image ? mono_image_get_name (image) : "<no_image>";
	set_error_message ();
}
Exemple #15
0
void
mono_error_set_generic_error (MonoError *oerror, const char * name_space, const char *name, const char *msg_format, ...)
{
	MonoErrorInternal *error = (MonoErrorInternal*)oerror;
	mono_error_prepare (error);

	error->error_code = MONO_ERROR_GENERIC;
	mono_error_set_corlib_exception (oerror, name_space, name);
	set_error_message ();
}
Exemple #16
0
void
mono_error_set_member_access (MonoError *oerror, const char *msg_format, ...)
{
	MonoErrorInternal *error = (MonoErrorInternal*)oerror;

	mono_error_prepare (error);
	error->error_code = MONO_ERROR_MEMBER_ACCESS;

	set_error_message ();
}
Exemple #17
0
void
mono_error_set_bad_image_name (MonoError *oerror, const char *assembly_name, const char *msg_format, ...)
{
	MonoErrorInternal *error = (MonoErrorInternal*)oerror;
	mono_error_prepare (error);

	error->error_code = MONO_ERROR_BAD_IMAGE;
	mono_error_set_assembly_name (oerror, assembly_name);
	set_error_message ();
}
Exemple #18
0
void
mono_error_set_type_load_class (MonoError *oerror, MonoClass *klass, const char *msg_format, ...)
{
	MonoErrorInternal *error = (MonoErrorInternal*)oerror;
	mono_error_prepare (error);

	error->error_code = MONO_ERROR_TYPE_LOAD;
	mono_error_set_class (oerror, klass);
	set_error_message ();
}
Exemple #19
0
void
mono_error_set_out_of_memory (MonoError *oerror, const char *msg_format, ...)
{
	MonoErrorInternal *error = (MonoErrorInternal*)oerror;
	mono_error_prepare (error);

	error->error_code = MONO_ERROR_OUT_OF_MEMORY;

	set_error_message ();
}
Exemple #20
0
void
mono_error_set_field_load (MonoError *oerror, MonoClass *klass, const char *field_name, const char *msg_format, ...)
{
	MonoErrorInternal *error = (MonoErrorInternal*)oerror;
	mono_error_prepare (error);

	error->error_code = MONO_ERROR_MISSING_FIELD;
	mono_error_set_class (oerror, klass);
	mono_error_set_member_name (oerror, field_name);
	set_error_message ();	
}
Exemple #21
0
void
mono_error_set_assembly_load (MonoError *oerror, const char *assembly_name, const char *msg_format, ...)
{
	MonoErrorInternal *error = (MonoErrorInternal*)oerror;
	mono_error_prepare (error);

	error->error_code = MONO_ERROR_FILE_NOT_FOUND;
	mono_error_set_assembly_name (oerror, assembly_name);

	set_error_message ();
}
Exemple #22
0
void
mono_error_set_argument_null (MonoError *oerror, const char *argument, const char *msg_format, ...)
{
	MonoErrorInternal *error = (MonoErrorInternal*)oerror;
	mono_error_prepare (error);

	error->error_code = MONO_ERROR_ARGUMENT_NULL;
	error->first_argument = argument;

	set_error_message ();
}
Exemple #23
0
void
mono_error_set_type_load_name (MonoError *oerror, const char *type_name, const char *assembly_name, const char *msg_format, ...)
{
	MonoErrorInternal *error = (MonoErrorInternal*)oerror;
	mono_error_prepare (error);

	error->error_code = MONO_ERROR_TYPE_LOAD;
	mono_error_set_type_name (oerror, type_name);
	mono_error_set_assembly_name (oerror, assembly_name);
	set_error_message ();
}
Exemple #24
0
void
mono_error_set_argument (MonoError *oerror, const char *argument, const char *msg_format, ...)
{
	MonoErrorInternal *error = (MonoErrorInternal*)oerror;
	mono_error_prepare (error);

	error->error_code = MONO_ERROR_ARGUMENT;
	error->type_name = argument; /*use the first available string slot*/

	set_error_message ();
}
int http_result_code_from_session() {
    const char *p = ne_get_error( dav_session.ctx );
    char *q;
    int err;

    set_error_message(p); /* remember the error message */

    err = strtol(p, &q, 10);
    if (p == q) {
        err = ERRNO_ERROR_STRING;
    }
    return err;
}
Exemple #26
0
void
mono_error_set_not_verifiable (MonoError *oerror, MonoMethod *method, const char *msg_format, ...)
{
	MonoErrorInternal *error = (MonoErrorInternal*)oerror;
	mono_error_prepare (error);

	error->error_code = MONO_ERROR_NOT_VERIFIABLE;
	mono_error_set_class (oerror, method->klass);
	if (method)
		mono_error_set_member_name (oerror, mono_method_full_name (method, 1));

	set_error_message ();
}
Exemple #27
0
static struct acl_data* load_acl(const char* config, struct plugin_handle* handle)
{

	struct acl_data* data = parse_config(config);

	if (!data)
		return 0;

	if (!data->file || !*data->file)
	{
		free_acl(data); data = 0;
		set_error_message(handle, "No configuration file given, missing \"file=<filename>\" configuration option.");
		return 0;
	}

	if (file_read_lines(data->file, data->users, &parse_line) == -1)
	{
		fprintf(stderr, "Unable to load %s\n", data->file);
		set_error_message(handle, "Unable to load file");
	}

	return data;
}
Exemple #28
0
// Parse the HTTP request line
// Format; Method SP Request-URI SP HTTP-Version CRLF
// Example: GET / HTTP/1.1
bool http_request_parse_request_line(HttpRequest* request, char* line)
{
  char* token = NULL;

  // Token 1: HTTP method
  token = trim(strsep(&line, " "));
  if (!token) {
    set_error_message(request, "Error parsing HTTP header line: didn't find method (token 1)");
    return false;
  }
  request->method = http_method_from_string(token);
  if(request->method == HTTP_METHOD_UNKNOWN) {
    set_error_message(request, "Error parsing HTTP header line: unknown method \"%s\"\n", token);
  }

  // Token 2: URI
  token = trim(strsep(&line, " "));
  if (!token) {
    set_error_message(request, "Error Parsing HTTP header line: didn't find request URI (token 2)");
    return false;
  }
  request->uri = strdup(token);

  // Token 3: HTTP version
  token = trim(strsep(&line, " "));
  if (!token) {
    set_error_message(request, "Error Parsing HTTP header line: didn't find HTTP version (token 3)");
    return false;
  }
  request->version = http_version_from_string(token);

  if (request->method == HTTP_VERSION_UNKNOWN) {
    set_error_message(request, "Unrecognized HTTP version \"%s\"\n", token);
    return false;
  }
  return true;
}
Exemple #29
0
const char *PsrGetErrorMessage(void)
{
	const int err_no = parser_errno;
	/* TODO this is a temporal solution for plugin errors */
	/* TODO other errors will be handled in the same ways */
	if (err_no == PSR_ERR_PLUGINNOTFOUND) {
		if (error_message == NULL)
			return "";

		return error_message;
	} else {
		set_error_message(err_no);
		return error_message;
	}
}
Exemple #30
0
    virtual int sync()
    {
        if (pbase() != pptr())
        {
            // Replace '\n' at the end of the message with '\0'
            *(pptr() - 1) = '\0';

            // Call the function in sf.pyx that handles new messages
            set_error_message(pbase());

            setp(pbase(), epptr());
        }

        return 0;
    }