~ubuntu-branches/debian/jessie/netatalk/jessie

« back to all changes in this revision

Viewing changes to libatalk/dsi/dsi_stream.c

  • Committer: Package Import Robot
  • Author(s): Jonas Smedegaard
  • Date: 2012-03-20 23:37:08 UTC
  • mfrom: (1.1.12)
  • Revision ID: package-import@ubuntu.com-20120320233708-sp2k0av7f9sjnf4w
Tags: 2.2.2-1
* New upstream release.
* Drop patch cherry-picked upstream: Included in new upstream release.
* Build-depend on libldap2-dev and libacl1-dev, to enable LDAP support
  and support for extended ACLs (and possibly avoid FTBFS).
  Closes: bug#645290, #651406. Thanks to Peter Eisentraut and masc.
* Update copyright file:
  + Bump format to 1.0.
  + Fix double-indent in Copyright fields as per Policy §5.6.13.
  + Add Files paragraph for ACL code.
* Bump standards-version to 3.9.3.
* Update copyright file: Add disclaimer to License paragraph
  GAP~Makefile.in.
* Bump debhelper compat level to 7.
* Add patch 101 to start avahi-daemon (if available) before atalkd.
  Recommend avahi-daemon.

Show diffs side-by-side

added added

removed removed

Lines of Context:
266
266
  dsi->in_write++;
267
267
  written = 0;
268
268
 
269
 
  LOG(log_maxdebug, logtype_dsi, "dsi_stream_write: sending %u bytes", length);
 
269
  LOG(log_maxdebug, logtype_dsi, "dsi_stream_write(send: %zd bytes): START", length);
270
270
 
271
271
  if (dsi->flags & DSI_DISCONNECTED)
272
272
      return -1;
305
305
  }
306
306
 
307
307
  dsi->write_count += written;
 
308
  LOG(log_maxdebug, logtype_dsi, "dsi_stream_write(send: %zd bytes): END", length);
308
309
 
309
310
exit:
310
311
  dsi->in_write--;
317
318
#ifdef WITH_SENDFILE
318
319
ssize_t dsi_stream_read_file(DSI *dsi, int fromfd, off_t offset, const size_t length)
319
320
{
 
321
  int ret = 0;
320
322
  size_t written;
321
323
  ssize_t len;
 
324
  off_t pos = offset;
322
325
 
323
 
  LOG(log_maxdebug, logtype_dsi, "dsi_stream_read_file: sending %u bytes", length);
 
326
  LOG(log_maxdebug, logtype_dsi, "dsi_stream_read_file(send %zd bytes): START", length);
324
327
 
325
328
  if (dsi->flags & DSI_DISCONNECTED)
326
329
      return -1;
329
332
  written = 0;
330
333
 
331
334
  while (written < length) {
332
 
    len = sys_sendfile(dsi->socket, fromfd, &offset, length - written);
 
335
    len = sys_sendfile(dsi->socket, fromfd, &pos, length - written);
333
336
        
334
337
    if (len < 0) {
335
338
      if (errno == EINTR)
336
339
          continue;
337
 
      if (errno == EINVAL || errno == ENOSYS)
338
 
          return -1;
339
 
          
 
340
      if (errno == EINVAL || errno == ENOSYS) {
 
341
          ret = -1;
 
342
          goto exit;
 
343
      }          
340
344
      if (errno == EAGAIN || errno == EWOULDBLOCK) {
 
345
#if defined(SOLARIS) || defined(FREEBSD)
 
346
          if (pos > offset) {
 
347
              /* we actually have sent sth., adjust counters and keep trying */
 
348
              len = pos - offset;
 
349
              written += len;
 
350
              offset = pos;
 
351
          }
 
352
#endif
341
353
          if (dsi_peek(dsi)) {
342
354
              /* can't go back to blocking mode, exit, the next read
343
355
                 will return with an error and afpd will die.
351
363
    }
352
364
    else if (!len) {
353
365
        /* afpd is going to exit */
354
 
        errno = EIO;
355
 
        return -1; /* I think we're at EOF here... */
 
366
          ret = -1;
 
367
          goto exit;
356
368
    }
357
369
    else 
358
370
        written += len;
359
371
  }
360
372
 
361
373
  dsi->write_count += written;
 
374
 
 
375
exit:
362
376
  dsi->in_write--;
 
377
  LOG(log_maxdebug, logtype_dsi, "dsi_stream_read_file: sent: %zd", written);
 
378
  if (ret != 0)
 
379
      return -1;
363
380
  return written;
364
381
}
365
382
#endif
423
440
  size_t towrite;
424
441
  ssize_t len;
425
442
 
426
 
  LOG(log_maxdebug, logtype_dsi, "dsi_stream_send: %u bytes",
427
 
      length ? length : sizeof(block));
 
443
  LOG(log_maxdebug, logtype_dsi, "dsi_stream_send(%u bytes): START", length);
428
444
 
429
445
  if (dsi->flags & DSI_DISCONNECTED)
430
446
      return 0;
439
455
         sizeof(dsi->header.dsi_reserved));
440
456
 
441
457
  if (!length) { /* just write the header */
 
458
      LOG(log_maxdebug, logtype_dsi, "dsi_stream_send(%u bytes): DSI header, no data", sizeof(block));
442
459
    length = (dsi_stream_write(dsi, block, sizeof(block), 0) == sizeof(block));
443
460
    return length; /* really 0 on failure, 1 on success */
444
461
  }
482
499
          iov[1].iov_len -= len;
483
500
      }
484
501
  }
 
502
 
 
503
  LOG(log_maxdebug, logtype_dsi, "dsi_stream_send(%u bytes): END", length);
485
504
  
486
505
  unblock_sig(dsi);
487
506
  return 1;
488
507
}
489
508
 
490
509
 
491
 
/* ---------------------------------------
492
 
 * read data. function on success. 0 on failure. data length gets
493
 
 * stored in length variable. this should really use size_t's, but
494
 
 * that would require changes elsewhere. */
495
 
int dsi_stream_receive(DSI *dsi, void *buf, const size_t ilength,
496
 
                       size_t *rlength)
 
510
/*!
 
511
 * Read DSI command and data
 
512
 *
 
513
 * @param  dsi   (rw) DSI handle
 
514
 *
 
515
 * @return    DSI function on success, 0 on failure
 
516
 */
 
517
int dsi_stream_receive(DSI *dsi)
497
518
{
498
519
  char block[DSI_BLOCKSIZ];
499
520
 
500
 
  LOG(log_maxdebug, logtype_dsi, "dsi_stream_receive: %u bytes", ilength);
 
521
  LOG(log_maxdebug, logtype_dsi, "dsi_stream_receive: START");
501
522
 
502
523
  if (dsi->flags & DSI_DISCONNECTED)
503
524
      return 0;
508
529
 
509
530
  dsi->header.dsi_flags = block[0];
510
531
  dsi->header.dsi_command = block[1];
511
 
  /* FIXME, not the right place, 
512
 
     but we get a server disconnect without reason in the log
513
 
  */
514
 
  if (!block[1]) {
515
 
      LOG(log_error, logtype_dsi, "dsi_stream_receive: invalid packet, fatal");
 
532
 
 
533
  if (dsi->header.dsi_command == 0)
516
534
      return 0;
517
 
  }
518
535
 
519
 
  memcpy(&dsi->header.dsi_requestID, block + 2, 
520
 
         sizeof(dsi->header.dsi_requestID));
 
536
  memcpy(&dsi->header.dsi_requestID, block + 2, sizeof(dsi->header.dsi_requestID));
521
537
  memcpy(&dsi->header.dsi_code, block + 4, sizeof(dsi->header.dsi_code));
522
538
  memcpy(&dsi->header.dsi_len, block + 8, sizeof(dsi->header.dsi_len));
523
 
  memcpy(&dsi->header.dsi_reserved, block + 12,
524
 
         sizeof(dsi->header.dsi_reserved));
 
539
  memcpy(&dsi->header.dsi_reserved, block + 12, sizeof(dsi->header.dsi_reserved));
525
540
  dsi->clientID = ntohs(dsi->header.dsi_requestID);
526
541
  
527
542
  /* make sure we don't over-write our buffers. */
528
 
  *rlength = min(ntohl(dsi->header.dsi_len), ilength);
529
 
  if (dsi_stream_read(dsi, buf, *rlength) != *rlength) 
 
543
  dsi->cmdlen = min(ntohl(dsi->header.dsi_len), DSI_CMDSIZ);
 
544
  if (dsi_stream_read(dsi, dsi->commands, dsi->cmdlen) != dsi->cmdlen) 
530
545
    return 0;
531
546
 
 
547
  LOG(log_debug, logtype_dsi, "dsi_stream_receive: DSI cmdlen: %zd", dsi->cmdlen);
 
548
 
532
549
  return block[1];
533
550
}