cgi_soap.c File Reference

#include "cgi.h"
#include <winsock2.h>

Include dependency graph for cgi_soap.c:

Go to the source code of this file.

Functions

int WinsockConnect (char *host, int port, unsigned int *s)
int SOAPExec (char *host, int port, char *function, char *action, char *data)


Function Documentation

int SOAPExec char *  host,
int  port,
char *  function,
char *  action,
char *  data
 

Definition at line 66 of file cgi_soap.c.

References WinsockConnect().

00067 {
00068  unsigned int s;
00069 #ifdef XP_WIN
00070  WSADATA d;
00071 #endif
00072  int err;
00073  char temp[128];
00074 
00075 #if 0
00076 #define send(a,b,c,d) fwrite(b,c,1,stdout)
00077 #endif
00078 
00079 #ifdef XP_WIN
00080  if (WSAStartup(2, &d) != 0)     /* init winsock lib. want v2.0 */
00081   {
00082    WSACleanup();
00083    return 61;
00084   }
00085 #endif
00086 
00087  err = WinsockConnect(host, port, &s);
00088  if (!err)
00089  {
00090   send(s, "POST /", 6, 0);
00091   send(s, function, strlen(function), 0);
00092   send(s, " HTTP/1.1\r\n", 11, 0);
00093   send(s, "Host: ", 6, 0);
00094   send(s, host, strlen(host), 0);
00095   send(s, "\r\nContent-Type: text/xml; charset=\"utf-8\"\r\n", 43, 0);
00096   send(s, "Content-Length: ", 16, 0);
00097   sprintf(temp,"%d",strlen(data));  
00098 /* itoa(strlen(data), temp, 10); */
00099   send(s, temp, strlen(temp), 0);
00100   send(s, "\r\nSOAPAction: " , 14, 0);
00101   send(s, action, strlen(action), 0);
00102   send(s, "\r\n\r\n", 4, 0);
00103   send(s, data, strlen(data), 0);
00104  }
00105 
00106  if (s != INVALID_SOCKET) /* shutdown and close the socket if needed */
00107    { shutdown(s, 2);   /* shutdown both channels (read+write) */
00108 #ifdef XP_WIN
00109      closesocket(s);
00110 #else
00111      close(s);
00112 #endif
00113    }
00114 #ifdef XP_WIN
00115  WSACleanup();
00116 #endif
00117  return err;
00118 }

int WinsockConnect char *  host,
int  port,
unsigned int *  s
 

defined in cgi_soap.c

Definition at line 31 of file cgi_soap.c.

00032 {
00033  long int hostaddr = 0;
00034  unsigned long *p;
00035  struct sockaddr_in svraddr;
00036  struct hostent *he;
00037  *s = INVALID_SOCKET;
00038 
00039  if (isdigit(host[0]))        /* something like 192.168.0.1 */
00040    {
00041       hostaddr = inet_addr(host);      /* convert to 32bit unsigned int */
00042    }
00043  else                         /* something like phoenix.ttdev.com */
00044    {
00045       he = gethostbyname(host); /* convert to 32bit unsigned int */
00046       if (!he) {return 62;}
00047       p = (unsigned long*)he->h_addr_list[0];
00048       hostaddr = *p;
00049    }
00050 
00051    *s = socket(AF_INET, SOCK_STREAM, 0); /* make Internet socket */
00052 
00053    if (*s == INVALID_SOCKET) return 63;
00054 
00055    svraddr.sin_family = AF_INET;       /* Internet address family */
00056    svraddr.sin_port = htons(port);     /* port */
00057    memcpy(&svraddr.sin_addr.s_addr, &hostaddr, sizeof(INADDR_ANY)); /* host addr */
00058    memset(svraddr.sin_zero,0,sizeof(svraddr.sin_zero));
00059 
00060    if (connect(*s, (SOCKADDR*)&svraddr, sizeof(svraddr)) != 0)
00061     return 64;
00062 
00063    return 0;
00064 }



Raosoft, Inc.
Raosoft EZReport, EZSurvey, InterForm, RapidReport, Raosoft, and SurveyWin are registered trademarks of Raosoft, Inc. Page contents © 1996-2007 by Raosoft, Inc. You may use and modify this file for your own use, but may not distribute it or derivative works without the prior written consent of Raosoft, Inc. This software is provided "as is," and Raosoft makes no warranty, express or implied, of fitness for a particular application. Every measure has been taken to anticipate risks inherent to computer networks, but we cannot guarantee safety or reliability of this program in every situation.
Tel: 206-525-4025 (US) Email: raosoft@raosoft.com
http://www.raosoft.com/