Fix for 114926. Also fixes for some leaks etc in cspi/spi_streamablecontent.c,
authorbillh <billh@e2bd861d-eb25-0410-b326-f6ed22b6b98c>
Wed, 3 Dec 2003 12:56:35 +0000 (12:56 +0000)
committerbillh <billh@e2bd861d-eb25-0410-b326-f6ed22b6b98c>
Wed, 3 Dec 2003 12:56:35 +0000 (12:56 +0000)
courtesy of Michael Meeks.

git-svn-id: http://svn.gnome.org/svn/at-spi/trunk@565 e2bd861d-eb25-0410-b326-f6ed22b6b98c

ChangeLog
cspi/spi.h
cspi/spi_streamablecontent.c

index 6588e4d..96a30c4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,28 @@
 2003-12-01  Bill Haneman <billh@gnome.org>
 
+       Fix for bug #114926.  Thanks to Michael Meeks for some of this patch.
+
+       * cspi/spi.h:
+       Added enum for AccessibleStreamableContentSeekType.
+       (AccessibleStreamableContent_freeContentTypeList): New.
+       
+       * cspi/spi_streamablecontent.c:
+       (accessible_bonobo_stream_client_seek): New private method.
+       (AccessibleStreamableContent_seek): Implemented this method,
+       using Bonobo_Stream_seek.
+       (AccessibleStreamableContent_freeContentTypeList): New method
+       for freeing the return value from 
+       AccessibleStreamableContent_getContentTypes.
+       (stream_cache_item_free): Replaces stream_release; stop leaks.
+       (stream_release): removed.
+       (AccessibleStreamableContent_read): Use properly init'd CORBA_evs, 
+       free the memory properly.
+
+2003-12-02  Padraig O'Briain <padraig.obriain@sun.com>
+
        Fix for bug #116009.
 
-       * cspi/spi-roletypes.h: Add SPI_ROL_EEDITBAR.
+       * cspi/spi-roletypes.h: Add SPI_ROLE_EDITBAR.
 
        * cspi/spi_accessible.c (cspi_init_role_table): Add SPI_ROLE_EDITBAR.
 
        * libspi/table.c (impl_getColumnDescription): Correct typo,
        pointed out by Bolian.Yin@sun.com.
 
-2003-09-21  Ã\85smund Skjæveland  <aasmunds@fys.uio.no>
+2003-09-21  Ã\83Â\85smund SkjÃ\83¦veland  <aasmunds@fys.uio.no>
 
        * configure.in: Added nn to ALL_LINGUAS (which is commented out).
 
 
        * configure.in: Added "ja" to ALL_LINGUAS.
 
-2003-08-22  Samúel Jón Gunnarsson  <sammi@techattack.nu>
+2003-08-22  SamÃ\83ºel JÃ\83³n Gunnarsson  <sammi@techattack.nu>
 
        * configure.in: Added "is" to ALL_LINGUAS.
        
 
        * configure.in: Added mn to ALL_LINGUAS.
 
-2003-08-16  Tõivo Leedjärv  <toivo@linux.ee>
+2003-08-16  TÃ\83µivo LeedjÃ\83¤rv  <toivo@linux.ee>
 
        * configure.in: Added et to ALL_LINGUAS.
 
 
         * configure.in: Added Portuguese (pt) to ALL_LINGUAS.
 
-2003-07-14  Danilo Šegan  <dsegan@gmx.net>
+2003-07-14  Danilo Å Segan  <dsegan@gmx.net>
 
        * configure.in: Added "sr" and "sr@Latn" (Serbian) to ALL_LINGUAS.
 
index eea3257..6463d55 100644 (file)
@@ -183,6 +183,21 @@ typedef enum {
 } AccessibleKeyListenerSyncType;
 
 
+/**
+ *AccessibleStreamableContentSeekType
+ *@SPI_STREAM_SEEK_SET: seek from the 'top' of the streamable
+ *@SPI_STREAM_SEEK_CUR: seek from the current position in the stream
+ *@SPI_STREAM_SEEK_END: seek from the end of the stream (if known)
+ *
+ *The seek type for a specified offset in AccessibleStreamableContent_seek.
+ **/
+typedef enum
+{
+  SPI_STREAM_SEEK_SET,
+  SPI_STREAM_SEEK_CUR,
+  SPI_STREAM_SEEK_END
+} AccessibleStreamableContentSeekType;
+
 typedef struct _SPIException SPIException;
 
 typedef SPIBoolean 
@@ -711,15 +726,19 @@ void
 AccessibleStreamableContent_unref (AccessibleStreamableContent *obj);
 char **
 AccessibleStreamableContent_getContentTypes (AccessibleStreamableContent *obj);
+void
+AccessibleStreamableContent_freeContentTypeList (AccessibleStreamableContent *obj,
+                                                char **list);
 SPIBoolean
 AccessibleStreamableContent_open (AccessibleStreamableContent *obj,
                                  const char *content_type);
 SPIBoolean
 AccessibleStreamableContent_close (AccessibleStreamableContent *obj);
-SPIBoolean
+
+long int
 AccessibleStreamableContent_seek (AccessibleStreamableContent *obj,
                                  long int offset,
-                                 unsigned int seek_type);
+                                 AccessibleStreamableContentSeekType seek_type);
 SPIBoolean
 AccessibleStreamableContent_read (AccessibleStreamableContent *obj,
                                  void *buff,
index 500b339..ca98642 100644 (file)
@@ -41,23 +41,13 @@ streams_equal_func (gconstpointer a, gconstpointer b)
 }
 
 static void
-stream_release (gpointer a)
-{
-  CORBA_Environment ev;
-
-  bonobo_object_release_unref (a, &ev);
-}
-
-static void
 stream_cache_item_free (gpointer a)
 {
   struct StreamCacheItem *cache_item = a;
-  CORBA_Environment ev;
-  if (cache_item) {
-    bonobo_object_release_unref (cache_item->stream, &ev);
-    SPI_freeString (cache_item->mimetype);
-    g_free (cache_item);
-  }
+
+  cspi_release_unref (cache_item->stream);
+  SPI_freeString (cache_item->mimetype);
+  g_free (cache_item);
 }
 
 static GHashTable *streams = NULL;
@@ -65,13 +55,38 @@ static GHashTable *streams = NULL;
 GHashTable *
 get_streams (void) 
 {
-  if (streams == NULL) {
-    streams = g_hash_table_new_full (g_direct_hash, streams_equal_func, 
-                                    stream_release, stream_cache_item_free);
-  }
+  if (streams == NULL)
+      streams = g_hash_table_new_full (g_direct_hash, streams_equal_func, 
+                                      NULL, stream_cache_item_free);
   return streams;
 }
 
+static CORBA_long
+accessible_bonobo_stream_client_seek (const Bonobo_Stream stream,
+                                     CORBA_long offset,
+                                     Bonobo_Stream_SeekType seek_type,
+                                     CORBA_Environment  *opt_ev)
+{
+       Bonobo_StorageInfo *info;
+       CORBA_Environment  *ev, temp_ev;
+       CORBA_long ret_offset;
+       
+       if (!opt_ev) {
+               CORBA_exception_init (&temp_ev);
+               ev = &temp_ev;
+       } else
+               ev = opt_ev;
+
+       ret_offset = Bonobo_Stream_seek (stream, offset, seek_type, ev);
+       if (BONOBO_EX (ev))
+               ret_offset = -1;
+
+       if (!opt_ev)
+               CORBA_exception_free (&temp_ev);
+       
+       return ret_offset;
+}
+
 /* internal use only, declared in cspi-private.h */
 void
 cspi_streams_close_all (void)
@@ -122,6 +137,7 @@ AccessibleStreamableContent_unref (AccessibleStreamableContent *obj)
  *       mimetypes for which the streamed content is available.
  *
  **/
+
 char **
 AccessibleStreamableContent_getContentTypes (AccessibleStreamableContent *obj)
 {
@@ -131,17 +147,33 @@ AccessibleStreamableContent_getContentTypes (AccessibleStreamableContent *obj)
 
   mimeseq = Accessibility_StreamableContent_getContentTypes (CSPI_OBJREF (obj),
                                                             cspi_ev ());
+  cspi_return_val_if_ev ("getContentTypes", NULL); 
 
   content_types = g_new0 (char *, mimeseq->_length + 1);
-  for (i = 0; i < mimeseq->_length; ++i) {
+  for (i = 0; i < mimeseq->_length; ++i)
     content_types[i] = CORBA_string_dup (mimeseq->_buffer[i]);
-  }
   content_types [mimeseq->_length] = NULL;
   CORBA_free (mimeseq);
 
   return content_types;
 }
 
+void
+AccessibleStreamableContent_freeContentTypesList (AccessibleStreamableContent *obj,
+                                                 char **content_types)
+{
+  if (content_types) 
+    {
+      gint i = 0;
+      while (content_types[i])
+       {
+         g_free (content_types[i]);
+         i++;
+       }
+      g_free (content_types);
+    }
+}
+
 /**
  * AccessibleStreamableContent_open:
  * @obj: a pointer to the #AccessibleStreamableContent implementor on which to operate.
@@ -162,7 +194,9 @@ AccessibleStreamableContent_open (AccessibleStreamableContent *obj,
   struct StreamCacheItem *cache;
   stream = Accessibility_StreamableContent_getContent (CSPI_OBJREF (obj),
                                                       content_type,
-                                                      cspi_ev ());    
+                                                      cspi_ev ());
+  cspi_return_val_if_ev ("getContent", FALSE); 
+
   if (stream != CORBA_OBJECT_NIL) {
     cache = g_new0 (struct StreamCacheItem, 1);
     cache->stream = stream;
@@ -208,13 +242,42 @@ AccessibleStreamableContent_close (AccessibleStreamableContent *obj)
  * Returns: #TRUE if successful, #FALSE if unsuccessful.
  *
  **/
-SPIBoolean
+long int
 AccessibleStreamableContent_seek (AccessibleStreamableContent *obj,
                                  long int offset,
-                                 unsigned int seek_type)
+                                 AccessibleStreamableContentSeekType seek_type)
 {
-  /* currently Bonobo_Stream does not appear to support seek operations */
-  return FALSE;
+  Bonobo_Stream stream;
+  long int ret_offset = 0;
+  struct StreamCacheItem *cached; 
+  Bonobo_Stream_SeekType bonobo_seek_type;
+
+  cached = g_hash_table_lookup (get_streams (), CSPI_OBJREF (obj));
+  if (cached)
+    {
+      stream = cached->stream;
+      if (stream != CORBA_OBJECT_NIL)
+       {
+          guint8 *mem;
+         switch (seek_type) {
+         case SPI_STREAM_SEEK_SET:
+           bonobo_seek_type = Bonobo_Stream_SeekSet; 
+           break;
+         case SPI_STREAM_SEEK_END:
+           bonobo_seek_type = Bonobo_Stream_SeekEnd; 
+           break;
+         case SPI_STREAM_SEEK_CUR:
+         default:
+           bonobo_seek_type = Bonobo_Stream_SeekCur; 
+           break;
+         }
+         /* bonobo-client doesn't wrap seek yet, so we have to. */
+         ret_offset = accessible_bonobo_stream_client_seek (stream, offset, 
+                                                            seek_type, cspi_ev ());
+         cspi_return_val_if_ev ("seek", FALSE);
+       }
+    }
+  return ret_offset;
 }
 
 /**
@@ -227,7 +290,9 @@ AccessibleStreamableContent_seek (AccessibleStreamableContent *obj,
  *        if blocking is not allowed, etc.
  *
  * Copy (read) bytes from the currently open streamable content connection
- *     to a buffer.
+ *     to a buffer.  This is a blocking API, in the sense that it does not 
+ *     return until the bytes have been read, or an error condition is 
+ *     detected.
  *
  * Returns: an integer indicating the number of bytes read, or -1 on error.
  *
@@ -241,17 +306,24 @@ AccessibleStreamableContent_read (AccessibleStreamableContent *obj,
   Bonobo_Stream stream;
   struct StreamCacheItem *cached; 
   cached = g_hash_table_lookup (get_streams (), CSPI_OBJREF (obj));
-  if (cached) {
-    CORBA_long len_read;
-    stream = cached->stream;
-    if (stream != CORBA_OBJECT_NIL) {
-      guint8 *mem;
-      mem = bonobo_stream_client_read (stream, (size_t) nbytes, &len_read, cspi_ev ());
-      if (mem) memcpy (buff, mem, len_read);   
-      if (mem && ((nbytes == -1) || (len_read == nbytes)))
-       return TRUE;
+  if (cached)
+    {
+      CORBA_long len_read;
+      stream = cached->stream;
+      if (stream != CORBA_OBJECT_NIL)
+       {
+          guint8 *mem;
+         mem = bonobo_stream_client_read (stream, (size_t) nbytes, &len_read, cspi_ev ());
+         cspi_return_val_if_ev ("read", FALSE);
+         if (mem)
+            {
+              memcpy (buff, mem, len_read);
+             g_free (mem);
+             if ((nbytes == -1) || (len_read == nbytes))
+                return TRUE;
+           }
+       }
     }
-  }
   return FALSE;
 }