mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-29 08:21:07 +02:00
yWeb 2.8.a.4
- updated nhttpd
- Code clean up
- changes to nhttpd.conf
- some changes for logo display
git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@416 e54a6e83-5905-42d5-8d5c-058d10e6a962
Origin commit data
------------------
Branch: ni/coolstream
Commit: bad0521f6c
Author: yjogol <yjogol2@online.de>
Date: 2010-02-25 (Thu, 25 Feb 2010)
------------------
This commit was generated by Migit
This commit is contained in:
@@ -4,9 +4,9 @@
|
||||
//=============================================================================
|
||||
|
||||
// c
|
||||
#include <cstdio> // printf prototype.
|
||||
#include <cstdlib> // calloc and free prototypes.
|
||||
#include <cstring> // str* and memset prototypes.
|
||||
#include <cstdio> // printf prototype.
|
||||
#include <cstdlib> // calloc and free prototypes.
|
||||
#include <cstring> // str* and memset prototypes.
|
||||
#include <cstdarg>
|
||||
|
||||
// yhttpd
|
||||
@@ -21,10 +21,11 @@
|
||||
//-------------------------------------------------------------------------
|
||||
// Check and set integer inside boundaries (min, max)
|
||||
//-------------------------------------------------------------------------
|
||||
int minmax(int value,int min, int max)
|
||||
{
|
||||
if(value < min) return min;
|
||||
if(value > max) return max;
|
||||
int minmax(int value, int min, int max) {
|
||||
if (value < min)
|
||||
return min;
|
||||
if (value > max)
|
||||
return max;
|
||||
return value;
|
||||
}
|
||||
//=============================================================================
|
||||
@@ -33,15 +34,14 @@ int minmax(int value,int min, int max)
|
||||
//-------------------------------------------------------------------------
|
||||
// Check and set Date/Time (tm*) inside boundaries
|
||||
//-------------------------------------------------------------------------
|
||||
void correctTime(struct tm *zt)
|
||||
{
|
||||
void correctTime(struct tm *zt) {
|
||||
|
||||
zt->tm_year = minmax(zt->tm_year,0,129);
|
||||
zt->tm_mon = minmax(zt->tm_mon,0,11);
|
||||
zt->tm_mday = minmax(zt->tm_mday,1,31); //-> eine etwas laxe pruefung, aber mktime biegt das wieder grade
|
||||
zt->tm_hour = minmax(zt->tm_hour,0,23);
|
||||
zt->tm_min = minmax(zt->tm_min,0,59);
|
||||
zt->tm_sec = minmax(zt->tm_sec,0,59);
|
||||
zt->tm_year = minmax(zt->tm_year, 0, 129);
|
||||
zt->tm_mon = minmax(zt->tm_mon, 0, 11);
|
||||
zt->tm_mday = minmax(zt->tm_mday, 1, 31); //-> eine etwas laxe pruefung, aber mktime biegt das wieder grade
|
||||
zt->tm_hour = minmax(zt->tm_hour, 0, 23);
|
||||
zt->tm_min = minmax(zt->tm_min, 0, 59);
|
||||
zt->tm_sec = minmax(zt->tm_sec, 0, 59);
|
||||
}
|
||||
//=============================================================================
|
||||
// Strings
|
||||
@@ -49,23 +49,20 @@ void correctTime(struct tm *zt)
|
||||
//-------------------------------------------------------------------------
|
||||
// Integer to Hexadecimal-String
|
||||
//-------------------------------------------------------------------------
|
||||
std::string itoh(unsigned int conv)
|
||||
{
|
||||
return string_printf("0x%06x",conv);
|
||||
std::string itoh(unsigned int conv) {
|
||||
return string_printf("0x%06x", conv);
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
// Integer to String
|
||||
//-------------------------------------------------------------------------
|
||||
std::string itoa(unsigned int conv)
|
||||
{
|
||||
return string_printf("%u",conv);
|
||||
std::string itoa(unsigned int conv) {
|
||||
return string_printf("%u", conv);
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
// convert timer_t to "<hour>:<minutes>" String
|
||||
//-------------------------------------------------------------------------
|
||||
std::string timeString(time_t time)
|
||||
{
|
||||
char tmp[7]={'\0'};
|
||||
std::string timeString(time_t time) {
|
||||
char tmp[7] = { '\0' };
|
||||
struct tm *tm = localtime(&time);
|
||||
if (strftime(tmp, 6, "%H:%M", tm))
|
||||
return std::string(tmp);
|
||||
@@ -77,13 +74,11 @@ std::string timeString(time_t time)
|
||||
// max length up to bufferlen -> then snip
|
||||
//-------------------------------------------------------------------------
|
||||
#define bufferlen 4*1024
|
||||
std::string string_printf(const char *fmt, ...)
|
||||
{
|
||||
std::string string_printf(const char *fmt, ...) {
|
||||
char buffer[bufferlen];
|
||||
va_list arglist;
|
||||
va_start( arglist, fmt );
|
||||
if(arglist)
|
||||
vsnprintf( buffer, bufferlen, fmt, arglist );
|
||||
va_start(arglist, fmt);
|
||||
vsnprintf(buffer, bufferlen, fmt, arglist);
|
||||
va_end(arglist);
|
||||
return std::string(buffer);
|
||||
}
|
||||
@@ -91,16 +86,13 @@ std::string string_printf(const char *fmt, ...)
|
||||
// ySplitString: spit string "str" in two strings "left" and "right" at
|
||||
// one of the chars in "delimiter" returns true if delimiter found
|
||||
//-------------------------------------------------------------------------
|
||||
bool ySplitString(std::string str, std::string delimiter, std::string& left, std::string& right)
|
||||
{
|
||||
bool ySplitString(std::string str, std::string delimiter, std::string& left,
|
||||
std::string& right) {
|
||||
std::string::size_type pos;
|
||||
if ((pos = str.find_first_of(delimiter)) != std::string::npos)
|
||||
{
|
||||
if ((pos = str.find_first_of(delimiter)) != std::string::npos) {
|
||||
left = str.substr(0, pos);
|
||||
right = str.substr(pos + 1, str.length() - (pos + 1 ));
|
||||
}
|
||||
else
|
||||
{
|
||||
right = str.substr(pos + 1, str.length() - (pos + 1));
|
||||
} else {
|
||||
left = str; //default if not found
|
||||
right = "";
|
||||
}
|
||||
@@ -110,16 +102,14 @@ bool ySplitString(std::string str, std::string delimiter, std::string& left, std
|
||||
// ySplitString: spit string "str" in two strings "left" and "right" at
|
||||
// one of the chars in "delimiter" returns true if delimiter found
|
||||
//-------------------------------------------------------------------------
|
||||
bool ySplitStringExact(std::string str, std::string delimiter, std::string& left, std::string& right)
|
||||
{
|
||||
bool ySplitStringExact(std::string str, std::string delimiter,
|
||||
std::string& left, std::string& right) {
|
||||
std::string::size_type pos;
|
||||
if ((pos = str.find(delimiter)) != std::string::npos)
|
||||
{
|
||||
if ((pos = str.find(delimiter)) != std::string::npos) {
|
||||
left = str.substr(0, pos);
|
||||
right = str.substr(pos + delimiter.length(), str.length() - (pos + delimiter.length() ));
|
||||
}
|
||||
else
|
||||
{
|
||||
right = str.substr(pos + delimiter.length(), str.length() - (pos
|
||||
+ delimiter.length()));
|
||||
} else {
|
||||
left = str; //default if not found
|
||||
right = "";
|
||||
}
|
||||
@@ -129,16 +119,13 @@ bool ySplitStringExact(std::string str, std::string delimiter, std::string& left
|
||||
// ySplitStringRight: spit string "str" in two strings "left" and "right" at
|
||||
// one of the chars in "delimiter" returns true if delimiter found
|
||||
//-------------------------------------------------------------------------
|
||||
bool ySplitStringLast(std::string str, std::string delimiter, std::string& left, std::string& right)
|
||||
{
|
||||
bool ySplitStringLast(std::string str, std::string delimiter,
|
||||
std::string& left, std::string& right) {
|
||||
std::string::size_type pos;
|
||||
if ((pos = str.find_last_of(delimiter)) != std::string::npos)
|
||||
{
|
||||
if ((pos = str.find_last_of(delimiter)) != std::string::npos) {
|
||||
left = str.substr(0, pos);
|
||||
right = str.substr(pos + 1, str.length() - (pos + 1 ));
|
||||
}
|
||||
else
|
||||
{
|
||||
right = str.substr(pos + 1, str.length() - (pos + 1));
|
||||
} else {
|
||||
left = str; //default if not found
|
||||
right = "";
|
||||
}
|
||||
@@ -147,33 +134,29 @@ bool ySplitStringLast(std::string str, std::string delimiter, std::string& left,
|
||||
//-------------------------------------------------------------------------
|
||||
// ySplitStringVector: spit string "str" and build vector of strings
|
||||
//-------------------------------------------------------------------------
|
||||
CStringArray ySplitStringVector(std::string str, std::string delimiter)
|
||||
{
|
||||
CStringArray ySplitStringVector(std::string str, std::string delimiter) {
|
||||
std::string left, right, rest;
|
||||
bool found;
|
||||
CStringArray split;
|
||||
rest = str;
|
||||
do
|
||||
{
|
||||
do {
|
||||
found = ySplitString(rest, delimiter, left, right);
|
||||
split.push_back(left);
|
||||
rest = right;
|
||||
}
|
||||
while(found);
|
||||
} while (found);
|
||||
return split;
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
// trim whitespaces
|
||||
//-------------------------------------------------------------------------
|
||||
std::string trim(std::string const& source, char const* delims)
|
||||
{
|
||||
std::string trim(std::string const& source, char const* delims) {
|
||||
std::string result(source);
|
||||
std::string::size_type index = result.find_last_not_of(delims);
|
||||
if(index != std::string::npos)
|
||||
if (index != std::string::npos)
|
||||
result.erase(++index);
|
||||
|
||||
index = result.find_first_not_of(delims);
|
||||
if(index != std::string::npos)
|
||||
if (index != std::string::npos)
|
||||
result.erase(0, index);
|
||||
else
|
||||
result.erase();
|
||||
@@ -182,53 +165,45 @@ std::string trim(std::string const& source, char const* delims)
|
||||
//-------------------------------------------------------------------------
|
||||
// replace all occurrences find_what
|
||||
//-------------------------------------------------------------------------
|
||||
void replace(std::string &str, const std::string &find_what, const std::string &replace_with)
|
||||
{
|
||||
std::string::size_type pos=0;
|
||||
while((pos=str.find(find_what, pos))!=std::string::npos)
|
||||
{
|
||||
void replace(std::string &str, const std::string &find_what,
|
||||
const std::string &replace_with) {
|
||||
std::string::size_type pos = 0;
|
||||
while ((pos = str.find(find_what, pos)) != std::string::npos) {
|
||||
str.erase(pos, find_what.length());
|
||||
str.insert(pos, replace_with);
|
||||
pos+=replace_with.length();
|
||||
pos += replace_with.length();
|
||||
}
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
// equal-function for case insensitive compare
|
||||
//-------------------------------------------------------------------------
|
||||
bool nocase_compare (char c1, char c2)
|
||||
{
|
||||
bool nocase_compare(char c1, char c2) {
|
||||
return toupper(c1) == toupper(c2);
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
// Decode URLEncoded std::string
|
||||
//-----------------------------------------------------------------------------
|
||||
std::string decodeString(std::string encodedString)
|
||||
{
|
||||
std::string decodeString(std::string encodedString) {
|
||||
const char *string = encodedString.c_str();
|
||||
unsigned int count=0;
|
||||
char hex[3]={'\0'};
|
||||
unsigned int count = 0;
|
||||
char hex[3] = { '\0' };
|
||||
unsigned long iStr;
|
||||
std::string result = "";
|
||||
count = 0;
|
||||
|
||||
while(count<encodedString.length()) /* use the null character as a loop terminator */
|
||||
while (count < encodedString.length()) /* use the null character as a loop terminator */
|
||||
{
|
||||
if(string[count] == '%' && count+2 <encodedString.length())
|
||||
{
|
||||
hex[0]=string[count+1];
|
||||
hex[1]=string[count+2];
|
||||
hex[2]='\0';
|
||||
iStr = strtoul(hex,NULL,16); /* convert to Hex char */
|
||||
result += (char)iStr;
|
||||
if (string[count] == '%' && count + 2 < encodedString.length()) {
|
||||
hex[0] = string[count + 1];
|
||||
hex[1] = string[count + 2];
|
||||
hex[2] = '\0';
|
||||
iStr = strtoul(hex, NULL, 16); /* convert to Hex char */
|
||||
result += (char) iStr;
|
||||
count += 3;
|
||||
}
|
||||
else if(string[count] == '+')
|
||||
{
|
||||
} else if (string[count] == '+') {
|
||||
result += ' ';
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
result += string[count];
|
||||
count++;
|
||||
}
|
||||
@@ -238,29 +213,27 @@ std::string decodeString(std::string encodedString)
|
||||
//-----------------------------------------------------------------------------
|
||||
// Encode URLEncoded std::string
|
||||
//-----------------------------------------------------------------------------
|
||||
std::string encodeString(std::string decodedString)
|
||||
{
|
||||
unsigned int len = sizeof(char) * decodedString.length()*5 + 1;
|
||||
std::string result( len, '\0' );
|
||||
char *newString = (char *)result.c_str();
|
||||
char *dstring = (char *)decodedString.c_str();
|
||||
std::string encodeString(std::string decodedString) {
|
||||
unsigned int len = sizeof(char) * decodedString.length() * 5 + 1;
|
||||
std::string result(len, '\0');
|
||||
char *newString = (char *) result.c_str();
|
||||
char *dstring = (char *) decodedString.c_str();
|
||||
char one_char;
|
||||
if(len == result.length()) // got memory needed
|
||||
if (len == result.length()) // got memory needed
|
||||
{
|
||||
while((one_char = *dstring++)) /* use the null character as a loop terminator */
|
||||
while ((one_char = *dstring++)) /* use the null character as a loop terminator */
|
||||
{
|
||||
if(isalnum(one_char))
|
||||
if (isalnum(one_char))
|
||||
*newString++ = one_char;
|
||||
else
|
||||
newString += sprintf(newString, "&#%d;", (unsigned char) one_char);
|
||||
newString += sprintf(newString, "&#%d;",
|
||||
(unsigned char) one_char);
|
||||
}
|
||||
|
||||
*newString='\0'; /* when done copying the string,need to terminate w/ null char */
|
||||
result.resize((unsigned int)(newString - result.c_str()), '\0');
|
||||
*newString = '\0'; /* when done copying the string,need to terminate w/ null char */
|
||||
result.resize((unsigned int) (newString - result.c_str()), '\0');
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -268,9 +241,8 @@ std::string encodeString(std::string decodedString)
|
||||
//-----------------------------------------------------------------------------
|
||||
// returns string in lower case
|
||||
//-----------------------------------------------------------------------------
|
||||
std::string string_tolower(std::string str)
|
||||
{
|
||||
for(unsigned int i = 0; i < str.length(); i++)
|
||||
std::string string_tolower(std::string str) {
|
||||
for (unsigned int i = 0; i < str.length(); i++)
|
||||
str[i] = tolower(str[i]);
|
||||
return str;
|
||||
}
|
||||
@@ -278,16 +250,14 @@ std::string string_tolower(std::string str)
|
||||
//-----------------------------------------------------------------------------
|
||||
// write string to a file
|
||||
//-----------------------------------------------------------------------------
|
||||
bool write_to_file(std::string filename, std::string content)
|
||||
{
|
||||
bool write_to_file(std::string filename, std::string content) {
|
||||
FILE *fd = NULL;
|
||||
if((fd = fopen(filename.c_str(),"w")) != NULL) // open file
|
||||
if ((fd = fopen(filename.c_str(), "w")) != NULL) // open file
|
||||
{
|
||||
fwrite(content.c_str(), content.length(), 1, fd);
|
||||
fflush(fd); // flush and close file
|
||||
fflush(fd); // flush and close file
|
||||
fclose(fd);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user