idm_text.c (8872:16322ca7ce0d) idm_text.c (9601:e0ed15140e6d)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 1350 unchanged lines hidden (view full) ---

1359 ASSERT(itb != NULL);
1360 itb->itb_mem = textbuf;
1361 itb->itb_mem_len = textbuflen;
1362 itb->itb_offset = validlen;
1363 return ((void *)itb);
1364}
1365
1366/*
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 1350 unchanged lines hidden (view full) ---

1359 ASSERT(itb != NULL);
1360 itb->itb_mem = textbuf;
1361 itb->itb_mem_len = textbuflen;
1362 itb->itb_offset = validlen;
1363 return ((void *)itb);
1364}
1365
1366/*
1367 * Update the pdu data up to min of max_xfer_len or data left.
1367 * Copy as much of the text buffer as will fit in the pdu.
1368 * The first call to this routine should send
1369 * a NULL bufptr. Subsequent calls send in the buffer returned.
1370 * Call this routine until the string returned is NULL
1371 */
1372char *
1373idm_pdu_init_text_data(idm_pdu_t *pdu, void *arg,
1374 int max_xfer_len, char *bufptr, int *transit)
1375{
1376 char *start_ptr, *end_ptr, *ptr;
1377 idm_textbuf_t *itb = arg;
1378 iscsi_hdr_t *ihp = pdu->isp_hdr;
1379 int send = 0;
1380
1381 ASSERT(itb != NULL);
1382 ASSERT(pdu != NULL);
1383 ASSERT(transit != NULL);
1384 if (bufptr == NULL) {
1385 /* first call - check the length */
1386 if (itb->itb_offset <= max_xfer_len) {
1368 * The first call to this routine should send
1369 * a NULL bufptr. Subsequent calls send in the buffer returned.
1370 * Call this routine until the string returned is NULL
1371 */
1372char *
1373idm_pdu_init_text_data(idm_pdu_t *pdu, void *arg,
1374 int max_xfer_len, char *bufptr, int *transit)
1375{
1376 char *start_ptr, *end_ptr, *ptr;
1377 idm_textbuf_t *itb = arg;
1378 iscsi_hdr_t *ihp = pdu->isp_hdr;
1379 int send = 0;
1380
1381 ASSERT(itb != NULL);
1382 ASSERT(pdu != NULL);
1383 ASSERT(transit != NULL);
1384 if (bufptr == NULL) {
1385 /* first call - check the length */
1386 if (itb->itb_offset <= max_xfer_len) {
1387 idm_pdu_init_data(pdu, (uint8_t *)itb->itb_mem,
1388 itb->itb_offset);
1387 /*
1388 * the entire text buffer fits in the pdu
1389 */
1390 bcopy((uint8_t *)itb->itb_mem, pdu->isp_data,
1391 (size_t)itb->itb_offset);
1392 pdu->isp_datalen = itb->itb_offset;
1389 ihp->flags &= ~ISCSI_FLAG_TEXT_CONTINUE;
1390 *transit = 1;
1391 return (NULL);
1392 }
1393 /* we have more data than will fit in one pdu */
1394 start_ptr = itb->itb_mem;
1395 end_ptr = &itb->itb_mem[max_xfer_len - 1];
1396
1397 } else {
1393 ihp->flags &= ~ISCSI_FLAG_TEXT_CONTINUE;
1394 *transit = 1;
1395 return (NULL);
1396 }
1397 /* we have more data than will fit in one pdu */
1398 start_ptr = itb->itb_mem;
1399 end_ptr = &itb->itb_mem[max_xfer_len - 1];
1400
1401 } else {
1398 if ((uintptr_t)&itb->itb_mem[itb->itb_offset] -
1399 (uintptr_t)bufptr <= max_xfer_len) {
1400 idm_pdu_init_data(pdu, (uint8_t *)bufptr,
1401 (uintptr_t)&itb->itb_mem[itb->itb_offset] -
1402 (uintptr_t)bufptr);
1402 uint_t len;
1403
1404 len = (uintptr_t)&itb->itb_mem[itb->itb_offset] -
1405 (uintptr_t)bufptr;
1406 if (len <= max_xfer_len) {
1407 /*
1408 * the remaining text fits in the pdu
1409 */
1410 bcopy(bufptr, pdu->isp_data, (size_t)len);
1411 pdu->isp_datalen = len;
1403 ihp->flags &= ~ISCSI_FLAG_TEXT_CONTINUE;
1404 *transit = 1;
1405 return (NULL);
1406 }
1412 ihp->flags &= ~ISCSI_FLAG_TEXT_CONTINUE;
1413 *transit = 1;
1414 return (NULL);
1415 }
1407 /* we have more data then will fit in one pdu */
1416 /* we still have more data then will fit in one pdu */
1408 start_ptr = bufptr;
1409 end_ptr = &bufptr[max_xfer_len - 1];
1410 }
1411 /* break after key, after =, after the value or after '\0' */
1412 ptr = end_ptr;
1413 if (end_ptr + 1 <= &itb->itb_mem[itb->itb_offset]) {
1414 /* if next char is an '=' or '\0' send it */
1415 if (*(end_ptr + 1) == '=' || *(end_ptr + 1) == '\0') {
1416 send = 1;
1417 }
1418 }
1419 if (!send) {
1420 while (*ptr != '\0' && *ptr != '=' && ptr != start_ptr) {
1421 ptr--;
1422 }
1423 }
1417 start_ptr = bufptr;
1418 end_ptr = &bufptr[max_xfer_len - 1];
1419 }
1420 /* break after key, after =, after the value or after '\0' */
1421 ptr = end_ptr;
1422 if (end_ptr + 1 <= &itb->itb_mem[itb->itb_offset]) {
1423 /* if next char is an '=' or '\0' send it */
1424 if (*(end_ptr + 1) == '=' || *(end_ptr + 1) == '\0') {
1425 send = 1;
1426 }
1427 }
1428 if (!send) {
1429 while (*ptr != '\0' && *ptr != '=' && ptr != start_ptr) {
1430 ptr--;
1431 }
1432 }
1424 idm_pdu_init_data(pdu, (uint8_t *)start_ptr,
1433 bcopy(start_ptr, pdu->isp_data,
1425 ((uintptr_t)ptr - (uintptr_t)start_ptr) + 1);
1434 ((uintptr_t)ptr - (uintptr_t)start_ptr) + 1);
1435 pdu->isp_datalen = ((uintptr_t)ptr - (uintptr_t)start_ptr) + 1;
1426 ihp->flags |= ISCSI_FLAG_TEXT_CONTINUE;
1427 *transit = 0;
1428 return (++ptr);
1429}
1430
1431void
1432idm_itextbuf_free(void *arg)
1433{

--- 185 unchanged lines hidden ---
1436 ihp->flags |= ISCSI_FLAG_TEXT_CONTINUE;
1437 *transit = 0;
1438 return (++ptr);
1439}
1440
1441void
1442idm_itextbuf_free(void *arg)
1443{

--- 185 unchanged lines hidden ---