| 152 | */ |
| 153 | |
| 154 | http_uri_status_t /* O - URI status */ |
| 155 | httpAssembleURI( |
| 156 | http_uri_coding_t encoding, /* I - Encoding flags */ |
| 157 | char *uri, /* I - URI buffer */ |
| 158 | int urilen, /* I - Size of URI buffer */ |
| 159 | const char *scheme, /* I - Scheme name */ |
| 160 | const char *username, /* I - Username */ |
| 161 | const char *host, /* I - Hostname or address */ |
| 162 | int port, /* I - Port number */ |
| 163 | const char *resource) /* I - Resource */ |
| 164 | { |
| 165 | char *ptr, /* Pointer into URI buffer */ |
| 166 | *end; /* End of URI buffer */ |
| 167 | |
| 168 | |
| 169 | /* |
| 170 | * Range check input... |
| 171 | */ |
| 172 | |
| 173 | if (!uri || urilen < 1 || !scheme || port < 0) |
| 174 | { |
| 175 | if (uri) |
| 176 | *uri = '\0'; |
| 177 | |
| 178 | return (HTTP_URI_STATUS_BAD_ARGUMENTS); |
| 179 | } |
| 180 | |
| 181 | /* |
| 182 | * Assemble the URI starting with the scheme... |
| 183 | */ |
| 184 | |
| 185 | end = uri + urilen - 1; |
| 186 | ptr = http_copy_encode(uri, scheme, end, NULL, NULL, 0); |
| 187 | |
| 188 | if (!ptr) |
| 189 | goto assemble_overflow; |
| 190 | |
| 191 | if (!strcmp(scheme, "geo") || !strcmp(scheme, "mailto") || !strcmp(scheme, "tel")) |
| 192 | { |
| 193 | /* |
| 194 | * geo:, mailto:, and tel: only have :, no //... |
| 195 | */ |
| 196 | |
| 197 | if (ptr < end) |
| 198 | *ptr++ = ':'; |
| 199 | else |
| 200 | goto assemble_overflow; |
| 201 | } |
| 202 | else |
| 203 | { |
| 204 | /* |
| 205 | * Schemes other than geo:, mailto:, and tel: typically have //... |
| 206 | */ |
| 207 | |
| 208 | if ((ptr + 2) < end) |
| 209 | { |
| 210 | *ptr++ = ':'; |
| 211 | *ptr++ = '/'; |