aboutsummaryrefslogtreecommitdiff
path: root/src/nat/miniupnp/minisoap.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nat/miniupnp/minisoap.c')
-rw-r--r--src/nat/miniupnp/minisoap.c106
1 files changed, 0 insertions, 106 deletions
diff --git a/src/nat/miniupnp/minisoap.c b/src/nat/miniupnp/minisoap.c
deleted file mode 100644
index a020f9a64..000000000
--- a/src/nat/miniupnp/minisoap.c
+++ /dev/null
@@ -1,106 +0,0 @@
1/* $Id: minisoap.c,v 1.16 2008/10/11 16:39:29 nanard Exp $ */
2/* Project : miniupnp
3 * Author : Thomas Bernard
4 * Copyright (c) 2005 Thomas Bernard
5 * This software is subject to the conditions detailed in the
6 * LICENCE file provided in this distribution.
7 *
8 * Minimal SOAP implementation for UPnP protocol.
9 */
10#include <stdio.h>
11#include <string.h>
12#ifdef WIN32
13#include <io.h>
14#include <winsock2.h>
15#define snprintf _snprintf
16#else
17#include <unistd.h>
18#include <sys/types.h>
19#include <sys/socket.h>
20#endif
21#include "minisoap.h"
22#include "miniupnpcstrings.h"
23
24/* only for malloc */
25#include <stdlib.h>
26
27#ifdef WIN32
28#define PRINT_SOCKET_ERROR(x) printf("Socket error: %s, %d\n", x, WSAGetLastError());
29#else
30#define PRINT_SOCKET_ERROR(x) perror(x)
31#endif
32
33/* httpWrite sends the headers and the body to the socket
34 * and returns the number of bytes sent */
35static int
36httpWrite (int fd, const char *body, int bodysize,
37 const char *headers, int headerssize)
38{
39 int n = 0;
40 /*n = write(fd, headers, headerssize); */
41 /*if(bodysize>0)
42 n += write(fd, body, bodysize); */
43 /* Note : my old linksys router only took into account
44 * soap request that are sent into only one packet */
45 char *p;
46 /* TODO: AVOID MALLOC */
47 p = malloc (headerssize + bodysize);
48 if (!p)
49 return 0;
50 memcpy (p, headers, headerssize);
51 memcpy (p + headerssize, body, bodysize);
52 /*n = write(fd, p, headerssize+bodysize); */
53 n = send (fd, p, headerssize + bodysize, 0);
54 if (n < 0)
55 {
56 PRINT_SOCKET_ERROR ("send");
57 }
58 /* disable send on the socket */
59 /* draytek routers dont seems to like that... */
60#if 0
61#ifdef WIN32
62 if (shutdown (fd, SD_SEND) < 0)
63 {
64#else
65 if (shutdown (fd, SHUT_WR) < 0)
66 { /*SD_SEND */
67#endif
68 PRINT_SOCKET_ERROR ("shutdown");
69 }
70#endif
71 free (p);
72 return n;
73}
74
75/* self explanatory */
76int
77soapPostSubmit (int fd,
78 const char *url,
79 const char *host,
80 unsigned short port, const char *action, const char *body)
81{
82 int bodysize;
83 char headerbuf[512];
84 int headerssize;
85 char portstr[8];
86 bodysize = (int) strlen (body);
87 /* We are not using keep-alive HTTP connections.
88 * HTTP/1.1 needs the header Connection: close to do that.
89 * This is the default with HTTP/1.0 */
90 /* Connection: Close is normally there only in HTTP/1.1 but who knows */
91 portstr[0] = '\0';
92 if (port != 80)
93 snprintf (portstr, sizeof (portstr), ":%hu", port);
94 headerssize = snprintf (headerbuf, sizeof (headerbuf),
95 "POST %s HTTP/1.1\r\n"
96/* "POST %s HTTP/1.0\r\n"*/
97 "Host: %s%s\r\n" "User-Agent: " OS_STRING ", UPnP/1.0, MiniUPnPc/" MINIUPNPC_VERSION_STRING "\r\n" "Content-Length: %d\r\n" "Content-Type: text/xml\r\n" "SOAPAction: \"%s\"\r\n" "Connection: Close\r\n" "Cache-Control: no-cache\r\n" /* ??? */
98 "Pragma: no-cache\r\n"
99 "\r\n", url, host, portstr, bodysize, action);
100#ifdef DEBUG
101 printf ("SOAP request : headersize=%d bodysize=%d\n",
102 headerssize, bodysize);
103 /*printf("%s", headerbuf); */
104#endif
105 return httpWrite (fd, body, bodysize, headerbuf, headerssize);
106}