Commit 3e4464eb authored by rswindell's avatar rswindell

Create/use common function for getting a sub-boards's newsgroup name

(configured or auto-generated): getsubnewsgroupname().
parent 4dfe1ff4
......@@ -107,7 +107,6 @@ struct js_msg_area_priv {
BOOL DLLCALL js_CreateMsgAreaProperties(JSContext* cx, scfg_t* cfg, JSObject* subobj, uint subnum)
{
char str[128];
int c;
JSString* js_str;
jsval val;
sub_t* sub;
......@@ -154,36 +153,7 @@ BOOL DLLCALL js_CreateMsgAreaProperties(JSContext* cx, scfg_t* cfg, JSObject* su
if(!JS_DefineProperty(cx, subobj, "qwk_name", STRING_TO_JSVAL(js_str)
,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY))
return(FALSE);
if(sub->newsgroup[0])
SAFECOPY(str,sub->newsgroup);
else {
sprintf(str,"%s.%s",cfg->grp[sub->grp]->sname,sub->sname);
/*
* From RFC5536:
* newsgroup-name = component *( "." component )
* component = 1*component-char
* component-char = ALPHA / DIGIT / "+" / "-" / "_"
*/
if (str[0] == '.')
str[0] = '_';
for(c=0;str[c];c++) {
/* Legal characters */
if ((str[c] >= 'A' && str[c] <= 'Z')
|| (str[c] >= 'a' && str[c] <= 'z')
|| (str[c] >= '0' && str[c] <= '9')
|| str[c] == '+'
|| str[c] == '-'
|| str[c] == '_'
|| str[c] == '.')
continue;
str[c] = '_';
}
c--;
if (str[c] == '.')
str[c] = '_';
}
if((js_str=JS_NewStringCopyZ(cx, str))==NULL)
if((js_str=JS_NewStringCopyZ(cx, subnewsgroupname(cfg, sub, str, sizeof(str))))==NULL)
return(FALSE);
if(!JS_DefineProperty(cx, subobj, "newsgroup", STRING_TO_JSVAL(js_str)
,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY))
......
......@@ -1175,6 +1175,7 @@ extern "C" {
DLLEXPORT BOOL str_has_ctrl(const char*);
DLLEXPORT BOOL str_is_ascii(const char*);
DLLEXPORT char * utf8_to_cp437_str(char* str);
DLLEXPORT char * subnewsgroupname(scfg_t*, sub_t*, char*, size_t);
/* msg_id.c */
DLLEXPORT char * DLLCALL ftn_msgid(sub_t*, smbmsg_t*, char* msgid, size_t);
......
......@@ -684,3 +684,38 @@ char* utf8_to_cp437_str(char* str)
,/* unsupported zero-width ch: */0
,/* decode error char: */CP437_INVERTED_EXCLAMATION_MARK);
}
char* subnewsgroupname(scfg_t* cfg, sub_t* sub, char* str, size_t size)
{
memset(str, 0, size);
if(sub->newsgroup[0])
strncpy(str, sub->newsgroup, size - 1);
else {
snprintf(str, size - 1, "%s.%s", cfg->grp[sub->grp]->sname, sub->sname);
/*
* From RFC5536:
* newsgroup-name = component *( "." component )
* component = 1*component-char
* component-char = ALPHA / DIGIT / "+" / "-" / "_"
*/
if (str[0] == '.')
str[0] = '_';
size_t c;
for(c = 0; str[c] != 0; c++) {
/* Legal characters */
if ((str[c] >= 'A' && str[c] <= 'Z')
|| (str[c] >= 'a' && str[c] <= 'z')
|| (str[c] >= '0' && str[c] <= '9')
|| str[c] == '+'
|| str[c] == '-'
|| str[c] == '_'
|| str[c] == '.')
continue;
str[c] = '_';
}
c--;
if (str[c] == '.')
str[c] = '_';
}
return str;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment