]> code.citadel.org Git - citadel.git/blobdiff - libcitadel/lib/stringbuf.c
* add function to decode hex strings
[citadel.git] / libcitadel / lib / stringbuf.c
index 03459bd789fe42fbb8c2ff8b470ed72a5555f81f..c59361263d5b203c243389dea3266be4185ef6d2 100644 (file)
@@ -1414,7 +1414,7 @@ int StrBufTCP_read_buffered_line_fast(StrBuf *Line,
                        *fd = -1;
                        return -1;
                }               
-               if (FD_ISSET(*fd, &rfds)) {
+               if (FD_ISSET(*fd, &rfds) != 0) {
                        rlen = read(*fd, 
                                    &buf->buf[buf->BufUsed], 
                                    buf->BufSize - buf->BufUsed - 1);
@@ -1916,6 +1916,32 @@ int StrBufDecodeBase64(StrBuf *Buf)
        return siz;
 }
 
+/**
+ * \brief decode a buffer from base 64 encoding; destroys original
+ * \param Buf Buffor to transform
+ */
+int StrBufDecodeHex(StrBuf *Buf)
+{
+       unsigned int ch;
+       char *pch, *pche, *pchi;
+
+       if (Buf == NULL) return -1;
+
+       pch = pchi = Buf->buf;
+       pche = pch + Buf->BufUsed;
+
+       while (pchi < pche){
+               ch = decode_hex(pchi);
+               *pch = ch;
+               pch ++;
+               pchi += 2;
+       }
+
+       *pch = '\0';
+       Buf->BufUsed = pch - Buf->buf;
+       return Buf->BufUsed;
+}
+
 /**
  * \brief replace all chars >0x20 && < 0x7F with Mute
  * \param Mute char to put over invalid chars