mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-02-05 12:01:25 -05:00
Rough in a Uri class, use it to populate onvif_url if not filled in
This commit is contained in:
@@ -71,6 +71,7 @@ set(ZM_BIN_SRC_FILES
|
||||
zm_stream.cpp
|
||||
zm_swscale.cpp
|
||||
zm_time.cpp
|
||||
zm_uri.cpp
|
||||
zm_user.cpp
|
||||
zm_utils.cpp
|
||||
zm_videostore.cpp
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "zm_signal.h"
|
||||
#include "zm_time.h"
|
||||
#include "zm_utils.h"
|
||||
#include "zm_uri.h"
|
||||
#include "zm_zone.h"
|
||||
|
||||
|
||||
@@ -531,6 +532,12 @@ void Monitor::Load(MYSQL_ROW dbrow, bool load_zones=true, Purpose p = QUERY) {
|
||||
|
||||
/* "`ONVIF_URL`, `ONVIF_Username`, `ONVIF_Password`, `ONVIF_Options`, `ONVIF_Event_Listener`, `use_Amcrest_API`, " */
|
||||
onvif_url = std::string(dbrow[col] ? dbrow[col] : ""); col++;
|
||||
if (onvif_url.empty()) {
|
||||
Uri path_uri(path);
|
||||
if (!path_uri.Host.empty()) {
|
||||
onvif_url = "http://"+path_uri.Host+"/onvif/device_service";
|
||||
}
|
||||
}
|
||||
onvif_username = std::string(dbrow[col] ? dbrow[col] : ""); col++;
|
||||
onvif_password = std::string(dbrow[col] ? dbrow[col] : ""); col++;
|
||||
onvif_options = std::string(dbrow[col] ? dbrow[col] : ""); col++;
|
||||
|
||||
51
src/zm_uri.cpp
Normal file
51
src/zm_uri.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <algorithm> // find
|
||||
|
||||
#include "zm_uri.h"
|
||||
|
||||
Uri::Uri(const std::string &uri) {
|
||||
if (uri.empty()) return;
|
||||
|
||||
typedef std::string::const_iterator iterator_t;
|
||||
|
||||
iterator_t uriEnd = uri.end();
|
||||
|
||||
// get query start
|
||||
iterator_t queryStart = std::find(uri.begin(), uriEnd, '?');
|
||||
|
||||
// protocol
|
||||
iterator_t protocolStart = uri.begin();
|
||||
iterator_t protocolEnd = std::find(protocolStart, uriEnd, ':'); //"://");
|
||||
|
||||
if (protocolEnd != uriEnd) {
|
||||
std::string prot = &*(protocolEnd);
|
||||
if ((prot.length() > 3) && (prot.substr(0, 3) == "://")) {
|
||||
Protocol = std::string(protocolStart, protocolEnd);
|
||||
protocolEnd += 3; // ://
|
||||
} else {
|
||||
protocolEnd = uri.begin(); // no protocol
|
||||
}
|
||||
} else {
|
||||
protocolEnd = uri.begin(); // no protocol
|
||||
}
|
||||
|
||||
// host
|
||||
iterator_t hostStart = protocolEnd;
|
||||
iterator_t pathStart = std::find(hostStart, uriEnd, '/'); // get pathStart
|
||||
|
||||
iterator_t hostEnd = std::find(protocolEnd,
|
||||
(pathStart != uriEnd) ? pathStart : queryStart,
|
||||
':'); // check for port
|
||||
|
||||
Host = std::string(hostStart, hostEnd);
|
||||
|
||||
// port
|
||||
if ((hostEnd != uriEnd) && ((&*(hostEnd))[0] == ':')) {
|
||||
// we have a port
|
||||
hostEnd++;
|
||||
iterator_t portEnd = (pathStart != uriEnd) ? pathStart : queryStart;
|
||||
Port = std::string(hostEnd, portEnd);
|
||||
}
|
||||
|
||||
if (pathStart != uriEnd) Path = std::string(pathStart, queryStart);
|
||||
if (queryStart != uriEnd) QueryString = std::string(queryStart, uri.end());
|
||||
}
|
||||
31
src/zm_uri.h
Normal file
31
src/zm_uri.h
Normal file
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// ZoneMinder Uri Class
|
||||
// Copyright (C) 2023 ZoneMinder Inc
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
|
||||
#ifndef ZM_URI_H
|
||||
#define ZM_URI_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class Uri {
|
||||
public:
|
||||
std::string QueryString, Path, Protocol, Host, Port;
|
||||
|
||||
Uri(const std::string &uri);
|
||||
};
|
||||
#endif
|
||||
Reference in New Issue
Block a user