#ifndef SQUID_STORE_H
#define SQUID_STORE_H
-/**
- \defgroup StoreAPI Store API
- \ingroup FileSystems
- */
-
+#include "base/Packable.h"
#include "base/RefCount.h"
#include "comm/forward.h"
#include "CommRead.h"
/// maximum number of entries per cache_dir
enum { SwapFilenMax = 0xFFFFFF }; // keep in sync with StoreEntry::swap_filen
-/**
- \ingroup StoreAPI
- */
-class StoreEntry : public hash_link
+class StoreEntry : public hash_link, public Packable
{
public:
ESIElement::Pointer cachedESITree;
#endif
- /** append bytes to the buffer */
- virtual void append(char const *, int len);
/** disable sending content to the clients */
virtual void buffer();
/** flush any buffered content */
void kickProducer();
#endif
+ /* Packable API */
+ virtual void append(char const *, int);
+ virtual void vappendf(const char *, va_list);
+
protected:
void transientsAbandonmentCheck();
write(tempBuffer);
}
+void
+StoreEntry::vappendf(const char *fmt, va_list vargs)
+{
+ LOCAL_ARRAY(char, buf, 4096);
+ *buf = 0;
+ int x;
+
+ errno = 0;
+ if ((x = vsnprintf(buf, sizeof(buf), fmt, vargs)) < 0) {
+ fatalf( xstrerror(errno));
+ return;
+ }
+
+ if (x < sizeof(buf)) {
+ append(buf, x);
+ return;
+ }
+
+ // okay, do it the slow way.
+ char *buf2 = new char[x+1];
+ int y = vsnprintf(buf2, x+1, fmt, vargs);
+ assert(y >= 0 && y == x);
+ append(buf2, y);
+ delete[] buf2;
+}
+
+// deprecated. use StoreEntry::appendf() instead.
void
storeAppendPrintf(StoreEntry * e, const char *fmt,...)
{
va_list args;
va_start(args, fmt);
-
- storeAppendVPrintf(e, fmt, args);
+ e->vappendf(fmt, args);
va_end(args);
}
-/* used be storeAppendPrintf and Packer */
+// deprecated. use StoreEntry::appendf() instead.
void
storeAppendVPrintf(StoreEntry * e, const char *fmt, va_list vargs)
{
- LOCAL_ARRAY(char, buf, 4096);
- buf[0] = '\0';
- vsnprintf(buf, 4096, fmt, vargs);
- e->append(buf, strlen(buf));
+ e->vappendf(fmt, vargs);
}
struct _store_check_cachable_hist {
//#if USE_SQUID_ESI
//ESIElement::Pointer StoreEntry::cachedESITree STUB_RETVAL(NULL)
//#endif
-void StoreEntry::append(char const *, int len) STUB
void StoreEntry::buffer() STUB
void StoreEntry::flush() STUB
int StoreEntry::unlock(const char *) STUB_RETVAL(0)
void StoreEntry::lock(const char *) STUB
void StoreEntry::touch() STUB
void StoreEntry::release() STUB
+void StoreEntry::append(char const *, int) STUB
+void StoreEntry::vappendf(const char *, va_list) STUB
NullStoreEntry *NullStoreEntry::getInstance() STUB_RETVAL(NULL)
const char *NullStoreEntry::getMD5Text() const STUB_RETVAL(NULL)