svn commit: samba r15432 - in trunk/source: lib libsmb torture web

jelmer at samba.org jelmer at samba.org
Thu May 4 13:04:23 GMT 2006


Author: jelmer
Date: 2006-05-04 13:04:22 +0000 (Thu, 04 May 2006)
New Revision: 15432

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=15432

Log:
Make some functions non-static and import some utility functions from Samba 4 

Modified:
   trunk/source/lib/charcnv.c
   trunk/source/lib/data_blob.c
   trunk/source/lib/substitute.c
   trunk/source/lib/time.c
   trunk/source/lib/util.c
   trunk/source/lib/util_str.c
   trunk/source/libsmb/trusts_util.c
   trunk/source/torture/rpctorture.c
   trunk/source/web/swat.c


Changeset:
Modified: trunk/source/lib/charcnv.c
===================================================================
--- trunk/source/lib/charcnv.c	2006-05-04 12:57:27 UTC (rev 15431)
+++ trunk/source/lib/charcnv.c	2006-05-04 13:04:22 UTC (rev 15432)
@@ -702,7 +702,7 @@
  *
  * @returns Size in bytes of the converted string; or -1 in case of error.
  **/
-static size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to,
+size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to,
 		      		void const *src, size_t srclen, void **dest, BOOL allow_bad_conv)
 {
 	size_t dest_len;

Modified: trunk/source/lib/data_blob.c
===================================================================
--- trunk/source/lib/data_blob.c	2006-05-04 12:57:27 UTC (rev 15431)
+++ trunk/source/lib/data_blob.c	2006-05-04 13:04:22 UTC (rev 15432)
@@ -102,7 +102,7 @@
  Clear a DATA_BLOB's contents
 *******************************************************************/
 
-static void data_blob_clear(DATA_BLOB *d)
+void data_blob_clear(DATA_BLOB *d)
 {
 	if (d->data) {
 		memset(d->data, 0, d->length);

Modified: trunk/source/lib/substitute.c
===================================================================
--- trunk/source/lib/substitute.c	2006-05-04 12:57:27 UTC (rev 15431)
+++ trunk/source/lib/substitute.c	2006-05-04 13:04:22 UTC (rev 15432)
@@ -522,7 +522,7 @@
 			a_string = realloc_string_sub(a_string, "%R", remote_proto);
 			break;
 		case 'T' :
-			a_string = realloc_string_sub(a_string, "%T", timestring(False));
+			a_string = realloc_string_sub(a_string, "%T", current_timestring(False));
 			break;
 		case 'a' :
 			a_string = realloc_string_sub(a_string, "%a", remote_arch);

Modified: trunk/source/lib/time.c
===================================================================
--- trunk/source/lib/time.c	2006-05-04 12:57:27 UTC (rev 15431)
+++ trunk/source/lib/time.c	2006-05-04 13:04:22 UTC (rev 15432)
@@ -639,7 +639,7 @@
  Return the date and time as a string
 ****************************************************************************/
 
-char *timestring(BOOL hires)
+char *current_timestring(BOOL hires)
 {
 	static fstring TimeBuf;
 	struct timeval tp;
@@ -1057,3 +1057,49 @@
 	return ret;
 }
 #endif
+
+
+/**
+ Return the date and time as a string
+**/
+char *timestring(TALLOC_CTX *mem_ctx, time_t t)
+{
+	char *TimeBuf;
+	char tempTime[80];
+	struct tm *tm;
+
+	tm = localtime(&t);
+	if (!tm) {
+		return talloc_asprintf(mem_ctx,
+				       "%ld seconds since the Epoch",
+				       (long)t);
+	}
+
+#ifdef HAVE_STRFTIME
+	/* some versions of gcc complain about using %c. This is a bug
+	   in the gcc warning, not a bug in this code. See a recent
+	   strftime() manual page for details.
+	 */
+	strftime(tempTime,sizeof(tempTime)-1,"%c %Z",tm);
+	TimeBuf = talloc_strdup(mem_ctx, tempTime);
+#else
+	TimeBuf = talloc_strdup(mem_ctx, asctime(tm));
+#endif
+
+	return TimeBuf;
+}
+
+
+/**
+  return a talloced string representing a NTTIME for human consumption
+*/
+const char *nt_time_string(TALLOC_CTX *mem_ctx, NTTIME nt)
+{
+	time_t t;
+	if (nt.low == 0 && nt.high == 0) {
+		return "NTTIME(0)";
+	}
+	t = nt_time_to_unix(&nt);
+	return timestring(mem_ctx, t);
+}
+

Modified: trunk/source/lib/util.c
===================================================================
--- trunk/source/lib/util.c	2006-05-04 12:57:27 UTC (rev 15431)
+++ trunk/source/lib/util.c	2006-05-04 13:04:22 UTC (rev 15432)
@@ -447,26 +447,6 @@
 }
 
 /*******************************************************************
- Return a string representing an attribute for a file.
-********************************************************************/
-
-char *attrib_string(uint16 mode)
-{
-	static fstring attrstr;
-
-	attrstr[0] = 0;
-
-	if (mode & aVOLID) fstrcat(attrstr,"V");
-	if (mode & aDIR) fstrcat(attrstr,"D");
-	if (mode & aARCH) fstrcat(attrstr,"A");
-	if (mode & aHIDDEN) fstrcat(attrstr,"H");
-	if (mode & aSYSTEM) fstrcat(attrstr,"S");
-	if (mode & aRONLY) fstrcat(attrstr,"R");	  
-
-	return(attrstr);
-}
-
-/*******************************************************************
  Show a smb message structure.
 ********************************************************************/
 

Modified: trunk/source/lib/util_str.c
===================================================================
--- trunk/source/lib/util_str.c	2006-05-04 12:57:27 UTC (rev 15431)
+++ trunk/source/lib/util_str.c	2006-05-04 13:04:22 UTC (rev 15432)
@@ -795,40 +795,7 @@
 	return num_chars;
 }
 
-DATA_BLOB strhex_to_data_blob(TALLOC_CTX *mem_ctx, const char *strhex) 
-{
-	DATA_BLOB ret_blob;
-
-	if (mem_ctx != NULL)
-		ret_blob = data_blob_talloc(mem_ctx, NULL, strlen(strhex)/2+1);
-	else
-		ret_blob = data_blob(NULL, strlen(strhex)/2+1);
-
-	ret_blob.length = strhex_to_str((char*)ret_blob.data, 	
-					strlen(strhex), 
-					strhex);
-
-	return ret_blob;
-}
-
 /**
- * Routine to print a buffer as HEX digits, into an allocated string.
- */
-
-char *hex_encode(TALLOC_CTX *mem_ctx, const unsigned char *buff_in, size_t len)
-{
-	int i;
-	char *hex_buffer;
-
-	hex_buffer = TALLOC_ARRAY(mem_ctx, char, (len*2)+1);
-
-	for (i = 0; i < len; i++)
-		slprintf(&hex_buffer[i*2], 3, "%02X", buff_in[i]);
-
-	return hex_buffer;
-}
-
-/**
  Check if a string is part of a list.
 **/
 
@@ -2415,3 +2382,52 @@
 	return True;
 }
 
+
+/**
+return the number of bytes occupied by a buffer in ASCII format
+the result includes the null termination
+limited by 'n' bytes
+**/
+size_t ascii_len_n(const char *src, size_t n)
+{
+	size_t len;
+
+	len = strnlen(src, n);
+	if (len+1 <= n) {
+		len += 1;
+	}
+
+	return len;
+}
+
+/**
+return the number of bytes occupied by a buffer in CH_UTF16 format
+the result includes the null termination
+**/
+size_t utf16_len(const void *buf)
+{
+	size_t len;
+
+	for (len = 0; SVAL(buf,len); len += 2) ;
+
+	return len + 2;
+}
+
+/**
+return the number of bytes occupied by a buffer in CH_UTF16 format
+the result includes the null termination
+limited by 'n' bytes
+**/
+size_t utf16_len_n(const void *src, size_t n)
+{
+	size_t len;
+
+	for (len = 0; (len+2 < n) && SVAL(src, len); len += 2) ;
+
+	if (len+2 <= n) {
+		len += 2;
+	}
+
+	return len;
+}
+

Modified: trunk/source/libsmb/trusts_util.c
===================================================================
--- trunk/source/libsmb/trusts_util.c	2006-05-04 12:57:27 UTC (rev 15431)
+++ trunk/source/libsmb/trusts_util.c	2006-05-04 13:04:22 UTC (rev 15432)
@@ -95,7 +95,7 @@
 	
 	if (NT_STATUS_IS_OK(nt_status)) {
 		DEBUG(3,("%s : trust_pw_change_and_store_it: Changed password.\n", 
-			 timestring(False)));
+			 current_timestring(False)));
 		/*
 		 * Return the result of trying to write the new password
 		 * back into the trust account file.

Modified: trunk/source/torture/rpctorture.c
===================================================================
--- trunk/source/torture/rpctorture.c	2006-05-04 12:57:27 UTC (rev 15431)
+++ trunk/source/torture/rpctorture.c	2006-05-04 13:04:22 UTC (rev 15432)
@@ -493,7 +493,7 @@
 	strupper_m(global_myname);
 	fstrcpy(cli_info.myhostname, global_myname);
 
-	DEBUG(3,("%s client started (version %s)\n",timestring(False),SAMBA_VERSION_STRING));
+	DEBUG(3,("%s client started (version %s)\n",current_timestring(False),SAMBA_VERSION_STRING));
 
 	if (*smb_cli->domain == 0)
 	{

Modified: trunk/source/web/swat.c
===================================================================
--- trunk/source/web/swat.c	2006-05-04 12:57:27 UTC (rev 15431)
+++ trunk/source/web/swat.c	2006-05-04 13:04:22 UTC (rev 15432)
@@ -432,7 +432,7 @@
 {
 	fprintf(f, "# Samba config file created using SWAT\n");
 	fprintf(f, "# from %s (%s)\n", cgi_remote_host(), cgi_remote_addr());
-	fprintf(f, "# Date: %s\n\n", timestring(False));
+	fprintf(f, "# Date: %s\n\n", current_timestring(False));
 	
 	lp_dump(f, show_defaults, iNumNonAutoPrintServices);
 }



More information about the samba-cvs mailing list