Changeset 36883 in vbox for trunk/src/VBox/Main/webservice
- Timestamp:
- Apr 29, 2011 9:40:55 AM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 71461
- Location:
- trunk/src/VBox/Main/webservice
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/webservice/vboxweb.cpp
r36702 r36883 47 47 #include <iprt/path.h> 48 48 #include <iprt/system.h> 49 #include <iprt/base64.h> 49 50 50 51 // workaround for compile problems on gcc 4.1 … … 1190 1191 } 1191 1192 1193 /** Code to handle string <-> byte arrays base64 conversion. */ 1194 std::string Base64EncodeByteArray(ComSafeArrayIn(BYTE, aData)) 1195 { 1196 1197 com::SafeArray<BYTE> sfaData(ComSafeArrayInArg(aData)); 1198 ssize_t cbData = sfaData.size(); 1199 1200 if (cbData == 0) 1201 return ""; 1202 1203 ssize_t cchOut = RTBase64EncodedLength(cbData); 1204 1205 RTCString aStr; 1206 1207 aStr.reserve(cchOut+1); 1208 int rc = RTBase64Encode(sfaData.raw(), cbData, 1209 aStr.mutableRaw(), aStr.capacity(), 1210 NULL); 1211 AssertRC(rc); 1212 aStr.jolt(); 1213 1214 return aStr.c_str(); 1215 } 1216 1217 void Base64DecodeByteArray(std::string& aStr, ComSafeArrayOut(BYTE, aData)) 1218 { 1219 const char* pszStr = aStr.c_str(); 1220 ssize_t cbOut = RTBase64DecodedSize(pszStr, NULL); 1221 1222 Assert(cbOut > 0); 1223 1224 com::SafeArray<BYTE> result(cbOut); 1225 int rc = RTBase64Decode(pszStr, result.raw(), cbOut, NULL, NULL); 1226 AssertRC(rc); 1227 1228 result.detachTo(ComSafeArrayOutArg(aData)); 1229 } 1230 1192 1231 /** 1193 1232 * Raises a SOAP runtime fault. Implementation for the RaiseSoapRuntimeFault template -
trunk/src/VBox/Main/webservice/vboxweb.h
r35458 r36883 97 97 std::string ConvertComString(const com::Guid &bstr); 98 98 99 std::string Base64EncodeByteArray(ComSafeArrayIn(BYTE, aData)); 100 101 void Base64DecodeByteArray(std::string& aStr, ComSafeArrayOut(BYTE, aData)); 99 102 /**************************************************************************** 100 103 * -
trunk/src/VBox/Main/webservice/websrv-cpp.xsl
r34563 r36883 412 412 </xsl:choose> 413 413 </xsl:when> 414 <xsl:when test="//collection[@name=$type]">415 <xsl:variable name="thatif" select="//collection[@name=$type]" />416 <xsl:variable name="thatifname" select="$thatif/@name" />417 <xsl:value-of select="concat('ComPtr<', $thatifname, '>')" />418 </xsl:when>419 414 <xsl:otherwise> 420 415 <xsl:call-template name="fatalError"> … … 543 538 <xsl:call-template name="emitNewlineIndent8" /> 544 539 545 <xsl:choose> 540 <xsl:choose> 541 <xsl:when test="$safearray='yes' and $type='octet'"> 542 <xsl:value-of select="concat('com::SafeArray<BYTE> comcall_',$name, ';')" /> 543 <xsl:call-template name="emitNewlineIndent8" /> 544 <xsl:value-of select="concat('Base64DecodeByteArray(',$structprefix,$name,', ComSafeArrayAsOutParam(comcall_',$name, '));')" /> 545 </xsl:when> 546 546 547 <xsl:when test="$safearray='yes'"> 547 548 <xsl:value-of select="concat('size_t c', $name, ' = ', $structprefix, $name, '.size();')" /> … … 598 599 <xsl:call-template name="emitNewlineIndent8" /> 599 600 <xsl:value-of select="concat(' comcall_', $name, '[i] = ', $G_funcPrefixInputEnumConverter, $type, '(', $structprefix, $name, '[i]);')" /> 600 </xsl:when> 601 <xsl:when test="$type='octet'"> 602 <xsl:call-template name="emitNewlineIndent8" /> 603 <xsl:value-of select="concat(' comcall_', $name, '[i] = ', $structprefix, $name, '[i];')" /> 604 </xsl:when> 601 </xsl:when> 605 602 <xsl:otherwise> 606 603 <xsl:call-template name="fatalError"> … … 995 992 996 993 <xsl:choose> 994 <xsl:when test="$safearray='yes' and $type='octet'"> 995 <xsl:value-of select="concat($receiverVariable, ' = Base64EncodeByteArray(ComSafeArrayAsInParam(', $varname,'));')" /> 996 <xsl:call-template name="emitNewlineIndent8" /> 997 </xsl:when> 998 997 999 <xsl:when test="$safearray='yes'"> 998 1000 <xsl:value-of select="concat('for (size_t i = 0; i < ', $varname, '.size(); ++i)')" /> -
trunk/src/VBox/Main/webservice/websrv-python.xsl
r31117 r36883 64 64 <xsl:param name="safearray" /> 65 65 66 <xsl:call-template name="emitConvertedType"> 67 <xsl:with-param name="ifname" select="$ifname" /> 68 <xsl:with-param name="methodname" select="$methodname" /> 69 <xsl:with-param name="type" select="$type" /> 70 </xsl:call-template> 71 <xsl:text>(</xsl:text> 72 <xsl:text>self.mgr,</xsl:text> 73 <xsl:value-of select="$value"/> 74 <xsl:if test="$safearray='yes'"> 75 <xsl:value-of select="', True'"/> 76 </xsl:if> 77 <xsl:text>)</xsl:text> 66 <xsl:choose> 67 <xsl:when test="$type='octet' and $safearray"> 68 <xsl:value-of select="concat('self.mgr.decodebase64(',$value,')')" /> 69 </xsl:when> 70 <xsl:otherwise> 71 <xsl:call-template name="emitConvertedType"> 72 <xsl:with-param name="ifname" select="$ifname" /> 73 <xsl:with-param name="methodname" select="$methodname" /> 74 <xsl:with-param name="type" select="$type" /> 75 </xsl:call-template> 76 <xsl:text>(</xsl:text> 77 <xsl:text>self.mgr,</xsl:text> 78 <xsl:value-of select="$value"/> 79 <xsl:if test="$safearray='yes'"> 80 <xsl:value-of select="', True'"/> 81 </xsl:if> 82 <xsl:text>)</xsl:text> 83 </xsl:otherwise> 84 </xsl:choose> 78 85 </xsl:template> 79 86 … … 342 349 </xsl:template> 343 350 351 <xsl:template name="convertInParam"> 352 <xsl:param name="type" /> 353 <xsl:param name="safearray" /> 354 <xsl:param name="arg" /> 355 356 <xsl:choose> 357 <xsl:when test="$type='octet' and $safearray"> 358 <xsl:value-of select="concat('self.mgr.encodebase64(',$arg,')')" /> 359 </xsl:when> 360 <xsl:otherwise> 361 <xsl:value-of select="$arg" /> 362 </xsl:otherwise> 363 </xsl:choose> 364 </xsl:template> 365 344 366 <xsl:template name="genreq"> 345 367 <xsl:text>req=</xsl:text><xsl:value-of select="../@name"/>_<xsl:value-of select="@name"/>RequestMsg() 346 368 req._this=self.handle 347 369 <xsl:for-each select="param[@dir='in']"> 348 req._<xsl:value-of select="@name" />=_arg_<xsl:value-of select="@name" /> 370 req._<xsl:value-of select="@name" />=<xsl:call-template name="convertInParam"> 371 <xsl:with-param name="type" select="@type" /> 372 <xsl:with-param name="safearray" select="@safearray" /> 373 <xsl:with-param name="arg" select="concat('_arg_', @name)" /> 374 </xsl:call-template> 349 375 </xsl:for-each> 350 376 val=self.mgr.getPort().<xsl:value-of select="../@name"/>_<xsl:value-of select="@name"/>(req) … … 443 469 444 470 <xsl:template match="/"> 445 <xsl:text># Copyright (C) 2008-201 0Oracle Corporation471 <xsl:text># Copyright (C) 2008-2011 Oracle Corporation 446 472 # 447 473 # This file is part of a free software library; you can redistribute … … 679 705 return self.handle >= other 680 706 681 import struct 682 683 class Octet(Number): 684 def __init__(self, mgr, handle, isarray = False): 685 self.handle = handle 686 self.mgr = mgr 687 self.isarray = isarray 688 689 def __getitem__(self, index): 690 if self.isarray: 691 return Octet(self.mgr, self.handle[index]) 692 raise TypeError, "iteration over non-sequence" 707 class Octet: 708 def __init__(self, mgr, handle, isarray = False): 709 self.mgr = mgr 710 self.isarray = isarray 711 if isarray: 712 self.handle = mgr.decodebase64(handle) 713 else: 714 raise TypeError, "only octet arrays" 715 716 def __getitem__(self, index): 717 return self.handle[index] 693 718 694 719 def __str__(self): 695 if self.isarray: 696 # array of octets is binary data 697 list = map (None, self.handle) 698 return struct.pack("%dB" % (len(list)), *list) 699 else: 700 return str(self.handle) 720 return str(self.handle) 721 722 def __len__(self): 723 return self.handle.__len__() 701 724 702 725 class UnsignedInt(Number): … … 844 867 <xsl:call-template name="interfacestruct"/> 845 868 </xsl:for-each> 846 <xsl:for-each select="//collection">847 <xsl:call-template name="collection"/>848 </xsl:for-each>849 869 <xsl:for-each select="//enum"> 850 870 <xsl:call-template name="enum"/> 851 871 </xsl:for-each> 872 873 import base64 852 874 853 875 class IWebsessionManager2(IWebsessionManager): … … 866 888 return self.port 867 889 890 def decodebase64(self, str): 891 return base64.decodestring(str) 892 893 def encodebase64(self, str): 894 return base64.encodestring(str) 895 868 896 </xsl:template> 869 897 -
trunk/src/VBox/Main/webservice/websrv-wsdl.xsl
r33540 r36883 211 211 <xsl:call-template name="debugMsg"><xsl:with-param name="msg" select="concat('....convertTypeAndEmitPartOrElement: arg name: ', $name)" /></xsl:call-template> 212 212 <xsl:choose> 213 <xsl:when test="$safearray='yes' and $type='octet'"> 214 <!-- we pass octet arrays as Base64-encoded strings. --> 215 <xsl:element name="{$elname}"> 216 <xsl:attribute name="name"><xsl:value-of select="$name" /></xsl:attribute> 217 <xsl:attribute name="type"><xsl:value-of select="'xsd:string'" /></xsl:attribute> 218 </xsl:element> 219 </xsl:when> 220 213 221 <xsl:when test="$safearray='yes'"> 214 222 <xsl:element name="{$elname}"> <!-- <part> or <element> -->
Note:
See TracChangeset
for help on using the changeset viewer.