static carray * mailstream_low_cfstream_get_certificate_chain(mailstream_low * s) { #if HAVE_CFNETWORK struct mailstream_cfstream_data * cfstream_data; unsigned int i; carray * result; cfstream_data = (struct mailstream_cfstream_data *) s->data; SecTrustRef secTrust = (SecTrustRef)CFReadStreamCopyProperty(cfstream_data->readStream, kCFStreamPropertySSLPeerTrust); if (secTrust == NULL) return NULL; CFIndex count = SecTrustGetCertificateCount(secTrust); result = carray_new(4); for(i = 0 ; i < count ; i ++) { SecCertificateRef cert = (SecCertificateRef) SecTrustGetCertificateAtIndex(secTrust, i); CFDataRef data = SecCertificateCopyData(cert); CFIndex length = CFDataGetLength(data); const UInt8 * bytes = CFDataGetBytePtr(data); MMAPString * str = mmap_string_sized_new(length); mmap_string_append_len(str, (char*) bytes, length); carray_add(result, str, NULL); CFRelease(data); } CFRelease(secTrust); return result; #else return NULL; #endif }
size_t oxws_write_response_to_buffer_callback(char *ptr, size_t size, size_t nmemb, void *userdata) { oxws_internal* internal = (oxws_internal*) userdata; if(internal != NULL && internal->response_buffer) { size_t length = size * nmemb < 1 ? 0 : size * nmemb; mmap_string_append_len(internal->response_buffer, ptr, length); return length; } else { return 0; /* error */ } }
void oxws_autodiscover_sax_handler_characters(void* user_data, const xmlChar* chars, int length) { if(user_data == NULL || chars == NULL) return; oxws_autodiscover_sax_context* context = (oxws_autodiscover_sax_context*) user_data; if(OXWS_AUTODISCOVER_SAX_CONTEXT_STATE_IS_ERROR()) return; if(context->string != NULL) { mmap_string_append_len(context->string, (const char*) chars, length); } else { /* TODO warn for suspicious states? */ } }
MMAPString* mmap_string_new_len (const char *init, size_t len) { MMAPString *string; if (len <= 0) return mmap_string_new (init); else { string = mmap_string_sized_new (len); if (init) mmap_string_append_len (string, init, len); return string; } }
int generic_cache_flags_read(struct mail_cache_db * cache_db, MMAPString * mmapstr, char * keyname, struct mail_flags ** result) { int r; int res; size_t cur_token; struct mail_flags * flags; void * data; size_t data_len; data = NULL; data_len = 0; r = mail_cache_db_get(cache_db, keyname, strlen(keyname), &data, &data_len); if (r != 0) { res = MAIL_ERROR_CACHE_MISS; goto err; } r = mail_serialize_clear(mmapstr, &cur_token); if (r != MAIL_NO_ERROR) { res = r; goto err; } if (mmap_string_append_len(mmapstr, data, data_len) == NULL) { res = MAIL_ERROR_MEMORY; goto err; } flags = NULL; r = generic_flags_read(mmapstr, &cur_token, &flags); if (r != MAIL_NO_ERROR) { res = r; goto err; } * result = flags; return MAIL_NO_ERROR; err: return res; }
static char * make_quoted_printable(const char * display_charset, const char * phrase) { char * str; const char * cur; MMAPString * mmapstr; int r; mmapstr = mmap_string_new(""); if (mmapstr == NULL) return NULL; cur = phrase; while (* cur != '\0') { const char * begin; const char * end; int do_quote; int quote_words; begin = cur; end = begin; quote_words = 0; do_quote = 1; while (* cur != '\0') { get_word(cur, &cur, &do_quote); if (do_quote) { quote_words = 1; end = cur; } else break; if (* cur != '\0') cur ++; } if (quote_words) { r = quote_word(display_charset, mmapstr, begin, end - begin); if (r < 0) { mmap_string_free(mmapstr); return NULL; } if ((* end == ' ') || (* end == '\t')) { if (mmap_string_append_c(mmapstr, * end) == NULL) { mmap_string_free(mmapstr); return NULL; } end ++; } if (* end != '\0') { if (mmap_string_append_len(mmapstr, end, cur - end) == NULL) { mmap_string_free(mmapstr); return NULL; } } } else { if (mmap_string_append_len(mmapstr, begin, cur - begin) == NULL) { mmap_string_free(mmapstr); return NULL; } } if ((* cur == ' ') || (* cur == '\t')) { if (mmap_string_append_c(mmapstr, * cur) == 0) { mmap_string_free(mmapstr); return NULL; } cur ++; } } str = strdup(mmapstr->str); if (str == NULL) { mmap_string_free(mmapstr); return NULL; } mmap_string_free(mmapstr); return str; }
static int db_get_next_msg_number(struct mail_cache_db * maildb, uint32_t * p_num) { int r; char key_value[PATH_MAX]; uint32_t num; void * serialized; size_t serialized_len; int res; MMAPString * mmapstr; size_t cur_token; mmapstr = mmap_string_new(""); if (mmapstr == NULL) { res = MAIL_ERROR_MEMORY; goto err; } snprintf(key_value, sizeof(key_value), "next-msg"); r = mail_cache_db_get(maildb, key_value, strlen(key_value), &serialized, &serialized_len); if (r >= 0) { if (mmap_string_append_len(mmapstr, serialized, serialized_len) == NULL) { res = MAIL_ERROR_MEMORY; goto err; } cur_token = 0; r = mailimf_cache_int_read(mmapstr, &cur_token, &num); if (r < 0) num = 1; } else { num = 1; } mmap_string_set_size(mmapstr, 0); cur_token = 0; r = mailimf_cache_int_write(mmapstr, &cur_token, num + 1); if (r < 0) { res = MAIL_ERROR_MEMORY; goto free_mmapstr; } r = mail_cache_db_put(maildb, key_value, strlen(key_value), mmapstr->str, mmapstr->len); if (r < 0) { res = MAIL_ERROR_FILE; goto free_mmapstr; } mmap_string_free(mmapstr); * p_num = num; return MAIL_NO_ERROR; free_mmapstr: mmap_string_free(mmapstr); err: return res; }
static carray * mailstream_low_cfstream_get_certificate_chain(mailstream_low * s) { #if HAVE_CFNETWORK struct mailstream_cfstream_data * cfstream_data; unsigned int i; carray * result; CFArrayRef certs; CFIndex count; cfstream_data = (struct mailstream_cfstream_data *) s->data; SecTrustRef secTrust = (SecTrustRef)CFReadStreamCopyProperty(cfstream_data->readStream, kCFStreamPropertySSLPeerTrust); if (secTrust) { // SecTrustEvaluate() needs to be called before SecTrustGetCertificateCount() in Mac OS X <= 10.8 SecTrustEvaluate(secTrust, NULL); count = SecTrustGetCertificateCount(secTrust); result = carray_new(4); for(i = 0 ; i < count ; i ++) { SecCertificateRef cert = (SecCertificateRef) SecTrustGetCertificateAtIndex(secTrust, i); CFDataRef data = SecCertificateCopyData(cert); if (data == NULL) { carray_free(result); CFRelease(secTrust); return NULL; } CFIndex length = CFDataGetLength(data); const UInt8 * bytes = CFDataGetBytePtr(data); MMAPString * str = mmap_string_sized_new(length); mmap_string_append_len(str, (char*) bytes, length); carray_add(result, str, NULL); CFRelease(data); } CFRelease(secTrust); } else { certs = CFReadStreamCopyProperty(cfstream_data->readStream, kCFStreamPropertySSLPeerCertificates); if (certs) { count = CFArrayGetCount(certs); result = carray_new(4); for(i = 0 ; i < count ; i ++) { SecCertificateRef cert = (SecCertificateRef) CFArrayGetValueAtIndex(certs, i); CFDataRef data = SecCertificateCopyData(cert); if (data == NULL) { carray_free(result); CFRelease(certs); return NULL; } CFIndex length = CFDataGetLength(data); const UInt8 * bytes = CFDataGetBytePtr(data); MMAPString * str = mmap_string_sized_new(length); mmap_string_append_len(str, (char*) bytes, length); carray_add(result, str, NULL); CFRelease(data); } CFRelease(certs); } else { return NULL; } } return result; #else return NULL; #endif }