API Reference | developer.brewmp.com API Reference | developer.brewmp.com

Developer

API Reference

IOBEXSRVSESSION

Brew Release
Brew MP 1.0.2
See Also
None.
Description


This interface enables OBEX server applications to service requests from a client.When the server receives the AEEOBEX_EVT_SRV_NEW_CLI event, it receives a pointer to a session object. All further requests from this client are delivered to the application via this interface.
Usage

Usage example:

   ===== To Register for events;

   // create a signal for example, use ISignalCBFactory_CreateSignal()
   IOBEXSrvSession_OnEventNotify(pMe->piSsn, piSignal);

   
   ===== To retrieve and handle events when signal is triggered:

   // re-enable signal
   ISignalCtl_Enable (pMe->piSsnSignalCtl); 
   
   while (IOBEXSrvSession_GetEvent (pMe->piSsn, &evtId, &piHdr, &evtData) != AEE_ENOMORE)
   {
      switch (event)
      {
         case AEEOBEX_EVT_SRV_CONN_REQ:
         ...
         case AEEOBEX_EVT_SRV_GET_REQ:
         ...
         case AEEOBEX_EVT_ERROR:
      }
   }
   
   ===== To accept/ reject connection

   switch (event)
   {
      case AEEOBEX_EVT_SRV_CONN_REQ:
      
      // To accept the connection
      IOBEXSrvSession_AcceptConnection(pMe->piSsn, NULL, AEEOBEX_STAT_SUCCESS);

      OR

      // To Reject the connection, with an error status
      IOBEXSrvSession_AcceptConnection(pMe->piSsn, NULL, AEEOBEX_STAT_NO_RESOURCE);
   }

   ===== To authenticate the client before connection
   
   // in the event handler when there is a connection request 
   switch (event)
   {
      case AEEOBEX_EVT_SRV_CONN_REQ:

      IOBEXSrvSession_Authenticate();
   }
   ...
   ...

   // authentication completes
   switch (event)
   {
      case AEEOBEX_EVT_AUTH_COMPL:
      
      // To accept the connection
      IOBEXSrvSession_AcceptConnection(pMe->piSsn, NULL, AEEOBEX_STAT_SUCCESS);

      OR

      // To Reject the connection, with an error status
      IOBEXSrvSession_AcceptConnection(pMe->piSsn, NULL, AEEOBEX_STAT_NO_RESOURCE);
   }

   ===== To handle authentication challenge event 

   // In the event handler 
   switch (event)
   {
      ...

      case AEEOBEX_EVT_AUTH_CHALLENGE:

      // client has requested for authentication
      IOBEXSrvSession_GetAuthChallenge(pMe->piSsn,&uid,&acs,&charSet, &bufRealm, bufRelamLen, &reqLen);

      // get the password and user id ( if required) from the user
      IOBEXSrvSession_SetUidPassword(pMe->piSsn,uid, uidLen, pswd, pswdLen);

   }
   
   ===== To handle authentication response event 

   // In the event handler 
   switch (event)
   {
      case AEEOBEX_EVT_AUTH_RESPONSE:

      
      IOBEXSrvSession_GetAuthResponse(pMe->piSsn,&authResp);

      // get the password from the user and send to implementation
      IOBEXSrvSession_SetUidPassword(pMe->piSsn,NULL,0, pswd, pswdLen);
   }

   ===== To send response to the client

   // In the event handler 
   switch (event)
   {
      case AEEOBEX_EVT_SRV_GET_REQ:
      
      //  Parse the request
      ...

      // respond with the data
      ret = IOBEXSrvSession_CreateHeaderList(pMe->pSsn, &piHdr);

      if (AEE_SUCCESS == ret)
      {
         IOBEXHeader_AddByteSeq(piHdr, AEEOBEX_HDR_BODY, data, dataLen);
      
         IOBEXSrvSession_SendResponse(pMe->pSsn, AEEOBEX_REQ_GET, piHdr, AEEOBEX_STAT_CONTINUE, 0);

         // done sending the header list
         IOBEXHeader_Release(piHdr);
      }

   ===== To disconnect from the client

   IOBEXSrvSession_Disconnect(pMe->piSsn);

   // Object can no longer be used
   IOBEXSrvSession_Release(pMe->piSsn);

   ===== To handle event error

   switch (event)
   {
      case AEEOBEX_EVT_ERROR:

      // Object can no longer be used
      IOBEXSrvSession_Release(pMe->piSsn);
   }

   ===== To handle disconnect Request

   switch (event)
   {
      case AEEOBEX_EVT_SRV_DISC_REQ:
      IOBEXSrvSession_SendResponse(pMe->piSsn, AEEOBEX_REQ_DISCONNECT, NULL, AEEOBEX_STAT_SUCCESS, 0);
      IOBEXSrvSession_Release(pMe->piSsn);
   }