Source
xxxxxxxxxx
// returns the file path of this url, i.e. '/dir/file.html' in the url 'http://server/dir/file.html'
/*
** Zabbix
** Copyright (C) 2001-2022 Zabbix SIA
**
** 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.
**/
/**
* WARNING: the class doesn't support parsing query strings with multi-dimentional arrays.
*
* @param url
* @param add_sid boolean Add SID to given URL. Default: true.
*/
var Curl = function(url, add_sid) {
url = url || location.href;
if (typeof add_sid === 'undefined') {
add_sid = true;
}
this.url = url;
this.args = {};
this.query = (this.url.indexOf('?') >= 0) ? this.url.substring(this.url.indexOf('?') + 1) : '';
if (this.query.indexOf('#') >= 0) {
this.query = this.query.substring(0, this.query.indexOf('#'));
}
var protocolSepIndex = this.url.indexOf('://');
if (protocolSepIndex >= 0) {
this.protocol = this.url.substring(0, protocolSepIndex).toLowerCase();
this.host = this.url.substring(protocolSepIndex + 3);
if (this.host.indexOf('/') >= 0) {
this.host = this.host.substring(0, this.host.indexOf('/'));
}
var atIndex = this.host.indexOf('@');
if (atIndex >= 0) {
var credentials = this.host.substring(0, atIndex);
var colonIndex = credentials.indexOf(':');
if (colonIndex >= 0) {
this.username = credentials.substring(0, colonIndex);
this.password = credentials.substring(colonIndex);
}
else {
this.username = credentials;
}
this.host = this.host.substring(atIndex + 1);
}