|
pianod2
multisource multiuser scriptable networked music player
|
Various helpful templates, classes and functions. More...
#include <config.h>#include <cstdio>#include <cstring>#include <cctype>#include <cstdint>#include <cassert>#include <exception>#include <stdexcept>#include "utility.h"
Functions | |
| static const char * | title_adjusted (const char *title) |
| int | compare_title_order (const std::string &astr, const std::string &bstr) |
| Compare titles, ignoring 'a', 'an', or 'the'. More... | |
| static int | count_words (const char *start, const char *end) |
| Count words. More... | |
| bool | compare_person_or_title (const std::string &astr, const std::string &bstr) |
| Compare an artist's name, which might be a person's name or a band. More... | |
| std::string | makeIdentity (std::string s) |
| Remove whitespace and other desireable characters, and make all lowercase for use as an ID. More... | |
| std::vector< std::string > | split_string (const std::string &value) |
| Split a string to words. More... | |
| std::vector< std::string > | split_string (const std::string &value, const std::string separator, const bool include_empty_last) |
| Split a string on a fixed pattern. More... | |
| std::string | join_strings (const std::vector< std::string > &list, const std::string joiner) |
| Join strings together. More... | |
| lamerkey_t | compute_crc (const char *data, lamerkey_t divisor, lamerkey_t remainder) |
| Compute a key from a string using a CRC algorithm. More... | |
| lamerkey_t | create_key_from_string (const char *source) |
| Generate a key from a string. More... | |
| char * | lamer_cipher (const char *keystr, const char *item) |
| Encipher or decipher an item based on a key. More... | |
| std::string | lamer_cipher (const std::string &keystr, const std::string &item) |
Variables | |
| static const lamerkey_t | lamer_crc_generator = 0xae060ed2 |
| Symmetrical cipher using a text string as a key. More... | |
| static const int | lamer_keybits = sizeof (lamerkey_t) * 8 - 1 |
Various helpful templates, classes and functions.
| bool compare_person_or_title | ( | const std::string & | astr, |
| const std::string & | bstr | ||
| ) |
Compare an artist's name, which might be a person's name or a band.
If it's a title, it may have 'a', 'an', or 'the', or maybe not. If it's a person, it may be /first last/ or /last, first/.
| astr | First title. |
| bstr | Second title. |


| int compare_title_order | ( | const std::string & | astr, |
| const std::string & | bstr | ||
| ) |
Compare titles, ignoring 'a', 'an', or 'the'.
| astr | First title. |
| bstr | Second title. |


| lamerkey_t compute_crc | ( | const char * | data, |
| lamerkey_t | divisor, | ||
| lamerkey_t | remainder | ||
| ) |
Compute a key from a string using a CRC algorithm.
If VARIABLE_SIZE_DIVISORS is set, the CRC length is determined dynamically by the value in the divisor. Otherwise, it is determined by the length of the generator set in constants above.
| data | The string to use to generate the key. |
| divisor | The generator/divisor for performing the CRC. |
| remainder | For unit testing; set to 0 for generating keys. For test purposes, reinvoke this function pass the function's result for remainder. The result should be 0; if not, it's broken. |

|
static |
Count words.
| start | Start of string to count. |
| end | End of string to count. |
start and end. 
| lamerkey_t create_key_from_string | ( | const char * | source | ) |
Generate a key from a string.
| source | The string. |


| std::string join_strings | ( | const std::vector< std::string > & | list, |
| const std::string | joiner | ||
| ) |
Join strings together.
| list | The strings to join. |
| joiner | The string to insert between list strings. |

| char* lamer_cipher | ( | const char * | keystr, |
| const char * | item | ||
| ) |
Encipher or decipher an item based on a key.
| keystr | The string to use to generate a key. |
| item | The string to encipher or decipher. |


| std::string lamer_cipher | ( | const std::string & | keystr, |
| const std::string & | item | ||
| ) |

| std::string makeIdentity | ( | std::string | s | ) |
Remove whitespace and other desireable characters, and make all lowercase for use as an ID.
| std::vector<std::string> split_string | ( | const std::string & | value | ) |
Split a string to words.
Mid-word punctuation is retained.
| value | The string to split. |

| std::vector<std::string> split_string | ( | const std::string & | value, |
| const std::string | separator, | ||
| const bool | include_empty_last | ||
| ) |
Split a string on a fixed pattern.
| value | The string to split. |
| separator | The pattern for splitting the string. It is removed from the result strings. |
| include_empty_last | If false, then if the separator occurs at end of string, then the null space following it is omitted from the results. |
|
inlinestatic |


|
static |
Symmetrical cipher using a text string as a key.
This is a simplistic cipher intended to be difficult enough to inconvenience hand deciphering, but nothing truly secure. In short: Enough to keep the riff-raff out.
Usernames cannot be changed in pianod. The user's name will be used to generate the key by feeding it through a 32-bit CRC generator. Note that a 32-bit generator yields 31 bits of CRC. We will then encipher the password symetrically with the key/CRC as follows:
This is certainly not NSA quality, and there are hazards of inventing your own encryption system; but given the inherent insecurity of anyone being able to strategically add printf ("%s's password is %s\n", user->password, user->name) and recompiling, this is adequate. It is, after all, only a music server.
|
static |