2017-11-27 17:41:10 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#ifndef PARSE_H
|
|
|
|
#define PARSE_H
|
|
|
|
|
2020-10-25 08:14:16 +00:00
|
|
|
#include "event.h"
|
2020-10-25 12:28:55 +00:00
|
|
|
#include "equipment.h" // for cylinder_t
|
|
|
|
#include "extradata.h"
|
2020-06-17 20:45:33 +00:00
|
|
|
#include "filterpreset.h"
|
2020-10-25 12:28:55 +00:00
|
|
|
#include "picture.h"
|
2020-05-01 11:43:52 +00:00
|
|
|
|
2024-03-01 21:44:45 +00:00
|
|
|
#include <memory>
|
2019-03-03 21:29:40 +00:00
|
|
|
#include <sqlite3.h>
|
2024-05-04 15:55:50 +00:00
|
|
|
#include <string>
|
2020-10-25 12:28:55 +00:00
|
|
|
#include <time.h>
|
2024-05-31 06:22:30 +00:00
|
|
|
#include <vector>
|
2019-03-03 21:29:40 +00:00
|
|
|
|
2020-10-17 18:15:23 +00:00
|
|
|
struct xml_params;
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
struct divelog;
|
2024-05-31 06:22:30 +00:00
|
|
|
struct fingerprint_record;
|
2020-10-17 18:15:23 +00:00
|
|
|
|
2017-11-27 17:41:10 +00:00
|
|
|
/*
|
|
|
|
* Dive info as it is being built up..
|
|
|
|
*/
|
|
|
|
|
2018-01-03 22:48:50 +00:00
|
|
|
struct parser_settings {
|
2017-11-27 17:41:10 +00:00
|
|
|
struct {
|
2024-02-29 06:56:27 +00:00
|
|
|
std::string model;
|
|
|
|
uint32_t deviceid = 0;
|
|
|
|
std::string nickname, serial_nr, firmware;
|
2017-11-27 17:41:10 +00:00
|
|
|
} dc;
|
2021-10-30 23:31:29 +00:00
|
|
|
struct {
|
|
|
|
uint32_t model;
|
|
|
|
uint32_t serial;
|
|
|
|
uint32_t fdeviceid;
|
|
|
|
uint32_t fdiveid;
|
2024-02-29 06:56:27 +00:00
|
|
|
std::string data;
|
2021-10-30 23:31:29 +00:00
|
|
|
} fingerprint;
|
2018-01-03 22:48:50 +00:00
|
|
|
};
|
2017-11-27 17:41:10 +00:00
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
/*
|
|
|
|
* parser_state is the state needed by the parser(s). It is initialized
|
2024-02-29 06:56:27 +00:00
|
|
|
* "owning" marks pointers to objects that are freed in the destructor.
|
2018-10-17 16:45:22 +00:00
|
|
|
* In contrast, "non-owning" marks pointers to objects that are owned
|
|
|
|
* by other data-structures.
|
|
|
|
*/
|
|
|
|
struct parser_state {
|
2024-02-29 06:56:27 +00:00
|
|
|
enum import_source {
|
|
|
|
UNKNOWN,
|
|
|
|
LIBDIVECOMPUTER,
|
|
|
|
DIVINGLOG,
|
|
|
|
UDDF,
|
|
|
|
};
|
|
|
|
|
|
|
|
bool metric = true;
|
2018-10-17 16:45:22 +00:00
|
|
|
struct parser_settings cur_settings;
|
2024-02-29 06:56:27 +00:00
|
|
|
enum import_source import_source = UNKNOWN;
|
|
|
|
|
|
|
|
struct divecomputer *cur_dc = nullptr; /* non-owning */
|
2024-05-16 18:11:21 +00:00
|
|
|
std::unique_ptr<dive> cur_dive; /* owning */
|
2024-05-04 11:39:04 +00:00
|
|
|
std::unique_ptr<dive_site> cur_dive_site; /* owning */
|
2024-05-04 17:15:47 +00:00
|
|
|
location_t cur_location;
|
2024-05-31 15:15:47 +00:00
|
|
|
std::unique_ptr<dive_trip> cur_trip; /* owning */
|
2024-02-29 06:56:27 +00:00
|
|
|
struct sample *cur_sample = nullptr; /* non-owning */
|
2024-05-30 13:00:28 +00:00
|
|
|
struct picture cur_picture; /* owning */
|
2024-03-01 21:44:45 +00:00
|
|
|
std::unique_ptr<filter_preset> cur_filter; /* owning */
|
2024-02-29 06:56:27 +00:00
|
|
|
std::string fulltext; /* owning */
|
|
|
|
std::string fulltext_string_mode; /* owning */
|
|
|
|
std::string filter_constraint_type; /* owning */
|
|
|
|
std::string filter_constraint_string_mode; /* owning */
|
|
|
|
std::string filter_constraint_range_mode; /* owning */
|
|
|
|
bool filter_constraint_negate = false;
|
|
|
|
std::string filter_constraint; /* owning */
|
|
|
|
std::string country, city; /* owning */
|
|
|
|
int taxonomy_category = 0, taxonomy_origin = 0;
|
|
|
|
|
|
|
|
bool in_settings = false;
|
|
|
|
bool in_userid = false;
|
|
|
|
bool in_fulltext = false;
|
|
|
|
bool in_filter_constraint = false;
|
|
|
|
struct tm cur_tm{ 0 };
|
|
|
|
int lastcylinderindex = 0, next_o2_sensor = 0;
|
|
|
|
int o2pressure_sensor = 0;
|
|
|
|
int sample_rate = 0;
|
2024-03-01 21:53:43 +00:00
|
|
|
struct { std::string key; std::string value; } cur_extra_data;
|
2018-10-17 16:45:22 +00:00
|
|
|
struct units xml_parsing_units;
|
2024-02-29 06:56:27 +00:00
|
|
|
struct divelog *log = nullptr; /* non-owning */
|
2024-05-31 06:22:30 +00:00
|
|
|
std::vector<fingerprint_record> *fingerprints = nullptr;
|
|
|
|
/* non-owning */
|
2018-10-17 16:45:22 +00:00
|
|
|
|
2024-02-29 06:56:27 +00:00
|
|
|
sqlite3 *sql_handle = nullptr; /* for SQL based parsers */
|
|
|
|
bool event_active = false;
|
2024-05-04 17:15:47 +00:00
|
|
|
event cur_event;
|
2024-05-04 11:39:04 +00:00
|
|
|
parser_state();
|
2024-02-29 06:56:27 +00:00
|
|
|
~parser_state();
|
2018-10-17 16:45:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void event_start(struct parser_state *state);
|
|
|
|
void event_end(struct parser_state *state);
|
|
|
|
struct divecomputer *get_dc(struct parser_state *state);
|
|
|
|
|
|
|
|
bool is_dive(struct parser_state *state);
|
|
|
|
void reset_dc_info(struct divecomputer *dc, struct parser_state *state);
|
|
|
|
void reset_dc_settings(struct parser_state *state);
|
|
|
|
void settings_start(struct parser_state *state);
|
|
|
|
void settings_end(struct parser_state *state);
|
2021-10-30 23:31:29 +00:00
|
|
|
void fingerprint_settings_start(struct parser_state *state);
|
|
|
|
void fingerprint_settings_end(struct parser_state *state);
|
2018-10-17 16:45:22 +00:00
|
|
|
void dc_settings_start(struct parser_state *state);
|
|
|
|
void dc_settings_end(struct parser_state *state);
|
|
|
|
void dive_site_start(struct parser_state *state);
|
|
|
|
void dive_site_end(struct parser_state *state);
|
|
|
|
void dive_start(struct parser_state *state);
|
|
|
|
void dive_end(struct parser_state *state);
|
2020-06-17 20:45:33 +00:00
|
|
|
void filter_preset_start(struct parser_state *state);
|
|
|
|
void filter_preset_end(struct parser_state *state);
|
|
|
|
void filter_constraint_start(struct parser_state *state);
|
|
|
|
void filter_constraint_end(struct parser_state *state);
|
|
|
|
void fulltext_start(struct parser_state *state);
|
|
|
|
void fulltext_end(struct parser_state *state);
|
2018-10-17 16:45:22 +00:00
|
|
|
void trip_start(struct parser_state *state);
|
|
|
|
void trip_end(struct parser_state *state);
|
|
|
|
void picture_start(struct parser_state *state);
|
|
|
|
void picture_end(struct parser_state *state);
|
2019-08-04 16:59:14 +00:00
|
|
|
cylinder_t *cylinder_start(struct parser_state *state);
|
2018-10-17 16:45:22 +00:00
|
|
|
void cylinder_end(struct parser_state *state);
|
|
|
|
void ws_start(struct parser_state *state);
|
|
|
|
void ws_end(struct parser_state *state);
|
|
|
|
|
|
|
|
void sample_start(struct parser_state *state);
|
|
|
|
void sample_end(struct parser_state *state);
|
|
|
|
void divecomputer_start(struct parser_state *state);
|
|
|
|
void divecomputer_end(struct parser_state *state);
|
|
|
|
void userid_start(struct parser_state *state);
|
|
|
|
void userid_stop(struct parser_state *state);
|
2024-02-29 06:56:27 +00:00
|
|
|
void utf8_string_std(const char *buffer, std::string *res);
|
2017-11-27 17:41:10 +00:00
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
void add_dive_site(const char *ds_name, struct dive *dive, struct parser_state *state);
|
2024-02-29 06:56:27 +00:00
|
|
|
|
|
|
|
int trimspace(char *buffer);
|
|
|
|
void start_match(const char *type, const char *name, char *buffer);
|
|
|
|
void nonmatch(const char *type, const char *name, char *buffer);
|
2017-11-27 18:28:41 +00:00
|
|
|
int atoi_n(char *ptr, unsigned int len);
|
2017-11-27 18:01:19 +00:00
|
|
|
|
2024-05-04 16:53:41 +00:00
|
|
|
void parse_xml_init();
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
int parse_xml_buffer(const char *url, const char *buf, int size, struct divelog *log, const struct xml_params *params);
|
2024-05-04 16:53:41 +00:00
|
|
|
void parse_xml_exit();
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
|
|
|
|
int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
|
|
|
|
int parse_seac_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
|
|
|
|
int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
|
|
|
|
int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
|
|
|
|
int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
|
|
|
|
int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct divelog *log);
|
|
|
|
int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log);
|
2024-02-28 21:01:51 +00:00
|
|
|
std::string trimspace(const char *buffer);
|
2019-03-03 21:29:40 +00:00
|
|
|
|
2017-11-27 17:41:10 +00:00
|
|
|
#endif
|