Bool16 AcceptSession(QTSS_RTSPSessionObject inRTSPSession)
{   
    char remoteAddress[20] = {0};
    StrPtrLen theClientIPAddressStr(remoteAddress,sizeof(remoteAddress));
    QTSS_Error err = QTSS_GetValue(inRTSPSession, qtssRTSPSesRemoteAddrStr, 0, (void*)theClientIPAddressStr.Ptr, &theClientIPAddressStr.Len);
    if (err != QTSS_NoErr) return false;
    
    return AcceptAddress(&theClientIPAddressStr);    
}
/** 
 * For the given rtsp session, will return true if the client is in the configured
 * bypass list in the prefs, false if they aren't
 */
static Bool16 IsClientInBypassList(QTSS_RTSPSessionObject* theRTSPSession) {
    qtss_printf("QTSSIcecastAuthModule::IsClientInBypassList method start\n");
    // don't forget to *deref the param!
    char remoteAddress[20] = {0};
    StrPtrLen theClientIPAddressStr(remoteAddress,sizeof(remoteAddress));
    QTSS_Error err = QTSS_GetValue(*theRTSPSession, qtssRTSPSesRemoteAddrStr, 0, (void*)theClientIPAddressStr.Ptr, &theClientIPAddressStr.Len);
    if (err != QTSS_NoErr) return false;

    if  (QTSSModuleUtils::AddressInList(sModulePrefs, sIPBypassListID, &theClientIPAddressStr)) {
        qtss_printf("QTSSIcecastAuthModule::IsClientInBypassList client is in list\n");
        return true;
    }
    else {
        qtss_printf("QTSSIcecastAuthModule::IsClientInBypassList client is NOT in list\n");
        return false;
    }
}
static Bool16 CallAuthorizeSession(QTSS_ClientSessionObject* theClientSession, QTSS_RTSPSessionObject* theRTSPSession,
        QTSS_RTSPRequestObject* theRTSPRequest, char* username, char* password) {
    qtss_printf("QTSSIcecastAuthModule::CallAuthorizeSession called\n");
    //{ :action => "listener_add", :server => "server", :port => "8000", :client => "sessionidone",
    //  :mount => "somemount.sdp", :user => "lstoll", :pass => @working_hash, :ip => "127.0.0.1", :agent => "RSPEC"}

    // generate the client session id (and save in client) format <start time millis>-<rtsp session id>
    char ice_sessid[128];

    QTSS_TimeVal clientSessCreateTime = NULL;
    UInt32 createTimeLen = sizeof (clientSessCreateTime);
    QTSS_GetValue(*theClientSession, qtssCliSesCreateTimeInMsec, 0, (void*) & clientSessCreateTime, &createTimeLen);

    char* qtssRTSPSesIDString = NULL;
    (void) QTSS_GetValueAsString(*theRTSPSession, qtssRTSPSesID, 0, &qtssRTSPSesIDString);

    sprintf(ice_sessid, "%lld-%s", clientSessCreateTime, qtssRTSPSesIDString);

    printf("QTSSIcecastAuthModule::CallAuthorizeSession generated session id: %s\n", ice_sessid);

    (void) QTSS_SetValue(*theClientSession, attrClientSessionFullSessionID, 0, &ice_sessid, sizeof (ice_sessid));

    // get the user agent
    char* userAgentString = NULL;
    (void) QTSS_GetValueAsString(*theClientSession, qtssCliSesFirstUserAgent, 0, &userAgentString);
    printf("QTSSIcecastAuthModule::CallAuthorizeSession: request user agent: %s\n", userAgentString);
    
    // get the client IP address
    char remoteAddress[20] = {0};
    StrPtrLen theClientIPAddressStr(remoteAddress,sizeof(remoteAddress));
    (void)QTSS_GetValue(*theRTSPSession, qtssRTSPSesRemoteAddrStr, 0, (void*)theClientIPAddressStr.Ptr, &theClientIPAddressStr.Len);
    
    // get the mount point
    char mountPoint[128] = {0};
    StrPtrLen mountPointStr(mountPoint,sizeof(mountPoint));
    (void)QTSS_GetValue(*theRTSPRequest, qtssRTSPReqURI, 0, (void*)mountPointStr.Ptr, &mountPointStr.Len);
    printf("QTSSIcecastAuthModule::CallAuthorizeSession: mount point: %s\n", mountPoint);
    // and set it in the client for use on session end
    (void) QTSS_SetValue(*theClientSession, attrClientSessionMountPoint, 0, mountPointStr.Ptr, mountPointStr.Len);
    
    char postdata[512];
    
    qtss_sprintf(postdata, "action=listener_add&server=%s&port=554&client=%s&mount=%s&user=%s&pass=%s&ip=%s&agent%s",
            hostname, ice_sessid, mountPoint, username, password, remoteAddress, userAgentString);
    
    
    printf("QTSSIcecastAuthModule::CallAuthorizeSession: generated postdata: %s\n", postdata);
    
    printf("QTSSIcecastAuthModule::CallAuthorizeSession: i would post this to: %s\n", sStartSessionEndpoint);
    
    return true;
    
//    
//    CURL *easyhandle = NULL; 
//    easyhandle = curl_easy_init();
//    CURLcode curl_code;
//
//    
//    curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDS, postdata);
//    curl_easy_setopt(easyhandle, CURLOPT_URL, "http://posthere.com/");
//    curl_easy_perform(easyhandle); /* post away! */
//
//    long http_code = 0;
//    curl_easy_getinfo(easyhandle, CURLINFO_HTTP_CODE, &http_code);
//    if (http_code == 200 && curl_code != CURLE_ABORTED_BY_CALLBACK) {
//        // the call to the remote server was OK. pass.
//        return true;
//    } else {
//        return false;
//    }
//    return false;
}