View Issue Details

IDProjectCategoryView StatusLast Update
0004614libmicrohttpdotherpublic2016-10-17 19:21
Reportersilvioprog Assigned ToChristian Grothoff  
PrioritynormalSeverityfeatureReproducibilityhave not tried
Status closedResolutionfixed 
Product VersionGit master 
Target Version0.9.52Fixed in Version0.9.52 
Summary0004614: Declares all log and errors messages in constants

It is known MHD has many internal logs and error messages, however, if you need to translate them, it can be hard, unless you find all messages on MHD sources. See an example below:


      CONNECTION_CLOSE_ERROR (connection,
                  "Internal application error, closing connection.\n");

In my application I want to translate it to pt-BR: "Erro interno na aplicação, fechando a conexão", but MHD has many other messages on its sources, and I'm not sure if all of them are messages or only internal strings.

I have an idea that can solve this problem: declare all logs and error messages in constants and in specific headers, something like MHD_log_msgs.h and MHD_error_msgs.h, so the code could be upgrated to:


#DEFINE MHD_error_internal_application_error "Internal application error, closing connection.\n"



      CONNECTION_CLOSE_ERROR (connection,

Or, if you prefer to update the messages without interfere in third party codes, just use functions:


const * char MHD_error_internal_application_error {
  return "Internal application error, closing connection.\n"



      CONNECTION_CLOSE_ERROR (connection,

And in my application I would use:

  if sametext(error, MHD_error_internal_application_error) {
    error = my_tranlated_internal_application_error_message;


  if sametext(error, MHD_error_internal_application_error()) {
    error = my_tranlated_internal_application_error_message;

Having all messages centralized in an only place, the MHD logs/errors translation would be very easy. :-)

Thank you!
TagsNo tags attached.


Christian Grothoff

2016-08-10 16:27

manager   ~0011016

Well, I must honestly say I never expected anyone to want to bother with MHD error message translations, especially given that I'd expect them to happen deep in the bowels of a (likely unadministered) embedded system.

My view for doing this would be that we could support gettext-style _tagging_, i.e. we

#define _(s) s

and put

log (_("message text"))

into the code. Then GNU gettext can be used to extract all of the strings, and your code _could_ use gettext(msg) to find translations in a .po-file. I would not do the common

#define _(s) gettext(s)

as I'd want to avoid MHD ever depending directly on GNU gettext. But with the above method, the application can choose to involve gettext. WDYT?


2016-08-10 16:42

developer   ~0011017

I'd like to suggest the third way: provide each message to the log function as message number, message string (in English) and optional additional string (error description from system if any). In this way we only need to add numbers to messages and move them to some internal header.
Additional advantage - application can easily filer unwanted messages on their side or log only required messages.
We could also group numbers like (100-299 - informal messages, 300-499 - warning messages, 500-699 - error messages, 700-899 - critical messages).
I missed that feature for Kodi - I want to write to log all MHD messages except most popular "connection aborted".

Christian Grothoff

2016-08-10 16:56

manager   ~0011018

Adding a numeric code will break API compatibility, I don't think this is important enough to do that.

And moving the messages all to some internal header is really not nice for readability of the code.

The GNU style is to use GNU gettext here, and it does seem to satisfy the reporters needs.


2016-08-10 17:30

developer   ~0011019

Both suggested ways sounds very good. The Christian's way would allow to translate all MHD msgs. The Evgeny's way would allow to filter messages, it would really be a very good feature, for example, for messages 700-899, I would use a own generic message like "Critical error, see the log for more details". I agree it breaks API compatibility, but couldn't MHD increase a major version?

Christian Grothoff

2016-08-10 18:01

manager   ~0011020

Well, the "correct" method would probably be to add a 4th argument to the logger callback (at the end, to remain backwards-compatible). I just noticed we don't even export that function type, so we shouldn't even introduce compiler warnings if we do this.


2016-08-10 19:31

developer   ~0011021

I'm not sure that adding more arguments at the end will not break ABI compatibility on all platforms.
As alternative, I'd suggest to add new options MHD_OPTION_EXTERNAL_LOGGER2 or MHD_OPTION_EXTERNAL_LOGGER_EX and optionally deprecate old MHD_OPTION_EXTERNAL_LOGGER.
In this case we will preserve full backward ABI compatibility.


2016-08-10 19:38

developer   ~0011022

We have 'MHD_LogCallback' type in "microhttpd.h".
Not possible to add parameter at the end with 'va_list'.

Christian Grothoff

2016-08-10 22:41

manager   ~0011024

Karlson2k: C technically requires that I must be able to pass extra arguments. So yes, this would not require a .so version bump.

Christian Grothoff

2016-08-10 22:44

manager   ~0011025

Oh, I confused the MHD_OPTION_URI_LOG_CALLBACK with the MHD_OPTION_EXTERNAL_LOGGER. Still, I think you can actually pass arguments after a va_list argument. We would, however, get compiler warnings for the type missmatch.

Christian Grothoff

2016-09-05 16:33

manager   ~0011090

Started to add the "_"-hack and gettext environment. po/libmicrohttpd.pot is the file with the translatable strings (after running 'make dist'). However, I'm not yet done marking them all.

Christian Grothoff

2016-09-07 00:30

manager   ~0011096

_-macro has been introduced where applicable in 37902.

gettext-logic to extract translatable strings is also in place.

Issue History

Date Modified Username Field Change
2016-08-10 15:27 silvioprog New Issue
2016-08-10 16:27 Christian Grothoff Note Added: 0011016
2016-08-10 16:27 Christian Grothoff Assigned To => Christian Grothoff
2016-08-10 16:27 Christian Grothoff Status new => acknowledged
2016-08-10 16:27 Christian Grothoff Status acknowledged => feedback
2016-08-10 16:42 Karlson2k Note Added: 0011017
2016-08-10 16:56 Christian Grothoff Note Added: 0011018
2016-08-10 17:30 silvioprog Note Added: 0011019
2016-08-10 17:30 silvioprog Status feedback => assigned
2016-08-10 18:01 Christian Grothoff Note Added: 0011020
2016-08-10 19:31 Karlson2k Note Added: 0011021
2016-08-10 19:38 Karlson2k Note Added: 0011022
2016-08-10 22:41 Christian Grothoff Note Added: 0011024
2016-08-10 22:44 Christian Grothoff Note Added: 0011025
2016-08-27 11:49 Christian Grothoff Severity minor => feature
2016-08-27 11:49 Christian Grothoff Product Version => Git master
2016-08-27 19:11 Christian Grothoff Summary [FEATURE REQUEST] Declares all log and errors messages in constants => Declares all log and errors messages in constants
2016-08-27 19:13 Christian Grothoff Target Version => 0.9.52
2016-09-05 16:33 Christian Grothoff Note Added: 0011090
2016-09-07 00:30 Christian Grothoff Note Added: 0011096
2016-09-07 00:30 Christian Grothoff Status assigned => resolved
2016-09-07 00:30 Christian Grothoff Fixed in Version => 0.9.52
2016-09-07 00:30 Christian Grothoff Resolution open => fixed
2016-10-17 19:21 Christian Grothoff Status resolved => closed