Lines 103-108
Link Here
|
103 |
int btContent::CreateMetainfoFile(const char *mifn) |
103 |
int btContent::CreateMetainfoFile(const char *mifn) |
104 |
{ |
104 |
{ |
105 |
FILE *fp; |
105 |
FILE *fp; |
|
|
106 |
char *m_ann1, *m_ann2, *m_ann3, *m_ann_tmp; |
107 |
int m_announce_count, list_delimiter; |
108 |
|
106 |
fp = fopen(mifn, "r"); |
109 |
fp = fopen(mifn, "r"); |
107 |
if( fp ){ |
110 |
if( fp ){ |
108 |
CONSOLE.Warning(1, "error, file \"%s\" already exists.", mifn); |
111 |
CONSOLE.Warning(1, "error, file \"%s\" already exists.", mifn); |
Lines 123-131
Link Here
|
123 |
// Entries in dictionary must be sorted by key! |
126 |
// Entries in dictionary must be sorted by key! |
124 |
|
127 |
|
125 |
// announce |
128 |
// announce |
126 |
if( bencode_str("announce", fp) != 1 ) goto err; |
129 |
if ((strchr(m_announce, '|') == NULL) && (strchr(m_announce, ',') == NULL)) { |
127 |
if( bencode_str(m_announce, fp) != 1 ) goto err; |
130 |
if (bencode_str("announce", fp) != 1) goto err; |
128 |
|
131 |
if (bencode_str(m_announce, fp) != 1) goto err; |
|
|
132 |
} else { |
133 |
CONSOLE.Debug("announce_list detected:\n"); |
134 |
m_ann1 = m_announce; |
135 |
m_ann_tmp = (char *)malloc(strlen(m_announce)); |
136 |
m_announce_count = 0; |
137 |
m_ann2 = strchr(m_ann1, ','); |
138 |
m_ann3 = strchr(m_ann1, '|'); |
139 |
while (m_ann2 || m_ann3) { |
140 |
if (m_ann2 && !m_ann3) { |
141 |
strlcpy(m_ann_tmp, m_ann1, m_ann2 - m_ann1 + 1); |
142 |
m_ann1 = m_ann2 + sizeof(','); |
143 |
list_delimiter = 0; |
144 |
} else { |
145 |
if (!m_ann2 && m_ann3) { |
146 |
strlcpy(m_ann_tmp, m_ann1, m_ann3 - m_ann1 + 1); |
147 |
m_ann1 = m_ann3 + sizeof('|'); |
148 |
list_delimiter = 1; |
149 |
} else { |
150 |
if (m_ann2 < m_ann3) { |
151 |
strlcpy(m_ann_tmp, m_ann1, m_ann2 - m_ann1 + 1); |
152 |
m_ann1 = m_ann2 + sizeof(','); |
153 |
list_delimiter = 0; |
154 |
} else { |
155 |
strlcpy(m_ann_tmp, m_ann1, m_ann3 - m_ann1 + 1); |
156 |
m_ann1 = m_ann3 + sizeof('|'); |
157 |
list_delimiter = 1; |
158 |
} |
159 |
} |
160 |
} |
161 |
if (m_announce_count == 0) { |
162 |
if (bencode_str("announce", fp) != 1) goto err; |
163 |
if (bencode_str(m_ann_tmp, fp) != 1) goto err; |
164 |
if (bencode_str("announce-list", fp) != 1) goto err; |
165 |
if (fwrite("ll", strlen("ll"), 1, fp) != 1) goto err; |
166 |
} |
167 |
m_announce_count++; |
168 |
CONSOLE.Debug(" URL: %s\n", m_ann_tmp); |
169 |
if (bencode_str(m_ann_tmp, fp) != 1) goto err; |
170 |
if (list_delimiter == 1) { |
171 |
if (fwrite("el", strlen("el"), 1, fp) != 1) goto err; |
172 |
} |
173 |
m_ann2 = strchr(m_ann1, ','); |
174 |
m_ann3 = strchr(m_ann1, '|'); |
175 |
} |
176 |
CONSOLE.Debug(" URL: %s\n", m_ann1); |
177 |
if (bencode_str(m_ann1, fp) != 1) goto err; |
178 |
if (fwrite("ee", strlen("ee"), 1, fp) != 1) goto err; |
179 |
} |
129 |
// comment |
180 |
// comment |
130 |
if( arg_comment ){ |
181 |
if( arg_comment ){ |
131 |
if( bencode_str("comment", fp) != 1 ) goto err; |
182 |
if( bencode_str("comment", fp) != 1 ) goto err; |
Lines 172-177
Link Here
|
172 |
return 0; |
223 |
return 0; |
173 |
err: |
224 |
err: |
174 |
if( fp ) fclose(fp); |
225 |
if( fp ) fclose(fp); |
|
|
226 |
if (m_ann_tmp) { |
227 |
free(m_ann_tmp); |
228 |
} |
175 |
return -1; |
229 |
return -1; |
176 |
} |
230 |
} |
177 |
|
231 |
|