Mpd 4.1 User Manual : Internals : Hints for developers
Previous: Authentication
Next: References

8.3. Hints for developers

This chapter describes describes some hints for developers.

Source-Code-Style

There is not so much to say about that, just take a look at the existing source files.
The Tab-Width is eight with an indent of two. Please make a space between operators and operands.

NgFuncGetStats

NEVER call NgFuncGetStats() with the clear parameter set to true, because there are other functions (echo requests/replies, bandwidth management) wich relies on increasing link-stats. Mpd carries a copy of the netgraph link-stats at link-level, just use these instead. You can call LinkUpdateStats() for updating the internal stats-struct.

New Authentication-Backends

Authentication backends must run independently from the rest of Mpd, i.e. you must not access the global bund, link or any other global ressource of Mpd, because the authentication process is started in its own thread (you have to take care about thread-safety). An AuthData object is passed to your authenticating function which carries a copy of the link and other parameters. If your backend provides other parameters, like MTU, IP, etc. then put these at the appropriate place into AuthData or Auth. To be sure to not accidentally accessing the global lnk, use something like this:


static int
WhateverAuthenticate(AuthData auth)
{
  Link		const lnk = auth->lnk;	/* hide the global "lnk" */
  Auth		const a = &lnk->lcp.auth;
[...]

If you can't avoid reading from Mpd's internal data, then acquire the Giant Mutex:
[...]
  pthread_mutex_lock(&gGiantMutex);
  [do whatever]
  pthread_mutex_unlock(&gGiantMutex);
[...]

IMPORTANT: Never use the global bund, because it may be changed in the meantime, use the pointer provided by the link:
  Bund		const bund = auth->lnk->bund;	/* hide the global "bund" */

NOTE: The copy of the link is not a deep-copy, so accessing bundle values via auth->lnk->bund is NOT thread-safe.


Mpd 4.1 User Manual : Internals : Hints for developers
Previous: Authentication
Next: References