comparison src/mail/ngx_mail_auth_http_module.c @ 408:4243eecbd594

Merge with nginx 0.6.11.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 11 Aug 2008 03:17:24 +0400
parents 481e8f936572 390b8f8309d6
children 52b28d322d76
comparison
equal deleted inserted replaced
407:fa809001e681 408:4243eecbd594
19 ngx_str_t host_header; 19 ngx_str_t host_header;
20 ngx_str_t uri; 20 ngx_str_t uri;
21 ngx_str_t header; 21 ngx_str_t header;
22 22
23 ngx_array_t *headers; 23 ngx_array_t *headers;
24
25 u_char *file;
26 ngx_uint_t line;
24 } ngx_mail_auth_http_conf_t; 27 } ngx_mail_auth_http_conf_t;
25 28
26 29
27 typedef struct ngx_mail_auth_http_ctx_s ngx_mail_auth_http_ctx_t; 30 typedef struct ngx_mail_auth_http_ctx_s ngx_mail_auth_http_ctx_t;
28 31
1275 1278
1276 1279
1277 static ngx_int_t 1280 static ngx_int_t
1278 ngx_mail_auth_http_escape(ngx_pool_t *pool, ngx_str_t *text, ngx_str_t *escaped) 1281 ngx_mail_auth_http_escape(ngx_pool_t *pool, ngx_str_t *text, ngx_str_t *escaped)
1279 { 1282 {
1280 u_char ch, *p; 1283 u_char *p;
1281 ngx_uint_t i, n; 1284 uintptr_t n;
1282 1285
1283 n = 0; 1286 n = ngx_escape_uri(NULL, text->data, text->len, NGX_ESCAPE_MAIL_AUTH);
1284
1285 for (i = 0; i < text->len; i++) {
1286 ch = text->data[i];
1287
1288 if (ch == CR || ch == LF) {
1289 n++;
1290 }
1291 }
1292 1287
1293 if (n == 0) { 1288 if (n == 0) {
1294 *escaped = *text; 1289 *escaped = *text;
1295 return NGX_OK; 1290 return NGX_OK;
1296 } 1291 }
1300 p = ngx_palloc(pool, escaped->len); 1295 p = ngx_palloc(pool, escaped->len);
1301 if (p == NULL) { 1296 if (p == NULL) {
1302 return NGX_ERROR; 1297 return NGX_ERROR;
1303 } 1298 }
1304 1299
1300 (void) ngx_escape_uri(p, text->data, text->len, NGX_ESCAPE_MAIL_AUTH);
1301
1305 escaped->data = p; 1302 escaped->data = p;
1306
1307 for (i = 0; i < text->len; i++) {
1308 ch = text->data[i];
1309
1310 if (ch == CR) {
1311 *p++ = '%';
1312 *p++ = '0';
1313 *p++ = 'D';
1314 continue;
1315 }
1316
1317 if (ch == LF) {
1318 *p++ = '%';
1319 *p++ = '0';
1320 *p++ = 'A';
1321 continue;
1322 }
1323
1324 *p++ = ch;
1325 }
1326 1303
1327 return NGX_OK; 1304 return NGX_OK;
1328 } 1305 }
1329 1306
1330 1307
1337 if (ahcf == NULL) { 1314 if (ahcf == NULL) {
1338 return NGX_CONF_ERROR; 1315 return NGX_CONF_ERROR;
1339 } 1316 }
1340 1317
1341 ahcf->timeout = NGX_CONF_UNSET_MSEC; 1318 ahcf->timeout = NGX_CONF_UNSET_MSEC;
1319
1320 ahcf->file = cf->conf_file->file.name.data;
1321 ahcf->line = cf->conf_file->line;
1342 1322
1343 return ahcf; 1323 return ahcf;
1344 } 1324 }
1345 1325
1346 1326
1357 1337
1358 if (conf->peer == NULL) { 1338 if (conf->peer == NULL) {
1359 conf->peer = prev->peer; 1339 conf->peer = prev->peer;
1360 conf->host_header = prev->host_header; 1340 conf->host_header = prev->host_header;
1361 conf->uri = prev->uri; 1341 conf->uri = prev->uri;
1342
1343 if (conf->peer == NULL) {
1344 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
1345 "no \"http_auth\" is defined for server in %s:%ui",
1346 conf->file, conf->line);
1347
1348 return NGX_CONF_ERROR;
1349 }
1362 } 1350 }
1363 1351
1364 ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 60000); 1352 ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 60000);
1365 1353
1366 if (conf->headers == NULL) { 1354 if (conf->headers == NULL) {
1410 u.url = value[1]; 1398 u.url = value[1];
1411 u.default_port = 80; 1399 u.default_port = 80;
1412 u.uri_part = 1; 1400 u.uri_part = 1;
1413 u.one_addr = 1; 1401 u.one_addr = 1;
1414 1402
1403 if (ngx_strncmp(u.url.data, "http://", 7) == 0) {
1404 u.url.len -= 7;
1405 u.url.data += 7;
1406 }
1407
1415 if (ngx_parse_url(cf, &u) != NGX_OK) { 1408 if (ngx_parse_url(cf, &u) != NGX_OK) {
1416 if (u.err) { 1409 if (u.err) {
1417 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 1410 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1418 "%s in auth_http \"%V\"", u.err, &u.url); 1411 "%s in auth_http \"%V\"", u.err, &u.url);
1419 } 1412 }
1413
1414 return NGX_CONF_ERROR;
1420 } 1415 }
1421 1416
1422 ahcf->peer = u.addrs; 1417 ahcf->peer = u.addrs;
1423 1418
1424 ahcf->host_header = u.host; 1419 ahcf->host_header = u.host;