Cleaned up source codes

No changes for logic, only changes layout of functions and valiables between a file to a file.
    Adds s3fs_util.cpp/s3fs_util.h/common.h



git-svn-id: http://s3fs.googlecode.com/svn/trunk@396 df820570-a93a-0410-bd06-b72b767a4274
This commit is contained in:
ggtakec@gmail.com
2013-03-30 13:37:14 +00:00
parent 00b735beaa
commit 953aedd7ad
12 changed files with 1380 additions and 1347 deletions

View File

@ -22,42 +22,50 @@
#include <sstream>
#include <string>
#include <map>
#include "common.h"
#include "string_util.h"
using namespace std;
static const char hexAlphabet[] = "0123456789ABCDEF";
string lower(string s) {
string lower(string s)
{
// change each character of the string to lower case
for(unsigned int i = 0; i < s.length(); i++)
for(unsigned int i = 0; i < s.length(); i++){
s[i] = tolower(s[i]);
}
return s;
}
string IntToStr(int n) {
string IntToStr(int n)
{
stringstream result;
result << n;
return result.str();
}
string trim_left(const string &s, const string &t /* = SPACES */) {
string trim_left(const string &s, const string &t /* = SPACES */)
{
string d(s);
return d.erase(0, s.find_first_not_of(t));
}
string trim_right(const string &s, const string &t /* = SPACES */) {
string trim_right(const string &s, const string &t /* = SPACES */)
{
string d(s);
string::size_type i(d.find_last_not_of(t));
if (i == string::npos)
if(i == string::npos){
return "";
else
}else{
return d.erase(d.find_last_not_of(t) + 1);
}
}
string trim(const string &s, const string &t /* = SPACES */) {
string trim(const string &s, const string &t /* = SPACES */)
{
string d(s);
return trim_left(trim_right(d, t), t);
}
@ -67,18 +75,19 @@ string trim(const string &s, const string &t /* = SPACES */) {
* taking into special consideration "/",
* otherwise regular urlEncode.
*/
string urlEncode(const string &s) {
string urlEncode(const string &s)
{
string result;
for (unsigned i = 0; i < s.length(); ++i) {
if (s[i] == '/') // Note- special case for fuse paths...
if (s[i] == '/') { // Note- special case for fuse paths...
result += s[i];
else if (isalnum(s[i]))
} else if (isalnum(s[i])) {
result += s[i];
else if (s[i] == '.' || s[i] == '-' || s[i] == '*' || s[i] == '_')
} else if (s[i] == '.' || s[i] == '-' || s[i] == '*' || s[i] == '_') {
result += s[i];
else if (s[i] == ' ')
} else if (s[i] == ' ') {
result += '+';
else {
} else {
result += "%";
result += hexAlphabet[static_cast<unsigned char>(s[i]) / 16];
result += hexAlphabet[static_cast<unsigned char>(s[i]) % 16];
@ -88,9 +97,9 @@ string urlEncode(const string &s) {
return result;
}
string prepare_url(const char* url) {
if(debug)
syslog(LOG_DEBUG, "URL is %s", url);
string prepare_url(const char* url)
{
SYSLOGDBG("URL is %s", url);
string uri;
string host;
@ -101,17 +110,16 @@ string prepare_url(const char* url) {
int bucket_length = token.size();
int uri_length = 7;
if(!strncasecmp(url_str.c_str(), "https://", 8))
if(!strncasecmp(url_str.c_str(), "https://", 8)){
uri_length = 8;
}
uri = url_str.substr(0, uri_length);
host = bucket + "." + url_str.substr(uri_length, bucket_pos - uri_length).c_str();
path = url_str.substr((bucket_pos + bucket_length));
url_str = uri + host + path;
if(debug)
syslog(LOG_DEBUG, "URL changed is %s", url_str.c_str());
SYSLOGDBG("URL changed is %s", url_str.c_str());
return str(url_str);
}
@ -120,9 +128,11 @@ string prepare_url(const char* url) {
* Returns the current date
* in a format suitable for a HTTP request header.
*/
string get_date() {
string get_date()
{
char buf[100];
time_t t = time(NULL);
strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&t));
return buf;
}