Ticket #117: libsyncml_session_support_cred.diff

File libsyncml_session_support_cred.diff, 3.8 kB (added by Ganadist, 1 year ago)
  • ./parser/sml_xml_assm.c

    old new  
    742747                if (!_smlXmlAssemblerEndNode(assm, error)) 
    743748                        goto error_free_writer; 
    744749        } 
     750 
     751        if (session->cred) { 
     752            if (!smlCredAssemble(session->cred, assm, error)) { 
     753                goto error_free_writer; 
     754            } 
     755        } 
    745756         
    746757        if (!_smlXmlAssemblerEndNode(assm, error)) 
    747758                goto error_free_writer; 
  • ./sml_session.c

    old new  
    11141114        session->end = FALSE; 
    11151115        session->sessionType = sessionType; 
    11161116        session->lastCommandID = 0; 
     1117        session->cred = NULL; 
    11171118         
    11181119        if (sessionType == SML_SESSION_TYPE_CLIENT) 
    11191120                session->sending = TRUE; 
     
    11991200                 
    12001201                if (session->parentCommand) 
    12011202                        smlCommandUnref(session->parentCommand); 
     1203                if (session->cred) 
     1204                        smlCredFree(session->cred); 
    12021205                 
    12031206                g_free(session); 
    12041207        } 
     
    15971600        return FALSE; 
    15981601} 
    15991602 
     1603SmlBool smlSessionRegisterCred(SmlSession *session, SmlAuthType type, const char *user, const char *password, SmlError **error) 
     1604{ 
     1605        smlTrace(TRACE_ENTRY, "%s(%p, %u, %p, %p)", __func__, session, type, user, password, error); 
     1606        SmlCred *cred = smlTryMalloc0(sizeof(SmlCred), error); 
     1607        gchar *data = NULL, *encoded = NULL; 
     1608        if (!cred) 
     1609            goto error; 
     1610        /*  
     1611         * FIXME 
     1612         * Currently, libsyncml supports basic authentication only. 
     1613         */ 
     1614        cred->format = SML_FORMAT_TYPE_BASE64; 
     1615        cred->type = type; 
     1616 
     1617        data = g_strconcat(user, ":", password, NULL); 
     1618        if (!data) { 
     1619                smlErrorSet(error, SML_ERROR_NO_MEMORY, "No memory left"); 
     1620                goto error_free_cred; 
     1621        } 
     1622        switch (type) { 
     1623            case SML_AUTH_TYPE_BASIC: 
     1624                if (smlBase64Encode(data, &encoded, error)) { 
     1625                    cred->data = encoded; 
     1626                    g_free(data); 
     1627                    if (session->cred) 
     1628                        smlCredFree(session->cred); 
     1629                    session->cred = cred; 
     1630                    smlTrace(TRACE_EXIT, "%s", __func__); 
     1631                    return TRUE; 
     1632                } 
     1633                break; 
     1634            default: 
     1635                break; 
     1636        } 
     1637 
     1638        smlErrorSet(error, SML_ERROR_NOT_SUPPORTED, "Basic authentication type support only"); 
     1639        free(data); 
     1640error_free_cred: 
     1641        smlCredFree(cred); 
     1642error: 
     1643        smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); 
     1644        return FALSE; 
     1645} 
    16001646/*@}*/ 
    16011647 
    16021648/*@}*/ 
  • ./sml_session.h

    old new  
    7979 
    8080SmlBool smlSessionCheck(SmlSession *session); 
    8181void smlSessionDispatch(SmlSession *session); 
     82SmlBool smlSessionRegisterCred(SmlSession *session, SmlAuthType type, const char *user, const char *password, SmlError **error); 
    8283 
    8384#endif //_SML_SESSION_H_ 
  • ./sml_session_internals.h

    old new  
    8282        void *frag_userdata; 
    8383         
    8484        SmlBool active; 
     85        SmlCred *cred; 
    8586}; 
    8687 
    8788struct SmlPendingStatus {