summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorRichard Sharpe <sharpe@samba.org>2001-02-06 19:25:12 +0000
committerRichard Sharpe <sharpe@samba.org>2001-02-06 19:25:12 +0000
commit5455f2896f65a650a32f18dfb4bc4ae81a79848e (patch)
treef706e16828fd8b8b5eaf187c1f4dc216aac7def6 /source3
parentca03ad79cfaad48fb20426dfb98a30740fe80a0d (diff)
downloadsamba-5455f2896f65a650a32f18dfb4bc4ae81a79848e.tar.gz
samba-5455f2896f65a650a32f18dfb4bc4ae81a79848e.tar.bz2
samba-5455f2896f65a650a32f18dfb4bc4ae81a79848e.zip
Fix problems in libsmbclient with pring job struct plus add implementation
of last two print routines ... (This used to be commit 7c50af3b71eeedfef8ed0d5771c2dc578fa95741)
Diffstat (limited to 'source3')
-rw-r--r--source3/include/libsmbclient.h12
-rw-r--r--source3/libsmb/libsmbclient.c96
2 files changed, 108 insertions, 0 deletions
diff --git a/source3/include/libsmbclient.h b/source3/include/libsmbclient.h
index 5469966cf8..fe383e845a 100644
--- a/source3/include/libsmbclient.h
+++ b/source3/include/libsmbclient.h
@@ -43,6 +43,18 @@ struct smbc_dirent {
};
+#ifndef _CLIENT_H
+typedef unsigned short uint16;
+struct print_job_info {
+ uint16 id;
+ uint16 priority;
+ size_t size;
+ char user[128];
+ char name[128];
+ time_t t;
+};
+#endif
+
/*
* Entity types
*/
diff --git a/source3/libsmb/libsmbclient.c b/source3/libsmb/libsmbclient.c
index 68dbe666f7..3afa98b28e 100644
--- a/source3/libsmb/libsmbclient.c
+++ b/source3/libsmb/libsmbclient.c
@@ -2149,8 +2149,104 @@ int smbc_fstatdir(int fd, struct stat *st)
int smbc_print_file(const char *fname, const char *printq)
{
+ int fid1, fid2, bytes, saverr, tot_bytes = 0;
+ char buf[4096];
+ if (!smbc_initialized) {
+
+ errno = EUCLEAN;
+ return -1;
+
+ }
+
+ if (!fname && !printq) {
+
+ errno = EINVAL;
+ return -1;
+
+ }
+
+ /* Try to open the file for reading ... */
+
+ if ((fid1 = smbc_open(fname, O_RDONLY, 0666)) < 0) {
+
+ return -1; /* smbc_open sets errno */
+
+ }
+
+ /* Now, try to open the printer file for writing */
+
+ if ((fid2 = smbc_open_print_job(printq)) < 0) {
+
+ saverr = errno; /* Save errno */
+ smbc_close(fid1);
+ errno = saverr;
+ return -1;
+
+ }
+
+ while ((bytes = smbc_read(fid1, buf, sizeof(buf))) > 0) {
+
+ tot_bytes += bytes;
+
+ if ((smbc_write(fid2, buf, bytes)) < 0) {
+
+ saverr = errno;
+ smbc_close(fid1);
+ smbc_close(fid2);
+ errno = saverr;
+
+ }
+
+ }
+
+ saverr = errno;
+
+ smbc_close(fid1); /* We have to close these anyway */
+ smbc_close(fid2);
+
+ if (bytes < 0) {
+
+ errno = saverr;
+ return -1;
+
+ }
+
+ return tot_bytes;
+
+}
+
+/*
+ * Open a print file to be written to by other calls
+ */
+
+int smbc_open_print_job(const char *fname)
+{
+ struct smbc_server *srv;
+ fstring server, share, user, password;
+ pstring path;
+
+ if (!smbc_initialized) {
+
+ errno = EUCLEAN;
+ return -1;
+
+ }
+
+ if (!fname) {
+
+ errno = EINVAL;
+ return -1;
+
+ }
+
+ DEBUG(4, ("smbc_open_print_job(%s)\n", fname));
+
+ smbc_parse_path(fname, server, share, path, user, password); /*FIXME, errors*/
+
+ /* What if the path is empty, or the file exists? */
+ return smbc_open(fname, O_WRONLY, 666);
}