Advertisement
Guest User

Untitled

a guest
Aug 9th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.51 KB | None | 0 0
  1. e_ews_connection_new (const gchar *uri, const gchar *username, const gchar *password,
  2.               GCallback authenticate_cb, gpointer authenticate_ctx,
  3.               GError **error)
  4. {
  5.     EEwsConnection *cnc;
  6.     gchar *hash_key;
  7.  
  8.     g_static_mutex_lock (&connecting);
  9.  
  10.     /* search the connection in our hash table */
  11.     if (loaded_connections_permissions != NULL) {
  12.         hash_key = g_strdup_printf ("%s@%s",
  13.                 username ? username : "",
  14.                 uri);
  15.         cnc = g_hash_table_lookup (loaded_connections_permissions, hash_key);
  16.         g_free (hash_key);
  17.  
  18.         if (E_IS_EWS_CONNECTION (cnc)) {
  19.             g_object_ref (cnc);
  20.             g_static_mutex_unlock (&connecting);
  21.             return cnc;
  22.         }
  23.     }
  24.    
  25.     /* not found, so create a new connection */
  26.     cnc = g_object_new (E_TYPE_EWS_CONNECTION, NULL);
  27.    
  28.     cnc->priv->username = g_strdup (username);
  29.     cnc->priv->password = g_strdup (password);
  30.     cnc->priv->uri = g_strdup (uri);
  31.  
  32.     /* register a handler to the authenticate signal */
  33.     if (authenticate_cb)
  34.         g_signal_connect (cnc, "authenticate",
  35.                   authenticate_cb, authenticate_ctx);
  36.  
  37.     /* add the connection to the loaded_connections_permissions hash table */
  38.     hash_key = g_strdup_printf ("%s@%s",
  39.             cnc->priv->username ? cnc->priv->username : "",
  40.             cnc->priv->uri);
  41.     if (loaded_connections_permissions == NULL)
  42.         loaded_connections_permissions = g_hash_table_new_full (g_str_hash, g_str_equal,
  43.                 g_free, NULL);
  44.     g_hash_table_insert (loaded_connections_permissions, hash_key, cnc);
  45.  
  46.     /* free memory */
  47.     g_static_mutex_unlock (&connecting);
  48.     return cnc;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement