2 * @file miranda-connection.c
6 * Copyright (C) 2010-11 SIPE Project <http://sipe.sourceforge.net/>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "sipe-backend.h"
28 #include "sipe-core.h"
30 #include "newpluginapi.h"
31 #include "m_protosvc.h"
32 #include "m_protoint.h"
33 #include "miranda-private.h"
35 void sipe_miranda_connection_destroy(SIPPROTO
*pr
)
39 SIPE_DEBUG_INFO("valid <%d> state <%d>", pr
->valid
, pr
->state
);
40 if (!pr
->valid
) return;
42 set_buddies_offline(pr
);
43 sipe_miranda_close(pr
);
44 pr
->state
= SIPE_MIRANDA_DISCONNECTED
;
47 oldStatus
= pr
->proto
.m_iStatus
;
48 pr
->proto
.m_iDesiredStatus
= ID_STATUS_OFFLINE
;
49 pr
->proto
.m_iStatus
= pr
->proto
.m_iDesiredStatus
;
50 sipe_miranda_SendBroadcast(pr
, NULL
, ACKTYPE_STATUS
, ACKRESULT_SUCCESS
, (HANDLE
)oldStatus
, pr
->proto
.m_iStatus
);
53 void sipe_miranda_connection_error_reason(SIPPROTO
*pr
, sipe_connection_error error
, const gchar
*msg
)
55 SIPE_DEBUG_INFO("valid <%d> state <%d> error <%d> message <%s>", pr
->valid
, pr
->state
, error
, msg
);
56 if (!pr
->valid
) return;
57 if (pr
->state
== SIPE_MIRANDA_DISCONNECTED
) return;
58 pr
->disconnecting
= TRUE
;
59 sipe_miranda_connection_destroy(pr
);
61 pr
->disconnecting
= FALSE
;
65 void sipe_backend_connection_completed(struct sipe_core_public
*sipe_public
)
67 SIPPROTO
*pr
= sipe_public
->backend_private
;
68 int oldStatus
= pr
->proto
.m_iStatus
;
69 pr
->state
= SIPE_MIRANDA_CONNECTED
;
70 pr
->proto
.m_iStatus
= pr
->proto
.m_iDesiredStatus
;
71 sipe_miranda_SendBroadcast(pr
, NULL
, ACKTYPE_STATUS
, ACKRESULT_SUCCESS
, (HANDLE
)oldStatus
, pr
->proto
.m_iStatus
);
74 void sipe_backend_connection_error(struct sipe_core_public
*sipe_public
,
75 sipe_connection_error error
,
78 SIPE_DEBUG_INFO("reason <%d> message <%s>", error
, msg
);
79 sipe_miranda_connection_error_reason(sipe_public
->backend_private
, error
, msg
);
82 gboolean
sipe_backend_connection_is_disconnecting(struct sipe_core_public
*sipe_public
)
84 SIPPROTO
*pr
= sipe_public
->backend_private
;
85 return (pr
->disconnecting
);
88 gboolean
sipe_backend_connection_is_valid(struct sipe_core_public
*sipe_public
)
90 SIPPROTO
*pr
= sipe_public
->backend_private
;
91 return (pr
->state
== SIPE_MIRANDA_CONNECTED
);