<commit_before>var https = require("https");
var xmljs = require("libxmljs");

module.exports = {
	
    /**
     * Get a list of Folders/Calendars from a given url
     *
     * @param  {String} url
	* @param  {String} user
	* @param  {String} pass
	* @param  {function} cb
   
     */
	
  getList: function(url,user,pass,cb){
	 
	 var urlparts = /(https?)\:\/\/(.*?)(\/.*)/gi.exec(url)
	 var port = 80;
	 if( urlparts[1] == "https" ){ port = 443 }
	 var host = urlparts[2];
	 var path = urlparts[3];
	  
	var xml = '<?xml version="1.0" encoding="utf-8" ?>\n' +
	' <D:propfind xmlns:D="DAV:" xmlns:C="http://calendarserver.org/ns/">\n' +
	'     <D:prop>\n' +
	'             <D:displayname />\n' +
	'     </D:prop>\n' +
	' </D:propfind>';
	
	var options = {
	  rejectUnauthorized: false,
	  hostname: host,
	  port: port,
	  path: path,
	  method: 'PROPFIND',
	  headers : {
		  "Content-type" 	: 	"text/xml",
		  "Content-Length"	: 	xml.length,
		  "User-Agent"		: 	"calDavClient",
		  "Connection" 		: 	"close",
		  "Depth"			: 	"1", 
	  }
	};
	
	if( user && pass ){
		var userpass = new Buffer( user + ":" + pass ).toString('base64');
		options.headers["Authorization"] = "Basic " + userpass;
	}
	
	
	var req = https.request(options, function(res) {
	 var s = "";
	  res.on('data', function (chunk) {
	    s += chunk;
	  });
  
	  req.on('close', function(){
		var reslist = [];  
		try{
	  	var xmlDoc = xmljs.parseXml(s);
		// console.log(xmlDoc.toString() );
		var resp = xmlDoc.find("a:response",{ a: 'DAV:'});
	  	for(i in resp){
	  		var el = resp[i];
			var href = el.get("a:href",{ a: 'DAV:'});
			var dspn = el.get("a:propstat/a:prop/a:displayname",{ a: 'DAV:'});
			if( dspn ){
				var resobj = {};
				resobj.displayName = dspn.text();
				resobj.href = href.text();
				reslist.push( resobj );
			}
	  	}
		} catch(e){
			console.log("Error parsing response")
		}
		
		cb(reslist);
		
	  });
	});

	req.end( xml );

	req.on('error', function(e) {
	  console.log('problem with request: ' + e.message);
	});
	
},

/**
 * Get a list of Events from a given Calendarurl
 *
 * @param  {String} url
* @param  {String} user
* @param  {String} pass
* @param  {function} cb

 */
  getEvents: function (url,user,pass,cb){
	  
 	 var urlparts = /(https?)\:\/\/(.*?)(\/.*)/gi.exec(url)
 	 var port = 80;
 	 if( urlparts[1] == "https" ){ port = 443 }
 	 var host = urlparts[2];
 	 var path = urlparts[3];
	
	var xml = '<?xml version="1.0" encoding="utf-8" ?>\n' +
	'<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">\n' +
	'  <D:prop>\n' +
	'    <C:calendar-data/>\n' +
	'  </D:prop>\n' +
	'  <C:filter>\n' +
	'    <C:comp-filter name="VCALENDAR">\n' +
	'      <C:comp-filter name="VEVENT">\n' +
	'        <C:time-range start="20140617T112033Z"/>\n' +
	'      </C:comp-filter>\n' +
	'    </C:comp-filter>\n' +<commit_msg>Support port of url.<commit_after>var https = require("https");
var xmljs = require("libxmljs");

module.exports = {
	
    /**
     * Get a list of Folders/Calendars from a given url
     *
     * @param  {String} url
	* @param  {String} user
	* @param  {String} pass
	* @param  {function} cb
   
     */
	
  getList: function(url,user,pass,cb){

      var urlparts = /(https?)\:\/\/(.*?):?(\d*)?(\/.*\/?)/gi.exec(url);
      var protocol = urlparts[1];
      var host = urlparts[2];
      var port = urlparts[3] || (protocol === "https" ? 443 : 80);
      var path = urlparts[4];
	  
	var xml = '<?xml version="1.0" encoding="utf-8" ?>\n' +
	' <D:propfind xmlns:D="DAV:" xmlns:C="http://calendarserver.org/ns/">\n' +
	'     <D:prop>\n' +
	'             <D:displayname />\n' +
	'     </D:prop>\n' +
	' </D:propfind>';
	
	var options = {
	  rejectUnauthorized: false,
	  hostname: host,
	  port: port,
	  path: path,
	  method: 'PROPFIND',
	  headers : {
		  "Content-type" 	: 	"text/xml",
		  "Content-Length"	: 	xml.length,
		  "User-Agent"		: 	"calDavClient",
		  "Connection" 		: 	"close",
		  "Depth"			: 	"1", 
	  }
	};
	
	if( user && pass ){
		var userpass = new Buffer( user + ":" + pass ).toString('base64');
		options.headers["Authorization"] = "Basic " + userpass;
	}
	
	
	var req = https.request(options, function(res) {
	 var s = "";
	  res.on('data', function (chunk) {
	    s += chunk;
	  });
  
	  req.on('close', function(){
		var reslist = [];  
		try{
	  	var xmlDoc = xmljs.parseXml(s);
		// console.log(xmlDoc.toString() );
		var resp = xmlDoc.find("a:response",{ a: 'DAV:'});
	  	for(i in resp){
	  		var el = resp[i];
			var href = el.get("a:href",{ a: 'DAV:'});
			var dspn = el.get("a:propstat/a:prop/a:displayname",{ a: 'DAV:'});
			if( dspn ){
				var resobj = {};
				resobj.displayName = dspn.text();
				resobj.href = href.text();
				reslist.push( resobj );
			}
	  	}
		} catch(e){
			console.log("Error parsing response")
		}
		
		cb(reslist);
		
	  });
	});

	req.end( xml );

	req.on('error', function(e) {
	  console.log('problem with request: ' + e.message);
	});
	
},

/**
 * Get a list of Events from a given Calendarurl
 *
 * @param  {String} url
* @param  {String} user
* @param  {String} pass
* @param  {function} cb

 */
  getEvents: function (url,user,pass,cb){

  var urlparts = /(https?)\:\/\/(.*?):?(\d*)?(\/.*\/?)/gi.exec(url);
  var protocol = urlparts[1];
  var host = urlparts[2];
  var port = urlparts[3] || (protocol === "https" ? 443 : 80);
  var path = urlparts[4];

	var xml = '<?xml version="1.0" encoding="utf-8" ?>\n' +
	'<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">\n' +
	'  <D:prop>\n' +
	'    <C:calendar-data/>\n' +
	'  </D:prop>\n' +
	'  <C:filter>\n' +
	'    <C:comp-filter name="VCALENDAR">\n' +
	'      <C:comp-filter name="VEVENT">\n' +
	'        <C:time-range start="20140617T112033Z"/>\n' +
	'      </C:comp-filter>\n' +
	'    </C:comp-filter>\n' +
{'fraction_non_alphanumeric': 0.2215889464594128, 'fraction_numerical': 0.013816925734024179, 'mean_word_length': 2.669835234474018, 'pattern_counts': {'":': 2, '<': 37, '<?xml version=': 4, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 36}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4831341', 'n_tokens_mistral': 2564, 'n_tokens_neox': 2321, 'n_words': 453}