• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10/webdavfs-367/webdavlib/

Lines Matching refs:ctx

93 static enum WEBDAVLIBAuthStatus finalStatusFromStatusCode(struct callback_ctx *ctx, int *error);
94 static int handleStreamError(struct callback_ctx *ctx, boolean_t *tryAgain, CFReadStreamRef rdStream, CFURLRef a_url);
95 static int handleSSLErrors(struct callback_ctx *ctx, boolean_t *tryAgain, CFReadStreamRef rdStream, CFURLRef a_url);
96 static enum WEBDAVLIBAuthStatus sendOptionsRequest(CFURLRef a_url, struct callback_ctx *ctx, int *result);
97 static enum WEBDAVLIBAuthStatus sendOptionsRequestAuthenticated(CFURLRef a_url, struct callback_ctx *ctx, CFDictionaryRef creds, int *result);
98 static void applyCredentialsToRequest(struct callback_ctx *ctx, CFDictionaryRef creds, CFHTTPMessageRef request);
100 static int updateNetworkProxies(struct callback_ctx *ctx);
101 static void releaseContextItems(struct callback_ctx *ctx);
102 static void initContext(struct callback_ctx *ctx);
414 struct callback_ctx ctx;
417 initContext(&ctx);
419 finalStatus = sendOptionsRequest(a_url, &ctx, &result);
428 if(ctx.httpProxyEnabled == TRUE) {
431 CFDictionarySetValue(proxyInfo, kWebDAVLibProxyServerNameKey, ctx.httpProxyServer);
433 if (ctx.proxyRealm != NULL)
434 CFDictionarySetValue(proxyInfo, kWebDAVLibProxyRealmKey, ctx.proxyRealm);
436 cf_port = CFStringCreateWithFormat(NULL, NULL, CFSTR("%d"), ctx.httpProxyPort);
446 CFDictionarySetValue(proxyInfo, kWebDAVLibProxyServerNameKey, ctx.httpsProxyServer);
448 if (ctx.proxyRealm != NULL)
449 CFDictionarySetValue(proxyInfo, kWebDAVLibProxyRealmKey, ctx.proxyRealm);
451 cf_port = CFStringCreateWithFormat(NULL, NULL, CFSTR("%d"), ctx.httpsProxyPort);
470 releaseContextItems(&ctx);
480 struct callback_ctx ctx;
483 initContext(&ctx);
486 ctx.requireSecureLogin = requireSecureLogin;
488 finalStatus = sendOptionsRequestAuthenticated(a_url, &ctx, creds, &result);
510 releaseContextItems(&ctx);
517 sendOptionsRequest(CFURLRef a_url, struct callback_ctx *ctx, int *err)
529 ctx->status = CheckAuthInprogress;
530 ctx->theData = CFDataCreateMutable(NULL, 0);
531 ctx->sslPropDict = NULL;
535 CFStreamClientContext context = {0, ctx, NULL, NULL, NULL};
538 updateNetworkProxies(ctx);
551 ctx->status = CheckAuthInprogress;
554 if (ctx->sslPropDict != NULL)
555 CFReadStreamSetProperty(rdStream, kCFStreamPropertyHTTPProxy, ctx->sslPropDict);
558 if (ctx->sslPropDict != NULL)
559 CFReadStreamSetProperty(rdStream, kCFStreamPropertySSLSettings, ctx->sslPropDict);
571 while (ctx->status == CheckAuthInprogress) {
575 if (ctx->status == CheckAuthCallbackDone) {
577 finalStatus = finalStatusFromStatusCode(ctx, err);
581 ctx->proxyAuth = CFHTTPAuthenticationCreateFromResponse(kCFAllocatorDefault, ctx->response);
582 ctx->proxyRealm = CFHTTPAuthenticationCopyRealm(ctx->proxyAuth);
587 else if (ctx->status == CheckAuthRedirection) {
589 if(++ctx->againCount > WEBDAVLIB_MAX_AGAIN_COUNT)
597 urlStr = CFHTTPMessageCopyHeaderFieldValue(ctx->response, CFSTR("Location"));
618 else if (ctx->status == CheckAuthCallbackStreamError) {
619 *err = handleStreamError(ctx, &tryAgain, rdStream, a_url);
621 if ((tryAgain == FALSE) || (++ctx->againCount > WEBDAVLIB_MAX_AGAIN_COUNT)) {
634 CFRelease(ctx->theData);
635 ctx->theData = CFDataCreateMutable(NULL, 0);
645 sendOptionsRequestAuthenticated(CFURLRef a_url, struct callback_ctx *ctx, CFDictionaryRef creds, int *err)
660 ctx->status = CheckAuthInprogress;
661 ctx->theData = CFDataCreateMutable(NULL, 0);
662 ctx->sslPropDict = NULL;
664 CFStreamClientContext context = {0, ctx, NULL, NULL, NULL};
667 updateNetworkProxies(ctx);
677 applyCredentialsToRequest(ctx, creds, message);
683 ctx->status = CheckAuthInprogress;
686 if (ctx->sslPropDict != NULL)
687 CFReadStreamSetProperty(rdStream, kCFStreamPropertyHTTPProxy, ctx->sslPropDict);
690 if (ctx->sslPropDict != NULL)
691 CFReadStreamSetProperty(rdStream, kCFStreamPropertySSLSettings, ctx->sslPropDict);
703 while (ctx->status == CheckAuthInprogress) {
707 if (ctx->status == CheckAuthCallbackDone) {
709 finalStatus = finalStatusFromStatusCode(ctx, err);
714 if (ctx->serverAuth == NULL) {
716 ctx->serverAuth = CFHTTPAuthenticationCreateFromResponse(kCFAllocatorDefault, ctx->response);
718 if (ctx->serverAuth != NULL) {
719 if (CFHTTPAuthenticationIsValid(ctx->serverAuth, NULL) == FALSE) {
727 if ( (done == FALSE) && (CFHTTPAuthenticationRequiresUserNameAndPassword(ctx->serverAuth) == TRUE) ) {
736 if ( (done == FALSE) && (ctx->requireSecureLogin == TRUE) && (ctx->secureConnection == FALSE) ) {
737 method = CFHTTPAuthenticationCopyMethod(ctx->serverAuth);
760 if (CFHTTPAuthenticationIsValid(ctx->serverAuth, NULL) == FALSE) {
761 CFRelease(ctx->serverAuth);
762 ctx->serverAuth = CFHTTPAuthenticationCreateFromResponse(kCFAllocatorDefault, ctx->response);
764 if (ctx->serverAuth != NULL) {
765 if (CFHTTPAuthenticationIsValid(ctx->serverAuth, NULL) == FALSE) {
773 if ( (done == FALSE) && (CFHTTPAuthenticationRequiresUserNameAndPassword(ctx->serverAuth) == TRUE) ) {
782 if ( (done == FALSE) && (ctx->triedServerCredentials == TRUE) ) {
789 if ( (done == FALSE) && (ctx->requireSecureLogin == TRUE) && (ctx->secureConnection == FALSE)) {
790 method = CFHTTPAuthenticationCopyMethod(ctx->serverAuth);
814 if (ctx->proxyAuth == NULL) {
823 ctx->proxyAuth = CFHTTPAuthenticationCreateFromResponse(kCFAllocatorDefault, ctx->response);
825 if (ctx->proxyAuth != NULL) {
826 if (CFHTTPAuthenticationIsValid(ctx->proxyAuth, NULL) == FALSE) {
834 if ( (done == FALSE) && (CFHTTPAuthenticationRequiresUserNameAndPassword(ctx->proxyAuth) == TRUE) ) {
843 if ( (done == FALSE) && (ctx->requireSecureLogin == TRUE) && (ctx->secureConnection == FALSE)) {
844 method = CFHTTPAuthenticationCopyMethod(ctx->proxyAuth);
866 if (CFHTTPAuthenticationIsValid(ctx->proxyAuth, NULL) == FALSE) {
867 CFRelease(ctx->proxyAuth);
868 ctx->proxyAuth = CFHTTPAuthenticationCreateFromResponse(kCFAllocatorDefault, ctx->response);
870 if (ctx->proxyAuth != NULL) {
871 if (CFHTTPAuthenticationIsValid(ctx->proxyAuth, NULL) == FALSE) {
879 if ((done == FALSE) && (CFHTTPAuthenticationRequiresUserNameAndPassword(ctx->proxyAuth) == TRUE) ) {
888 if ((done == FALSE) && (ctx->triedProxyServerCredentials == TRUE) ) {
894 if ( (done == FALSE) && (ctx->requireSecureLogin == TRUE) && (ctx->secureConnection == FALSE)) {
895 method = CFHTTPAuthenticationCopyMethod(ctx->proxyAuth);
922 else if (ctx->status == CheckAuthRedirection) {
924 if(++ctx->againCount > WEBDAVLIB_MAX_AGAIN_COUNT)
932 urlStr = CFHTTPMessageCopyHeaderFieldValue(ctx->response, CFSTR("Location"));
953 else if (ctx->status == CheckAuthCallbackStreamError) {
954 *err = handleStreamError(ctx, &tryAgain, rdStream, a_url);
956 if ((tryAgain == FALSE) || (++ctx->againCount > WEBDAVLIB_MAX_AGAIN_COUNT)) {
969 CFRelease(ctx->theData);
970 ctx->theData = CFDataCreateMutable(NULL, 0);
979 static void applyCredentialsToRequest(struct callback_ctx *ctx, CFDictionaryRef creds, CFHTTPMessageRef request)
984 if (ctx->serverAuth != NULL) {
989 CFHTTPMessageApplyCredentials(request, ctx->serverAuth, user, password, NULL);
990 ctx->triedServerCredentials = TRUE;
994 if (ctx->proxyAuth != NULL) {
999 CFHTTPMessageApplyCredentials(request, ctx->proxyAuth, user, password, NULL);
1000 ctx->triedProxyServerCredentials = TRUE;
1005 finalStatusFromStatusCode(struct callback_ctx *ctx, int *error)
1014 switch (ctx->statusCode / 100) {
1019 if (ctx->statusCode == 401) {
1023 else if (ctx->statusCode == 407) {
1028 syslog(LOG_ERR, "%s: unexpected http status code %ld\n", __FUNCTION__, ctx->statusCode);
1037 syslog(LOG_ERR, "%s: unexpected http status code %ld\n", __FUNCTION__, ctx->statusCode);
1046 handleStreamError(struct callback_ctx *ctx, boolean_t *tryAgain, CFReadStreamRef rdStream,CFURLRef a_url)
1053 if (ctx->streamError.domain == kCFStreamErrorDomainSSL) {
1055 result = handleSSLErrors(ctx, tryAgain, rdStream, a_url);
1060 else if (ctx->streamError.domain == kCFStreamErrorDomainPOSIX) {
1061 result = ctx->streamError.error;
1069 syslog(LOG_ERR, "%s: stream error domain: posix error: %d\n", __FUNCTION__, (int)ctx->streamError.error);
1071 else if (ctx->streamError.domain == kCFStreamErrorDomainHTTP) {
1072 if (ctx->streamError.error == kCFStreamErrorHTTPConnectionLost) {
1079 syslog(LOG_ERR, "%s: stream error domain: http error: %d", __FUNCTION__, (int)ctx->streamError.error);
1083 else if (ctx->streamError.domain == kCFStreamErrorDomainNetDB) {
1084 switch (ctx->streamError.error) {
1094 syslog(LOG_ERR, "%s: stream error domain: netdb error: %d\n", __FUNCTION__, (int)ctx->streamError.error);
1100 syslog(LOG_ERR, "%s: stream error domain: %ld error: %d\n", __FUNCTION__, ctx->streamError.domain, (int)ctx->streamError.error);
1107 handleSSLErrors(struct callback_ctx *ctx, boolean_t *tryAgain, CFReadStreamRef readStreamRef, CFURLRef a_url)
1119 ctx->secureConnection = TRUE;
1121 error = ctx->streamError.error;
1123 syslog(LOG_DEBUG, "%s: stream error domain: ssl error: %d", __FUNCTION__, (int)ctx->streamError.error);
1125 if (ctx->sslPropDict == NULL)
1126 ctx->sslPropDict = CFDictionaryCreateMutable(kCFAllocatorDefault,
1130 if (ctx->sslPropDict == NULL) {
1135 if ( (CFDictionaryGetValue(ctx->sslPropDict, kCFStreamSSLLevel) == NULL) &&
1143 CFDictionarySetValue(ctx->sslPropDict, kCFStreamSSLLevel, kCFStreamSocketSecurityLevelSSLv3);
1147 switch ( ctx->streamError.error )
1152 if ( ConfirmCertificate(readStreamRef, error, a_url, ctx->sslPropDict) )
1165 if ( ConfirmCertificate(readStreamRef, error, a_url, ctx->sslPropDict) )
1177 if ( ConfirmCertificate(readStreamRef, error, a_url, ctx->sslPropDict) )
1188 syslog(LOG_ERR, "%s: stream error domain: ssl error: %d", __FUNCTION__, (int)ctx->streamError.error);
1199 struct callback_ctx *ctx;
1205 ctx = (struct callback_ctx *)clientCallBackInfo;
1211 CFDataAppendBytes(ctx->theData, buffer, bytesRead);
1218 ctx->response = *((CFHTTPMessageRef*)((void*)&theResponsePropertyRef));
1219 ctx->statusCode = CFHTTPMessageGetResponseStatusCode(ctx->response);
1220 if ((ctx->statusCode / 100) == 3) {
1222 ctx->status = CheckAuthRedirection;
1225 ctx->status = CheckAuthCallbackDone;
1226 syslog(LOG_DEBUG, "%s: StreamEventEndEncountered, status code %ld\n", __FUNCTION__, ctx->statusCode);
1233 ctx->streamError = streamError;
1234 ctx->status = CheckAuthCallbackStreamError;
1243 static int updateNetworkProxies(struct callback_ctx *ctx)
1250 if (ctx->proxyStore == NULL) {
1251 ctx->proxyStore = SCDynamicStoreCreate(kCFAllocatorDefault, CFSTR("WebDAVFSPlugin"), NULL, NULL);
1252 if (ctx->proxyStore == NULL)
1257 if (ctx->proxyRealm != NULL) {
1258 CFRelease(ctx->proxyRealm);
1259 ctx->proxyRealm = NULL;
1262 ctx->httpProxyEnabled = FALSE;
1263 ctx->httpsProxyEnabled = FALSE;
1265 if (ctx->httpProxyServer != NULL)
1267 CFRelease(ctx->httpProxyServer);
1268 ctx->httpProxyServer = NULL;
1271 if (ctx->httpsProxyServer != NULL)
1273 CFRelease(ctx->httpsProxyServer);
1274 ctx->httpsProxyServer = NULL;
1277 if (ctx->proxyDict != NULL)
1279 CFRelease(ctx->proxyDict);
1280 ctx->proxyDict = NULL;
1283 ctx->httpProxyEnabled = FALSE;
1284 ctx->httpsProxyEnabled = FALSE;
1287 ctx->proxyDict = SCDynamicStoreCopyProxies(gProxyStore);
1289 if (ctx->proxyDict != NULL) {
1295 cf_enabled = CFDictionaryGetValue(ctx->proxyDict, kSCPropNetProxiesHTTPEnable);
1299 ctx->httpProxyServer = CFDictionaryGetValue(ctx->proxyDict, kSCPropNetProxiesHTTPProxy);
1300 if ( ctx->httpProxyServer != NULL )
1302 CFRetain(ctx->httpProxyServer);
1305 cf_port = CFDictionaryGetValue(ctx->proxyDict, kSCPropNetProxiesHTTPPort);
1306 if ( (cf_port != NULL) && CFNumberGetValue(cf_port, kCFNumberIntType, &ctx->httpProxyPort) )
1308 if ( ctx->httpProxyPort == 0 )
1311 ctx->httpProxyPort = kHttpDefaultPort;
1313 ctx->httpProxyEnabled = TRUE;
1323 cf_enabled = CFDictionaryGetValue(ctx->proxyDict, kSCPropNetProxiesHTTPSEnable);
1327 ctx->httpsProxyServer = CFDictionaryGetValue(ctx->proxyDict, kSCPropNetProxiesHTTPSProxy);
1328 if ( ctx->httpsProxyServer != NULL )
1330 CFRetain(ctx->httpsProxyServer);
1333 cf_port = CFDictionaryGetValue(ctx->proxyDict, kSCPropNetProxiesHTTPSPort);
1334 if ( (cf_port != NULL) && CFNumberGetValue(cf_port, kCFNumberIntType, &ctx->httpsProxyPort) )
1336 if ( ctx->httpsProxyPort == 0 )
1339 ctx->httpsProxyPort = kHttpsDefaultPort;
1341 ctx->httpsProxyEnabled = TRUE;
1348 static void initContext(struct callback_ctx *ctx)
1350 ctx->theData = NULL;
1351 ctx->response = NULL;
1352 ctx->sslPropDict = NULL;
1353 ctx->serverAuth = NULL;
1354 ctx->againCount = 0;
1355 ctx->triedServerCredentials = FALSE;
1356 ctx->triedProxyServerCredentials = FALSE;
1357 ctx->requireSecureLogin = FALSE;
1358 ctx->secureConnection = FALSE;
1359 ctx->proxyRealm = NULL;
1360 ctx->httpProxyEnabled = FALSE;
1361 ctx->httpProxyServer = NULL;
1362 ctx->httpsProxyEnabled = FALSE;
1363 ctx->httpsProxyServer = NULL;
1364 ctx->proxyDict = NULL;
1365 ctx->proxyStore = NULL;
1366 ctx->proxyAuth = NULL;
1369 static void releaseContextItems(struct callback_ctx *ctx)
1371 CFReleaseNull(ctx->theData);
1372 CFReleaseNull(ctx->response);
1373 CFReleaseNull(ctx->sslPropDict);
1374 CFReleaseNull(ctx->serverAuth);
1375 CFReleaseNull(ctx->proxyRealm);
1376 CFReleaseNull(ctx->httpProxyServer);
1377 CFReleaseNull(ctx->httpsProxyServer);
1378 CFReleaseNull(ctx->proxyDict);
1379 CFReleaseNull (ctx->proxyStore);
1380 CFReleaseNull(ctx->proxyAuth);