Zero bytes sent back to client from IIS using ISAPI extension - c++

I'm trying to write a pro-forma ISAPI extension in an attempt to better understand IIS. I have the following code for the exension:
#include <httpext.h>
#include <cstring>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <windows.h>
BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO * versionInfo)
{
versionInfo->dwExtensionVersion = HSE_VERSION;
strcpy_s( versionInfo->lpszExtensionDesc, "ISAPIExtension.dll");
return TRUE;
}
DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK* ecb)
{
char * msg = "<html><head/><body>Hello world</body></html>";
DWORD msg_length = strlen(msg) * sizeof(char);
DWORD sent_length = msg_length;
std::cout << sent_length;
auto result = ecb->WriteClient(ecb->ConnID, msg, &sent_length, 0);
if (!result || sent_length != msg_length)
{
std::fstream output("errors.txt");
output << "Could not write to client. Last error was " << GetLastError();
output.flush();
output.close();
return HSE_STATUS_ERROR;
}
std::cout << sent_length;
return HSE_STATUS_SUCCESS;
}
IIS Express responds with HTTP 200, but zero bytes were sent back to the client. Is anything in the above wrong? For reference, this is my applicationhost.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<configSections>
<sectionGroup name="system.applicationHost">
<section name="applicationPools"/>
<section name="sites"/>
</sectionGroup>
<sectionGroup name="system.webServer">
<section name="globalModules"/>
<section name="handlers"/>
<section name="caching"/>
<section name="modules"/>
<section name="staticContent"/>
<section name="httpErrors"/>
<sectionGroup name="tracing">
<section name="traceFailedRequests" overrideModeDefault="Allow" />
<section name="traceProviderDefinitions" overrideModeDefault="Deny" />
</sectionGroup>
<!-- The following section elements are not specified in this file, but without these
declarations, IIS will 500 requests -->
<sectionGroup name="security">
<section name="isapiCgiRestriction"/>
<section name="access"/>
<sectionGroup name="authentication">
<section name="anonymousAuthentication"/>
</sectionGroup>
</sectionGroup>
<section name="serverRuntime"/>
</sectionGroup>
</configSections>
<system.applicationHost>
<applicationPools>
<add name="UnmanagedClassicAppPool" managedRuntimeVersion="" managedPipelineMode="Classic" autoStart="true" />
</applicationPools>
<sites>
<site name="Default Web Site" id="1" serverAutoStart="true">
<application path="/" applicationPool="UnmanagedClassicAppPool">
<virtualDirectory path="/" physicalPath="%IIS_USER_HOME%\blog" />
</application>
<bindings>
<binding protocol="http" bindingInformation=":8080:localhost" />
</bindings>
<traceFailedRequestsLogging directory="%IIS_USER_HOME%\TraceLogFiles" enabled="true" maxLogFileSizeKB="1024" />
</site>
</sites>
</system.applicationHost>
<system.webServer>
<security>
<isapiCgiRestriction notListedIsapisAllowed="true"/>
</security>
<globalModules>
<add name="StaticFileModule" image="%IIS_BIN%\static.dll" />
<add name="AnonymousAuthenticationModule" image="%IIS_BIN%\authanon.dll" />
<add name="IsapiModule" image="%IIS_BIN%\isapi.dll" />
<add name="FailedRequestsTracingModule" image="%IIS_BIN%\iisfreb.dll" />
</globalModules>
<staticContent>
<mimeMap fileExtension=".html" mimeType="text/html" />
</staticContent>
<modules>
<add name="StaticFileModule"/>
<add name="AnonymousAuthenticationModule"/>
<add name="IsapiModule"/>
<add name="FailedRequestsTracingModule"/>
</modules>
<handlers accessPolicy="Read, Execute, Script">
<add name="ISAPI-dll" path="*.dll" verb="*" modules="IsapiModule" resourceType="File" requireAccess="Execute" allowPathInfo="true" />
<add name="StaticFile" path="*.html" verb="*" modules="StaticFileModule" resourceType="Either" requireAccess="Read" />
</handlers>
<tracing>
<traceProviderDefinitions>
<add name="ISAPI Extension" guid="{a1c2040e-8840-4c31-ba11-9871031a19ea}">
<areas>
<clear />
</areas>
</add>
</traceProviderDefinitions>
<traceFailedRequests>
<add path="*">
<traceAreas>
<add provider="ISAPI Extension" verbosity="Verbose" />
</traceAreas>
<failureDefinitions statusCodes="200-999" />
</add>
</traceFailedRequests>
</tracing>
</system.webServer>
</configuration>

Adding a Content-Type header fixes the issue:
DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK* ecb)
{
char msg [] = "<html><head/><body>Hello world</body></html>";
DWORD msg_length = strlen(msg);
DWORD sent_length = msg_length;
HSE_SEND_HEADER_EX_INFO HeaderExInfo;
HeaderExInfo.pszStatus = "200 OK";
HeaderExInfo.pszHeader = "Content-type: text/html\r\n\r\n";
HeaderExInfo.cchStatus = strlen(HeaderExInfo.pszStatus);
HeaderExInfo.cchHeader = strlen(HeaderExInfo.pszHeader);
HeaderExInfo.fKeepConn = FALSE;
ecb->ServerSupportFunction(ecb->ConnID, HSE_REQ_SEND_RESPONSE_HEADER_EX, &HeaderExInfo, NULL, NULL);
auto result = ecb->WriteClient(ecb->ConnID, msg, &sent_length, 0);
if (!result || sent_length != msg_length)
{
return HSE_STATUS_ERROR;
}
return HSE_STATUS_SUCCESS;
}
Microsoft has posted a similar ISAPI extension sample on their GitHub account: https://github.com/Microsoft/Windows-classic-samples/tree/master/Samples/Win7Samples/web/iis/extensions/simple

Related

Unable to get ros::params defined in bash and roslaunch to print in c++ script

I have a bash script as follows:
foldername=camera_calibration_$(date +"%m-%d-%Y")
im_name="/cam0"
roslaunch image_pub cam_calibration.launch foldername:=$foldername image_name:=$im_name
My roslaunch script is as follows:
<launch>
<arg name = "foldername" default="camera_calibration" />
<arg name = "image_name" default="/cam1" />
<param name="foldername" type="string" value="$(arg foldername)" />
<param name="image_name" type="string" value="$(arg image_name)" />
<param name="size_name" type="string" value="12x8" />
<param name="square" type="string" value="0.05" />
<node name="im_pub_sub_node" pkg="image_pub" type="im_pub_sub" output="screen"/>
<node name="cameracalibrator_node" pkg="camera_calibration" type="cameracalibrator.py" output="screen"/>
</launch>
My C++ script (im_pub_sub.cpp) as follows:
int main(int argc, char** argv) {
std::string foldername;
std::string imagename;
std::string si_name;
ros::param::get("/size_name", si_name);
ros::param::get("/foldername", foldername);
ros::param::get("/image_name", imagename);
std::cout<<imagename<<std::endl;
std::cout<<foldername<<std::endl;
std::cout<<si_name<<std::endl;
std::cout<<"hi"<<std::endl;
}
When I launch it I only get "hi" print on my console but not foldername, image_name defined from bash and si_name param defined in launch file. It prints empty like nothing for other params defined.
I can get these params printed in my python script, but I am unable to do the same using c++. This is completely "weird".
Can anyone please let me know what is wrong in my syntax?
I got it. That's because you can't get rosparams from launch file until rosnode initilaization and node Nodehandler is being defined.
int main(int argc, char** argv) {
ros::init(argc, argv, "im_sub_pub_cpp");
ros::NodeHandle nh_;
std::string foldername;
std::string imagename;
std::string si_name;
ros::param::get("/size_name", si_name);
ros::param::get("/foldername", foldername);
ros::param::get("/image_name", imagename);
std::cout<<imagename<<std::endl;
std::cout<<foldername<<std::endl;
std::cout<<si_name<<std::endl;
std::cout<<"hi"<<std::endl;
}
Then this works.

How to fix Element <PrecompiledHeader> has an invalid value of "/Yu" error in C++?

I am learning by myself and i want to know how to use precompiled headers in my console app. I have read a lot of guides, it seems i am doind everything right but i still get error.
I use visual studio 2019. So i have main.cpp file with code that uses and libraries i would like to be precompiled. I have created a file called stdafx.h and have included all libraries there. Then i created stdafx.cpp which only includes stdafx.h. In project properties for stdafx.cpp precompiler headers are /Yc and for main it is /Yu.
stdafx.h:
#include <iostream>
#include <cmath>
stdafx.cpp:
#include "stdafx.h"
main.cpp:
#include "stdafx.h"
using namespace std;
double getInfoFromUser()
{
double info;
cin >> info;
return info;
}
double computeSqrtDiscriminant(double A, double B, double C)
{
double i{ sqrt(pow(B, 2) - 4 * A * C) };
return i;
}
double computeX1(double A, double B, double SqrtDiscriminant)
{
double X1{ (-B + SqrtDiscriminant) / (2 * A) };
return X1;
}
double computeX2(double A, double B, double SqrtDiscriminant)
{
double X2{ (-B - SqrtDiscriminant) / (2 * A) };
return X2;
}
void computePoint1(double X1, double K, double M)
{
double Y{ X1 * K + M };
cout << "Первая точка пересечения:[" << X1 << "," << Y << "]" << endl;
}
void computePoint2(double X2, double K, double M)
{
double Y{ X2 * K + M };
cout << "Вторая точка пересечения:[" << X2 << "," << Y << "]";
}
double equateX(double B, double K)
{
double NewB{ B - K };
return NewB;
}
double equateC(double C, double M)
{
double NewC{ C - M };
return NewC;
}
int main()
{
setlocale(LC_ALL, "rus");
cout << "Введите уравнение параболы (aх^2+bx+c=0):" << endl;
cout << "Введите a:";
double A{ getInfoFromUser() };
cout << "Введите b:";
double B{ getInfoFromUser() };
cout << "Введите c:";
double C{ getInfoFromUser() };
cout << "Введите уравнение прямой (Kx+m)" << endl;
cout << "Введите k:";
double K{ getInfoFromUser() };
cout << "Введите m:";
double M{ getInfoFromUser() };
B = equateX(B, K);
C = equateC(C, M);
double SqrtDiscriminant = computeSqrtDiscriminant(A, B, C);
double X1{ computeX1(A, B, SqrtDiscriminant) };
double X2{ computeX2(A, B, SqrtDiscriminant) };
computePoint1(X1, K, M);
if (X1 != X2)
{
computePoint2(X2, K, M);
}
return 0;
}
main.cpp compiles greatly even without precompiled headers, but i want to learn how to use them. If compiled with precompiled headers i get theese two errors:
error : Element has an invalid value of "/Yu".
error MSB6011: в задачу Microsoft.Build.CPPTasks.CL переданы недопустимые параметры.(i am from Ukraine so i use Russian localization).
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{9F202045-E5DB-4685-9FCD-AFA97F3F750B}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>ConsoleApplicationParabolaIpryama</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>ParabolaPryamaya</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">/Yu</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">/Yu</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">/Yu</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">/Yu</PrecompiledHeader>
</ClCompile>
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">/Yc</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">/Yc</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">/Yc</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">/Yc</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
So the problem was that i was typing manually the /Yu and /Yc in the file`s properties, although there is dropbox-box in the upper right corner. If you use the dropbox the problem fade away.
The translation unit for the precompiled header needs to use /Yc instead of /Yu.
In your example you need to enable that setting for stdafx.cpp
In the GUI this is done like this:
1. Right click the file in the Solution explorer
2. Select "Properties"
3. Make sure that "Configuration" at the top is set to "All Configurations" and the Plaform setting is what you want it to be
4. Go to the "C/C++ -> Precompiled Headers" menu on the right
5. Change the "Precompiled Header" setting to "Create (/YC)"
The values in the *.vcxproj file should be
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- ... -->
<ItemDefinitionGroup>
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<!-- ... -->
and for the precompiled header file
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- ... -->
<ItemGroup>
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<!-- ... -->

can anyone create a simple libvirt program which just starts the domain

virConnectCreateXML doest seem to work for me
i created the following program and compiled it but it seems some linking problems or some kind of problem so i get these error
me.cpp: In function ‘int main(int, char**)’:
me.cpp:21:45: error: ‘virConnectCreateXML’ was not declared in this scope
dom = virConnectCreateXML(conn, xmlconfig, 0);
^
me.cpp:24:5: error: return-statement with no value, in function returning ‘int’ [-fpermissive]
return;
^
me.cpp:26:57: error: ‘virDomainName’ was not declared in this scope
fprintf(stderr, "Guest %s has booted", virDomainName(dom));
^
Program:
/* example ex9.c */
/* compile with: gcc -g -Wall ex9.c -o ex9 -lvirt */
#include <stdio.h>
#include <stdlib.h>
#include <libvirt/libvirt.h>
int main(int argc,char *argv[]){virConnectPtr conn;
char *host;
conn = virConnectOpen("qemu:///system");
if (conn == NULL) {
fprintf(stderr, "Failed to open connection to qemu:///system\n");
return 1;
}
virDomainPtr dom;
const char *xmlconfig = "<domain type='kvm'>
<name>win7</name>
<uuid>3666e50e-c616-42eb-aec8-b7fb1ad5f8f9</uuid>
<memory unit='KiB'>2072576</memory>
<currentMemory unit='KiB'>2072576</currentMemory>
<vcpu placement='static'>2</vcpu>
<os>
<type arch='x86_64' machine='pc-i440fx-2.5'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<hyperv>
<relaxed state='on'/>
<vapic state='on'/>
<spinlocks state='on' retries='8191'/>
</hyperv>
<vmport state='off'/>
</features>
<cpu mode='host-model'>
<model fallback='allow'/>
</cpu>
<clock offset='localtime'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
<timer name='hpet' present='no'/>
<timer name='hypervclock' present='yes'/>
</clock>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<pm>
<suspend-to-mem enabled='no'/>
<suspend-to-disk enabled='no'/>
</pm>
<devices>
<emulator>/usr/sbin/qemu-system-x86_64</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/win7.qcow2'/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='/home/dravigon/win7.iso'/>
<target dev='hdb' bus='ide'/>
<readonly/>
<address type='drive' controller='0' bus='0' target='0' unit='1'/>
</disk>
<controller type='usb' index='0' model='ich9-ehci1'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x7'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci1'>
<master startport='0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0' multifunction='on'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci2'>
<master startport='2'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x1'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci3'>
<master startport='4'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'/>
<controller type='ide' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<controller type='virtio-serial' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</controller>
<interface type='direct'>
<mac address='52:54:00:56:27:95'/>
<source dev='enp3s0' mode='bridge'/>
<model type='rtl8139'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<channel type='spicevmc'>
<target type='virtio' name='com.redhat.spice.0'/>
<address type='virtio-serial' controller='0' bus='0' port='1'/>
</channel>
<input type='tablet' bus='usb'/>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<graphics type='spice' autoport='yes'>
<image compression='off'/>
</graphics>
<sound model='ich6'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</sound>
<video>
<model type='vga' vram='16384' heads='1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<redirdev bus='usb' type='spicevmc'>
</redirdev>
<redirdev bus='usb' type='spicevmc'>
</redirdev>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</memballoon>
</devices>
</domain>";
dom = virConnectCreateXML(conn, xmlconfig, 0);
if (!dom) {
fprintf(stderr, "Domain creation failed");
return;
}
fprintf(stderr, "Guest %s has booted", virDomainName(dom));
virDomainFree(dom);
virConnectClose(conn);
return 0;
}
help is thanked in advance
yeah found out the problem the functions
virConnectCreateXML
and its relaced by virDomainCreateXML function

How to read xsd file where root element is not a named type

I have an XML and XSD file. I can read the XML using Xerces if XSD file has the root XML element define as a named complexType but I am trying to figure out how to read the file if root item in XSD is not named type. Here are my files:
The XML file
<?xml version="1.0"?>
<x:books xmlns:x="urn:BookStore"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:BookStore books.xsd">
<book id="bk001">
<author>Writer</author>
<title>The First Book</title>
<genre>Fiction</genre>
<price>44.95</price>
<pub_date>2000-10-01</pub_date>
<review>An amazing story of nothing.</review>
</book>
<book id="bk002">
<author>Poet</author>
<title>The Poet's First Poem</title>
<genre>Poem</genre>
<price>24.95</price>
<pub_date>2001-10-01</pub_date>
<review>Least poetic poems.</review>
</book>
</x:books>
The XSD file:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:BookStore"
xmlns:bks="urn:BookStore">
<xsd:complexType name="BookForm">
<xsd:sequence>
<xsd:element name="author" type="xsd:string"/>
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="genre" type="xsd:string"/>
<xsd:element name="price" type="xsd:float" />
<xsd:element name="pub_date" type="xsd:date" />
<xsd:element name="review" type="xsd:string"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string"/>
</xsd:complexType>
<xsd:element name="books"> <!-- not mapped to named typed! -->
<xsd:complexType >
<xsd:sequence>
<xsd:element name="book"
type="bks:BookForm"
minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Reading the library (reading only two fields)
#include <iostream>
#include "books.h"
using namespace std;
using namespace BookStore;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
try {
// what do I do here since BooksForm is not defined now and XSD file
// doesn't map it to the root element of XML?
auto_ptr<BooksForm> bookBank (books( "books.xml" ));
for (BooksForm::book_const_iterator i = (bookBank->book().begin());
i != bookBank->book().end();
++i)
{
cout << "Author is '" << i->author() << "'' " << endl;
cout << "Title is '" << i->title() << "'' " << endl;
cout << endl;
}
}
catch (const xml_schema::exception& e)
{
cerr << e << endl;
return 1;
}
return a.exec();
}
So this code works if XSD file is in format as in this post but I want to know how can I read the XML if the XSD file is in above format. I need to do this in this small demo so I can resolve the similar situation in another larger and more complex XML file which is a given thing.

Failed to compile gsoap-generated server code with C++ Builder

I am trying to build a server application using gsoap 2.8.17. I've created a header file with service function prototype and a result record definition
testserver.h:
#ifndef TESTSERVER_H
#define TESTSERVER_H
#include <string>
//gsoap ns service name: TestServer
//gsoap ns service namespace: http://mycomp:8080/TestServer.wsdl
//gsoap ns service location: http://mycomp:8080/TestServer.cgi
//gsoap ns schema namespace: urn:TestServer
class Record
{
public:
int id;
std::string name;
std::string address;
double param1;
};
int ns__GetRecord(int id, Record* result);
#endif
Then I've invoked the gSOAP RPC compiler:
soapcpp2.exe testserver.h
The compiler produced the following files:
soapC.cpp
soapClient.cpp
soapClientLib.cpp
soapServer.cpp
soapServerLib.cpp
soapH.h
soapStub.h
TestServer.h
TestServer.nsmap
TestServer.wsdl
TestServer.GetRecord.req.xml
TestServer.GetRecord.res.xml
ns.xsd
TestServer.wsdl
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="TestServer"
targetNamespace="http://mycomp:8080/TestServer.wsdl"
xmlns:tns="http://mycomp:8080/TestServer.wsdl"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns="urn:TestServer"
xmlns:SOAP="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:HTTP="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:MIME="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:DIME="http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/"
xmlns:WSDL="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<schema targetNamespace="urn:TestServer"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns="urn:TestServer"
xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="unqualified"
attributeFormDefault="unqualified">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="Record"><!-- Record -->
<sequence>
<element name="id" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- Record::id -->
<element name="name" type="xsd:string" minOccurs="1" maxOccurs="1"/><!-- Record::name -->
<element name="address" type="xsd:string" minOccurs="1" maxOccurs="1"/><!-- Record::address -->
<element name="param1" type="xsd:double" minOccurs="1" maxOccurs="1"/><!-- Record::param1 -->
</sequence>
</complexType>
<!-- operation request element -->
<element name="GetRecord">
<complexType>
<sequence>
<element name="id" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__GetRecord::id -->
</sequence>
</complexType>
</element>
<!-- operation response element -->
<element name="GetRecordResponse">
<complexType>
<sequence>
<element name="result" type="ns:Record" minOccurs="0" maxOccurs="1" nillable="true"/><!-- ns__GetRecord::result -->
</sequence>
</complexType>
</element>
</schema>
</types>
<message name="GetRecordRequest">
<part name="Body" element="ns:GetRecord"/><!-- ns__GetRecord::ns__GetRecord -->
</message>
<message name="GetRecordResponse">
<part name="Body" element="ns:GetRecordResponse"/>
</message>
<portType name="TestServerPortType">
<operation name="GetRecord">
<documentation>Service definition of function ns__GetRecord</documentation>
<input message="tns:GetRecordRequest"/>
<output message="tns:GetRecordResponse"/>
</operation>
</portType>
<binding name="TestServer" type="tns:TestServerPortType">
<SOAP:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetRecord">
<SOAP:operation soapAction=""/>
<input>
<SOAP:body parts="Body" use="literal"/>
</input>
<output>
<SOAP:body parts="Body" use="literal"/>
</output>
</operation>
</binding>
<service name="TestServer">
<documentation>gSOAP 2.8.17 generated service definition</documentation>
<port name="TestServer" binding="tns:TestServer">
<SOAP:address location="http://mycomp:8080/TestServer.cgi"/>
</port>
</service>
</definitions>
As documentation recommends I added soapServerLib.cpp to my project, but the C++ Builder 2010 compiler produces errors:
[BCC32 Error] soapC.cpp(1611): E2238 Multiple declaration for 'ns__GetRecord(soap *,int,Record *)'
[BCC32 Error] soapStub.h(224): E2344 Earlier declaration of 'ns__GetRecord(soap *,int,Record *)'
[BCC32 Error] soapC.cpp(1611): E2303 Type name expected
[BCC32 Error] soapC.cpp(1611): E2379 Statement missing ;
[BCC32 Error] soapC.cpp(1717): E2379 Statement missing ;
soapStub.h(224):
SOAP_FMAC5 int SOAP_FMAC6 ns__GetRecord(struct soap*, int id, Record *result);
soapC.cpp(1598-1619):
SOAP_FMAC1 struct ns__GetRecord * SOAP_FMAC2 soap_instantiate_ns__GetRecord(struct soap *soap, int n, const char *type, const char *arrayType, size_t *size)
{
(void)type; (void)arrayType; /* appease -Wall -Werror */
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "soap_instantiate_ns__GetRecord(%d, %s, %s)\n", n, type?type:"", arrayType?arrayType:""));
struct soap_clist *cp = soap_link(soap, NULL, SOAP_TYPE_ns__GetRecord, n, soap_fdelete);
if (!cp)
return NULL;
if (n < 0)
{ cp->ptr = (void*)SOAP_NEW(struct ns__GetRecord);
if (size)
*size = sizeof(struct ns__GetRecord);
}
else
{ cp->ptr = (void*)SOAP_NEW_ARRAY(struct ns__GetRecord, n); // <<<-- error here
if (size)
*size = n * sizeof(struct ns__GetRecord);
}
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Instantiated location=%p\n", cp->ptr));
if (!cp->ptr)
soap->error = SOAP_EOM;
return (struct ns__GetRecord*)cp->ptr;
}
Why is ns__GetRecord interpreted as a structure while it's a function name? What should I fix in my TestServer.h to make soapcpp2.exe produce a compilable code ?
The only solution I found is to remove the soap_instantiate_ns__GetRecord function body.
SOAP_FMAC1 struct ns__GetRecord * SOAP_FMAC2 soap_instantiate_ns__GetRecord(struct
soap *soap, int n, const char *type, const char *arrayType, size_t *size)
{
return NULL;
}
Then the server code compiles and works fine.