@@ -1255,36 +1255,22 @@ int xmpp_conn_is_disconnected(xmpp_conn_t *conn)
12551255}
12561256
12571257/**
1258- * This returns the Stream Management state of a connection object after
1259- * it has been disconnected.
1260- * One can then initialise a fresh connection object and set this Stream
1261- * Management state by calling \ref xmpp_conn_set_sm_state
1258+ * This sets the Stream Management callback function
12621259 *
1263- * In case one wants to dispose of the state w/o setting it into a fresh
1264- * connection object, one can call \ref xmpp_free_sm_state
1260+ * After setting this API, the library will call the given callback function
1261+ * each time when the internal SM state is updated.
12651262 *
1266- * After calling this function to retrieve the state, only call one of the
1267- * other two.
1263+ * This can be used in conjunction with \ref xmpp_conn_restore_sm_state to
1264+ * e.g. implement a mechanism that retains an SM state over potential
1265+ * application terminations.
12681266 *
12691267 * @param conn a Strophe connection object
1270- * @return The Stream Management state of the connection or NULL on error
1268+ * @param cb a callback function or NULL to disable
1269+ * @param ctx a context that will be passed on invocation of the callback
1270+ * function
12711271 *
12721272 * @ingroup Connections
12731273 */
1274- xmpp_sm_state_t * xmpp_conn_get_sm_state (xmpp_conn_t * conn )
1275- {
1276- xmpp_sm_state_t * ret ;
1277-
1278- /* We can only return the SM state when we're disconnected */
1279- if (conn -> state != XMPP_STATE_DISCONNECTED )
1280- return NULL ;
1281-
1282- ret = conn -> sm_state ;
1283- conn -> sm_state = NULL ;
1284-
1285- return ret ;
1286- }
1287-
12881274void xmpp_conn_set_sm_callback (xmpp_conn_t * conn ,
12891275 xmpp_sm_callback cb ,
12901276 void * ctx )
@@ -1342,6 +1328,22 @@ static int sm_load_string(struct sm_restore *sm, char **val, size_t *len)
13421328 return 0 ;
13431329}
13441330
1331+ /**
1332+ * This restores the serialized Stream Management state
1333+ *
1334+ * After setting this API, the library will call the given callback function
1335+ * each time when the internal SM state is updated.
1336+ *
1337+ * This can be used in conjunction with \ref xmpp_conn_restore_sm_state to
1338+ * e.g. implement a mechanism that retains an SM state over potential
1339+ * application terminations.
1340+ *
1341+ * @param conn a Strophe connection object
1342+ * @param sm_state a buffer as passed to the SM callback
1343+ * @param sm_state_len the length of `sm_state`
1344+ *
1345+ * @ingroup Connections
1346+ */
13451347int xmpp_conn_restore_sm_state (xmpp_conn_t * conn ,
13461348 const unsigned char * sm_state ,
13471349 size_t sm_state_len )
@@ -1611,6 +1613,37 @@ static void _reset_sm_state_for_reconnect(xmpp_conn_t *conn)
16111613 }
16121614}
16131615
1616+ /**
1617+ * This returns the Stream Management state of a connection object after
1618+ * it has been disconnected.
1619+ * One can then initialise a fresh connection object and set this Stream
1620+ * Management state by calling \ref xmpp_conn_set_sm_state
1621+ *
1622+ * In case one wants to dispose of the state w/o setting it into a fresh
1623+ * connection object, one can call \ref xmpp_free_sm_state
1624+ *
1625+ * After calling this function to retrieve the state, only call one of the
1626+ * other two.
1627+ *
1628+ * @param conn a Strophe connection object
1629+ * @return The Stream Management state of the connection or NULL on error
1630+ *
1631+ * @ingroup Connections
1632+ */
1633+ xmpp_sm_state_t * xmpp_conn_get_sm_state (xmpp_conn_t * conn )
1634+ {
1635+ xmpp_sm_state_t * ret ;
1636+
1637+ /* We can only return the SM state when we're disconnected */
1638+ if (conn -> state != XMPP_STATE_DISCONNECTED )
1639+ return NULL ;
1640+
1641+ ret = conn -> sm_state ;
1642+ conn -> sm_state = NULL ;
1643+
1644+ return ret ;
1645+ }
1646+
16141647/**
16151648 * @param conn a Strophe connection object
16161649 * @param sm_state A Stream Management state returned from a call to
0 commit comments