Nikolay Sivov : msxml3: Implement IMXAttributes::addAttribute().

Alexandre Julliard julliard at winehq.org
Tue Mar 13 13:50:37 CDT 2012


Module: wine
Branch: master
Commit: 70aa4f1a43b80d65330f857ad01fbd3fa62419a6
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=70aa4f1a43b80d65330f857ad01fbd3fa62419a6

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Tue Mar 13 10:59:53 2012 +0300

msxml3: Implement IMXAttributes::addAttribute().

---

 dlls/msxml3/mxwriter.c        |   68 +++++++++++++++++++++++++++++++++++++++-
 dlls/msxml3/tests/saxreader.c |    2 -
 2 files changed, 66 insertions(+), 4 deletions(-)

diff --git a/dlls/msxml3/mxwriter.c b/dlls/msxml3/mxwriter.c
index 2188557..d0ce946 100644
--- a/dlls/msxml3/mxwriter.c
+++ b/dlls/msxml3/mxwriter.c
@@ -120,10 +120,25 @@ typedef struct
 
 typedef struct
 {
+    BSTR qname;
+    BSTR local;
+    BSTR uri;
+    BSTR type;
+    BSTR value;
+} mxattribute;
+
+typedef struct
+{
     DispatchEx dispex;
     IMXAttributes IMXAttributes_iface;
     ISAXAttributes ISAXAttributes_iface;
     LONG ref;
+
+    MSXML_VERSION class_version;
+
+    mxattribute *attr;
+    int length;
+    int allocated;
 } mxattributes;
 
 static inline mxattributes *impl_from_IMXAttributes( IMXAttributes *iface )
@@ -136,6 +151,16 @@ static inline mxattributes *impl_from_ISAXAttributes( ISAXAttributes *iface )
     return CONTAINING_RECORD(iface, mxattributes, ISAXAttributes_iface);
 }
 
+static HRESULT mxattributes_grow(mxattributes *This)
+{
+    if (This->length < This->allocated) return S_OK;
+
+    This->allocated *= 2;
+    This->attr = heap_realloc(This->attr, This->allocated*sizeof(mxattribute));
+
+    return This->attr ? S_OK : E_OUTOFMEMORY;
+}
+
 static xml_encoding parse_encoding_name(const WCHAR *encoding)
 {
     static const WCHAR utf8W[]  = {'U','T','F','-','8',0};
@@ -1505,7 +1530,19 @@ static ULONG WINAPI MXAttributes_Release(IMXAttributes *iface)
 
     if (ref == 0)
     {
+        int i;
+
+        for (i = 0; i < This->length; i++)
+        {
+            SysFreeString(This->attr[i].qname);
+            SysFreeString(This->attr[i].local);
+            SysFreeString(This->attr[i].uri);
+            SysFreeString(This->attr[i].type);
+            SysFreeString(This->attr[i].value);
+        }
+
         release_dispex(&This->dispex);
+        heap_free(This->attr);
         heap_free(This);
     }
 
@@ -1557,9 +1594,29 @@ static HRESULT WINAPI MXAttributes_addAttribute(IMXAttributes *iface,
     BSTR uri, BSTR localName, BSTR QName, BSTR type, BSTR value)
 {
     mxattributes *This = impl_from_IMXAttributes( iface );
-    FIXME("(%p)->(%s %s %s %s %s): stub\n", This, debugstr_w(uri), debugstr_w(localName),
+    mxattribute *attr;
+    HRESULT hr;
+
+    TRACE("(%p)->(%s %s %s %s %s)\n", This, debugstr_w(uri), debugstr_w(localName),
         debugstr_w(QName), debugstr_w(type), debugstr_w(value));
-    return E_NOTIMPL;
+
+    if ((!uri || !localName || !QName || !type || !value) && This->class_version != MSXML6)
+        return E_INVALIDARG;
+
+    /* ensure array is large enough */
+    hr = mxattributes_grow(This);
+    if (hr != S_OK) return hr;
+
+    attr = &This->attr[This->length];
+
+    attr->qname = SysAllocString(QName);
+    attr->local = SysAllocString(localName);
+    attr->uri   = SysAllocString(uri);
+    attr->type  = SysAllocString(type);
+    attr->value = SysAllocString(value);
+    This->length++;
+
+    return S_OK;
 }
 
 static HRESULT WINAPI MXAttributes_addAttributeFromIndex(IMXAttributes *iface,
@@ -1806,6 +1863,7 @@ static dispex_static_data_t mxattrs_dispex = {
 
 HRESULT SAXAttributes_create(MSXML_VERSION version, IUnknown *outer, void **ppObj)
 {
+    static const int default_count = 10;
     mxattributes *This;
 
     TRACE("(%p, %p)\n", outer, ppObj);
@@ -1818,6 +1876,12 @@ HRESULT SAXAttributes_create(MSXML_VERSION version, IUnknown *outer, void **ppOb
     This->ISAXAttributes_iface.lpVtbl = &SAXAttributesVtbl;
     This->ref = 1;
 
+    This->class_version = version;
+
+    This->attr = heap_alloc(default_count*sizeof(mxattribute));
+    This->length = 0;
+    This->allocated = default_count;
+
     *ppObj = &This->IMXAttributes_iface;
 
     init_dispex(&This->dispex, (IUnknown*)&This->IMXAttributes_iface, &mxattrs_dispex);
diff --git a/dlls/msxml3/tests/saxreader.c b/dlls/msxml3/tests/saxreader.c
index 505acaf..4aca3af 100644
--- a/dlls/msxml3/tests/saxreader.c
+++ b/dlls/msxml3/tests/saxreader.c
@@ -3332,7 +3332,6 @@ todo_wine {
 }
         hr = IMXAttributes_addAttribute(mxattr, _bstr_(table->uri), _bstr_(table->local),
             _bstr_(table->qname), _bstr_(table->type), _bstr_(table->value));
-todo_wine
         ok(hr == table->hr, "%d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
 
         len = -1;
@@ -3380,7 +3379,6 @@ todo_wine
 
     hr = IMXAttributes_addAttribute(mxattr, _bstr_("uri"), _bstr_("local"),
         _bstr_("qname"), _bstr_("type"), _bstr_("value"));
-todo_wine
     EXPECT_HR(hr, S_OK);
 
     len = -1;




More information about the wine-cvs mailing list