Added support for mystery person (aka mystery man)
the build was successful
Details
the build was successful
Details
This commit is contained in:
parent
ed83a9c4a8
commit
43232d802b
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required (VERSION 3.2)
|
cmake_minimum_required (VERSION 3.2)
|
||||||
project(libravatarserv
|
project(libravatarserv
|
||||||
VERSION 0.3.2
|
VERSION 0.4.0
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ images tied to email or OpenID addresses.
|
||||||
* MD5 hashes
|
* MD5 hashes
|
||||||
* SHA256 hashes
|
* SHA256 hashes
|
||||||
* Variable image size (`s` or `size`)
|
* Variable image size (`s` or `size`)
|
||||||
* Default actions (`d` or `default`): 404, URL
|
* Default actions (`d` or `default`): 404, URL, mp/mm
|
||||||
|
|
||||||
The default behaviour for unknown users is to return a 404 error. If a default
|
The default behaviour for unknown users is to return a 404 error. If a default
|
||||||
image is put in the avatar directory, that is returned instead. The default
|
image is put in the avatar directory, that is returned instead. The default
|
||||||
|
@ -47,6 +47,10 @@ variable `${LIBRAVATARSERV_DIR}` (until 0.3.0 `${AVATAR_DIR}`).
|
||||||
The image files are named like your email address, no file extension. If you
|
The image files are named like your email address, no file extension. If you
|
||||||
want to deliver a default image for unknown email addresses, name it `default`.
|
want to deliver a default image for unknown email addresses, name it `default`.
|
||||||
|
|
||||||
|
If you want to support "Mystery persons" (mp/mm) as default avatars, place a
|
||||||
|
file named `mp` in the avatar dir. You can use the [default libravatar mystery
|
||||||
|
person](https://seccdn.libravatar.org/mm/512.png), for example.
|
||||||
|
|
||||||
Test your setup on https://www.libravatar.org/tools/check/.
|
Test your setup on https://www.libravatar.org/tools/check/.
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "libravatarserv.hpp"
|
#include "libravatarserv.hpp"
|
||||||
|
|
||||||
|
using std::cout;
|
||||||
using std::cerr;
|
using std::cerr;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
using global::avatar_dir;
|
using global::avatar_dir;
|
||||||
|
@ -61,3 +62,10 @@ const Image image::get(const string &digest, const uint16_t size)
|
||||||
|
|
||||||
return { error, img };
|
return { error, img };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void image::write(Image &image)
|
||||||
|
{
|
||||||
|
cout << "Content-type: image/png\n\n";
|
||||||
|
cout.flush(); // We need to flush before we use /dev/stdout directly.
|
||||||
|
image.image.write("/dev/stdout");
|
||||||
|
}
|
||||||
|
|
|
@ -54,16 +54,14 @@ int main()
|
||||||
|
|
||||||
http::Request avatar = http::parse_request(request);
|
http::Request avatar = http::parse_request(request);
|
||||||
|
|
||||||
image::Image answer = image::get(avatar.digest, avatar.size);
|
image::Image image = image::get(avatar.digest, avatar.size);
|
||||||
if (answer.error == 0)
|
if (image.error == 0)
|
||||||
{
|
{
|
||||||
cout << "Content-type: image/png\n\n";
|
image::write(image);
|
||||||
cout.flush(); // We need to flush before we use /dev/stdout directly.
|
|
||||||
answer.image.write("/dev/stdout");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cerr << "Error " << std::to_string(answer.error) << ": Could not open file.\n";
|
cerr << "Error " << std::to_string(image.error) << ": Could not open file.\n";
|
||||||
if (avatar.fallback.empty())
|
if (avatar.fallback.empty())
|
||||||
{
|
{
|
||||||
cout << "Status: 404 Not Found\n\n";
|
cout << "Status: 404 Not Found\n\n";
|
||||||
|
@ -75,6 +73,22 @@ int main()
|
||||||
cout << "Status: 307 Temporary Redirect\n";
|
cout << "Status: 307 Temporary Redirect\n";
|
||||||
cout << "Location: " << avatar.fallback << endl << endl;
|
cout << "Location: " << avatar.fallback << endl << endl;
|
||||||
}
|
}
|
||||||
|
else if (avatar.fallback.substr(0, 2) == "mp" ||
|
||||||
|
avatar.fallback.substr(0, 2) == "mm")
|
||||||
|
{
|
||||||
|
// MD5 hash of 'mp'
|
||||||
|
image = image::get("1f2dfa567dcf95833eddf7aec167fec7",
|
||||||
|
avatar.size);
|
||||||
|
if (image.error == 0)
|
||||||
|
{
|
||||||
|
image::write(image);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cout << "Status: 404 Not Found\n\n";
|
||||||
|
cerr << "Mystery person not found.\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,11 +69,12 @@ namespace image // image.cpp
|
||||||
{
|
{
|
||||||
struct Image
|
struct Image
|
||||||
{
|
{
|
||||||
const uint8_t error;
|
uint8_t error;
|
||||||
Magick::Image image;
|
Magick::Image image;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Image get(const string &digest, const uint16_t size);
|
const Image get(const string &digest, const uint16_t size);
|
||||||
|
void write(Image &image);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // LIBRAVATARSERV_HPP
|
#endif // LIBRAVATARSERV_HPP
|
||||||
|
|
Loading…
Reference in New Issue