Commit Graph

58 Commits

Author SHA1 Message Date
Max Kellermann
a92903983d client: use bool
Return bool instead of int.
2008-10-31 13:58:00 +01:00
Max Kellermann
5ef17ac1aa client: don't try again after partial write
After a partial write, chances are vanishing that another write() will
succeed.  Don't try immediately.
2008-10-31 09:19:40 +01:00
Max Kellermann
94cbdffb72 client: use GQueue instead of sllist.h for deferred_send
Another custom data structore converted to GLib.
2008-10-31 09:18:11 +01:00
Max Kellermann
90e9079142 client: use GSList instead of struct strnode for command lists
Replace a custom data structure with a GLib one.
2008-10-31 09:17:56 +01:00
Max Kellermann
e5ef2d8a37 client: removed list_cache
The list cache aims to save memory allocations, and complicates the
code a bit.  We should rather use GLib slices later, which are easy to
use.
2008-10-31 09:17:52 +01:00
Max Kellermann
51a6ee88f7 command: no CamelCase
Eliminate CamelCase in all public and static functions.
2008-10-22 21:40:44 +02:00
Max Kellermann
02a2a407c1 client: converted permissions to unsigned
client->permission is a bit set, and should be unsigned.
2008-10-17 23:53:28 +02:00
Max Kellermann
f8d5b74071 client: eliminate variable "left" in client_write()
Reduce two temporary variables to only one.
2008-10-17 23:53:16 +02:00
Max Kellermann
bdbccc633d client: fixed send buffer
There is no sense in using the kernel's send buffer size (SO_SNDBUF)
for MPD's send buffer.  Convert it into a static buffer of 4 kB.
2008-10-17 23:52:47 +02:00
Max Kellermann
48c11c52ac client: removed CLIENT_MAX_BUFFER_LENGTH
Use a literal in the struct declaration, and sizeof(client->buffer)
everywhere else.  Also shrink the buffer from 40 kB to 4 kB.  The
buffer must only be large enough to hold one line of input, and 4 kB
is still more than enough.
2008-10-17 23:52:40 +02:00
Max Kellermann
3689d5e4ed client: added assertions on the buffer pointers
The buffer pointers must not exceed the buffer size.
2008-10-17 23:29:41 +02:00
Max Kellermann
d691577a96 client: read() return value is ssize_t
Use ssize_t instead of int.
2008-10-17 23:26:40 +02:00
Max Kellermann
79459d08d9 client: handle partial lines correctly
Commit 6eb62e47 didn't obey partial lines correctly: when a line
wasn't finished in one read, the first part was ignored when the rest
arrived.
2008-10-17 23:23:54 +02:00
Max Kellermann
4a7ad5b618 listen, client: enable SO_PASSCRED, get client's uid
Enable authentication over unix sockets.  Store the client's uid in
the client struct.
2008-10-15 22:34:21 +02:00
Max Kellermann
cf7ed8c5df idle: client command "noidle" aborts idle 2008-10-15 18:21:57 +02:00
Max Kellermann
6eb62e4761 client: optimized client_input_received()
Use memchr() instead of manually traversing the input buffer.  Update
the client's properties after all commands have been processed.  Check
for buffer overflow once.
2008-10-15 18:21:45 +02:00
Max Kellermann
a3e3d2c950 command: added command "idle"
"idle" waits until something noteworthy happens on the server,
e.g. song change, playlist modified, database updated.  This allows
clients to keep up to date without polling.
2008-10-14 22:38:14 +02:00
Max Kellermann
71351160b1 don't include os_compat.h
When there are standardized headers, use these instead of the bloated
os_compat.h.
2008-10-08 10:49:29 +02:00
Max Kellermann
ef0e2fdc1b client: check expired after client_process_line()
The assertion on "!client_is_expired(client)" was wrong, because
writing the command response may cause the client to become expired.
Replace that assertion with a check.
2008-09-17 22:02:13 +02:00
Max Kellermann
9ceadb0561 client: simplified client_read()
Remove one comparison by changing branch order.
2008-09-10 11:43:09 +02:00
Max Kellermann
1bb154098d client: client_input_received() returns 0
Since the caller chain doesn't care about the return value (except for
COMMAND_RETURN_KILL, COMMAND_RETURN_CLOSE), just return 0 if there is
nothing special.  This saves one local variable initialization, and
one access to it.

Also remove one unreachable "return 1" from client_read().
2008-09-10 11:42:30 +02:00
Max Kellermann
48191d5661 client: check for COMMAND_RETURN_CLOSE
Don't close the client within client_process_line(), return
COMMAND_RETURN_CLOSE instead.  This is the signal for the caller chain
to actually close it.  This makes dealing with the client pointer a
lot safer, since the caller always knows whether it is still valid.
2008-09-10 11:42:26 +02:00
Max Kellermann
a580f5fe68 client: renamed local variable "selret" to "ret"
It's easier to reuse the variable if it has a more generic name.
2008-09-10 11:41:34 +02:00
Max Kellermann
a49b1d145e client: moved CLOSE/KILL check after client_process_line()
Don't update client data if it is going to be closed anyway.
2008-09-10 11:41:33 +02:00
Max Kellermann
1ce5f4d75b command: use client_[gs]et_permission()
Don't pass a pointer to client->permission to processCommand(), better
let the code in command.c use the new permission getter/setter
functions.
2008-09-07 19:17:25 +02:00
Max Kellermann
2835e37684 client: added client_[gs]et_permission()
The code in command.c shouldn't mess with a pointer to
client->permission.  Provide an API for accessing this value.
2008-09-07 19:16:34 +02:00
Max Kellermann
86d261bdb5 removed fdprintf() and client_print()
All callers of fdprintf() have been converted to client_printf() or
fprintf(); it is time to remove this clumsy hack now.  We can also
remove client_print() which took a file descriptor as parameter.
2008-09-07 14:08:37 +02:00
Max Kellermann
322e908893 client: removed client_get_fd()
Now that we have removed all invocations of client_get_fd(), we can
safely remove this transitional function.  All access to the file
descriptor is now hidden behind the interface declared in client.h.
2008-09-07 14:05:02 +02:00
Max Kellermann
54371add13 command: added command_success() and command_error()
These two functions take a client struct instead of the file
descriptor.  We will now begin passing the client struct around
instead of a raw file descriptor (which needed a linear lookup in the
client list to be useful).
2008-09-07 13:51:59 +02:00
Max Kellermann
f73319c048 client: added client_printf()
Based on client_puts(), client_printf() is the successor of
fdprintf().  As soon as all fdprintf() callers have been rewritten to
use client_printf(), we can remove fdprintf().
2008-09-07 13:25:54 +02:00
Max Kellermann
33aec0d673 client: added client_write() and client_puts()
client_write() writes a buffer to the client and buffers it if
required.  client_puts() does the same for a C string.  The next patch
will add more tools which will replace fdprintf() later.
2008-09-07 13:24:51 +02:00
Max Kellermann
a34e1d2b84 include cleanup
As usual, include only headers which are really needed.
2008-09-06 20:28:31 +02:00
Max Kellermann
6146d4f5bb client: don't check FD_ISSET(client->fd) on expired client
client->fd becomes -1 when the client expires.  Don't use FD_ISSET()
with this expired client; doing so would cause a crash due to SIGBUS.
2008-09-06 15:31:55 +02:00
Max Kellermann
77b1671662 client: removed assert(client->fd)>=0
Since client->fd==-1 has become our "expired" flag, it may already be
-1 when client_close() is called.  Don't assert that it is still
non-negative, and call client_set_expired() instead.
2008-09-06 15:31:55 +02:00
Max Kellermann
8811c0e059 export the function client_is_expired()
Instead of passing the pointer to the "expired" flag to
processListOfCommands(), this function should use the client API to
check this flag.  We can now remove the "global_expired" hack
introduced recently.
2008-08-29 09:37:11 +02:00
Max Kellermann
8b1b82b363 client: pass the client struct to processCommand()
Start exporting the client struct as an opaque struct.  For now, pass
it only to processCommand() and processListOfCommands(), and provide a
function to extract the socket handle.  Later, we will propagate the
pointer to all command implementations, and of course to
client_print() etc.
2008-08-29 09:36:42 +02:00
Max Kellermann
e743d71b89 client: check "expired" after command execution
The old code tried to write a response to the client, without even
checking if it was already closed.  Now that we have added more
assertions, these may fail...  perform the "expired" check earlier.
2008-08-29 09:36:40 +02:00
Max Kellermann
76ecc30243 client: added global "expired" flag
Patch bdeb8e14 ("client: moved "expired" accesses into inline
function") was created under the wrong assumption that
processListOfCommands() could modify the expired flag, which is not
the case.  Although "expired" is a non-const pointer,
processListOfCommands() just reads it, using it as the break condition
in a "while" loop.  I will address this issue with a better overall
solution, but for now provide a pointer to a global "expired" flag.
2008-08-29 09:36:38 +02:00
Max Kellermann
d8a8fa63b4 client: removed superfluous assertion
client_defer_output() was modified so that it can create the
deferred_send list.  With this patch, the assertion on
"deferred_send!=NULL" has become invalid.  Remove it.
2008-08-29 06:17:54 +02:00
Max Kellermann
08c9de7b68 client: more assertions 2008-08-28 20:23:22 +02:00
Max Kellermann
4e17ab11a8 client: replace "expired" flag with fd==-1
Why waste 4 bytes for a flag which we can hide in another variable.
2008-08-28 20:20:10 +02:00
Max Kellermann
bdeb8e148e client: moved "expired" accesses into inline function
Hiding this flag allows us later to remove it easily.
2008-08-28 20:20:10 +02:00
Max Kellermann
e0fd63ecf8 moved code to sockaddr_to_tmp_string()
Unclutter the client_new() constructor by moving unrelated complex
code into a separate function.
2008-08-28 20:20:10 +02:00
Max Kellermann
34735fab66 client: no while loop in client_manager_io()
The last patch removed the "continue" directive, and now the while
loop is without function.  Remove it.  Also make client_manager_io()
return 0.
2008-08-28 20:20:10 +02:00
Max Kellermann
f6a7dd2b45 client: select() errors are fatal
Previously, when select() failed, we assumed that there was an invalid
file descriptor in one of the client structs.  Thus we tried select()
one by one.  This is bogus, because we should never have invalid file
descriptors.  Remove it, and make select() errors fatal.
2008-08-28 20:20:10 +02:00
Max Kellermann
32bb19d03f client: use client_defer_output() in client_write()
Eliminate duplicated code, call client_defer_output() which we
splitted from client_write_output() earlier.
2008-08-28 20:20:04 +02:00
Max Kellermann
709b795e4a moved code to client_write()
Move the second part of client_write_output() into a separate
function.
2008-08-28 20:03:58 +02:00
Max Kellermann
4516bd117c client: client_defer_output() can create the first defer buffer
client_defer_output() was designed to add new buffers to an existing
deferred_send buffer.  Tweak it and allow it to create a new buffer
list.
2008-08-28 20:03:56 +02:00
Max Kellermann
20f06162dd client: return early on error in client_defer_output()
Exit the function when an error occurs, and move the rest of the
following code one indent level left.
2008-08-28 20:03:54 +02:00
Max Kellermann
7774cd2774 client: moved code to client_defer_output()
Split the large function client_write_output() into two parts; this is
the first code moving patch.
2008-08-28 20:03:51 +02:00