Commit Graph

601 Commits

Author SHA1 Message Date
Chandra Penke
8eec345e49 Refactor HTTP Client API 2012-02-25 23:38:21 -02:00
Marcelo Roberto Jimenez
ee9f83c3d5 Fix for incorrectly exported include files.
The files FreeList.h, LinkedList.h, ThreadPool.h and TimerThread.h
from the threautil library were being installed in the include
directory of the library, incorrectly exposing internal data structure
of the library.
(cherry picked from commit 0bbe9f62df)
2011-02-06 11:55:04 -02:00
Marcelo Roberto Jimenez
2da8a7fba1 White spaces and indentation. 2011-01-30 09:46:51 -02:00
Chandra Penke
40239ca44a Fix for compilation errors
Fix for compilation warnings of unused variables in upnpdebug.c in
release builds.
(cherry picked from commit 6c125feea0)
2011-01-30 09:43:00 -02:00
Chandra Penke
a2eca3b19d Fix for Race condition can hang miniserver thread.
Add 'requiredThreads' field to the ThreadPool structure, to avoid
a race condition when waiting for a new thread to be created. The
race condition occurs when a thread is destroyed while the master
thread is waiting for a new thread to be created.

Thanks to Chuck Thomason for pointing the problem.

Summary: Race condition can hang miniserver thread - ID: 3158591

Details:
Hello,

I have found a race condition in the thread pool handling of
libupnp-1.6.6 that periodically results in the miniserver thread
getting blocked infinitely.

In my setup, I have the miniserver thread pool configured with 1
job per thread, 2 threads minimum, and 50 threads maximum.

Just before the lockup occurs, the miniserver thread pool contains
2 threads: one worker thread hanging around from a previous HTTP
request job (let's call that thread "old_worker") and the
miniserver thread itself.

A new HTTP request comes in. Accordingly, the miniserver enters
schedule_request_job() and then ThreadPoolAdd(). In
ThreadPoolAdd(), the job gets added to the medium-priority queue,
and AddWorker() is called. In AddWorker(), jobs = 1 and threads =
1, so CreateWorker gets called.

When we enter CreateWorker(), tp->totalThreads is 2, so
currentThreads is 3. The function creates a new thread and then
blocks on tp->start_and_shutdown. The miniserver thread expects
the newly created thread to increment tp->totalThreads and then
signal the condition variable to wake up the miniserver thread and
let it proceed.

The newly created thread starts in the WorkerThread() function. It
increments tp->totalThreads to 3, does a broadcast on the
start_and_shutdown condition, and starts running its job. However,
before the miniserver thread wakes up, "old_worker" times out. It
sees that there are no jobs in any queue and that the total number
of threads (3) is more than the minimum (2). As a result, it
reduces tp->totalThreads to 2 and dies.

Now the miniserver thread finally wakes up. It checks
tp->totalThreads and sees that its value is 2, so it blocks on
tp->start_and_shutdown again. It has now "missed" seeing
tp->totalThreads get incremented to 3 and will never be unblocked
again.

When this issue does occur for a server device, the miniserver
port remains open, but becomes unresponsive since the miniserver
thread is stuck. SSDP alive messages keep getting sent out, as
they are handled by a separate thread. Reproducing the issue is
difficult due to the timing coincidence involved, but in my
environment I am presently seeing it at least once a day. I
figured out the sequence described above through addition of my
own debug logs.

The relevant code involved in this bug has not changed
substantially in libupnp-1.6.10, though I am planning to test
against 1.6.10 as well in the near future.

Do you have any input for an elegant fix for this issue?

Thanks,

Chuck Thomason
(cherry picked from commit c4e9757bcf)
2011-01-20 04:46:57 -02:00
Marcelo Roberto Jimenez
28548e596c Update the documentation about samples in README.
Thanks to Tom (tomdev2).
(cherry picked from commit 639d3a5a03)
2011-01-17 11:37:45 -02:00
Chandra Penke
56ab9ba913 Fix for typo in strndup() function definition.
(cherry picked from commit f46683fd0e)
2011-01-17 09:04:51 -02:00
Chandra Penke
1a574ed6cf Fix for large file definitions, FileInfo.h must include upnpconfig.h 2011-01-17 08:55:57 -02:00
Marcelo Roberto Jimenez
7dae12f17d Fix some ChangeLog dates. 2011-01-17 08:40:00 -02:00
Chandra Penke
bf30519f6c Fix for warnings in Apple systems 2011-01-17 08:18:32 -02:00
Marcelo Roberto Jimenez
bdb3f880b7 Define _FILE_OFFSET_BITS, _LARGEFILE_SOURCE and _LARGE_FILE_SOURCE in upnpconfig.h.
Make these definitions available to programs using the library.
Thanks to Chandra Penke for pointing the problem.
(cherry picked from commit abfa841318)
2011-01-16 22:39:37 -02:00
Chandra Penke
03c3c0913f Allow virtual callbacks to use chunked encoding by setting the file length of a UpnpFileInfo object to be UPNP_USING_CHUNKED. 2011-01-16 21:21:47 -02:00
Marcelo Roberto Jimenez
348bf19412 Use config.h to test for the availability of strndup() and strnlen().
(cherry picked from commit 541679d651)
2011-01-16 21:06:00 -02:00
Marcelo Roberto Jimenez
60c9e95637 Fix for UpnpFileInfo_get_LastModified() in http_MakeMessage().
UpnpFileInfo_get_LastModified() returns time_t, and http_MakeMessage()
takes a "time_t *". Thanks to Chandra Penke for pointing the bug.
2011-01-16 15:09:01 -02:00
Chandra Penke
1e2172819d Fixes chunked transfer encoding in HTTP client API
(cherry picked from commit cb1188d2bc)
2011-01-15 21:14:00 -02:00
Marcelo Roberto Jimenez
6333504d45 Null termination of strndup() implementation on systems missing it.
Also, implementation of strnlen() on systems missing it.
(cherry picked from commit 189ce59dbe)
2011-01-14 22:06:26 -02:00
Marcelo Roberto Jimenez
1232119540 Doxygen on membuffer.
(cherry picked from commit 4815e52586)
2011-01-14 10:28:29 -02:00
Marcelo Roberto Jimenez
9d667685ec Minor change in membuffer.c to include "membuffer.h"
...without looking in the standard header path. This allows pupnp
to build in xcode.
(cherry picked from commit 9051731a93)
2011-01-14 10:28:23 -02:00
Marcelo Roberto Jimenez
82207a3e92 Leave just one call to gmtime() in http_MakeMessage().
(cherry picked from commit 39fd869db8)
2011-01-02 22:37:25 -02:00
Marcelo Roberto Jimenez
8190adb3b9 Make sure va_end() is called in http_MakeMessage().
(cherry picked from commit 8997e7fff6)
2011-01-02 22:37:18 -02:00
Marcelo Roberto Jimenez
7ec5511a8d Fixes many problems in sample code.
In particular, undoes 25c908c558:
SF Patch Tracker [ 2836704 ] Search for nested serviceList (not
stopping at the first lis
Submitted By: zephyrus ( zephyrus00jp )

The original zephyrus' code is still #ifdef'd in the file, if someone
wishes to fix it, check for "#ifdef OLD_FIND_SERVICE_CODE".
(cherry picked from commit 7e8d1787c9)
2010-12-23 22:23:51 -02:00
Marcelo Roberto Jimenez
d4ef92e1bd Simplify code in SampleUtil_GetFirstDocumentItem().
(cherry picked from commit 70d2a7c9e7)
2010-12-23 22:17:52 -02:00
Marcelo Roberto Jimenez
3bf350cceb Doxygen and white spaces in samples. 2010-12-22 11:59:24 -02:00
Marcelo Roberto Jimenez
e07ba67188 Remove unnecessary inclusion of param.h.
(cherry picked from commit 4b0c8d52b8)
2010-12-22 11:56:38 -02:00
Marcelo Roberto Jimenez
e91e4bea0f Fix for segfault in sample code.
(cherry picked from commit c05bbec6ec)
2010-12-22 11:56:31 -02:00
Marcelo Roberto Jimenez
c38724dfa9 Fix debug compilation when CFLAGS is set on the configure line.
(cherry picked from commit d5af7efeb8)
2010-12-22 10:00:40 -02:00
Marcelo Roberto Jimenez
0679697ffd White spaces and some debugging information.
(cherry picked from commit c8af5ec806)
2010-12-22 10:00:32 -02:00
Marcelo Roberto Jimenez
3ec9b0c015 Ivan Romanov's system file inclusion patch for WIN32 (mingw).
(cherry picked from commit 1ee8cd9e1a)
2010-12-21 08:35:43 -02:00
Marcelo Roberto Jimenez
270160b644 Missed this inline in ssdplib.h.
(cherry picked from commit a0ebf23785)
2010-12-19 22:57:44 -02:00
Marcelo Roberto Jimenez
5ef17de780 Remove unused enum SsdpCmdType and unused typedef Event.
(cherry picked from commit cdf35baa34)
2010-12-19 22:55:41 -02:00
Marcelo Roberto Jimenez
408d65ecc8 White spaces.
(cherry picked from commit 6af93e6ca6)
2010-12-19 21:20:29 -02:00
Marcelo Roberto Jimenez
66bdf6effb Less include file mess and doxygenation. 2010-12-19 20:00:56 -02:00
Marcelo Roberto Jimenez
d6f1b5de59 Doxygenation of SSDP library. 2010-12-19 19:57:04 -02:00
Marcelo Roberto Jimenez
6d7b3e65f8 Doxygen. 2010-12-19 19:18:43 -02:00
Marcelo Roberto Jimenez
3ad98ad746 SF Tracker: Patches - Fedora mingw32 compilation - ID: 3138849
Details:
Hello. I trying compile libupnp-1.6.10 on the Fedora 14 MinGW
Environment and get many errors. I create patch to fix it. With this
patch i can get static library. This patch is very raw.

Submitted: Ivan Romanov (ivanromanov) - 2010-12-16 23:29:19 UTC
(cherry picked from commit b2a88aa70b)
2010-12-19 19:10:44 -02:00
Marcelo Roberto Jimenez
82738e3ea5 Get rid of useless integer typedefs.
Remove unsigned32, unsigned16 and unsigned8 references in the code.
(cherry picked from commit bb5a80c05b)
2010-12-19 19:10:23 -02:00
Marcelo Roberto Jimenez
2ccaf7fac8 Remove unnecessary header <sys/utsname.h> from upnpapi.c.
(cherry picked from commit 7e8e5621a8)
2010-12-19 19:10:09 -02:00
Marcelo Roberto Jimenez
b1ae4db35a Use the new include files UpnpIntTypes.h, UpnpStdInt.h and UpnpUniStd.h.
Trying to keep platform dependency on the headers and clean the main
code a little bit.
2010-12-19 19:09:35 -02:00
Marcelo Roberto Jimenez
dd75baab6b White spaces.
(cherry picked from commit d6418b3e17)
2010-12-19 19:07:18 -02:00
Marcelo Roberto Jimenez
59c70e2a0e Doxygen.
(cherry picked from commit e8106e4f05)
2010-12-19 19:07:03 -02:00
Marcelo Roberto Jimenez
ad0584150f Changelog fix from 1.6.x. 2010-12-11 16:53:32 -02:00
Marcelo Roberto Jimenez
72233660b7 Fixes a bug introduced in a previous commit in http_SendMessage.
The variable num_read was beeing used without beeing initialized.

Also, clean up the function return path and make sure va_end()
is beeing called.
(cherry picked from commit 9a28fcc95b)
2010-11-24 12:33:53 -02:00
Marcelo Roberto Jimenez
3bf6f90751 Reformat calls to http_SendMessage().
(cherry picked from commit bfbd07cb40)
2010-11-24 12:33:52 -02:00
Marcelo Roberto Jimenez
0977f8864d soap_device: Doxygen and code reformat. 2010-11-24 12:33:52 -02:00
Fabrice Fontaine
57e9584f4e Major bug fix in http_SendMessage.
Currently, http_SendMessage was not able to write to write a buffer
due to a bad use of file_buf instead of buf. This bug was introduced by
the 0197-Doxygen-reformating-compiler-warnings patch.
(cherry picked from commit 2c3bce13bd)
2010-11-24 11:54:54 -02:00
Fabrice Fontaine
86783f0329 Returning the SID in Upnp_Event_Subscribe.
Currently, Upnp_Event_Subscribe always contains an empty chain in the
Sid parameter. This patch now saves the client Subscription ID in this
parameter so Control Points can see and use the same SID in the
Upnp_Event_Subscribe and in the Upnp_Event structures.
2010-11-24 11:54:24 -02:00
Juergen Lock
25641ac51a Two fixes from Juergen Lock <nox(at)jelal.kn-bremen.de>:
1. varargs:  pass size of CRLF as size_t not as int:

--- upnp/src/gena/gena_device.c.orig
+++ upnp/src/gena/gena_device.c
@@ -225,7 +225,7 @@ static UPNP_INLINE int notify_send_and_r
		"bbb",
		start_msg.buf, start_msg.length,
		propertySet, strlen(propertySet),
-		"\r\n", 2);
+		"\r\n", sizeof "\r\n" - 1);
	if (ret_code) {
		membuffer_destroy(&start_msg);
		sock_destroy(&info, SD_BOTH);

2. Remove "b" arg here, there is no buffer passed:  (this caused a pointer
to be interpreted as a buffer size to be alloc'd/copied, hence the 32 GB.)

--- upnp/src/genlib/net/http/webserver.c.orig
+++ upnp/src/genlib/net/http/webserver.c
@@ -1262,7 +1262,7 @@ static int process_request(
			// Content-Range: bytes 222-3333/4000  HTTP_PARTIAL_CONTENT
			// Transfer-Encoding: chunked
			if (http_MakeMessage(headers, resp_major, resp_minor,
-				"R" "TLD" "s" "tcS" "b" "Xc" "sCc",
+				"R" "TLD" "s" "tcS" "Xc" "sCc",
				HTTP_OK,    // status code
				finfo.content_type, // content type
				RespInstr,  // language info
(cherry picked from commit ed0ebe1588)
2010-11-22 23:29:28 -02:00
Marcelo Roberto Jimenez
252a25af32 White spaces.
(cherry picked from commit d057b2f82a11f4f4d5b9a7524e96348ad3c16106)
2010-11-22 13:21:12 -02:00
Marcelo Roberto Jimenez
f260a0e9d6 Template object for ssdp_ResultData. 2010-11-22 10:22:06 -02:00
Marcelo Roberto Jimenez
9181020d3b Fix for compiler warning about conversion to off_t. 2010-11-22 10:21:28 -02:00