This repository was archived by the owner on Feb 4, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParsedDictionaryCreateFromThreadURL.c
More file actions
116 lines (91 loc) · 4.48 KB
/
ParsedDictionaryCreateFromThreadURL.c
File metadata and controls
116 lines (91 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* ParsedDictionaryCreateFromThreadURL.c
* threadread
*
* Created by mtakagi on 10/03/08.
* Copyright 2010 http://outofboundary.web.fc2.com/ All rights reserved.
*
*/
#include "ParsedDictionaryCreateFromThreadURL.h"
static CFDictionaryRef DictionaryCreateFromURL(CFURLRef url)
{
CFDataRef threadData; // url から読み込んだ thread ファイルのデータ
CFDictionaryRef thread; // 読み込んだ thread ファイルから作ったplist
Boolean status;
status = CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, url, &threadData, NULL, NULL, NULL);
if (!status) {
return NULL;
}
// 10.6,iOS 4.0 から CFPropertyListCreateFromXMLData は非推奨。マクロと関数が存在するかで切り分け。
// NOTE: CFPropertyListRef is a CFTypeRef!(and also return CFDictionaryRef or CFArrayRef)
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
if (CFPropertyListCreateWithData != NULL) {
// 現在のところ CFErrorRef を無視して NULL を渡している。
thread = (CFDictionaryRef)CFPropertyListCreateWithData(kCFAllocatorDefault, threadData, kCFPropertyListImmutable, NULL, NULL);
} else {
#endif
thread = (CFDictionaryRef)CFPropertyListCreateFromXMLData(kCFAllocatorDefault, threadData, kCFPropertyListImmutable, NULL);
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
}
#endif
CFRelease(threadData);
if (thread == NULL) return NULL;
return thread;
}
CFDictionaryRef ParsedDictionaryCreateFromThreadURL(CFURLRef url)
{
CFDictionaryRef thread; // 読み込んだ thread ファイルから作ったplist
CFMutableDictionaryRef threadDictinary; // 書き込みとIDのディクショナリ。これの値を返す。
CFMutableDictionaryRef idDictionary; // thread ファイルに含まれる ID の情報。
CFMutableArrayRef resDictionaryArray; // 書き込みを持つ配列。
CFArrayRef contents; // thread ファイルの contents を入れる配列。
CFStringRef boardName; // 板名 from BathyScaphe port
CFIndex i;
thread = DictionaryCreateFromURL(url);
if (thread == NULL) return NULL;
threadDictinary = CFDictionaryCreateMutable(kCFAllocatorDefault, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
idDictionary = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
resDictionaryArray = CFArrayCreateMutable(kCFAllocatorDefault, 1001, &kCFTypeArrayCallBacks);
contents = CFDictionaryGetValue(thread, CFSTR("Contents"));
boardName = CFDictionaryGetValue(thread, CFSTR("BoardName"));
CFRetain(boardName);
// content から必要な情報を取り出して resDictionaryArray に格納。
for (i = 0; i < CFArrayGetCount(contents); i++) {
CFMutableDictionaryRef content = CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 8, CFArrayGetValueAtIndex(contents, i));
CFStringRef id = CFDictionaryGetValue(content, k2ChMessageID);
// 一番最初にスレッドのサブジェクトをいれる。
if (i == 0) {
CFDictionarySetValue(content, k2ChMessageThreadSubject , CFDictionaryGetValue(thread, k2ChMessageThreadSubject));
}
// 必要のない値を削除。
CFDictionaryRemoveValue(content, CFSTR("Date"));
CFDictionaryRemoveValue(content, CFSTR("Status"));
// ID が存在する場合は ID の出現回数をチェックする。
if (id != NULL && CFStringCompare(id, CFSTR(""), 0) != kCFCompareEqualTo) {
CFNumberRef number; // これまでの出現回数。
CFNumberRef newNumber; // 現在の出現回数。 number に1を足した数。
int n = 0; // Scalar value
// number が idDictionary に存在する場合は、 n に number の数を入れる。
if (CFDictionaryGetValueIfPresent(idDictionary, id, (void *)&number)) {
CFNumberGetValue(number, kCFNumberIntType, &n);
}
// n をインクリメントし、 newNumber を作り idDictionary にセットする。
n += 1;
newNumber = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &n);
CFDictionarySetValue(idDictionary, id, newNumber);
CFRelease(newNumber);
}
// resDictionaryArray に追加。
CFArrayAppendValue(resDictionaryArray, content);
CFRelease(content);
}
CFDictionarySetValue(threadDictinary, RES_DICTIONARY_ARRAY, resDictionaryArray);
CFDictionarySetValue(threadDictinary, ID_COUNT_DICTIONARY, idDictionary);
CFDictionarySetValue(threadDictinary, CFSTR("BoardName"), boardName);
CFRelease(boardName);
// dealloc
CFRelease(thread);
CFRelease(idDictionary);
CFRelease(resDictionaryArray);
return threadDictinary;
}