⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mtom-stream-test.c

📁 linux下简单对象应用协议的开发库
💻 C
📖 第 1 页 / 共 2 页
字号:
/*	mtom-stream-test.c	Example streaming MTOM client and server.	Copyright (C) 2000-2006 Robert A. van Engelen, Genivia, Inc.	All Rights Reserved.	Usage (CGI server):		Install as CGI application, e.g. under cgi-bin	Usage (server):	mtom-stream-test 8085 &		Starts a server on your local host at port 8085.	Usage (client):	mtom-stream-test -p file1 file2 file3 ...		Stores files file1, file2, etc. at the server side. The server		saves them locally under a key. The storage keys are printed at		the client side. The keys provide access to the data using		option -g (get). The server saves files in its current		directory, or the directory specified by the TMPDIR environment		variable.	mtom-stream-test -g name1 name2 name3 ...		Retrieves files stored under keys name1, name2, etc.		The keys must correspond to the keys returned when storing		files. Files are stored by the server locally under the key		name.	Unix/Linux: add a sigpipe handler to avoid broken pipes.--------------------------------------------------------------------------------gSOAP XML Web services toolsCopyright (C) 2001-2006, Robert van Engelen, Genivia, Inc. All Rights Reserved.This software is released under one of the following two licenses:GPL or Genivia's license for commercial use.--------------------------------------------------------------------------------GPL license.This program is free software; you can redistribute it and/or modify it underthe terms of the GNU General Public License as published by the Free SoftwareFoundation; either version 2 of the License, or (at your option) any laterversion.This program is distributed in the hope that it will be useful, but WITHOUT ANYWARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR APARTICULAR PURPOSE. See the GNU General Public License for more details.You should have received a copy of the GNU General Public License along withthis program; if not, write to the Free Software Foundation, Inc., 59 TemplePlace, Suite 330, Boston, MA 02111-1307 USAAuthor contact information:engelen@genivia.com / engelen@acm.org--------------------------------------------------------------------------------A commercial use license is available from Genivia, Inc., contact@genivia.com--------------------------------------------------------------------------------*/#include "soapH.h"#include "mtom_stream_test.nsmap"#ifdef _POSIX_THREADS#include <pthread.h>#endif#include <sys/stat.h>/******************************************************************************\ * *	Default endpoint *\******************************************************************************/const char *endpoint = "http://localhost:8085";/******************************************************************************\ * *	Server-Side Location to Store Files (Changed by TMPDIR env var) *\******************************************************************************/const char *TMPDIR = ".";/******************************************************************************\ * *	Server-Side Streaming MIME Handler for Saving File Data Under Keys *\******************************************************************************/struct mime_server_handle{ char *key;	/* file name */  FILE *fd;	/* file fd */};/******************************************************************************\ * *	Forward Declarations *\******************************************************************************/int cgi_server();int run_server(int port);int run_client(int, char**);int open_data(struct soap *soap, const char *file, struct x__Data *data);int client_putData(struct soap *soap, int argc, char **argv);int client_getData(struct soap *soap, int argc, char **argv);void *mime_read_open(struct soap*, void*, const char*, const char*, const char*);void mime_read_close(struct soap*, void*);size_t mime_read(struct soap*, void*, char*, size_t);void *mime_server_write_open(struct soap *soap, void *handle, const char *id, const char *type, const char *description, enum soap_mime_encoding encoding);void mime_server_write_close(struct soap *soap, void *handle);int mime_server_write(struct soap *soap, void *handle, const char *buf, size_t len);void *mime_client_write_open(struct soap *soap, void *handle, const char *id, const char *type, const char *description, enum soap_mime_encoding encoding);void mime_client_write_close(struct soap *soap, void *handle);int mime_client_write(struct soap *soap, void *handle, const char *buf, size_t len);char *file_type(const char *file);/******************************************************************************\ * *	Main *\******************************************************************************/int main(int argc, char **argv){ const char *tmp = getenv("TMPDIR");  if (tmp)    TMPDIR = tmp;  if (argc < 2)    return cgi_server();  if (argc < 3)    return run_server(atoi(argv[1]));  return run_client(argc, argv);}/******************************************************************************\ * *	CGI Server *\******************************************************************************/int cgi_server(){ /* CGI-style: serve request from stdin to stdout */  return soap_serve(soap_new1(SOAP_ENC_MTOM)); /* Enable MTOM XOP attachments */}#ifndef _POSIX_THREADS/******************************************************************************\ * *	Stand-Alone Iterative Server *\******************************************************************************/int run_server(int port){ struct soap soap;  int ret;  /* Enable MTOM */  soap_init1(&soap, SOAP_ENC_MTOM);   /* Set the MIME callbacks */  soap.fmimereadopen = mime_read_open;  soap.fmimereadclose = mime_read_close;  soap.fmimeread = mime_read;  soap.fmimewriteopen = mime_server_write_open;  soap.fmimewriteclose = mime_server_write_close;  soap.fmimewrite = mime_server_write;  /* Bind socket */  if (!soap_valid_socket(soap_bind(&soap, NULL, port, 100)))    soap_print_fault(&soap, stderr);  else  { fprintf(stderr, "Bind to port %d successful\n", port);    /* Optional: let server time out after one hour */    soap.accept_timeout = 3600;    /* Unix/Linux SIGPIPE, this is OS dependent:    soap.accept_flags = SO_NOSIGPIPE;	// some systems like this    soap.socket_flags = MSG_NOSIGNAL;	// others need this    signal(SIGPIPE, sigpipe_handle);	// or a sigpipe handler (more portable)    */    /* Server loop */    for (;;)    { int sock = soap_accept(&soap);      if (!soap_valid_socket(sock))      { if (soap.errnum)          soap_print_fault(&soap, stderr);        else        { fprintf(stderr, "Server timed out (see code how to change this)\n");          break;        }      }      fprintf(stderr, "Accepting socket %d connection from IP %d.%d.%d.%d... ", sock, (int)(soap.ip>>24)&0xFF, (int)(soap.ip>>16)&0xFF, (int)(soap.ip>>8)&0xFF, (int)soap.ip&0xFF);      if (soap_serve(&soap))        soap_print_fault(&soap, stderr);      fprintf(stderr, "done\n");      soap_destroy(&soap);      soap_end(&soap);    }   }  ret = soap.error;  soap_destroy(&soap);  soap_end(&soap);  soap_done(&soap);  return ret;}#else/******************************************************************************\ * *	Multi-Threaded Stand-Alone Server *\******************************************************************************/void *process_request(void*);int run_server(int port){ struct soap soap;  int i, ret;  /* Enable MTOM */  soap_init1(&soap, SOAP_ENC_MTOM);   /* Set the MIME callbacks */  soap.fmimereadopen = mime_read_open;  soap.fmimereadclose = mime_read_close;  soap.fmimeread = mime_read;  soap.fmimewriteopen = mime_server_write_open;  soap.fmimewriteclose = mime_server_write_close;  soap.fmimewrite = mime_server_write;  /* Bind socket */  if (!soap_valid_socket(soap_bind(&soap, NULL, port, 100)))    soap_print_fault(&soap, stderr);  else  { fprintf(stderr, "Bind to port %d successful\n", port);    /* Optional: let server time out after one hour */    soap.accept_timeout = 3600;    /* Unix/Linux SIGPIPE, this is OS dependent:    soap.accept_flags = SO_NOSIGPIPE;	// some systems like this    soap.socket_flags = MSG_NOSIGNAL;	// others need this    signal(SIGPIPE, sigpipe_handle);	// or a sigpipe handler (more portable)    */    /* Main thread spawns server threads */    for (i = 1; ; i++)    { struct soap *tsoap;      pthread_t tid;      int sock = soap_accept(&soap);      if (!soap_valid_socket(sock))      { if (soap.errnum)          soap_print_fault(&soap, stderr);        else        { fprintf(stderr, "Server timed out (see code how to change this)\n");          break;        }      }      fprintf(stderr, "Thread %d accepts socket %d connection from IP %d.%d.%d.%d\n", i, sock, (int)(soap.ip>>24)&0xFF, (int)(soap.ip>>16)&0xFF, (int)(soap.ip>>8)&0xFF, (int)soap.ip&0xFF);      /* Copy soap environment and spawn thread */      tsoap = soap_copy(&soap);      pthread_create(&tid, NULL, (void*(*)(void*))process_request, (void*)tsoap);    }   }  ret = soap.error;  soap_done(&soap);  return ret;}void *process_request(void *soap){ pthread_detach(pthread_self());  /* Serve request (or multiple requests with keep-alive enabled) */  soap_serve((struct soap*)soap);  /* Cleanup and delete deserialized data */  soap_destroy((struct soap*)soap);  soap_end((struct soap*)soap);  /* Detach thread's copy of soap environment */  soap_done((struct soap*)soap);  /* Free soap environment */  free(soap);  fprintf(stderr, "done\n");  return NULL;}#endif/******************************************************************************\ * *	Client *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -