[OGo-Evolution] Address create patch but it only create an address, then crash

Oliver Jehle evolution@opengroupware.org
Fri, 08 Apr 2005 09:54:26 +0200


--=-Yyb/7szGfzMWuPdpMR92
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

due my limited knowledge of evolution i've the problem, that after
creating the address in ogo, i don't know how to update the internal
data structure of evolution.

i try to extract the "x-skyrix-newname" header field to catch the new
server id of the address and then send an update of the address

feel free to comment or to fix it ;-)

its diffed against evolution-groupdav-0.2.




 


--=-Yyb/7szGfzMWuPdpMR92
Content-Disposition: attachment; filename=addr.diff
Content-Type: text/x-patch; name=addr.diff; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Only in evolution-groupdav-0.2.oj-x/addressbook: .deps
diff -C 3 -r evolution-groupdav-0.2/addressbook/e-book-backend-ogo.c evolution-groupdav-0.2.oj-x/addressbook/e-book-backend-ogo.c
*** evolution-groupdav-0.2/addressbook/e-book-backend-ogo.c	2005-03-24 12:09:20.000000000 +0100
--- evolution-groupdav-0.2.oj-x/addressbook/e-book-backend-ogo.c	2005-04-08 08:57:14.000000000 +0200
***************
*** 39,46 ****
  
  #define d(x) x
  
! #define SUMMARY_FLUSH_TIMEOUT 5000
! 
  static EBookBackendClass *parent_class;
  
  struct _EBookBackendOGoPrivate {
--- 39,45 ----
  
  #define d(x) x
  
! #define SUMMARY_FLUSH_TIMEOUT 5000 
  static EBookBackendClass *parent_class;
  
  struct _EBookBackendOGoPrivate {
***************
*** 121,159 ****
  				   guint32 opid,
  				   const char *vcard)
  {
! 	EBookBackendOGo *ogo = E_BOOK_BACKEND_OGO (backend);
  	EContact *contact;
  	E2kProperties *props;
  	const gchar *name;
  	gchar *e2k_href, *href;
  	gchar *location;
  	OGoConnectionStatus status;
- 	
  	contact = e_contact_new_from_vcard (vcard);
! 	
! 	props = props_from_contact (ogo, contact, NULL); 
! 
  	/* figure out the right uri to be using */
  	name = contact_name (contact);
  	if (!name)
  		name = "No Subject";
- 
  	href = ogo_connection_get_item_uri (ogo->priv->conn, ogo->priv->item_path);
  	e2k_href = get_e2k_uri (href);
! 	g_free (href);
! 	
! 	status = ogo_connection_proppatch_new (ogo->priv->conn, e2k_href, name,
! 					       test_name, ogo,
! 					       props, &location, NULL);
! 	g_free (e2k_href);
! 	
  	if (status == OGO_CONNECTION_STATUS_OK) {
! 		ogo_book_backend_cache_put_contact (ogo->priv->cache, contact);
! 		e_data_book_respond_modify (book, opid, GNOME_Evolution_Addressbook_Success, contact);
  	} else {
! 		e_data_book_respond_modify (book, opid, GNOME_Evolution_Addressbook_OtherError, NULL);
  	}
! 
  	g_object_unref (contact);
  }
  
--- 120,160 ----
  				   guint32 opid,
  				   const char *vcard)
  {
!         EBookBackendOGo *ogo = E_BOOK_BACKEND_OGO (backend);
  	EContact *contact;
  	E2kProperties *props;
  	const gchar *name;
  	gchar *e2k_href, *href;
  	gchar *location;
+ 	gchar *newname;
+ 	gchar *uid;
+ 	GString *new_uri;
  	OGoConnectionStatus status;
  	contact = e_contact_new_from_vcard (vcard);
! 	props = props_from_contact (ogo, contact, NULL);
! 	uid = e_contact_get_const (contact, E_CONTACT_UID);
! 	g_print ("create Contact %s\n",uid);
  	/* figure out the right uri to be using */
  	name = contact_name (contact);
  	if (!name)
  		name = "No Subject";
  	href = ogo_connection_get_item_uri (ogo->priv->conn, ogo->priv->item_path);
  	e2k_href = get_e2k_uri (href);
! 	g_print ("create Contact uri %s || %s \n",e2k_href,ogo->priv->item_path);
! 	status = ogo_connection_proppatch_new (ogo->priv->conn, e2k_href, name, test_name, ogo, props, &location, &newname);
! 	g_print ("newname:  %s \n",newname);
! 	new_uri =  g_string_new (e2k_href);
!      	g_string_append_printf(new_uri, "/%s.vcf", newname);
! 	e2k_href=g_string_free (new_uri, FALSE);
! 	g_print ("newname href:  %s \n",e2k_href);
! 	status = ogo_connection_proppatch (ogo->priv->conn, e2k_href, props, FALSE, NULL);
  	if (status == OGO_CONNECTION_STATUS_OK) {
! 		e_data_book_respond_create (book, opid, GNOME_Evolution_Addressbook_Success, contact);
  	} else {
! 		e_data_book_respond_create (book, opid, GNOME_Evolution_Addressbook_OtherError, NULL);
  	}
! 	g_free (href);
! 	g_free (e2k_href);
  	g_object_unref (contact);
  }
  
***************
*** 1295,1319 ****
  get_ogo_info (EContact *contact, gchar **href, gchar **etag)
  {
  	GList *attrs;
  	gint n_found = 0;
  	for (attrs = e_vcard_get_attributes (E_VCARD (contact));
  	     attrs != NULL; attrs = attrs->next) {
  		EVCardAttribute *attr = attrs->data;
- 
   		if (strcmp (e_vcard_attribute_get_name (attr), OGO_ETAG_PROPERTY) == 0) {
! 			if (etag)
  				*etag = g_strdup (e_vcard_attribute_get_value (attr));
! 			printf("etag %s",etag)	;
! 			n_found ++;
  		} else if (strcmp (e_vcard_attribute_get_name (attr), OGO_HREF_PROPERTY) == 0) {
! 			if (href)
  				*href = g_strdup (e_vcard_attribute_get_value (attr));
! 			printf("href %s",href)	;
! 			n_found ++;
  		}
  	}
! 
! 	g_assert (n_found == 2);
  }
  
  EContact *
--- 1296,1328 ----
  get_ogo_info (EContact *contact, gchar **href, gchar **etag)
  {
  	GList *attrs;
+ 	EVCardAttribute *attr = NULL;
  	gint n_found = 0;
  	for (attrs = e_vcard_get_attributes (E_VCARD (contact));
  	     attrs != NULL; attrs = attrs->next) {
  		EVCardAttribute *attr = attrs->data;
   		if (strcmp (e_vcard_attribute_get_name (attr), OGO_ETAG_PROPERTY) == 0) {
! 			if (etag) {
  				*etag = g_strdup (e_vcard_attribute_get_value (attr));
! 				n_found ++;
! 			}
  		} else if (strcmp (e_vcard_attribute_get_name (attr), OGO_HREF_PROPERTY) == 0) {
! 			if (href) {
  				*href = g_strdup (e_vcard_attribute_get_value (attr));
! 				n_found ++;
! 			}
  		}
  	}
! 	/*
! 	if (n_found ==2 ){ 
! 		fprintf(2,"-------------------------------\n");
! 		if (attr)
! 			fprintf(2,"found:%d attr:%s\n",n_found,e_vcard_attribute_get_name(attr));
! 		else	
! 			fprintf(2,"found:%d with empty attr\n");
! 		fprintf(2,"-------------------------------\n");
! 	}
! 	g_assert (n_found == 2); */
  }
  
  EContact *
diff -C 3 -r evolution-groupdav-0.2/utils/ogo-connection.c evolution-groupdav-0.2.oj-x/utils/ogo-connection.c
*** evolution-groupdav-0.2/utils/ogo-connection.c	2005-02-25 03:42:48.000000000 +0100
--- evolution-groupdav-0.2.oj-x/utils/ogo-connection.c	2005-03-25 12:29:04.000000000 +0100
***************
*** 797,807 ****
  		     char        **repl_uid)
  {
  	const char *header;
  
  	if (repl_uid) {
! 		header = soup_message_get_header (msg->response_headers,
! 						  "Repl-UID");
! 		*repl_uid = g_strdup (header);
  	}
  	if (location) {
  		header = soup_message_get_header (msg->response_headers,
--- 797,828 ----
  		     char        **repl_uid)
  {
  	const char *header;
+ 	g_print(" enter in extract put result");
+ 	g_print("\nrepl_uid : ");
+ 	if (repl_uid) 
+ 	    g_print(" set");
+ 	else
+ 	    g_print(" unset");
+ 	g_print("\nlocation : ");
+ 	if (location) 
+ 	    g_print(" set\n");
+ 	else
+ 	    g_print(" unset\n");
  
+ 	header = soup_message_get_header (msg->response_headers, "Repl-UID");
  	if (repl_uid) {
! 	        g_print(" get header for Repl-UID\n");
! 		header = soup_message_get_header (msg->response_headers, "Repl-UID");
! 	        g_print(" get header done for Repl-UID\n");
! 		if (!header ||  strlen(header)==0) {
! 	           g_print(" get header for x-skyrix-newname\n");
! 		   header = soup_message_get_header (msg->response_headers, "x-skyrix-newname");
! 		}
! 		if (header) {
! 		     g_print("x-skyrix hack, newname used :%s \n",header);
! 		    *repl_uid = g_strdup (header);
! 		} else
! 		     g_print("x-skyrix hack, newname empty \n");
  	}
  	if (location) {
  		header = soup_message_get_header (msg->response_headers,
***************
*** 829,835 ****
  	setup_debug (message);
  
  	http_status = soup_session_send_message (conn->priv->soup_session, message);
- 
  	status = get_status_from_http_response (http_status);
  	
  	if (status == OGO_CONNECTION_STATUS_OK)
--- 850,855 ----
***************
*** 899,905 ****
  	soup_message_add_header (msg->request_headers, "If-None-Match", "*");
  
  	count = 1;
! 	do {
  		update_unique_uri (conn, msg, slash_uri, encoded_name, &count,
  				   test_callback, user_data);
  		setup_debug (msg);
--- 919,925 ----
  	soup_message_add_header (msg->request_headers, "If-None-Match", "*");
  
  	count = 1;
! 	do { 
  		update_unique_uri (conn, msg, slash_uri, encoded_name, &count,
  				   test_callback, user_data);
  		setup_debug (msg);
***************
*** 908,914 ****
  
  	if (location)
  		*location = soup_uri_to_string (soup_message_get_uri (msg), FALSE);
! 	extract_put_results (msg, NULL, repl_uid);
  
  	g_object_unref (msg);
  	g_free (slash_uri);
--- 928,935 ----
  
  	if (location)
  		*location = soup_uri_to_string (soup_message_get_uri (msg), FALSE);
! 
! 	extract_put_results (msg, location, repl_uid);
  
  	g_object_unref (msg);
  	g_free (slash_uri);

--=-Yyb/7szGfzMWuPdpMR92--